Skip to content

codegen: ComposedSchema should not always yield UNKNOWN_BASE_TYPE #475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lorenzleutgeb opened this issue Jul 5, 2018 · 2 comments
Closed

Comments

@lorenzleutgeb
Copy link

Description

I have the following scenario: In an API I want to perform some PUT requests that only differ in their bodies. So what I did is declare a composed schema using oneOf in the request body section of my OAS 3 spec. The code generation performs quite badly on this input.

The implementation of DefaultCodegen gives up on inferring a good type for composed schemas very easily. Basically for an composed schema, you'll always end up with an unknown base type. See

I dislike this because of two reasons:

  1. Some target languages might actually be able to infer a type that is the intersection of all models that are being composed, i.e. Intersection Types in TypeScript.
  2. Even if there is no concrete type that matches the intersection or disjoint union of the models that represent the composed schemas, there might be other ways to escape this. For example, if the composed schema covers a request body and the target language supports method overloading, then you might generate a request method for every type in the composition separately.

By bailing out on the codegen layer, one will never be able to implement generators for this, and a quite handy use case is obstructed.

openapi-generator version

020883f (master from 2018-07-04)

OpenAPI declaration file content or url

Quite big, and I cannot make it public. The relevant part is:

    patch:
      operationId: card__edit
      tags:
        - cards
      parameters:
        - name: id
          in: path
          required: true
          description: The id of the card to perform this action on
          schema:
            type: string
      requestBody:
        content:
          "application/vnd.api+json":
            schema:
              oneOf:
                - "$ref": "#/components/schemas/card__post"
                - "$ref": "#/components/schemas/card__lock"
                - "$ref": "#/components/schemas/card__unlock"
              discriminator:
                propertyName: modifying_action
                mapping:
                  post: "#/components/schemas/card__post"
                  lock: "#/components/schemas/card__lock"
                  unlock: "#/components/schemas/card__unlock"
Command line used for generation

java -jar openapi-generator-cli.jar generate -g java -i api.yml -o jclient

Suggest a fix/enhancement

Remove any type inference logic from the codegen part and leave that to be handled in the generators.

@jmini
Copy link
Member

jmini commented Jul 5, 2018

See also #15

@lorenzleutgeb
Copy link
Author

Right, sorry for the duplication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants