OpenAPITools / OpenAPITools/openapi-generator

[BUG] DefaultCodeGen doesn't recurse into nested types when looking for imports

Open
#11,220 3 comments 0 reactions 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?
  • 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?
Description

When specifying schemas that have nested types (for instance, Map<String, Map<String, MyType>>), the MyType custom type doesn't get added to the list of imports and so all the generated clients fail to resolve the MyType symbol in the related API. I noticed this with Python Client, but I believe it would effect others as well.

openapi-generator version

5.3.1

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: Test additional properties with ref
  version: '1.0'
servers:
  - url: 'http://localhost:8000/'
paths:
  /ping:
    post:
      operationId: ping
      responses:
        default:
          description: default response
          content:
            application/json:
              schema:
                type: object
                additionalProperties:
                  type: object
                  additionalProperties:
                    type: object
                    additionalProperties:
                      "$ref": "#/components/schemas/Person"
components:
  schemas:
    Person:
      type: object
      properties:
        lastName:
          type: string
        firstName:
          type: string

Also here

Generation Details

A simple generation command, like openapi-generator generate -g python will make a Python client that fails during symbol resolution because Person won't be imported in default_api.py.

Steps to reproduce

Assuming pipenv and openapi-generator-cli are both installed and on the path...

openapi-generator-cli generate -g python -i https://gist.githubusercontent.com/ethan92429/07a09ac228dcd2f9ec0b957ddb44148b/raw/074beff13727280dd8119c3547ac36d28e58559b/openApi_generator_issue_11220.yaml &&
pipenv install -r requirements.txt &&
pipenv install -r test-requirements.txt &&
pytest --cov=openapi_client
Related issues/PRs

#10279

Suggest a fix

Working on this...

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

Start with the DefaultCodeGen import handling and reproduce the issue using the YAML declaration and openapi-generator-cli generate -g python command shown here. Run the generated client's pytest commands and verify that the nested Person reference is imported in default_api.py and symbol resolution succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, python
Domain
backend-api-design, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.