OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Python] nullable reference not generating any_of_x

Open
#2,090 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Python
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)?
  • 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

I'm still having problems with the nullable reference. I've used the anyOf trick which passes the specification validation, but fails at runtime because the models.any_of_tier module is not generated.

ModuleNotFoundError: No module named '<my_package>.openapi_server.models.any_of_tier'

openapi-generator version

I just pulled the latest docker image.

OpenAPI declaration file content or url
        tier:
          anyOf:
            - $ref: '#/components/schemas/Tier'
          nullable: True

(for YAML code) or

Command line used for generation

docker run --rm -v ${BUILD_DIR}:/local openapitools/openapi-generator-cli generate
-i local/${ENDPOINT_SPEC}
-g python-flask
-o /local

Steps to reproduce

submit a request with tier: null

Related issues/PRs

https://github.com/OAI/OpenAPI-Specification/issues/1368

Suggest a fix

I've also tried:
alllOf and get
validation error: None is not of type 'object'
which makes sense because tier doesn't exist.

oneOf generates the same error as anyOf.
models.one_of_tier
ModuleNotFoundError: No module named '<my_package>.openapi_server.models.one_of_tier'

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 by running the issue's Docker command with the shown OpenAPI declaration and the python-flask generator, then inspect the generated models and the runtime error for tier: null. The fix is done when a nullable anyOf reference generates the needed model handling and a request containing tier: null no longer raises ModuleNotFoundError.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, openapi, python
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.