Remove models with same set of field.
See original GitHub issueIt would be good if we can identify that a similar model exists and use that model instead of creating a new model, especially when the FIELDS and DATA-TYPE are same.
For example, when my data is as follows,
{
"Arm Right": {
"Joint 1": 5,
"Joint 2": 3,
"Joint 3": 66
},
"Arm Left": {
"Joint 1": 55,
"Joint 2": 13,
"Joint 3": 6
}
}
we get the following output,
class ArmRight(BaseModel):
Joint_1: int = Field(..., alias='Joint 1')
Joint_2: int = Field(..., alias='Joint 2')
Joint_3: int = Field(..., alias='Joint 3')
class ArmLeft(BaseModel):
Joint_1: int = Field(..., alias='Joint 1')
Joint_2: int = Field(..., alias='Joint 2')
Joint_3: int = Field(..., alias='Joint 3')
class Model(BaseModel):
Arm_Right: ArmRight = Field(..., alias='Arm Right')
Arm_Left: ArmLeft = Field(..., alias='Arm Left')
Describe the solution you’d like I think it would be good if we can detect that models for ArmLeft and ArmRight are the same, and then to just use one of these models. For example,
class ArmRight (BaseModel):
Joint_1: int = Field(..., alias='Joint 1')
Joint_2: int = Field(..., alias='Joint 2')
Joint_3: int = Field(..., alias='Joint 3')
class Model(BaseModel):
Arm_Right: ArmRight = Field(..., alias='Arm Right')
Arm_Left: ArmRight = Field(..., alias='Arm Left')
Describe alternatives you’ve considered Currently, I just delete manually. But, we have a big system with many similar structures in JSON and many time we need to manually delete about 1000 models. 😦
Thank you very much for this excellent tool.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top Results From Across the Web
How to remove a field in Django model - Stack Overflow
I set the uniqueness of the record on ClientId and PersNumber. I have created 3 records in the database. Along the way I...
Read more >Delete a Data Model Object and Remove Mappings
You can delete a data model object (DMO) and remove data lake object (DLO) field mappings directly from the data mapping canvas.Required Editions...
Read more >db.collection.remove() — MongoDB Manual
By default, remove() removes all documents that match the query expression. Specify the justOne option to limit the operation to removing a single...
Read more >Models - Django documentation
Models ¶. A model is the single, definitive source of information about your data. It contains the essential fields and behaviors of the...
Read more >Mongoose v6.8.0: Models
Compiling your first model; Constructing Documents; Querying; Deleting ... The first argument is the singular name of the collection your model is for....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
@gk-patel OK. I released a new version as
0.6.17
This version has changed your idea.https://github.com/koxudaxi/datamodel-code-generator/blob/ada9b19d4c51b22ac4d4a872794416ad71f329cd/tests/data/expected/main/main_json_reuse_model/output.py#L16-L26
The enum will reuse the same model. A duplicate model will be created too. Because some models may need the enum from other modules. https://github.com/koxudaxi/datamodel-code-generator/blob/ada9b19d4c51b22ac4d4a872794416ad71f329cd/tests/data/expected/main/main_json_reuse_enum/output.py#L13-L28