Skip to content

[HASKELL] haskell-http-client generator doesn't understand allOf schemas #7411

Open
@thomasjm

Description

@thomasjm
Description

I'm trying to generate haskell-http-client code to use with Docker's API. However, the codegen seems to be not understanding what to do when an allOf is found in a schema. For example, Docker's v1.25 API contains this snippet:

paths:
  ...
  /containers/create:
    post:
      summary: "Create a container"
      ...
      parameters:
        ...
        - name: "body"
          in: "body"
          description: "Container to create"
          schema:
            allOf:
              - $ref: "#/definitions/Config"
              - type: "object"
                properties:
                  HostConfig:
                    $ref: "#/definitions/HostConfig"
                  NetworkingConfig:
                    description: "This container's networking configuration."
                    type: "object"
                    properties:
                      EndpointsConfig:
                        description: "A mapping of network name to endpoint configuration for that network."
                        type: "object"
                        additionalProperties:
                          $ref: "#/definitions/EndpointSettings"
...

However, in the generated code for this API endpoint, the "body" type is simply missing:

-- | @POST \/containers\/create@
-- 
-- Create a container
-- 
containerCreate 
  :: (Consumes ContainerCreate contentType, MimeRender contentType )
  => ContentType contentType -- ^ request content-type ('MimeType')
  -> Accept accept -- ^ request accept ('MimeType')
  ->  -- ^ "body" -  Container to create
  -> DockerEngineRequest ContainerCreate contentType InlineResponse201 accept
containerCreate _  _ body =
  _mkRequest "POST" ["/containers/create"]
    `setBodyParam` body
Swagger-codegen version

Version 2.3.1

Swagger declaration file content or url

See above for snippet; URL is https://docs.docker.com/engine/api/v1.25/swagger.yaml

Command line used for generation

rm -rf /tmp/haskell_api_client; mkdir /tmp/haskell_api_client; java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i https://docs.docker.com/engine/api/v1.25/swagger.yaml -l haskell-http-client -o /tmp/haskell_api_client

Steps to reproduce

Clone the swagger-codegen repo and then run the command above inside it. You can see the problematic code in /tmp/haskell_api_client/lib/DockerEngine/API.hs

Related issues/PRs

Not that I can see.

Suggest a fix/enhancement

I'm guessing the codegen is simply missing handling for this case. It might be necessary to generate a whole new type for the "combined" body created by an allOf. It might also be possible to do something clever with a product type of the components of the allOf and then handle packing/unpacking them in the Aeson ToJSON/FromJSON instances.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions