jacksmith15 / statham-schema

Statham is a Python Model Parsing Library for JSON Schema.
https://statham-schema.readthedocs.io/en/latest/
MIT License
38 stars 11 forks source link

Ability to Generate Python DataClasses with ability to inherit #89

Closed tanzimabsar closed 1 year ago

tanzimabsar commented 1 year ago

Description of requested feature Hi,

Thanks for creating an awesome library. Would it be possible to extend this so that generic dataclasses can be created? For this use case, the structure of objects (nested) and primitive data types are really only needed.

Possibly some inheritence also where these classes could be injected with another base class for the user to extend with. Something that comes to mind is: https://marcosschroh.github.io/dataclasses-avroschema/.

The use case for this is to have the ability to have a flexible tool to generate avro schemas. For that use case, there is no need to find compatible overlaps between specifications, just to generate code to then extend and manipulate.

Workaround

I have tried extending the methods in the classes _Property and serialize_python to add a flag to the serializer which producers dataclasses and only uses the python specific primitives likes (str, int etc.)

It does not work for all edge cases but that was not the point, I wanted this to serve as a starting point with the powerful dataclasses and integration with pydantic down the line, therefor JSON Schema specific features such as AnyOf and AllOf are not really needed.

tanzimabsar commented 1 year ago

shouldhavereadthedocs