mia-platform / crud-service

A lightweight application to expose restful CRUD API over HTTP interface
https://docs.mia-platform.eu/docs/how_to/crud_service/crud_oss_usage
Apache License 2.0
44 stars 4 forks source link

Cast nested values in POST/PUT/PATCH operations #283

Open ThisIsDemetrio opened 7 months ago

ThisIsDemetrio commented 7 months ago

Feature Description

Working with the CRUD Service, we noticed that all the values included in request body are casted to the relative type, accordingly to the JSON Schema definition, but this works only on first-level fields.

As example, taking into account the books collection definition, the publishDate property have type Date because I want it to be transformed from a string to an ISODate. The same doesn't happen from the property date inside editionDates, which is a { type: "string", format: "date-time" } but it is located inside an array, and any POST/PUT/PATCH operation will save the value as a regular string (or whatever it is included in the request body).

Desired solution

The function QueryParser.traverseBody is used to transform values of every field defined in the JSON Schema definition.

It would be great if the method would be recursive, and operates inside objects and arrays.

The property fieldDefinition already contains the definitions also for nested types (after #252), so that part is already done.

Possible alternatives

Unfortunately there are no alternative for this issue, other than having these fields at root level. If a property must be included into an array, however, the problem persist.

ste23droid commented 7 months ago

I'm interested in this issue. The main problem is that we need to potentially change our data model to avoid this limitation. It could be a very nice addition for the crud. Also: if the console would allow us to specify nested objects data models graphically, it would be even better