-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[Java][jersey2] fix oneOf, anyOf documentation #6695
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # {{classname}} | ||
|
|
||
| {{#description}} | ||
| {{&description}} | ||
|
|
||
| {{/description}} | ||
| ## anyOf schemas | ||
| {{#anyOf}} | ||
| * [{{{.}}}]({{{.}}}.md) | ||
| {{/anyOf}} | ||
|
|
||
| {{#isNullable}} | ||
| NOTE: this class is nullable. | ||
|
|
||
| {{/isNullable}} | ||
| ## Example | ||
| ```java | ||
| // Import classes: | ||
| import {{{package}}}.{{{classname}}}; | ||
| {{#anyOf}} | ||
| import {{{package}}}.{{{.}}}; | ||
| {{/anyOf}} | ||
|
|
||
| public class Example { | ||
| public static void main(String[] args) { | ||
| {{classname}} example{{classname}} = new {{classname}}(); | ||
| {{#anyOf}} | ||
|
|
||
| // create a new {{{.}}} | ||
| {{{.}}} example{{{.}}} = new {{{.}}}(); | ||
| // set {{{classname}}} to {{{.}}} | ||
| example{{classname}}.setActualInstance(example{{{.}}}); | ||
| // to get back the {{{.}}} set earlier | ||
| {{{.}}} test{{{.}}} = ({{{.}}}) example{{classname}}.getActualInstance(); | ||
| {{/anyOf}} | ||
| } | ||
| } | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| {{#models}}{{#model}} | ||
|
|
||
| {{#isEnum}} | ||
| {{>enum_outer_doc}} | ||
| {{/isEnum}} | ||
| {{^isEnum}} | ||
| {{^oneOf.isEmpty}} | ||
| {{>model_oneof_doc}} | ||
| {{/oneOf.isEmpty}} | ||
| {{^anyOf.isEmpty}} | ||
| {{>model_anyof_doc}} | ||
| {{/anyOf.isEmpty}} | ||
| {{^anyOf}} | ||
| {{^oneOf}} | ||
| {{>pojo_doc}} | ||
| {{/oneOf}} | ||
| {{/anyOf}} | ||
| {{/isEnum}} | ||
| {{/model}}{{/models}} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # {{classname}} | ||
|
|
||
| {{#description}} | ||
| {{&description}} | ||
|
|
||
| {{/description}} | ||
| ## oneOf schemas | ||
| {{#oneOf}} | ||
| * [{{{.}}}]({{{.}}}.md) | ||
| {{/oneOf}} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about when we combine allOf and oneOf together?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's step back. What does "combine allOf and oneOf together" really mean? Can you give an example of use case on that? What does the payload look like?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. A use case for this is when a user extracts common shared properties into a schema and they choose to have those properties stored in the oneOf schema as additionalProperties, not through allOf inheritance. And a sample payload is:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's focus on "ComposedSchema" and please forget about my implementation for the time being. Given the following: oneOf and allOf are defined at the same level. Your understanding is that the properties defined in the oneOf schema are automatically unfolded and included in the object "ComposedSchema" (same level as the properties defined in the allOf schema), right?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's what I am trying to convey with the question
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming the answer to your question is yes, then the following is also valid, right? Does it make sense to you? If it does, what does the payload (e.g. JSON) look like?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that it can only be combined when they are of the same type. What do you think?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
My view is that it's not up to me (or you) whether there's such a rule to ensure the same type. It comes down to the definition in JSON schema. I may have missed it but I don't see such a rule explicitly (or implicitly) defined. One more example. What about the following: I assume it's also valid. Do you agree?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm isn't oneof a key? I thought that it was and that you can't have two of the same key.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the spec allof is defined as: |
||
|
|
||
| {{#isNullable}} | ||
| NOTE: this class is nullable. | ||
|
|
||
| {{/isNullable}} | ||
| ## Example | ||
| ```java | ||
| // Import classes: | ||
| import {{{package}}}.{{{classname}}}; | ||
| {{#oneOf}} | ||
| import {{{package}}}.{{{.}}}; | ||
| {{/oneOf}} | ||
|
|
||
| public class Example { | ||
| public static void main(String[] args) { | ||
| {{classname}} example{{classname}} = new {{classname}}(); | ||
| {{#oneOf}} | ||
|
|
||
| // create a new {{{.}}} | ||
| {{{.}}} example{{{.}}} = new {{{.}}}(); | ||
| // set {{{classname}}} to {{{.}}} | ||
| example{{classname}}.setActualInstance(example{{{.}}}); | ||
| // to get back the {{{.}}} set earlier | ||
| {{{.}}} test{{{.}}} = ({{{.}}}) example{{classname}}.getActualInstance(); | ||
| {{/oneOf}} | ||
| } | ||
| } | ||
| ``` | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about when properties are set in the composed schema and we have oneOf or anyOf?