diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/anyof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/anyof_model.mustache index b54b371a122..c4d5e749cf4 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/anyof_model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/anyof_model.mustache @@ -57,7 +57,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im Object deserialized = null; {{#discriminator}} - Class cls = JSON.getClassForElement(tree, {{classname}}.class); + Class cls = JSON.getClassForElement(tree, new {{classname}}().getClass()); if (cls != null) { // When the OAS schema includes a discriminator, use the discriminator value to // discriminate the anyOf schemas. diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/anyof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/anyof_model.mustache index b54b371a122..c4d5e749cf4 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/anyof_model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/anyof_model.mustache @@ -57,7 +57,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im Object deserialized = null; {{#discriminator}} - Class cls = JSON.getClassForElement(tree, {{classname}}.class); + Class cls = JSON.getClassForElement(tree, new {{classname}}().getClass()); if (cls != null) { // When the OAS schema includes a discriminator, use the discriminator value to // discriminate the anyOf schemas. diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/anyof_model.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/anyof_model.mustache index 297ff64d049..dfb6464d579 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/native/anyof_model.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/anyof_model.mustache @@ -54,7 +54,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im Object deserialized = null; {{#discriminator}} - Class cls = JSON.getClassForElement(tree, {{classname}}.class); + Class cls = JSON.getClassForElement(tree, new {{classname}}().getClass()); if (cls != null) { // When the OAS schema includes a discriminator, use the discriminator value to // discriminate the anyOf schemas. diff --git a/modules/openapi-generator/src/test/resources/bugs/issue_18975.yaml b/modules/openapi-generator/src/test/resources/bugs/issue_18975.yaml new file mode 100755 index 00000000000..b50ba0d66e7 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/bugs/issue_18975.yaml @@ -0,0 +1,47 @@ +openapi: 3.0.1 +info: + title: sample issue 18975 + description: sample issue 18975 + version: "1.0" +paths: + /sample: + get: + summary: sample + operationId: getSample + responses: + "200": + description: Found vehicle. + content: + application/json: + schema: + $ref: '#/components/schemas/DifficultType' +components: + schemas: + SubA: + required: + - type + type: object + properties: + type: + type: string + sim: + type: string + SubB: + required: + - type + type: object + properties: + type: + type: string + system: + type: string + DifficultType: + type: object + discriminator: + propertyName: type + mapping: + "typeA": '#/components/schemas/SubA' + "typeB": '#/components/schemas/SubB' + anyOf: + - $ref: '#/components/schemas/SubA' + - $ref: '#/components/schemas/SubB'