aubergine-developers / nadia

Small and lightweight library for creating marshmallow Schemas for objects defined in OpenAPI 3 specs.
MIT License
1 stars 0 forks source link

Support for additional constraints in various data types #6

Open dexter2206 opened 6 years ago

dexter2206 commented 6 years ago

Some OpenAPI types can have additional constraints (min/max, boundaries on number of items in array etc.) that should be supported. Full list can be found in specification.

dexter2206 commented 5 years ago

After considering current architecture I think we should also implement format keyword (or at least plan accordingly so that keyword can be later implemented). I would also like to keep the possibility of controlling some building aspects (as for instance data type that is created upon deserialization). Therefore here is what I suggest:

I could implement all of the above. @magdanowak what do you think?

magdanowak commented 5 years ago

I'm for implementing the validators, and primitive builders seem to be the right place to do it. Right now something similar is done in ObjectBuilder with requirement parameter, so you can take a look. Are all possible constrainsts implemented by marshmallow, or do any need to be implemented by us? Might be good to separate those into another issue.

I would do the rest in a seperate issue. As I mentioned before, I don't feel like letting the user pass custom builders or create user defined fields is a priority at this stage. From your proposal I understand that the aspects of a field the user would be able to control is the field type name and add a format, is this correct?

dexter2206 commented 5 years ago

Some constraints are implemented in marshmallow, but most of them have to be implemented separately. I will create an issue with the details.

User-defined customizations are not a priority but I think we should plan so we won't have to rewrite everything from scratch when we plan to add it. For now, I think that only leaving the option for controlling field class would be ok. So the user would only control class (i.e. pass something reasonable instead of marshmallow.fields.Integer), with reasonable defaults defined. Implementing format is also crucial as 1) this is one of the constraints (although not a strict one), and 2) this is where user-defined fields can shine As I mentioned earlier it would be cool to pass fields that would deserialize e.g. into numpy objects, we could create plugin implementing such fields - it would be great for implementing APIs dealing with scientific computing.