Skip to content
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

[BUG] [html2][html][dynamic-html] using allOf/oneOf in request body generates broken documentation #11027

Closed
5 of 6 tasks
hauntingEcho opened this issue Dec 3, 2021 · 3 comments

Comments

@hauntingEcho
Copy link
Contributor

hauntingEcho commented Dec 3, 2021

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Using allOf or oneOf in a request body produces broken documentation. In the example below, it documents a body parameter of 'uNKNOWNBASETYPE' with a type of 'undefined'.

The following will be produced in the log:

[main] INFO  o.o.codegen.DefaultGenerator - Generating with dryRun=false
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: html2 (documentation)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'html2' is considered stable.
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] WARN  o.o.codegen.DefaultCodegen - Empty operationId found for path: patch /pets. Renamed to auto-generated operationId: petsPatch
[main] WARN  o.o.codegen.DefaultCodegen - The following schema has undefined (null) baseType. It could be due to form parameter defined in OpenAPI v2 spec with incorrect consumes. A correct 'consumes' for form parameters should be 'app
lication/x-www-form-urlencoded' or 'multipart/?'
[main] WARN  o.o.codegen.DefaultCodegen - schema: class ComposedSchema {
    class Schema {
        type: null
        format: null
        $ref: null
        description: null
        title: null
        multipleOf: null
        maximum: null
        exclusiveMaximum: null
        minimum: null
        exclusiveMinimum: null
        maxLength: null
        minLength: null
        pattern: null
        maxItems: null
        minItems: null
        uniqueItems: null
        maxProperties: null
        minProperties: null
        required: null
        not: null
        properties: null
        additionalProperties: null
        nullable: null
        readOnly: null
        writeOnly: null
        example: null
        externalDocs: null
        deprecated: null
        discriminator: null
        xml: null
    }
    allOf: null
    anyOf: null
    oneOf: [class ObjectSchema {
        class Schema {
            type: object
            format: null
            $ref: null
            description: null
            title: null
            multipleOf: null
            maximum: null
            exclusiveMaximum: null
            minimum: null
            exclusiveMinimum: null
            maxLength: null
            minLength: null
            pattern: null
            maxItems: null
            minItems: null
            uniqueItems: null
            maxProperties: null
            minProperties: null
            required: null
            not: null
            properties: {bark=class BooleanSchema {
                class Schema {
                    type: boolean
                    format: null
                    $ref: null
                    description: null
                    title: null
                    multipleOf: null
                    maximum: null
                    exclusiveMaximum: null
                    minimum: null
                    exclusiveMinimum: null
                    maxLength: null
                    minLength: null
                    pattern: null
                    maxItems: null
                    minItems: null
                    uniqueItems: null
                    maxProperties: null
                    minProperties: null
                    required: null
                    not: null
                    properties: null
                    additionalProperties: null
                    nullable: null
                    readOnly: null
                    writeOnly: null
                    example: null
                    externalDocs: null
                    deprecated: null
                    discriminator: null
                    xml: null
                }
            }}
            additionalProperties: null
            nullable: null
            readOnly: null
            writeOnly: null
            example: null
            externalDocs: null
            deprecated: null
            discriminator: null
            xml: null
        }
    }]
}
[main] WARN  o.o.codegen.DefaultCodegen - codegenModel is null. Default to UNKNOWN_BASE_TYPE
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/index.html
[main] INFO  o.o.codegen.TemplateManager - Skipped /local/out/.openapi-generator-ignore (Skipped by supportingFiles options supplied by user.)
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/.openapi-generator/VERSION
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/.openapi-generator/FILES
################################################################################
# Thanks for using OpenAPI Generator.                                          #
# Please consider donation to help us maintain this project 🙏                 #
# https://opencollective.com/openapi_generator/donate                          #
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/.openapi-generator/VERSION
[main] INFO  o.o.codegen.TemplateManager - writing file /local/out/.openapi-generator/FILES
################################################################################
# Thanks for using OpenAPI Generator.                                          #
# Please consider donation to help us maintain this project 🙏                 #
# https://opencollective.com/openapi_generator/donate                          #
################################################################################

openapi-generator version

5.3.0

OpenAPI declaration file content or url

This is a stripped-down version of the first oneOf example here. Using allOf instead produces the same error.

openapi: 3.0.3
info:
  title: test
  description: test
  version: 0.0.1
paths:
  /pets:
    patch:
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - type: object
                  properties:
                    bark:
                      type: boolean
      responses:
        '200':
          description: Updated

allOf seems to work only if the internal type is not a reference. The following will break it:

openapi: 3.0.3
info:
  title: test
  description: test
  version: 0.0.1
paths:
  /pets:
    patch:
      requestBody:
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/Dog'
      responses:
        '200':
          description: Updated
components:
  schemas:
    Dog:
      type: object
      properties:
        bark:
          type: boolean
Generation Details / Steps to reproduce
  1. start on Windows, having installed git-bash and docker
  2. Add the above YAML to test.yml
  3. MSYS_NO_PATHCONV=1 docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v5.3.0 generate --input-spec "/local/test.yml" --output "/local/out" --generator-name html2
  4. open out/index.html
Related issues/PRs
@hauntingEcho
Copy link
Contributor Author

From chasing this around some, it looks like definitions are being put into the 'definitions' property (used by Swagger v2) rather than 'components' (used by OpenAPI v3) here: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/htmlDocs2/paramB.mustache#L15

@marianhlavac
Copy link

I have the same issue when using FastAPI to generate automatic OpenAPI. Following output gives the same error.

        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "title": "Status",
                "allOf": [{ "$ref": "#/components/schemas/DeviceStatus" }],
                "description": "Device status with updated values"
              }
            }
          },
          "required": true
        },

According to this issue fastapi/fastapi#684 this has been already investigated by the author of the library and it seems that the OpenAPI document is according to the spec:

It's part of the OpenAPI spec. When using $ref, the object containing it cannot contain any additional properties. So the only way to have a $ref and a description is through allOf.

This object cannot be extended with additional properties and any properties added SHALL be ignored.
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#fixed-fields-19

It seems like there is, indeed, a bug in the generator.

@wing328
Copy link
Member

wing328 commented May 13, 2022

Should be fixed by #12353. Please pull the latest master to give it another try.

@wing328 wing328 closed this as completed May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants