Open kblief opened 6 years ago
looking into swagger-core lib where the model json converter is loaded. the possible solution is to override with custom converter to filter out unwanted bean properties: https://github.com/swagger-api/swagger-core/wiki/overriding-models
Adding a custom model converter to remove spring Errors property from Swagger model to json rendering. Also add an example jsonIgnore (from Jackson) annotation to example Book domain to block some Grails domain traits as global json marshalling configuration. This should be used with caution with specific RESTful resource response content exposure considerations.
One of the challenge is Swagger model overriding can not resolve a property by its name. This is due to the underlying Jackson objectMapper is only resolving object tree by type. Therefore, for some Grails domain traits such as 'version' or 'dirty', which are of primitive types (String, Boolean, etc), there's no way for Jackson objectMapper to tell them apart from other general bean properties.
v1.2.1 merged to dev-g32x main branch: https://github.com/binlecode/swagger/tree/dev-grails-32x
Not quite happy with current solution that a Grails domain class has to manually add "@JsonIgnoreProperties" annotation to mute some GORM traits fields. Need to find a systematic way of filtering out those fields at swagger document generation runtime.
As a api user, I want to example json to ONLY contain the fields that will be serialized to JSON when invoking APIs.
Grails Domain Classes list additional trait attributes that are not serialized to JSON when invoking the API calls.
Some Examples
Also does not work for Grails Command Objects