-
-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PolymorphicModelConverter only handles direct subtypes and misses ind…
…irect. Fixes #2603
- Loading branch information
1 parent
07e2c92
commit 497bfae
Showing
4 changed files
with
263 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...i-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app220/HelloController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package test.org.springdoc.api.v30.app220; | ||
|
||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes.Type; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class HelloController { | ||
|
||
@PostMapping("/parent") | ||
public void parentEndpoint(@RequestBody Superclass parent) { | ||
|
||
} | ||
|
||
} | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "@type") | ||
@JsonSubTypes({ | ||
@Type(value = IntermediateClass.class, name = IntermediateClass.SCHEMA_NAME), | ||
}) | ||
sealed class Superclass permits IntermediateClass { | ||
|
||
public Superclass() {} | ||
} | ||
|
||
@Schema(name = IntermediateClass.SCHEMA_NAME) | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "@type") | ||
@JsonSubTypes({ | ||
@Type(value = FirstChildClass.class, name = FirstChildClass.SCHEMA_NAME), | ||
@Type(value = SecondChildClass.class, name = SecondChildClass.SCHEMA_NAME) | ||
}) | ||
sealed class IntermediateClass extends Superclass permits FirstChildClass, SecondChildClass { | ||
|
||
public static final String SCHEMA_NAME = "IntermediateClass"; | ||
} | ||
|
||
@Schema(name = FirstChildClass.SCHEMA_NAME) | ||
final class FirstChildClass extends IntermediateClass { | ||
|
||
public static final String SCHEMA_NAME = "Image"; | ||
} | ||
|
||
@Schema(name = SecondChildClass.SCHEMA_NAME) | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "@type") | ||
@JsonSubTypes({ | ||
@Type(value = ThirdChildClass.class, name = ThirdChildClass.SCHEMA_NAME) | ||
}) | ||
sealed class SecondChildClass extends IntermediateClass { | ||
|
||
public static final String SCHEMA_NAME = "Mail"; | ||
} | ||
|
||
@Schema(name = ThirdChildClass.SCHEMA_NAME) | ||
final class ThirdChildClass extends SecondChildClass { | ||
|
||
public static final String SCHEMA_NAME = "Home"; | ||
} |
35 changes: 35 additions & 0 deletions
35
...arter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app220/SpringDocApp220Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* | ||
* * | ||
* * * | ||
* * * * | ||
* * * * * Copyright 2019-2022 the original author or authors. | ||
* * * * * | ||
* * * * * Licensed under the Apache License, Version 2.0 (the "License"); | ||
* * * * * you may not use this file except in compliance with the License. | ||
* * * * * You may obtain a copy of the License at | ||
* * * * * | ||
* * * * * https://www.apache.org/licenses/LICENSE-2.0 | ||
* * * * * | ||
* * * * * Unless required by applicable law or agreed to in writing, software | ||
* * * * * distributed under the License is distributed on an "AS IS" BASIS, | ||
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* * * * * See the License for the specific language governing permissions and | ||
* * * * * limitations under the License. | ||
* * * * | ||
* * * | ||
* * | ||
* | ||
*/ | ||
|
||
package test.org.springdoc.api.v30.app220; | ||
|
||
import test.org.springdoc.api.v30.AbstractSpringDocV30Test; | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
public class SpringDocApp220Test extends AbstractSpringDocV30Test { | ||
|
||
@SpringBootApplication | ||
static class SpringDocTestApp {} | ||
} |
132 changes: 132 additions & 0 deletions
132
springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app220.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
{ | ||
"openapi": "3.0.1", | ||
"info": { | ||
"title": "OpenAPI definition", | ||
"version": "v0" | ||
}, | ||
"servers": [ | ||
{ | ||
"url": "http://localhost", | ||
"description": "Generated server url" | ||
} | ||
], | ||
"paths": { | ||
"/parent": { | ||
"post": { | ||
"tags": [ | ||
"hello-controller" | ||
], | ||
"operationId": "parentEndpoint", | ||
"requestBody": { | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"oneOf": [ | ||
{ | ||
"$ref": "#/components/schemas/Superclass" | ||
}, | ||
{ | ||
"$ref": "#/components/schemas/IntermediateClass" | ||
}, | ||
{ | ||
"$ref": "#/components/schemas/Image" | ||
}, | ||
{ | ||
"$ref": "#/components/schemas/Mail" | ||
}, | ||
{ | ||
"$ref": "#/components/schemas/Home" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"required": true | ||
}, | ||
"responses": { | ||
"200": { | ||
"description": "OK" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"Home": { | ||
"type": "object", | ||
"allOf": [ | ||
{ | ||
"$ref": "#/components/schemas/Mail" | ||
} | ||
] | ||
}, | ||
"Image": { | ||
"type": "object", | ||
"allOf": [ | ||
{ | ||
"$ref": "#/components/schemas/IntermediateClass" | ||
} | ||
] | ||
}, | ||
"IntermediateClass": { | ||
"required": [ | ||
"@type" | ||
], | ||
"type": "object", | ||
"discriminator": { | ||
"propertyName": "@type" | ||
}, | ||
"allOf": [ | ||
{ | ||
"$ref": "#/components/schemas/Superclass" | ||
}, | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"@type": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"Mail": { | ||
"required": [ | ||
"@type" | ||
], | ||
"type": "object", | ||
"discriminator": { | ||
"propertyName": "@type" | ||
}, | ||
"allOf": [ | ||
{ | ||
"$ref": "#/components/schemas/IntermediateClass" | ||
}, | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"@type": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"Superclass": { | ||
"required": [ | ||
"@type" | ||
], | ||
"type": "object", | ||
"properties": { | ||
"@type": { | ||
"type": "string" | ||
} | ||
}, | ||
"discriminator": { | ||
"propertyName": "@type" | ||
} | ||
} | ||
} | ||
} | ||
} |