diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app237/OpenApiConfiguration.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app237/OpenApiConfiguration.java index 38dbb83a8..c60eb1d54 100644 --- a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app237/OpenApiConfiguration.java +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app237/OpenApiConfiguration.java @@ -1,6 +1,5 @@ package test.org.springdoc.api.v30.app237; -import io.swagger.v3.core.util.PrimitiveType; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; @@ -10,11 +9,6 @@ @Configuration public class OpenApiConfiguration { - public OpenApiConfiguration() { - // LocalTime support - PrimitiveType.enablePartialTime(); - } - private OpenAPI standardOpenApi() { String title = getClass().getPackage().getImplementationTitle(); String version = getClass().getPackage().getImplementationVersion(); diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app273/HelloController.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app273/HelloController.java new file mode 100644 index 000000000..a4eecec30 --- /dev/null +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app273/HelloController.java @@ -0,0 +1,23 @@ +package test.org.springdoc.api.v30.app273; + +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import java.time.*; + +@RestController +public class HelloController { + + @PostMapping("/time1") + public TimeDtoNoAnnotations postTime1( + @RequestBody TimeDtoNoAnnotations timeDto) { + return timeDto; + } + + public record TimeDtoNoAnnotations(LocalDateTime localDateTime, + LocalDate localDate, LocalTime localTime, + YearMonth yearMonth, MonthDay monthDay, + Year year) { + } +} \ No newline at end of file diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app273/SpringDocApp273Test.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app273/SpringDocApp273Test.java new file mode 100644 index 000000000..f3e294b34 --- /dev/null +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app273/SpringDocApp273Test.java @@ -0,0 +1,38 @@ +/* + * + * * + * * * + * * * * + * * * * * + * * * * * * Copyright 2019-2026 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.app273; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import test.org.springdoc.api.v30.AbstractSpringDocV30Test; + +public class SpringDocApp273Test extends AbstractSpringDocV30Test { + + @SpringBootApplication + static class SpringDocTestApp { + SpringDocTestApp() {} + } +} \ No newline at end of file diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app237/OpenApiConfiguration.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app237/OpenApiConfiguration.java index 0417b857e..b89d4f638 100644 --- a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app237/OpenApiConfiguration.java +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app237/OpenApiConfiguration.java @@ -1,6 +1,5 @@ package test.org.springdoc.api.v31.app237; -import io.swagger.v3.core.util.PrimitiveType; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; @@ -10,11 +9,6 @@ @Configuration public class OpenApiConfiguration { - public OpenApiConfiguration() { - // LocalTime support - PrimitiveType.enablePartialTime(); - } - private OpenAPI standardOpenApi() { String title = getClass().getPackage().getImplementationTitle(); String version = getClass().getPackage().getImplementationVersion(); diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app243/HelloController.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app243/HelloController.java index 16ea52b9a..4d9efd2ea 100644 --- a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app243/HelloController.java +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app243/HelloController.java @@ -1,11 +1,33 @@ +/* + * + * * + * * * + * * * * + * * * * * + * * * * * * Copyright 2019-2026 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.app243; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.MonthDay; -import java.time.Year; -import java.time.YearMonth; +import io.swagger.v3.oas.annotations.media.DiscriminatorMapping; +import io.swagger.v3.oas.annotations.media.Schema; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -14,15 +36,58 @@ @RestController public class HelloController { - @PostMapping("/time1") - public TimeDtoNoAnnotations postTime1( - @RequestBody TimeDtoNoAnnotations timeDto) { - return timeDto; + @PostMapping("/parent") + public void parentEndpoint(@RequestBody SuperClass parent) { + + } + +} + +@Schema(name = SuperClass.SCHEMA_NAME, + discriminatorProperty = "type", + oneOf = { + FirstChildClass.class, + SecondChildClass.class + }, + discriminatorMapping = { + @DiscriminatorMapping(value = FirstChildClass.SCHEMA_NAME, schema = FirstChildClass.class), + @DiscriminatorMapping(value = SecondChildClass.SCHEMA_NAME, schema = SecondChildClass.class) + } +) +sealed class SuperClass { + + public static final String SCHEMA_NAME = "SuperClass"; + + public String type; + + @Schema(requiredMode = Schema.RequiredMode.REQUIRED) + public String getType() { + return type; } +} + +@Schema(name = FirstChildClass.SCHEMA_NAME) +final class FirstChildClass extends SuperClass { + + public static final String SCHEMA_NAME = "Image"; + + public String type; + + @Schema(requiredMode = Schema.RequiredMode.REQUIRED) + public String getType() { + return type; + } +} + +@Schema(name = SecondChildClass.SCHEMA_NAME) +final class SecondChildClass extends SuperClass { + + public static final String SCHEMA_NAME = "Mail"; + + public String type; - public record TimeDtoNoAnnotations(LocalDateTime localDateTime, - LocalDate localDate, LocalTime localTime, - YearMonth yearMonth, MonthDay monthDay, - Year year) { + @Schema(requiredMode = Schema.RequiredMode.REQUIRED) + public String getType() { + return type; } -} \ No newline at end of file +} diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app243/SpringDocApp243Test.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app243/SpringDocApp243Test.java index 90dde88e9..85f98f124 100644 --- a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app243/SpringDocApp243Test.java +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app243/SpringDocApp243Test.java @@ -3,21 +3,19 @@ * * * * * * * * * + * * * * * Copyright 2025 the original author or authors. * * * * * - * * * * * * Copyright 2019-2026 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. + * * * * * 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. * * * * * * * * * @@ -26,9 +24,8 @@ package test.org.springdoc.api.v31.app243; -import test.org.springdoc.api.v31.AbstractSpringDocTest; - import org.springframework.boot.autoconfigure.SpringBootApplication; +import test.org.springdoc.api.v31.AbstractSpringDocTest; public class SpringDocApp243Test extends AbstractSpringDocTest { diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app273/HelloController.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app273/HelloController.java new file mode 100644 index 000000000..40c493ac2 --- /dev/null +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app273/HelloController.java @@ -0,0 +1,23 @@ +package test.org.springdoc.api.v31.app273; + +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import java.time.*; + +@RestController +public class HelloController { + + @PostMapping("/time1") + public TimeDtoNoAnnotations postTime1( + @RequestBody TimeDtoNoAnnotations timeDto) { + return timeDto; + } + + public record TimeDtoNoAnnotations(LocalDateTime localDateTime, + LocalDate localDate, LocalTime localTime, + YearMonth yearMonth, MonthDay monthDay, + Year year) { + } +} \ No newline at end of file diff --git a/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app273/SpringDocApp273Test.java b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app273/SpringDocApp273Test.java new file mode 100644 index 000000000..e6e6c4717 --- /dev/null +++ b/springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app273/SpringDocApp273Test.java @@ -0,0 +1,36 @@ +/* + * + * * + * * * + * * * * + * * * * * + * * * * * * Copyright 2019-2026 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.app273; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import test.org.springdoc.api.v31.AbstractSpringDocTest; + +public class SpringDocApp273Test extends AbstractSpringDocTest { + + @SpringBootApplication + static class SpringDocTestApp {} +} \ No newline at end of file diff --git a/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app273.json b/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app273.json new file mode 100644 index 000000000..4577c20d8 --- /dev/null +++ b/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app273.json @@ -0,0 +1,71 @@ +{ + "openapi" : "3.0.1", + "info" : { + "title" : "OpenAPI definition", + "version" : "v0" + }, + "servers" : [ { + "url" : "http://localhost", + "description" : "Generated server url" + } ], + "paths" : { + "/time1" : { + "post" : { + "tags" : [ "hello-controller" ], + "operationId" : "postTime1", + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/TimeDtoNoAnnotations" + } + } + }, + "required" : true + }, + "responses" : { + "200" : { + "description" : "OK", + "content" : { + "*/*" : { + "schema" : { + "$ref" : "#/components/schemas/TimeDtoNoAnnotations" + } + } + } + } + } + } + } + }, + "components" : { + "schemas" : { + "TimeDtoNoAnnotations" : { + "type" : "object", + "properties" : { + "localDateTime" : { + "type" : "string", + "format" : "date-time" + }, + "localDate" : { + "type" : "string", + "format" : "date" + }, + "localTime" : { + "type" : "string", + "format" : "time-local" + }, + "yearMonth" : { + "type" : "string" + }, + "monthDay" : { + "type" : "string" + }, + "year" : { + "type" : "string" + } + } + } + } + } +} \ No newline at end of file diff --git a/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app243.json b/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app243.json index 444a30ca9..f0d023dba 100644 --- a/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app243.json +++ b/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app243.json @@ -1,75 +1,77 @@ { - "openapi": "3.1.0", - "info": { - "title": "OpenAPI definition", - "version": "v0" + "openapi" : "3.1.0", + "info" : { + "title" : "OpenAPI definition", + "version" : "v0" }, - "servers": [ - { - "url": "http://localhost", - "description": "Generated server url" - } - ], - "paths": { - "/time1": { - "post": { - "tags": [ - "hello-controller" - ], - "operationId": "postTime1", - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/TimeDtoNoAnnotations" + "servers" : [ { + "url" : "http://localhost", + "description" : "Generated server url" + } ], + "paths" : { + "/parent" : { + "post" : { + "tags" : [ "hello-controller" ], + "operationId" : "parentEndpoint", + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/SuperClass" } } }, - "required": true + "required" : true }, - "responses": { - "200": { - "description": "OK", - "content": { - "*/*": { - "schema": { - "$ref": "#/components/schemas/TimeDtoNoAnnotations" - } - } - } + "responses" : { + "200" : { + "description" : "OK" } } } } }, - "components": { - "schemas": { - "TimeDtoNoAnnotations": { - "type": "object", - "properties": { - "localDateTime": { - "type": "string", - "format": "date-time" - }, - "localDate": { - "type": "string", - "format": "date" - }, - "localTime": { - "type": "string", - "format": "partial-time" - }, - "yearMonth": { - "type": "string" - }, - "monthDay": { - "type": "string" - }, - "year": { - "type": "string" + "components" : { + "schemas" : { + "Image" : { + "type" : "object", + "properties" : { + "type" : { + "type" : "string" } - } + }, + "required" : [ "type" ] + }, + "Mail" : { + "type" : "object", + "properties" : { + "type" : { + "type" : "string" + } + }, + "required" : [ "type" ] + }, + "SuperClass" : { + "type" : "object", + "discriminator" : { + "propertyName" : "type", + "mapping" : { + "Image" : "#/components/schemas/Image", + "Mail" : "#/components/schemas/Mail" + } + }, + "oneOf" : [ { + "$ref" : "#/components/schemas/Image" + }, { + "$ref" : "#/components/schemas/Mail" + } ], + "properties" : { + "type" : { + "type" : "string" + } + }, + "required" : [ "type" ] } } } -} +} \ No newline at end of file diff --git a/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app273.json b/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app273.json new file mode 100644 index 000000000..41f05c1f6 --- /dev/null +++ b/springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app273.json @@ -0,0 +1,71 @@ +{ + "openapi" : "3.1.0", + "info" : { + "title" : "OpenAPI definition", + "version" : "v0" + }, + "servers" : [ { + "url" : "http://localhost", + "description" : "Generated server url" + } ], + "paths" : { + "/time1" : { + "post" : { + "tags" : [ "hello-controller" ], + "operationId" : "postTime1", + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/TimeDtoNoAnnotations" + } + } + }, + "required" : true + }, + "responses" : { + "200" : { + "description" : "OK", + "content" : { + "*/*" : { + "schema" : { + "$ref" : "#/components/schemas/TimeDtoNoAnnotations" + } + } + } + } + } + } + } + }, + "components" : { + "schemas" : { + "TimeDtoNoAnnotations" : { + "type" : "object", + "properties" : { + "localDateTime" : { + "type" : "string", + "format" : "date-time" + }, + "localDate" : { + "type" : "string", + "format" : "date" + }, + "localTime" : { + "type" : "string", + "format" : "time-local" + }, + "yearMonth" : { + "type" : "string" + }, + "monthDay" : { + "type" : "string" + }, + "year" : { + "type" : "string" + } + } + } + } + } +} \ No newline at end of file