Tries to fix #18975 by changing how the deserializer interacts with its parent class (#18976)

* [JAVA] Fix for #18975, ensure static block of parent deser class loads

* Add sample spec with type with anyOf
This commit is contained in:
qbuzzdaan 2024-06-26 09:22:20 +02:00 committed by GitHub
parent 0d05ee35f0
commit 6b9d95be89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 50 additions and 3 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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'