Skip to content

Commit 905cbff

Browse files
Add test that shows how the sealed-model interpreter overrides manually specified schema annotations
1 parent 70057d0 commit 905cbff

File tree

3 files changed

+217
-0
lines changed

3 files changed

+217
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * *
7+
* * * * * * Copyright 2019-2025 the original author or authors.
8+
* * * * * *
9+
* * * * * * Licensed under the Apache License, Version 2.0 (the "License");
10+
* * * * * * you may not use this file except in compliance with the License.
11+
* * * * * * You may obtain a copy of the License at
12+
* * * * * *
13+
* * * * * * https://www.apache.org/licenses/LICENSE-2.0
14+
* * * * * *
15+
* * * * * * Unless required by applicable law or agreed to in writing, software
16+
* * * * * * distributed under the License is distributed on an "AS IS" BASIS,
17+
* * * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* * * * * * See the License for the specific language governing permissions and
19+
* * * * * * limitations under the License.
20+
* * * * *
21+
* * * *
22+
* * *
23+
* *
24+
*
25+
*/
26+
27+
package test.org.springdoc.api.v30.app242;
28+
29+
30+
import io.swagger.v3.oas.annotations.media.DiscriminatorMapping;
31+
import io.swagger.v3.oas.annotations.media.Schema;
32+
import org.springframework.web.bind.annotation.PostMapping;
33+
import org.springframework.web.bind.annotation.RequestBody;
34+
import org.springframework.web.bind.annotation.RestController;
35+
36+
@RestController
37+
public class HelloController {
38+
39+
@PostMapping("/parent")
40+
public void parentEndpoint(@RequestBody SuperClass parent) {
41+
42+
}
43+
44+
}
45+
46+
@Schema(name = SuperClass.SCHEMA_NAME,
47+
discriminatorProperty = "type",
48+
oneOf = {
49+
FirstChildClass.class,
50+
SecondChildClass.class
51+
},
52+
discriminatorMapping = {
53+
@DiscriminatorMapping(value = FirstChildClass.SCHEMA_NAME, schema = FirstChildClass.class),
54+
@DiscriminatorMapping(value = SecondChildClass.SCHEMA_NAME, schema = SecondChildClass.class)
55+
}
56+
)
57+
sealed class SuperClass permits FirstChildClass, SecondChildClass {
58+
59+
@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
60+
public String getType() {
61+
return type;
62+
}
63+
64+
public String type;
65+
66+
public static final String SCHEMA_NAME = "SuperClass";
67+
}
68+
69+
@Schema(name = FirstChildClass.SCHEMA_NAME)
70+
final class FirstChildClass extends SuperClass {
71+
72+
@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
73+
public String getType() {
74+
return type;
75+
}
76+
77+
public String type;
78+
79+
public static final String SCHEMA_NAME = "Image";
80+
}
81+
82+
@Schema(name = SecondChildClass.SCHEMA_NAME)
83+
final class SecondChildClass extends SuperClass {
84+
85+
@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
86+
public String getType() {
87+
return type;
88+
}
89+
90+
public String type;
91+
92+
public static final String SCHEMA_NAME = "Mail";
93+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * * Copyright 2019-2024 the original author or authors.
7+
* * * * *
8+
* * * * * Licensed under the Apache License, Version 2.0 (the "License");
9+
* * * * * you may not use this file except in compliance with the License.
10+
* * * * * You may obtain a copy of the License at
11+
* * * * *
12+
* * * * * https://www.apache.org/licenses/LICENSE-2.0
13+
* * * * *
14+
* * * * * Unless required by applicable law or agreed to in writing, software
15+
* * * * * distributed under the License is distributed on an "AS IS" BASIS,
16+
* * * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* * * * * See the License for the specific language governing permissions and
18+
* * * * * limitations under the License.
19+
* * * *
20+
* * *
21+
* *
22+
*
23+
*/
24+
25+
package test.org.springdoc.api.v30.app242;
26+
27+
import org.springframework.boot.autoconfigure.SpringBootApplication;
28+
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;
29+
30+
public class SpringDocApp242Test extends AbstractSpringDocV30Test {
31+
32+
@SpringBootApplication
33+
static class SpringDocTestApp {}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/parent": {
15+
"post": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "parentEndpoint",
20+
"requestBody": {
21+
"content": {
22+
"application/json": {
23+
"schema": {
24+
"$ref": "#/components/schemas/SuperClass"
25+
}
26+
}
27+
},
28+
"required": true
29+
},
30+
"responses": {
31+
"200": {
32+
"description": "OK"
33+
}
34+
}
35+
}
36+
}
37+
},
38+
"components": {
39+
"schemas": {
40+
"Image": {
41+
"required": [
42+
"type"
43+
],
44+
"type": "object",
45+
"properties": {
46+
"type": {
47+
"type": "string"
48+
}
49+
}
50+
},
51+
"Mail": {
52+
"required": [
53+
"type"
54+
],
55+
"type": "object",
56+
"properties": {
57+
"type": {
58+
"type": "string"
59+
}
60+
}
61+
},
62+
"SuperClass": {
63+
"required": [
64+
"type"
65+
],
66+
"type": "object",
67+
"properties": {
68+
"type": {
69+
"type": "string"
70+
}
71+
},
72+
"discriminator": {
73+
"propertyName": "type",
74+
"mapping": {
75+
"Image": "#/components/schemas/Image",
76+
"Mail": "#/components/schemas/Mail"
77+
}
78+
},
79+
"oneOf": [
80+
{
81+
"$ref": "#/components/schemas/Image"
82+
},
83+
{
84+
"$ref": "#/components/schemas/Mail"
85+
}
86+
]
87+
}
88+
}
89+
}
90+
}

0 commit comments

Comments
 (0)