OpenAPITools / OpenAPITools/openapi-generator
[BUG][Python] anyOf for string/array of strings not rendered correctly
Nobody has claimed this yet.
- 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?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I have a schema KeyValuePair which specifies that a property can either be a string or a list of strings:
anyOf:
- items:
type: string
type: array
- type: string
When rendering the Python client, this is turned into:
value: Optional[StrictStr]
Instead, I would expect this to be rendered to:
value: str | List[str]
openapi-generator version
7.3.0-SNAPSHOT
OpenAPI declaration file content or url
openapi: 3.1.0
info:
title: Test
version: 1.0.0
paths:
/:
get:
tags:
- collections
responses:
'200':
description: Request successful
content:
application/json:
schema:
$ref: '#/components/schemas/KeyValuePair'
components:
schemas:
KeyValuePair:
properties:
key:
type: string
title: Key
value:
anyOf:
- items:
type: string
type: array
- type: string
title: Value
type: object
required:
- key
- value
title: KeyValuePair
Generation Details
docker run --rm \
-v $(pwd):/local openapitools/openapi-generator-cli:latest generate \
-i ./local/swagger.yaml \
-g python \
-o /local/out/test \
--additional-properties generateSourceCodeOnly=true
Steps to reproduce
- Put swagger pasted above int ofile
- Run docker command above
- Inspect file:
cat out/test/openapi_client/models/key_value_pair.py
Related issues/PRs
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided OpenAPI declaration and reproduce the issue using the Docker generation command for the Python client. Inspect out/test/openapi_client/models/key_value_pair.py and trace how the value property's anyOf schema is rendered. Done means the generated model represents both a string and a list of strings instead of only StrictStr.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100