django-ninja-extra icon indicating copy to clipboard operation
django-ninja-extra copied to clipboard

Provide a way to pass model_config (ConfigDict) to the generated schemas

Open Tatsh opened this issue 1 year ago • 1 comments

I would like to pass model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True, from_attributes=True) to every generated schema and pass by_alias=True to every generated API view. This allows use of camelcase.

Currently in ninja-extra ModelConfig there is no way to apply properties to the generated schemas. I think at fault here is actually django-ninja's create_schema() function for not accepting a way to customise the Config or model_config options.

I think my latter point is fixed by adding create_route_info={'by_alias': True} or similar to the ModelConfig() arguments.

Tatsh avatar Aug 09 '24 02:08 Tatsh

@Tatsh It's a good idea. I will look at the implementation again and see how this can be achieved

eadwinCode avatar Aug 10 '24 06:08 eadwinCode

@Tatsh This has been resolved. Another solution to this would be to create the schema manually and pass ModelConfig

eadwinCode avatar Dec 30 '24 08:12 eadwinCode

Thanks for the update. Closing.

Tatsh avatar Dec 30 '24 08:12 Tatsh