You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem
Swagger creates its own ObjectMapper instance for serializing schemas. In the process of resolving a model, this object mapper is used to find the properties of the target class.
Applications always create their own ObjectMapper to serialize their API response objects. This object mapper might have different settings than the one from Swagger. An example is different visibility settings for a PropertyAccessor.
publicclassResponse {
privateStringvalue;
// getter and setter for valuepublicStringgetSomething() {
return"There should be no property 'something' in the generated schema";
}
}
Restricting serialzation of classes to their fields and ignoring getters is a common thing. When the application serializes the object, only value will appear in its result.
This is different to the generated schema from Swagger, which will also include a property something. This is due to Swagger using its own ObjectMapper and calling findProperties (see above).
Expectation
Swagger should allow to specify an ObjectMapper that is used for finding properties of a bean class. Calling findProperties with this ObjectMapper returns only visible properties.
The text was updated successfully, but these errors were encountered:
The problem
Swagger creates its own
ObjectMapper
instance for serializing schemas. In the process of resolving a model, this object mapper is used to find the properties of the target class.swagger-core/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java
Line 584 in dc8785e
Applications always create their own
ObjectMapper
to serialize their API response objects. This object mapper might have different settings than the one from Swagger. An example is different visibility settings for aPropertyAccessor
.Consider the following example:
Restricting serialzation of classes to their fields and ignoring getters is a common thing. When the application serializes the object, only
value
will appear in its result.This is different to the generated schema from Swagger, which will also include a property
something
. This is due to Swagger using its ownObjectMapper
and callingfindProperties
(see above).Expectation
Swagger should allow to specify an
ObjectMapper
that is used for finding properties of a bean class. CallingfindProperties
with thisObjectMapper
returns only visible properties.The text was updated successfully, but these errors were encountered: