datamodel-code-generator
datamodel-code-generator copied to clipboard
[Request] ability to reverse --collapse-root-models collapse order
Is your feature request related to a problem? Please describe. Currently, without --collapse-root-models, I get the following:
class ISectionBlockMetadata(BaseModel):
__root__: FieldType2
class FieldType2(BaseModel):
as_text: str = Field(..., alias='asText', title='asText')
with --collapse-root-models, I get this:
class FieldType2(BaseModel):
as_text: str = Field(..., alias='asText', title='asText')
The problem is that I want the merged class to be called ISectionBlockMetadata
Describe the solution you'd like I would like the ability to reverse which name is adopted for the merged class, for instance, in the above example I would I would expect the merged class to be
class ISectionBlockMetadata(BaseModel):
as_text: str = Field(..., alias='asText', title='asText')
Describe alternatives you've considered
For my use case (typescript -> json schema -> pydantic), I've submitted a feature request to the typescript-json-schema
library to add (if it doesn't already exist) the ability to transfer the name to the title within the json schema (details: https://github.com/YousefED/typescript-json-schema/issues/554)
Additional context N/A
As an update, I have implemented a work around for typescript-json-schema, I think the ability to remove nested / duplicated structures will lessen the need for work on this tool.
on a different note, when I do --reuse-model it would be nice to have the option to merge the naming / reference into a single one. i.e. currently I might have something like
class BoundingRegionSchema(BaseModel):
...etc
class BoundingRegion(BoundingRegionSchema):
pass
But this makes for more confusing relationships, is there a way to collapse these references into BoundingRegionSchema?