OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.58k stars 6.52k forks source link

[BUG] YAML fails validation; same JSON passes #7218

Open adamf opened 4 years ago

adamf commented 4 years ago

Bug Report Checklist

Description

YAML fails to generated python code; JSON for the same spec works.

I think this has to do with the *id/&id references not being valid, but the YAML passes the validator. The same JSON works fine (see both below).

Errors:

openapi-generator generate -v -i test-schema.yaml -g python --package-name test -o test
[main] INFO  o.o.c.config.CodegenConfigurator -
VERBOSE MODE: ON. Additional debug options are injected
 - [debugOpenAPI] prints the OpenAPI specification as interpreted by the codegen
 - [debugModels] prints models passed to the template engine
 - [debugOperations] prints operations passed to the template engine
 - [debugSupportingFiles] prints additional data passed to the template engine
Exception in thread "main" org.openapitools.codegen.SpecValidationException: There were issues with the specification. The option can be disabled via validateSpec (Maven/Gradle) or --skip-validate-spec (CLI).
 | Error count: 2, Warning count: 0
Errors:
    -attribute paths.'/_/api/users/{username}/'(put).requestBody.content.'application/x-www-form-urlencoded'.schema is not of type `object`
    -attribute paths.'/_/api/users/{username}/'(put).requestBody.content.'multipart/form-data'.schema is not of type `object`

    at org.openapitools.codegen.config.CodegenConfigurator.toContext(CodegenConfigurator.java:480)
    at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:507)
    at org.openapitools.codegen.cmd.Generate.execute(Generate.java:423)
    at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
    at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:61)
openapi-generator version
openapi-generator-cli 4.3.1
  commit : 003165c
  built  : 2020-05-06T09:38:39Z
  source : https://github.com/openapitools/openapi-generator
  docs   : https://openapi-generator.tech/
OpenAPI declaration file content or url

Given this YAML:

openapi: 3.0.2
info:
  title: REST API
  version: 1.0.0a
  description: API
paths:
  /_/api/users/{username}/:
    put:
      operationId: updateQUser
      description: API endpoint that allows users to be viewed or edited.
      parameters:
      - name: username
        in: path
        required: true
        description: Required. 150 characters or fewer. Letters, digits and @/./+/-/_
          only.
        schema:
          type: string
      requestBody:
        content:
          application/json:
            schema: &id002
              properties:
                username:
                  type: string
                  description: Required. 150 characters or fewer. Letters, digits
                    and @/./+/-/_ only.
                  pattern: ^[\w.@+-]+\Z
                  maxLength: 150
              required:
              - username
          application/x-www-form-urlencoded:
            schema: *id002
          multipart/form-data:
            schema: *id002
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  url:
                    type: string
                    readOnly: true
                  username:
                    type: string
                    description: Required. 150 characters or fewer. Letters, digits
                      and @/./+/-/_ only.
                    pattern: ^[\w.@+-]+\Z
                    maxLength: 150
                  repo_owner:
                    type: array
                    items:
                      type: string
                    readOnly: true
                required:
                - username
          description: ''

And the JSON:


        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "properties": {
                  "username": {
                    "type": "string",
                    "description": "Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
                    "pattern": "^[\\w.@+-]+\\Z",
                    "maxLength": 150
                  }
                },
                "required": [
                  "username"
                ]
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "properties": {
                  "username": {
                    "type": "string",
                    "description": "Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
                    "pattern": "^[\\w.@+-]+\\Z",
                    "maxLength": 150
                  }
                },
                "required": [
                  "username"
                ]
              }
            },
            "multipart/form-data": {
              "schema": {
                "properties": {
                  "username": {
                    "type": "string",
                    "description": "Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
                    "pattern": "^[\\w.@+-]+\\Z",
                    "maxLength": 150
                  }
                },
                "required": [
                  "username"
                ]
              }
            }
          }
        },
Generation Details

openapi-generator generate -v -i schema.yaml -g python --package-name test_package -o api

Steps to reproduce

Run the above YAML through openapi-generator.

Related issues/PRs

https://github.com/encode/django-rest-framework/issues/7479

Suggest a fix
auto-labeler[bot] commented 4 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.