Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update ModelResolver.java #1768

Merged
merged 1 commit into from
Dec 19, 2016
Merged

Update ModelResolver.java #1768

merged 1 commit into from
Dec 19, 2016

Conversation

sharonsu1
Copy link
Contributor

As I posted at https://groups.google.com/forum/#!topic/swagger-swaggersocket/FfJ3dJetmEA

In 1.5.0, io.swagger.jackson.ModelResolver is the default ModelConverter that analyse the bean structure. In the

public Model resolve(JavaType type, ModelConverterContext context, Iterator next) method around lines 263-280, there is a block of code to determine whether the field is readOnly as follows.

        boolean hasSetter = false, hasGetter = false;

        if (propDef.getSetter() == null) {

            hasSetter = false;

        } else {

            hasSetter = true;

        }

        if (propDef.getGetter() != null) {

            JsonProperty pd = propDef.getGetter().getAnnotation(JsonProperty.class);

            if (pd != null) {

                hasGetter = true;

            }

        }

        Boolean isReadOnly = null;

        if (!hasSetter & hasGetter) {

            isReadOnly = Boolean.TRUE;

        } else {

            isReadOnly = Boolean.FALSE;

        }

Note that propDef.getSetter() would throw exception if there are overloading setters. However, overloaded setters are very useful, and we want to keep them.

Consider a user case that we already implemented Apis with JaxRS, and would like to add swagger-jaxRS annotations to generate swagger.json using the bottom-up approach. Our data model contains more than one setters for some fields (overload setters), and uur Api uses Gson or customized serialization tools (not use jackson) to handle the serialization/deserialization of the data model without any problem. However, request swagger.json would fail because jackson throws conflict setters exception and io.swagger.jackson.ModelResolver does not suppress the exception.

It would be very useful it io.swagger.jackson.ModelResolver added try-catch block on if (propDef.getSetter() == null) to suppress the exception.

@fehguy fehguy merged commit 05b0b7d into swagger-api:master Dec 19, 2016
@fehguy fehguy modified the milestone: v1.5.11 Dec 19, 2016
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants