swagger-api / swagger-api/swagger-codegen

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

Open
#7,411 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Haskell Feature: Composition / Inheritance Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the documented swagger-codegen command and Docker's v1.25 swagger.yaml, then inspect the generated /tmp/haskell_api_client/lib/DockerEngine/API.hs for the containers/create endpoint. Trace the Haskell HTTP client generator's handling of the schema's allOf and confirm completion when the generated endpoint includes a usable body type.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.