OpenAPITools / OpenAPITools/openapi-generator

[BUG] Nested components are generated with no type

Open
#1,889 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
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.

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

Run the listed generator command with the provided OpenAPI declaration, then inspect gen/openapi_server/openapi/openapi.yaml and compare the Parent and Parent_child schemas. The issue is complete when the nested component includes its object type and a Parent request passes Flask validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, openapi, python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.