-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[Java][jersey2] Fix generated client code for oneOf models if datatype includes arrays #18042
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
1a9c01e
3c2b970
c03c323
b44e3be
711574e
772da21
d9c08d3
51b878d
b23037f
3702fa2
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,7 @@ | ||
| generatorName: java | ||
| outputDir: samples/client/others/java/jersey2-oneOf-duplicates | ||
| library: jersey2 | ||
| inputSpec: modules/openapi-generator/src/test/resources/3_0/oneOf_duplicateArray.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/Java | ||
| additionalProperties: | ||
| hideGenerationTimestamp: "true" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| generatorName: java | ||
| outputDir: samples/client/others/java/jersey2-oneOf-Mixed | ||
| library: jersey2 | ||
| inputSpec: modules/openapi-generator/src/test/resources/3_0/oneOf_primitiveAndArray.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/Java | ||
| additionalProperties: | ||
| hideGenerationTimestamp: "true" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8421,12 +8421,17 @@ private List<CodegenProperty> getComposedProperties(List<Schema> xOfCollection, | |
| xOf.add(cp); | ||
| i += 1; | ||
|
|
||
| if (dataTypeSet.contains(cp.dataType)) { | ||
| if (dataTypeSet.contains(cp.dataType) | ||
| || (isTypeErasedGenerics() && dataTypeSet.contains(cp.baseType))) { | ||
| // add "x-duplicated-data-type" to indicate if the dataType already occurs before | ||
| // in other sub-schemas of allOf/anyOf/oneOf | ||
| cp.vendorExtensions.putIfAbsent("x-duplicated-data-type", true); | ||
| } else { | ||
| dataTypeSet.add(cp.dataType); | ||
| if(isTypeErasedGenerics()) { | ||
| dataTypeSet.add(cp.baseType); | ||
| } else { | ||
| dataTypeSet.add(cp.dataType); | ||
| } | ||
| } | ||
| } | ||
| return xOf; | ||
|
|
@@ -8463,11 +8468,16 @@ public Set<String> getOpenAPIGeneratorIgnoreList() { | |
| return openapiGeneratorIgnoreList; | ||
| } | ||
|
|
||
| @Override | ||
|
Member
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. can you describe what
Contributor
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. Sorry for the late reply. public Constructor(final List<String> args) {...}
public Constructor(final List<Integer> args) {...}because both the signatures erase to the same signature
Member
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 using
Contributor
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. Yes I use that as well, but I have to determine on the codegen side whether that is even applicable. In languages that do not erase their generics, |
||
| public boolean isTypeErasedGenerics() { | ||
| return false; | ||
| } | ||
|
|
||
| /* | ||
| A function to convert yaml or json ingested strings like property names | ||
| And convert special characters like newline, tab, carriage return | ||
| Into strings that can be rendered in the language that the generator will output to | ||
| */ | ||
| A function to convert yaml or json ingested strings like property names | ||
| And convert special characters like newline, tab, carriage return | ||
| Into strings that can be rendered in the language that the generator will output to | ||
| */ | ||
| protected String handleSpecialCharacters(String name) { return name; } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| openapi: 3.0.1 | ||
| info: | ||
| version: 1.0.0 | ||
| title: Example - oneOf data type | ||
| license: | ||
| name: MIT | ||
| servers: | ||
| - url: http://api.example.xyz/v1 | ||
| paths: | ||
| /example: | ||
| get: | ||
| operationId: list | ||
| responses: | ||
| "200": | ||
| description: OK | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/Example" | ||
| components: | ||
| schemas: | ||
| Example: | ||
| oneOf: | ||
| - type: array | ||
| items: | ||
| type: number | ||
| - type: array | ||
| items: | ||
| type: integer |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| openapi: 3.0.1 | ||
| info: | ||
| version: 1.0.0 | ||
| title: Example - oneOf data type | ||
| license: | ||
| name: MIT | ||
| servers: | ||
| - url: http://api.example.xyz/v1 | ||
| paths: | ||
| /example: | ||
| get: | ||
| operationId: list | ||
| responses: | ||
| "200": | ||
| description: OK | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/Example" | ||
| components: | ||
| schemas: | ||
| Example: | ||
| oneOf: | ||
| - type: string | ||
| format: uuid | ||
| - type: array | ||
| items: | ||
| type: integer |
Uh oh!
There was an error while loading. Please reload this page.