rest-schemagen
rest-schemagen copied to clipboard
Wrong default value in schema
For the JSON-type boolean, always a default value is generated in the schema, see
com.mercateo.common.rest.schemagen.json.mapper.BooleanJsonPropertyMapper
This is not the case for Integer
com.mercateo.common.rest.schemagen.json.mapper.IntegerJsonPropertyMapper
Unfortunately this not always correct. In the following example there should be no default value:
/users
gives the list of all users
/users?admin=true
gives the list of all admin users
/users?admin=false
gives the list of all non-admin users
In Java Code the admin flag would be of type Boolean and its value would be null, if the query parameter is not given.
One solution would be, to remove the default value of all primitives and use only default values, if given by annotations.
Another solution would be to differentiate between the Java types boolean and Boolean (and similarly for other primitives) and use the java default values only for boolean, int, etc. If this solution is chosen, one should also think about if this should only happen in the schema or if it should also happen in the target_schema. Maybe one should leave it out for the target_schema as the Java primitives will always have a value when being returned and no default value would be needed.
Interesting places could be:
com.mercateo.common.rest.schemagen.SchemaPropertyGenerator#builtins
com.mercateo.common.rest.schemagen.PropertyTypeMapper#TYPE_MAP
com.mercateo.common.rest.schemagen.json.mapper.PropertyJsonSchemaMapperForRoot#primitivePropertyMappers