Is your feature request related to a problem? Please describe.
When using the --use-title-as-name flag, inline defined child schemas get a number appended to them because of name conflicts. For example, given the following schema definitions:
MyFirstSchema:
type: object
properties:
payload:
type: object
properties:
status:
type: string
id:
type: string
required:
- status
- id
required:
- payload
MySecondSchema:
type: object
properties:
payload:
type: object
properties:
userName:
type: string
randomField:
type: string
required:
- userName
- randomField
required:
- payload
Running the generator will create the following classes to represent the payload
fields:
class Payload1(BaseModel):
status: str
id: str
class MyFirstSchema(BaseModel):
payload: Payload1
class Payload2(BaseModel):
userName: str
randomField: str
class MySecondSchema(BaseModel):
payload: Payload2
These are hard to instantiate / use in code because they have no specific meaning and are inside the same module. Even worse, a new spec can cause the numbers to change which causes additive changes to unexpectedly be breaking.
Describe the solution you'd like
In these name conflict scenarios, I think it would be best to choose the parent schema's name as a prefix. For example, the payload classes would become:
class MyFirstSchemaPayload(BaseModel):
status: str
id: str
class MySecondSchemaPayload(BaseModel):
userName: str
randomField: str
This could be applied recursively, using the parent field name whenever a conflict occurs.
Describe alternatives you've considered
I've looked into having the OpenAPI spec use references instead of inline definitions, but it is itself being generated from code and adding behavior to support references would likely be more complex than this change. I am using this library for context.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too