OpenAPITools / OpenAPITools/openapi-generator

Incorrect code mapping when "Default" directive is used.

Open
#12,481 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hello! I'm trying out the new 6.0 release and noticed it generated some invalid Python-FastAPI code. Here is the offending line of code:

https://github.com/OpenAPITools/openapi-generator/blob/5307a8dafd5cb45e7425eb6ebdc012dedcc82be4/modules/openapi-generator/src/main/resources/python-fastapi/api.mustache#L34

And here is the OpenAPI.yaml that was used as input:

https://github.com/OAI/OpenAPI-Specification/blob/aa91a19c43f8a12c02efa42d64794e396473f3b1/examples/v3.0/petstore-expanded.yaml#L51

And lastly here is the invalid python code that was generated:

    responses={
        200: {"model": Pet, "description": "pet response"},
        200: {"model": Error, "description": "unexpected error"},
    },

In the openapi.yaml file there was a response model for status code 200 and a response model for "Default" (everything else). The code generator interpreted this "Default" as a 200 which resulted in a python dictionary with 2x keys for 200, which is invalid.

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 modules/openapi-generator/src/main/resources/python-fastapi/api.mustache at the referenced response mapping and compare it with the Default response in petstore-expanded.yaml at line 51. Regenerate the Python-FastAPI output from that specification and confirm the result preserves the explicit 200 response while handling Default without producing duplicate dictionary keys.

Written by the indexing model from the issue text.

Assessment

Tech stack
fastapi, java, python
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.