Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

A feature to have READ ONLY value fields on a model shown up in the swagger documentation #854

Closed
stephenleny opened this issue Feb 4, 2015 · 6 comments
Milestone

Comments

@stephenleny
Copy link

As a user of swagger, I want to have a feature to have READ ONLY value fields on a model shown up in the swagger documentation.

I.e. We have this field "lastUpdatedDateTime" that is only a READ ONLY field on the model, but we still want this field to show in the swagger specification/ documentation

As recommended when using Jackson 1.9 and higher, to support this READ ONLY field on the model, we use:

  1. @JsonIgnore on the member variable and the setter method
  2. @JsonProperty on the getter method.
    which means ONLY ignore on deserialization. (http://jackson.codehaus.org/1.9.9/javadoc/org/codehaus/jackson/annotate/JsonIgnore.html)

So, we want Swagger to parse it for READ ONLY fields to still showing up in the documentation.

@webron
Copy link
Contributor

webron commented Feb 4, 2015

To be sure, I assume here that you're using the 1.5.X version of Swagger (we recently released M1 of it), as only Swagger 2.0 has support for a readOnly property.

Have you seen #695? I'm not sure it adds support to parsing the Jackson annotations as you use them, but it does offer support using our own @ApiModelProperty annotation.

@stephenleny
Copy link
Author

Yes, we're using swagger-jersey2-jaxrs_2.10 version 1.3.7.

@webron
Copy link
Contributor

webron commented Feb 4, 2015

That's swagger-core 1.3.7 which produces Swagger 1.2 spec files. Unfortunately, there's no support for readOnly with that version of the spec.

If it's important to you, you'd have to upgrade to the newer version.

@stephenleny
Copy link
Author

Ok thanks for the update. It is just I need to check whether our team can upgrade now, or need to wait to upgrade with some other groups within our company.

@webron
Copy link
Contributor

webron commented Feb 4, 2015

No problem. Let us know if you need any assistance with it.

The upgrade to 1.5.0-M1 should be as simple as changing the dependency, assuming you have no custom configuration (such as custom converters).

Also, remember that as mentioned above, support for readOnly would only be available in M2 which should hopefully come out in 3-4 weeks.

@fehguy fehguy added this to the v1.5-M2 milestone Feb 5, 2015
@fehguy
Copy link
Contributor

fehguy commented Mar 4, 2015

now the absence of a setter (via @JsonIgnore) and presence of a getter will trigger readOnly to be true.

@fehguy fehguy closed this as completed Mar 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants