datamodel-code-generator
datamodel-code-generator copied to clipboard
Option to add Config details to specific classes
Is your feature request related to a problem? Please describe. There are a number of options which can be given for Config class. Need a option to define config and its attributes for a particular class which will be generated.
Describe the solution you'd like Need a way to specify that a specific class should have a config class with some options
type: object
properties:
Foo:
type: object
properties:
name:
type: string
Need some way to specify that generated class Foo should have a config class with arbitrary_types_allowed = True.
class Foo:
Class Config:
arbitrary_types_allowed = True
Here class Foo has Config with arbitrary_types_allowed
@gk12277
There is --custom-template-dir
option. And you can add the option to your custom template (jinja2 template).
What do you think about it?
@koxudaxi --custom-template-dir
option is common for all classes right. We wont be able to specify one particular property for one class and another property for another class. eg:
Class Foo:
Class Config:
arbitrary_types_allowed = True
Class Bar:
Class Config:
use_enum_values = True
Here class Foo needs arbitrary_types_allowed
and class Bar needs use_enum_values
.
@gk12277
I'm sorry for my late reply.
I think we can use if
condition in the jinja2 template.
But, I feel good that we can add an option from the CLI option or the schema.
Did you have an idea for giving config details to specific classes?
you can give the options to config with --extra-template-data EXTRA_TEMPLATE_DATA
https://github.com/koxudaxi/datamodel-code-generator/pull/861