Skip to content

Commit 35e2c82

Browse files
authored
Merge pull request #2353 from xiaoxiangmoe/main
Add more test for OpenAPI Specification v3.1
2 parents f99e78a + 5101b91 commit 35e2c82

File tree

6 files changed

+228
-0
lines changed

6 files changed

+228
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * * Copyright 2019-2023 the original author or authors.
6+
* * * *
7+
* * * * Licensed under the Apache License, Version 2.0 (the "License");
8+
* * * * you may not use this file except in compliance with the License.
9+
* * * * You may obtain a copy of the License at
10+
* * * *
11+
* * * * https://www.apache.org/licenses/LICENSE-2.0
12+
* * * *
13+
* * * * Unless required by applicable law or agreed to in writing, software
14+
* * * * distributed under the License is distributed on an "AS IS" BASIS,
15+
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* * * * See the License for the specific language governing permissions and
17+
* * * * limitations under the License.
18+
* * *
19+
* *
20+
*
21+
*/
22+
23+
package test.org.springdoc.api.v31.app8;
24+
25+
import org.springframework.web.bind.annotation.GetMapping;
26+
import org.springframework.web.bind.annotation.RestController;
27+
28+
@RestController
29+
public class ExamplesController {
30+
31+
@GetMapping(value = "/")
32+
public ExamplesResponse index() {
33+
return null;
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package test.org.springdoc.api.v31.app8;
2+
3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
5+
import java.util.List;
6+
7+
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED;
8+
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
9+
10+
public record ExamplesResponse(
11+
@Schema(description = "self's user info", requiredMode = REQUIRED)
12+
UserInfo self,
13+
@Schema(description = "friend, deprecated, use friends instead", requiredMode = NOT_REQUIRED)
14+
@Deprecated
15+
UserInfo friend,
16+
@Schema(description = "friends", requiredMode = NOT_REQUIRED)
17+
List<UserInfo> friends
18+
) {
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package test.org.springdoc.api.v31.app8;
2+
3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
5+
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
6+
7+
@Schema(description = "the foo bar", deprecated = true)
8+
public record FooBar(
9+
@Schema(description = "foo", requiredMode = REQUIRED, examples = {"1", "2"})
10+
int foo
11+
) {
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * * Copyright 2019-2023 the original author or authors.
6+
* * * *
7+
* * * * Licensed under the Apache License, Version 2.0 (the "License");
8+
* * * * you may not use this file except in compliance with the License.
9+
* * * * You may obtain a copy of the License at
10+
* * * *
11+
* * * * https://www.apache.org/licenses/LICENSE-2.0
12+
* * * *
13+
* * * * Unless required by applicable law or agreed to in writing, software
14+
* * * * distributed under the License is distributed on an "AS IS" BASIS,
15+
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* * * * See the License for the specific language governing permissions and
17+
* * * * limitations under the License.
18+
* * *
19+
* *
20+
*
21+
*/
22+
23+
package test.org.springdoc.api.v31.app8;
24+
25+
import test.org.springdoc.api.v31.AbstractSpringDocV31Test;
26+
27+
import org.springframework.boot.autoconfigure.SpringBootApplication;
28+
29+
public class SpringDocApp8Test extends AbstractSpringDocV31Test {
30+
31+
@SpringBootApplication
32+
static class SpringDocTestApp {
33+
34+
}
35+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package test.org.springdoc.api.v31.app8;
2+
3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
5+
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
6+
7+
@Schema(description = "user info")
8+
public record UserInfo(
9+
@Schema(description = "The user's name", requiredMode = REQUIRED, examples = {"Madoka", "Homura"})
10+
String name,
11+
@Schema(description = "The user's age", requiredMode = REQUIRED, examples = {"114", "514"})
12+
int age,
13+
@Schema(description = "The user's fooBar", requiredMode = REQUIRED)
14+
FooBar fooBar
15+
) {
16+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{
2+
"openapi": "3.1.0",
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+
"/": {
15+
"get": {
16+
"tags": [
17+
"examples-controller"
18+
],
19+
"operationId": "index",
20+
"responses": {
21+
"200": {
22+
"description": "OK",
23+
"content": {
24+
"*/*": {
25+
"schema": {
26+
"$ref": "#/components/schemas/ExamplesResponse"
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
},
35+
"components": {
36+
"schemas": {
37+
"ExamplesResponse": {
38+
"properties": {
39+
"self": {
40+
"$ref": "#/components/schemas/UserInfo",
41+
"description": "self's user info"
42+
},
43+
"friend": {
44+
"$ref": "#/components/schemas/UserInfo",
45+
"deprecated": true,
46+
"description": "friend, deprecated, use friends instead"
47+
},
48+
"friends": {
49+
"type": "array",
50+
"description": "friends",
51+
"items": {
52+
"$ref": "#/components/schemas/UserInfo"
53+
}
54+
}
55+
},
56+
"required": [
57+
"self"
58+
]
59+
},
60+
"FooBar": {
61+
"deprecated": true,
62+
"description": "the foo bar",
63+
"properties": {
64+
"foo": {
65+
"type": "integer",
66+
"format": "int32",
67+
"description": "foo",
68+
"examples": [
69+
"1",
70+
"2"
71+
]
72+
}
73+
},
74+
"required": [
75+
"foo"
76+
]
77+
},
78+
"UserInfo": {
79+
"description": "user info",
80+
"properties": {
81+
"name": {
82+
"type": "string",
83+
"description": "The user's name",
84+
"examples": [
85+
"Madoka",
86+
"Homura"
87+
]
88+
},
89+
"age": {
90+
"type": "integer",
91+
"format": "int32",
92+
"description": "The user's age",
93+
"examples": [
94+
"114",
95+
"514"
96+
]
97+
},
98+
"fooBar": {
99+
"$ref": "#/components/schemas/FooBar",
100+
"description": "The user's fooBar"
101+
}
102+
},
103+
"required": [
104+
"age",
105+
"fooBar",
106+
"name"
107+
]
108+
}
109+
}
110+
}
111+
}

0 commit comments

Comments
 (0)