Comments (6)
@gk-patel
Thank you for creating this issue.
I think it's a good idea.
The behavior may have to be an option of the command line 🤔
I will implement this feature after remove bugs.
from datamodel-code-generator.
@gk-patel
I have released a new version as 0.6.15.
The version has the --reuse-model
option that you want.
I put an example.
Input
datamodel-code-generator/tests/data/json/duplicate_models.json
Lines 1 to 15 in 681ca87
Output
I'm sorry, My work is too late.
from datamodel-code-generator.
@koxudaxi No worries man, looks nice.
Although, the following would have been much more cooler,
...
class ArmLeft(ArmRight):
pass
...
If you can do that, it would look much nicer. But if you cannot, then you can close the issue. I leave it up to you.
from datamodel-code-generator.
@gk-patel
No problem, It's a good idea.
I can implement the changes easily.
But, I found a problem with a case.
The code generator generates the Enum
class from JSONSchema/OpenAPI.
Enum class can't be extended.
>> class B(A): pass
TypeError: Cannot extend enumerations
We should assign to another value. or we don't touch duplicated enum 🤔
from datamodel-code-generator.
Well, IMHO the easiest way would be to check if the content of enums is exactly the same,
- if it is exactly the same, just use the same name everywhere (so in that case, dont create class B)
- if it not exactly the same, the create a seperate enum without inheritance, (so in that case, create class A and B)
Do you have any arguments against this idea ?
from datamodel-code-generator.
@gk-patel
OK. I released a new version as 0.6.17
This version has changed your idea.
The enum will reuse the same model. A duplicate model will be created too. Because some models may need the enum from other modules.
from datamodel-code-generator.
Related Issues (20)
- Pydantic discriminator is generated with alias instead of field name
- Consolidate Data Models for "oneOf"["required.. JSON Schema models
- Discriminated Union with Literal with multiple values results in single Literal value
- Is there a way to generate better class names for "oneOf" schemas? HOT 1
- Strict types don't enforce field constraints
- Missing Union import for `oneOf` definitions
- Imports break when schema files are named the same as a schema defined within them
- datamodel-codegen produces class with missing body parts
- Improve `mypy` hinting on `RootModel` with `oneOf` HOT 4
- How to change endpoints naming template?
- Support pydantic.dataclasses as output format
- Nullability info excluded from templates for optional, no-default OpenAPI fields
- [yaml] The generator does not generate Python code from models in external files referenced by $ref. HOT 1
- Generation of Shopify GraphQL schema fails
- oneOf with subschema array items not incorporated/generated as Any for pydantic.v2 HOT 4
- [graphql] Add support for --use-subclass-enum
- Base class for main object, not for properties HOT 1
- msgspec: Mandatory attributes follow optional ones
- msgspec: Optional fields are missing a default when using `--snake-case-field` HOT 6
- Generated models using RootModel to represent Annotated Unions are out of order HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from datamodel-code-generator.