OpenAPITools / OpenAPITools/openapi-generator
[BUG] Pydantic Field nullable=True changes generated schema and Python client
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When I generate a schema from
class Class(BaseModel):
field: Optional[PrefixField] = Field(default=None, nullable=True)
the schema contains
"Class": {
"properties": {
"field": {
"allOf": [
{
"$ref": "#/components/schemas/PrefixField"
}
],
"nullable": true,
}
instead of the desired
"Class": {
"properties": {
"field": {
"$ref": "#/components/schemas/PrefixField"
},
"nullable": true,
}
The Python client contains extra files corresponding to Field.md in addition to the desired PrefixField.md, and Class is linked to Field instead of the desired PrefixField.
I get the desired schema and Python client files without nullable=True, but then the field isn't allowed to be set to None.
openapi-generator version
v6.0.1
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
Reproduce the issue from the shown Pydantic Class model using openapi-generator v6.0.1, then trace schema generation and Python client generation for the nullable field. Compare the output with and without nullable=True. Done means the schema keeps the PrefixField reference without an unwanted Field model, and the client links Class to PrefixField while still allowing None.
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
- Mostly clear
- Newbie friendliness
- 35/100