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.54k stars 6.51k forks source link

[BUG] Nested components are generated with no type #1889

Open awrichar opened 5 years ago

awrichar commented 5 years ago

Bug Report Checklist

Description

When generating code for python-flask, the generated YAML spec does not include types for nested components. Unclear if this generation problem is specific to python-flask (seems to be a more generic issue with YAML generation), but it causes automatic validation to fail when passing these types to the Flask server in a request.

openapi-generator version

4.0.0-beta

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: "1.0"
  title: "{{title}}"
servers:
  - url: /v1
paths:
  /parent:
    post:
      operationId: create
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Parent"
      responses:
        200:
          description: OK
components:
  schemas:
    Parent:
      type: object
      properties:
        child:
          type: object
          properties:
            grandchild:
              type: string
Command line used for generation
./titan/openapi-generator-cli.sh generate -g python-flask -i openapi.yaml -o gen
Steps to reproduce

After running the generator command, the generated file gen/openapi_server/openapi/openapi.yaml contains these component definitions:

components:
  schemas:
    Parent:
      example:
        child:
          grandchild: grandchild
      properties:
        child:
          $ref: '#/components/schemas/Parent_child'
      type: object
    Parent_child:
      example:
        grandchild: grandchild
      properties:
        grandchild:
          type: string

Notice that the generated Parent_child component has no type. This causes it to fail with Body property 'child' not defined in body schema when passing a Parent object via request body.

Adding type: object to the Parent_child definition causes things to work properly.

i5heu commented 5 years ago

This Bug exist in typescript-fetch too!