Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom base class for models #37

Closed
Bobronium opened this issue Aug 5, 2019 · 3 comments
Closed

Allow custom base class for models #37

Bobronium opened this issue Aug 5, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@Bobronium
Copy link

Bobronium commented Aug 5, 2019

Is your feature request related to a problem? Please describe.
Didn't use this library yet, just looked at code and saw that BaseModel is hardcoded in templates as base class for models:

Describe the solution you'd like
Add ability to choose the name of base class of models (and even create one automatically)
This would be helpful if I wan't to have same config, methods, etc for all subclasses

Describe alternatives you've considered
This can be approached by renaming BaseModel in a result manually, but if it not hard to implement I'd preffered to have this built-in

Additional context
Add any other context or screenshots about the feature request here.

@koxudaxi koxudaxi added the enhancement New feature or request label Aug 5, 2019
@koxudaxi
Copy link
Owner

koxudaxi commented Aug 5, 2019

@MrMrRobat
Sounds great to me.

This can be approached by renaming BaseModel in a result manually, but if it not hard to implement I'd preffered to have this built-in

Did you expect to use inherited BasdModel?

I think the code generator should able to receive the alternative base class as arguments or a config file.

@koxudaxi
Copy link
Owner

koxudaxi commented Aug 6, 2019

@MrMrRobat
support and publish the feature. Thank you

Example

$ datamodel-codegen --input ./tests/data/api.yaml --base-class custom_module.CustomBase
Output:

class Pet(CustomBase):
    id: int
    name: str
    tag: Optional[str] = None
...

@Bobronium
Copy link
Author

Looks great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants