openapi-generators / openapi-generators/openapi-python-client

`anyOf` in responses generates invalid body parser

Open
#1,263 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2k
Forks
293
Avg merge
34m
Merged PRs (30d)
1

Description

Describe the bug
When a response media type has an anyOf schema, the generated code does not parse it properly/is not valid. (see add'l context)
OpenAPI Spec File
https://gist.github.com/nkrishnaswami/8c4a2068d8ac59cab153136a6069b44d

Desktop (please complete the following information):

  • OS: macOS 15.6
  • Python Version: 3.12.8
  • openapi-python-client version: git revision 13bf2e8

Additional context

        def _parse_response_200(data: object) -> Union["Response200", Literal["Why have a fixed response? I dunno"]]:
            response_200_type_0 = cast(Literal["Why have a fixed response? I dunno"], data)
            if response_200_type_0 != "Why have a fixed response? I dunno":
                raise ValueError(
                    f"response_200_type_0 must match const 'Why have a fixed response? I dunno', got '{response_200_type_0}'"
                )
            return response_200_type_0
            if not isinstance(data, dict):
                raise TypeError()
            response_200_type_1 = Response200.from_dict(data)

            return response_200_type_1

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 OpenAPI Spec File linked in the issue and reproduce the generated _parse_response_200 example for a response schema using anyOf. Compare the generated parser branches and verify that the output is valid and can parse both the fixed-value and Response200 alternatives.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.