OpenAPITools / OpenAPITools/openapi-generator
[BUG][Python] Schema property named _ (a single underscore) generates broken syntax
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Syntax error in generated Python code as the processing eats the underscore and leaves us with nothing:
class TestGet200Response(BaseModel):
"""
TestGet200Response
""" # noqa: E501
: Optional[StrictStr] = Field(default=None, alias="_")
__properties: ClassVar[List[str]] = ["_"]
model_config = ConfigDict(
openapi-generator version
git 9351217048ff3564dff
OpenAPI declaration file content or url
openapi: '3.0.0'
info:
version: 1.0.0
title: test
paths:
/test:
get:
summary: sample
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
_:
type: string
Generation Details
java -jar openapi-generator-cli-7.5.0-SNAPSHOT.jar generate -i undersc.yml -o undersc/ -g python
Steps to reproduce
Use the python generator on a spec with _ as the field name in a response.
Related issues/PRs
couldn't find any 🤷♀️
Suggest a fix
Don't eat the underscore? Or rename the field, seems like angular has turned it into _u 🤔
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 with the provided undersc.yml and the Python generator command, then inspect the generator path that produces the shown response model. Done means the generated Python is syntactically valid while retaining the schema property alias "_"; verify the result by compiling or otherwise parsing the generated model.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, python
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100