From 5101b910c85762ba4280991308bda9723776e076 Mon Sep 17 00:00:00 2001 From: ZHAO JinXiang Date: Mon, 21 Aug 2023 21:55:24 +0800 Subject: [PATCH] Add more test for OpenAPI Specification v3.1 --- .../api/v31/app8/ExamplesController.java | 35 ++++++ .../api/v31/app8/ExamplesResponse.java | 19 +++ .../org/springdoc/api/v31/app8/FooBar.java | 12 ++ .../api/v31/app8/SpringDocApp8Test.java | 35 ++++++ .../org/springdoc/api/v31/app8/UserInfo.java | 16 +++ .../test/resources/results/3.1.0/app8.json | 111 ++++++++++++++++++ 6 files changed, 228 insertions(+) create mode 100644 springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/ExamplesController.java create mode 100644 springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/ExamplesResponse.java create mode 100644 springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/FooBar.java create mode 100644 springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/SpringDocApp8Test.java create mode 100644 springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/UserInfo.java create mode 100644 springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app8.json diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/ExamplesController.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/ExamplesController.java new file mode 100644 index 000000000..7cdfc6811 --- /dev/null +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/ExamplesController.java @@ -0,0 +1,35 @@ +/* + * + * * + * * * + * * * * Copyright 2019-2023 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.v31.app8; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class ExamplesController { + + @GetMapping(value = "/") + public ExamplesResponse index() { + return null; + } +} diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/ExamplesResponse.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/ExamplesResponse.java new file mode 100644 index 000000000..8bbb89fee --- /dev/null +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/ExamplesResponse.java @@ -0,0 +1,19 @@ +package test.org.springdoc.api.v31.app8; + +import io.swagger.v3.oas.annotations.media.Schema; + +import java.util.List; + +import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.NOT_REQUIRED; +import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; + +public record ExamplesResponse( + @Schema(description = "self's user info", requiredMode = REQUIRED) + UserInfo self, + @Schema(description = "friend, deprecated, use friends instead", requiredMode = NOT_REQUIRED) + @Deprecated + UserInfo friend, + @Schema(description = "friends", requiredMode = NOT_REQUIRED) + List friends +) { +} diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/FooBar.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/FooBar.java new file mode 100644 index 000000000..58b43ae94 --- /dev/null +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/FooBar.java @@ -0,0 +1,12 @@ +package test.org.springdoc.api.v31.app8; + +import io.swagger.v3.oas.annotations.media.Schema; + +import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; + +@Schema(description = "the foo bar", deprecated = true) +public record FooBar( + @Schema(description = "foo", requiredMode = REQUIRED, examples = {"1", "2"}) + int foo +) { +} diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/SpringDocApp8Test.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/SpringDocApp8Test.java new file mode 100644 index 000000000..5864b1d8c --- /dev/null +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/SpringDocApp8Test.java @@ -0,0 +1,35 @@ +/* + * + * * + * * * + * * * * Copyright 2019-2023 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.v31.app8; + +import test.org.springdoc.api.v31.AbstractSpringDocV31Test; + +import org.springframework.boot.autoconfigure.SpringBootApplication; + +public class SpringDocApp8Test extends AbstractSpringDocV31Test { + + @SpringBootApplication + static class SpringDocTestApp { + + } +} diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/UserInfo.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/UserInfo.java new file mode 100644 index 000000000..66174b8cf --- /dev/null +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app8/UserInfo.java @@ -0,0 +1,16 @@ +package test.org.springdoc.api.v31.app8; + +import io.swagger.v3.oas.annotations.media.Schema; + +import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; + +@Schema(description = "user info") +public record UserInfo( + @Schema(description = "The user's name", requiredMode = REQUIRED, examples = {"Madoka", "Homura"}) + String name, + @Schema(description = "The user's age", requiredMode = REQUIRED, examples = {"114", "514"}) + int age, + @Schema(description = "The user's fooBar", requiredMode = REQUIRED) + FooBar fooBar +) { +} diff --git a/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app8.json b/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app8.json new file mode 100644 index 000000000..8bc72ac52 --- /dev/null +++ b/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app8.json @@ -0,0 +1,111 @@ +{ + "openapi": "3.1.0", + "info": { + "title": "OpenAPI definition", + "version": "v0" + }, + "servers": [ + { + "url": "http://localhost", + "description": "Generated server url" + } + ], + "paths": { + "/": { + "get": { + "tags": [ + "examples-controller" + ], + "operationId": "index", + "responses": { + "200": { + "description": "OK", + "content": { + "*/*": { + "schema": { + "$ref": "#/components/schemas/ExamplesResponse" + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "ExamplesResponse": { + "properties": { + "self": { + "$ref": "#/components/schemas/UserInfo", + "description": "self's user info" + }, + "friend": { + "$ref": "#/components/schemas/UserInfo", + "deprecated": true, + "description": "friend, deprecated, use friends instead" + }, + "friends": { + "type": "array", + "description": "friends", + "items": { + "$ref": "#/components/schemas/UserInfo" + } + } + }, + "required": [ + "self" + ] + }, + "FooBar": { + "deprecated": true, + "description": "the foo bar", + "properties": { + "foo": { + "type": "integer", + "format": "int32", + "description": "foo", + "examples": [ + "1", + "2" + ] + } + }, + "required": [ + "foo" + ] + }, + "UserInfo": { + "description": "user info", + "properties": { + "name": { + "type": "string", + "description": "The user's name", + "examples": [ + "Madoka", + "Homura" + ] + }, + "age": { + "type": "integer", + "format": "int32", + "description": "The user's age", + "examples": [ + "114", + "514" + ] + }, + "fooBar": { + "$ref": "#/components/schemas/FooBar", + "description": "The user's fooBar" + } + }, + "required": [ + "age", + "fooBar", + "name" + ] + } + } + } +}