-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Support for additional reference types (other than JDK8 and Guava Optional
)
#4103
Comments
@frantuma, @HugoMario I hate to mention random maintainers here but is there any chance this issue and the linked PRs (#4105, #4106) will get some love anytime soon? |
@frantuma, @HugoMario another 3 month later. Could someone perhaps have a look? The fix is non-breaking, straight forward and will add support for the same reference types supported by swagger. |
On a related note, it'd be great to be able to parameterize Swagger with a custom Example use-cases are for Fugue and Arrow Is this something that maintainers would be open to? |
@MiriChan as far as I understand the kotlin sources in your example my PRs would address the |
Yeah that's my understanding too, provided that Swagger's From my glance around the codebase earlier I thought it wasn't possible to BYO or customise Swagger's Anyway, psyched for this change to land. Hope it gets some love soon! |
In addition to the hard coded `Optional` reference types the type information from jackson is used to unwrap additional reference types (e.g. `AtomicReference`)
In addition to the hard coded `Optional` reference types the type information from jackson is used to unwrap additional reference types (e.g. `AtomicReference`)
In addition to the hard coded `Optional` reference types the type information from jackson is used to unwrap additional reference types (e.g. `AtomicReference`)
Thanks!! merged #4105 and #4106 On the side |
My project is experiencing issues because of this commit, schema generation fails when using |
@RickHuizing would you mind to open a separate issue for your problem. Best with some MVCE to help in reproducing the bug. |
I'm using reference types (i.e. AtomicReference<>) in my domain objects to model the three-state semantic of set (value is available), not set (no value available or not of interest) and unset (clear existing value). This is supported out-of-the-box by Jackson and is mapped to
<value>
,undefined
andnull
in JSON/JavaScript respectively.Everything work pretty well except for the generated API documentation. I'm using swagger 1.6.2 with spring (not boot) and CXF. The problem is that reference types are not "unwrapped" in the generated documentation.
For example the type MyDomainObject has a single String field description. In Java this value is wrapped by AtomicReference as outlined above:
And the corresponding type definition in the generated swagger looks like this:
But this is not correct as a JSON value for this type would look like this:
That is the swagger should simply look like this:
I tried to find a workaround for this problem and found that both JDK8 and Guava's
Optional
are supported by swagger out-of-the-box in the described way. However (IMHO) usingOptional
to model the described 3-state semantic kind of contradicts the intention ofOptional
as you'd have to performnull
-checks on theOptional
field - just my opinion. I know thatAtomicReference
was invented with another intention in mind as well but, as this is supported byjackson-databind
(without additional modules), I think this is currently the best way to implement this semantic.Browsing through the swagger code I found that support for additional reference types would be quite easy to add (OptionalUtils in 2.X and ModelResolver._isOptionalType in 1.6).
I'd happy to provide PRs for this enhancement but want to make sure this change is going to be accepted for both 1.6 and 2.X branches of swagger.
For completeness:
I posted related questions on stackoverflow and smartbear already but got no feedback, as of now
The text was updated successfully, but these errors were encountered: