From 07f4264000d2af8f482cda9f69fe1417b47d3616 Mon Sep 17 00:00:00 2001 From: dabdirb Date: Tue, 16 Dec 2025 16:58:09 +0800 Subject: [PATCH 1/6] fix #22492 [BUG][JAVA][MAVEN] Lombok @Getter disables validation and #19743 #18794 #17793 #17606 --- bin/configs/spring-boot-lombok-data.yaml | 4 + .../JavaSpring/lombokAnnotation.mustache | 38 + .../main/resources/JavaSpring/pojo.mustache | 18 +- .../.openapi-generator/FILES | 7 - .../petstore/springboot-lombok-data/README.md | 34 +- .../petstore/springboot-lombok-data/pom.xml | 45 +- .../OpenApiGeneratorApplication.java | 30 - .../org/openapitools/RFC3339DateFormat.java | 38 - .../java/org/openapitools/api/ApiUtil.java | 2 +- .../java/org/openapitools/api/PetApi.java | 148 +-- .../java/org/openapitools/api/StoreApi.java | 69 +- .../java/org/openapitools/api/UserApi.java | 83 +- .../configuration/HomeController.java | 20 - .../configuration/SpringDocConfiguration.java | 43 - .../java/org/openapitools/model/Category.java | 12 +- .../openapitools/model/ModelApiResponse.java | 15 +- .../java/org/openapitools/model/Order.java | 26 +- .../main/java/org/openapitools/model/Pet.java | 28 +- .../main/java/org/openapitools/model/Tag.java | 12 +- .../java/org/openapitools/model/User.java | 30 +- .../src/main/resources/application.properties | 3 - .../src/main/resources/openapi.yaml | 909 ------------------ 22 files changed, 245 insertions(+), 1369 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache delete mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/OpenApiGeneratorApplication.java delete mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/RFC3339DateFormat.java delete mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/configuration/HomeController.java delete mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/configuration/SpringDocConfiguration.java delete mode 100644 samples/server/petstore/springboot-lombok-data/src/main/resources/application.properties delete mode 100644 samples/server/petstore/springboot-lombok-data/src/main/resources/openapi.yaml diff --git a/bin/configs/spring-boot-lombok-data.yaml b/bin/configs/spring-boot-lombok-data.yaml index 57f54d71d3db..53b18feb535f 100644 --- a/bin/configs/spring-boot-lombok-data.yaml +++ b/bin/configs/spring-boot-lombok-data.yaml @@ -9,3 +9,7 @@ additionalProperties: additionalModelTypeAnnotations: "@lombok.Data;@lombok.Builder;@lombok.NoArgsConstructor;@lombok.AllArgsConstructor" generateConstructorWithAllArgs: true generateBuilders: true + useSpringBoot3: true + skipDefaultInterface: true + interfaceOnly: true + performBeanValidation: true, diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache new file mode 100644 index 000000000000..78e6a99613c7 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache @@ -0,0 +1,38 @@ +{{#lombok.RequiredArgsConstructor}} + {{^useBeanValidation}} + {{#required}} + @lombok.NonNull + {{/required}} + {{/useBeanValidation}} +{{/lombok.RequiredArgsConstructor}} +{{#lombok.ToString}} + {{#isPassword}} + @lombok.ToString.Exclude + {{/isPassword}} +{{/lombok.ToString}} +{{#lombok.Data}} + {{#isPassword}} + @lombok.ToString.Exclude + {{/isPassword}} + {{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} + {{^useBeanValidation}} + {{#required}} + @lombok.NonNull + {{/required}} + {{/useBeanValidation}} + {{#swagger2AnnotationLibrary}}@Schema(name = "{{{baseName}}}"{{#isReadOnly}}, accessMode = Schema.AccessMode.READ_ONLY{{/isReadOnly}}{{#example}}, example = "{{{.}}}"{{/example}}{{#description}}, description = "{{{.}}}"{{/description}}{{#deprecated}}, deprecated = true{{/deprecated}}, requiredMode = {{#required}}Schema.RequiredMode.REQUIRED{{/required}}{{^required}}Schema.RequiredMode.NOT_REQUIRED{{/required}}) + {{/swagger2AnnotationLibrary}} + {{#jackson}}@JsonProperty("{{baseName}}") + {{#withXml}} + @JacksonXmlProperty(localName = "{{items.xmlName}}{{^items.xmlName}}{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}{{/items.xmlName}}"{{#isXmlAttribute}}, isAttribute = true{{/isXmlAttribute}}{{#xmlNamespace}}, namespace = "{{.}}"{{/xmlNamespace}}) + {{#isContainer}} + @JacksonXmlElementWrapper({{#isXmlWrapped}}localName = "{{xmlName}}{{^xmlName}}{{baseName}}{{/xmlName}}", {{#xmlNamespace}}namespace = "{{.}}", {{/xmlNamespace}}{{/isXmlWrapped}}useWrapping = {{isXmlWrapped}}) + {{/isContainer}} + {{/withXml}} + {{/jackson}} +{{/lombok.Data}} +{{#lombok.Builder}} + {{#defaultValue}} + @lombok.Builder.Default + {{/defaultValue}} +{{/lombok.Builder}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache index ae13cc1f3633..d3334093b93f 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache @@ -57,26 +57,10 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}} {{#gson}} @SerializedName("{{baseName}}") {{/gson}} - {{#lombok.RequiredArgsConstructor}} - {{^useBeanValidation}} - {{#required}} - @lombok.NonNull - {{/required}} - {{/useBeanValidation}} - {{/lombok.RequiredArgsConstructor}} - {{#lombok.ToString}} - {{#isPassword}} - @lombok.ToString.Exclude - {{/isPassword}} - {{/lombok.ToString}} +{{>lombokAnnotation}} {{#vendorExtensions.x-field-extra-annotation}} {{{.}}} {{/vendorExtensions.x-field-extra-annotation}} - {{#lombok.Builder}} - {{#defaultValue}} - @lombok.Builder.Default - {{/defaultValue}} - {{/lombok.Builder}} {{#deprecated}} @Deprecated {{/deprecated}} diff --git a/samples/server/petstore/springboot-lombok-data/.openapi-generator/FILES b/samples/server/petstore/springboot-lombok-data/.openapi-generator/FILES index b15e2c45d45d..87837793235c 100644 --- a/samples/server/petstore/springboot-lombok-data/.openapi-generator/FILES +++ b/samples/server/petstore/springboot-lombok-data/.openapi-generator/FILES @@ -1,19 +1,12 @@ README.md pom.xml -src/main/java/org/openapitools/OpenApiGeneratorApplication.java -src/main/java/org/openapitools/RFC3339DateFormat.java src/main/java/org/openapitools/api/ApiUtil.java src/main/java/org/openapitools/api/PetApi.java src/main/java/org/openapitools/api/StoreApi.java src/main/java/org/openapitools/api/UserApi.java -src/main/java/org/openapitools/configuration/HomeController.java -src/main/java/org/openapitools/configuration/SpringDocConfiguration.java src/main/java/org/openapitools/model/Category.java src/main/java/org/openapitools/model/ModelApiResponse.java src/main/java/org/openapitools/model/Order.java src/main/java/org/openapitools/model/Pet.java src/main/java/org/openapitools/model/Tag.java src/main/java/org/openapitools/model/User.java -src/main/resources/application.properties -src/main/resources/openapi.yaml -src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java diff --git a/samples/server/petstore/springboot-lombok-data/README.md b/samples/server/petstore/springboot-lombok-data/README.md index 5cd22b6081a2..d43a1de307df 100644 --- a/samples/server/petstore/springboot-lombok-data/README.md +++ b/samples/server/petstore/springboot-lombok-data/README.md @@ -1,21 +1,27 @@ -# OpenAPI generated server -Spring Boot Server +# OpenAPI generated API stub -## Overview -This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. -By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub. -This is an example of building a OpenAPI-enabled server in Java using the SpringBoot framework. +Spring Framework stub -The underlying library integrating OpenAPI to Spring Boot is [springdoc](https://springdoc.org). -Springdoc will generate an OpenAPI v3 specification based on the generated Controller and Model classes. -The specification is available to download using the following url: -http://localhost:8080/v3/api-docs/ +## Overview +This code was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. +By using the [OpenAPI-Spec](https://openapis.org), you can easily generate an API stub. +This is an example of building API stub interfaces in Java using the Spring framework. -Start your server as a simple java application +The stubs generated can be used in your existing Spring-MVC or Spring-Boot application to create controller endpoints +by adding ```@Controller``` classes that implement the interface. Eg: +```java +@Controller +public class PetController implements PetApi { +// implement all PetApi methods +} +``` -You can view the api documentation in swagger-ui by pointing to -http://localhost:8080/swagger-ui.html +You can also use the interface to create [Spring-Cloud Feign clients](http://projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-feign-inheritance).Eg: +```java +@FeignClient(name="pet", url="http://petstore.swagger.io/v2") +public interface PetClient extends PetApi { -Change default port value in application.properties \ No newline at end of file +} +``` diff --git a/samples/server/petstore/springboot-lombok-data/pom.xml b/samples/server/petstore/springboot-lombok-data/pom.xml index 654fff511ba1..5ab5b9e5b37a 100644 --- a/samples/server/petstore/springboot-lombok-data/pom.xml +++ b/samples/server/petstore/springboot-lombok-data/pom.xml @@ -6,33 +6,48 @@ springboot-lombok-data 1.0.0 - 1.8 + 17 ${java.version} ${java.version} UTF-8 - 1.6.14 - 5.3.1 + 2.6.0 + 5.17.14 org.springframework.boot spring-boot-starter-parent - 2.7.15 + 3.1.3 + + + + repository.spring.milestone + Spring Milestone Repository + https://repo.spring.io/milestone + + + + + spring-milestones + https://repo.spring.io/milestone + + + src/main/java - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + @@ -48,7 +63,7 @@ org.springdoc - springdoc-openapi-ui + springdoc-openapi-starter-webmvc-ui ${springdoc.version} diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/OpenApiGeneratorApplication.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/OpenApiGeneratorApplication.java deleted file mode 100644 index 97252a8a9402..000000000000 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/OpenApiGeneratorApplication.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.openapitools; - -import com.fasterxml.jackson.databind.Module; -import org.openapitools.jackson.nullable.JsonNullableModule; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.FilterType; -import org.springframework.context.annotation.FullyQualifiedAnnotationBeanNameGenerator; - -@SpringBootApplication( - nameGenerator = FullyQualifiedAnnotationBeanNameGenerator.class -) -@ComponentScan( - basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"}, - nameGenerator = FullyQualifiedAnnotationBeanNameGenerator.class -) -public class OpenApiGeneratorApplication { - - public static void main(String[] args) { - SpringApplication.run(OpenApiGeneratorApplication.class, args); - } - - @Bean(name = "org.openapitools.OpenApiGeneratorApplication.jsonNullableModule") - public Module jsonNullableModule() { - return new JsonNullableModule(); - } - -} \ No newline at end of file diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/RFC3339DateFormat.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/RFC3339DateFormat.java deleted file mode 100644 index bcd3936d8b34..000000000000 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/RFC3339DateFormat.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.openapitools; - -import com.fasterxml.jackson.databind.util.StdDateFormat; - -import java.text.DateFormat; -import java.text.FieldPosition; -import java.text.ParsePosition; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.TimeZone; - -public class RFC3339DateFormat extends DateFormat { - private static final long serialVersionUID = 1L; - private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC"); - - private final StdDateFormat fmt = new StdDateFormat() - .withTimeZone(TIMEZONE_Z) - .withColonInTimeZone(true); - - public RFC3339DateFormat() { - this.calendar = new GregorianCalendar(); - } - - @Override - public Date parse(String source, ParsePosition pos) { - return fmt.parse(source, pos); - } - - @Override - public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { - return fmt.format(date, toAppendTo, fieldPosition); - } - - @Override - public Object clone() { - return this; - } -} \ No newline at end of file diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/ApiUtil.java index 1245b1dd0ccf..9bcd4f230ed3 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/ApiUtil.java @@ -2,7 +2,7 @@ import org.springframework.web.context.request.NativeWebRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; public class ApiUtil { diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApi.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApi.java index b621137c4a58..4491ffd52138 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApi.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApi.java @@ -20,30 +20,23 @@ import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.media.ExampleObject; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.multipart.MultipartFile; -import javax.validation.Valid; -import javax.validation.constraints.*; +import jakarta.validation.Valid; +import jakarta.validation.constraints.*; import java.util.List; import java.util.Map; import java.util.Optional; -import javax.annotation.Generated; +import jakarta.annotation.Generated; @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") @Validated @Tag(name = "pet", description = "Everything about your Pets") public interface PetApi { - default Optional getRequest() { - return Optional.empty(); - } - String PATH_ADD_PET = "/pet"; /** * POST /pet : Add a new pet to the store @@ -75,26 +68,9 @@ default Optional getRequest() { produces = { "application/xml", "application/json" }, consumes = { "application/json", "application/xml" } ) - default ResponseEntity addPet( + ResponseEntity addPet( @Parameter(name = "Pet", description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody Pet pet - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { - String exampleString = " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou "; - ApiUtil.setExampleResponse(request, "application/xml", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); String PATH_DELETE_PET = "/pet/{petId}"; @@ -122,13 +98,10 @@ default ResponseEntity addPet( method = RequestMethod.DELETE, value = PetApi.PATH_DELETE_PET ) - default ResponseEntity deletePet( + ResponseEntity deletePet( @NotNull @Parameter(name = "petId", description = "Pet id to delete", required = true, in = ParameterIn.PATH) @PathVariable("petId") Long petId, @Parameter(name = "api_key", description = "", in = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) @Nullable String apiKey - ) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); String PATH_FIND_PETS_BY_STATUS = "/pet/findByStatus"; @@ -161,26 +134,9 @@ default ResponseEntity deletePet( value = PetApi.PATH_FIND_PETS_BY_STATUS, produces = { "application/xml", "application/json" } ) - default ResponseEntity> findPetsByStatus( + ResponseEntity> findPetsByStatus( @NotNull @Parameter(name = "status", deprecated = true, description = "Status values that need to be considered for filter", required = true, in = ParameterIn.QUERY) @Valid @RequestParam(value = "status", required = true) @Deprecated List status - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "[ { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }, { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" } ]"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { - String exampleString = " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou "; - ApiUtil.setExampleResponse(request, "application/xml", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); String PATH_FIND_PETS_BY_TAGS = "/pet/findByTags"; @@ -216,26 +172,9 @@ default ResponseEntity> findPetsByStatus( value = PetApi.PATH_FIND_PETS_BY_TAGS, produces = { "application/xml", "application/json" } ) - default ResponseEntity> findPetsByTags( + ResponseEntity> findPetsByTags( @NotNull @Parameter(name = "tags", description = "Tags to filter by", required = true, in = ParameterIn.QUERY) @Valid @RequestParam(value = "tags", required = true) List tags - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "[ { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }, { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" } ]"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { - String exampleString = " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou "; - ApiUtil.setExampleResponse(request, "application/xml", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); String PATH_GET_PET_BY_ID = "/pet/{petId}"; @@ -270,26 +209,9 @@ default ResponseEntity> findPetsByTags( value = PetApi.PATH_GET_PET_BY_ID, produces = { "application/xml", "application/json" } ) - default ResponseEntity getPetById( + ResponseEntity getPetById( @NotNull @Parameter(name = "petId", description = "ID of pet to return", required = true, in = ParameterIn.PATH) @PathVariable("petId") Long petId - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { - String exampleString = " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou "; - ApiUtil.setExampleResponse(request, "application/xml", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); String PATH_UPDATE_PET = "/pet"; @@ -330,26 +252,9 @@ default ResponseEntity getPetById( produces = { "application/xml", "application/json" }, consumes = { "application/json", "application/xml" } ) - default ResponseEntity updatePet( + ResponseEntity updatePet( @Parameter(name = "Pet", description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody Pet pet - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { - String exampleString = " 123456789 doggie aeiou aeiou "; - ApiUtil.setExampleResponse(request, "application/xml", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); String PATH_UPDATE_PET_WITH_FORM = "/pet/{petId}"; @@ -379,14 +284,11 @@ default ResponseEntity updatePet( value = PetApi.PATH_UPDATE_PET_WITH_FORM, consumes = { "application/x-www-form-urlencoded" } ) - default ResponseEntity updatePetWithForm( + ResponseEntity updatePetWithForm( @NotNull @Parameter(name = "petId", description = "ID of pet that needs to be updated", required = true, in = ParameterIn.PATH) @PathVariable("petId") Long petId, @Parameter(name = "name", description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) String name, @Parameter(name = "status", description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) String status - ) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); String PATH_UPLOAD_FILE = "/pet/{petId}/uploadImage"; @@ -419,22 +321,10 @@ default ResponseEntity updatePetWithForm( produces = { "application/json" }, consumes = { "multipart/form-data" } ) - default ResponseEntity uploadFile( + ResponseEntity uploadFile( @NotNull @Parameter(name = "petId", description = "ID of pet to update", required = true, in = ParameterIn.PATH) @PathVariable("petId") Long petId, @Parameter(name = "additionalMetadata", description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) String additionalMetadata, @Parameter(name = "file", description = "file to upload") @RequestPart(value = "file", required = false) MultipartFile file - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"code\" : 0, \"type\" : \"type\", \"message\" : \"message\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); } diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApi.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApi.java index 9940dd598cd0..86fc7be9efa0 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApi.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApi.java @@ -19,30 +19,23 @@ import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.media.ExampleObject; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.multipart.MultipartFile; -import javax.validation.Valid; -import javax.validation.constraints.*; +import jakarta.validation.Valid; +import jakarta.validation.constraints.*; import java.util.List; import java.util.Map; import java.util.Optional; -import javax.annotation.Generated; +import jakarta.annotation.Generated; @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") @Validated @Tag(name = "store", description = "Access to Petstore orders") public interface StoreApi { - default Optional getRequest() { - return Optional.empty(); - } - String PATH_DELETE_ORDER = "/store/order/{orderId}"; /** * DELETE /store/order/{orderId} : Delete purchase order by ID @@ -66,12 +59,9 @@ default Optional getRequest() { method = RequestMethod.DELETE, value = StoreApi.PATH_DELETE_ORDER ) - default ResponseEntity deleteOrder( + ResponseEntity deleteOrder( @NotNull @Parameter(name = "orderId", description = "ID of the order that needs to be deleted", required = true, in = ParameterIn.PATH) @PathVariable("orderId") String orderId - ) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); String PATH_GET_INVENTORY = "/store/inventory"; @@ -100,12 +90,9 @@ default ResponseEntity deleteOrder( value = StoreApi.PATH_GET_INVENTORY, produces = { "application/json" } ) - default ResponseEntity> getInventory( + ResponseEntity> getInventory( - ) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); String PATH_GET_ORDER_BY_ID = "/store/order/{orderId}"; @@ -137,26 +124,9 @@ default ResponseEntity> getInventory( value = StoreApi.PATH_GET_ORDER_BY_ID, produces = { "application/xml", "application/json" } ) - default ResponseEntity getOrderById( + ResponseEntity getOrderById( @NotNull @Min(value = 1L) @Max(value = 5L) @Parameter(name = "orderId", description = "ID of pet that needs to be fetched", required = true, in = ParameterIn.PATH) @PathVariable("orderId") Long orderId - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { - String exampleString = " 123456789 123456789 123 2000-01-23T04:56:07.000Z aeiou true "; - ApiUtil.setExampleResponse(request, "application/xml", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); String PATH_PLACE_ORDER = "/store/order"; @@ -187,25 +157,8 @@ default ResponseEntity getOrderById( produces = { "application/xml", "application/json" }, consumes = { "application/json" } ) - default ResponseEntity placeOrder( + ResponseEntity placeOrder( @Parameter(name = "Order", description = "order placed for purchasing the pet", required = true) @Valid @RequestBody Order order - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { - String exampleString = " 123456789 123456789 123 2000-01-23T04:56:07.000Z aeiou true "; - ApiUtil.setExampleResponse(request, "application/xml", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); } diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApi.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApi.java index 533c83ec756c..c43fd8747c42 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApi.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApi.java @@ -19,30 +19,23 @@ import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.media.ExampleObject; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.multipart.MultipartFile; -import javax.validation.Valid; -import javax.validation.constraints.*; +import jakarta.validation.Valid; +import jakarta.validation.constraints.*; import java.util.List; import java.util.Map; import java.util.Optional; -import javax.annotation.Generated; +import jakarta.annotation.Generated; @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") @Validated @Tag(name = "user", description = "Operations about user") public interface UserApi { - default Optional getRequest() { - return Optional.empty(); - } - String PATH_CREATE_USER = "/user"; /** * POST /user : Create user @@ -68,12 +61,9 @@ default Optional getRequest() { value = UserApi.PATH_CREATE_USER, consumes = { "application/json" } ) - default ResponseEntity createUser( + ResponseEntity createUser( @Parameter(name = "User", description = "Created user object", required = true) @Valid @RequestBody User user - ) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); String PATH_CREATE_USERS_WITH_ARRAY_INPUT = "/user/createWithArray"; @@ -101,12 +91,9 @@ default ResponseEntity createUser( value = UserApi.PATH_CREATE_USERS_WITH_ARRAY_INPUT, consumes = { "application/json" } ) - default ResponseEntity createUsersWithArrayInput( + ResponseEntity createUsersWithArrayInput( @Parameter(name = "User", description = "List of user object", required = true) @Valid @RequestBody List<@Valid User> user - ) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); String PATH_CREATE_USERS_WITH_LIST_INPUT = "/user/createWithList"; @@ -134,12 +121,9 @@ default ResponseEntity createUsersWithArrayInput( value = UserApi.PATH_CREATE_USERS_WITH_LIST_INPUT, consumes = { "application/json" } ) - default ResponseEntity createUsersWithListInput( + ResponseEntity createUsersWithListInput( @Parameter(name = "User", description = "List of user object", required = true) @Valid @RequestBody List<@Valid User> user - ) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); String PATH_DELETE_USER = "/user/{username}"; @@ -168,12 +152,9 @@ default ResponseEntity createUsersWithListInput( method = RequestMethod.DELETE, value = UserApi.PATH_DELETE_USER ) - default ResponseEntity deleteUser( + ResponseEntity deleteUser( @NotNull @Parameter(name = "username", description = "The name that needs to be deleted", required = true, in = ParameterIn.PATH) @PathVariable("username") String username - ) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); String PATH_GET_USER_BY_NAME = "/user/{username}"; @@ -205,26 +186,9 @@ default ResponseEntity deleteUser( value = UserApi.PATH_GET_USER_BY_NAME, produces = { "application/xml", "application/json" } ) - default ResponseEntity getUserByName( + ResponseEntity getUserByName( @NotNull @Parameter(name = "username", description = "The name that needs to be fetched. Use user1 for testing.", required = true, in = ParameterIn.PATH) @PathVariable("username") String username - ) { - getRequest().ifPresent(request -> { - for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { - if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { - String exampleString = "{ \"firstName\" : \"firstName\", \"lastName\" : \"lastName\", \"password\" : \"password\", \"userStatus\" : 6, \"phone\" : \"phone\", \"id\" : 0, \"email\" : \"email\", \"username\" : \"username\" }"; - ApiUtil.setExampleResponse(request, "application/json", exampleString); - break; - } - if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { - String exampleString = " 123456789 aeiou aeiou aeiou aeiou aeiou aeiou 123 "; - ApiUtil.setExampleResponse(request, "application/xml", exampleString); - break; - } - } - }); - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); String PATH_LOGIN_USER = "/user/login"; @@ -255,13 +219,10 @@ default ResponseEntity getUserByName( value = UserApi.PATH_LOGIN_USER, produces = { "application/xml", "application/json" } ) - default ResponseEntity loginUser( + ResponseEntity loginUser( @NotNull @Pattern(regexp = "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Parameter(name = "username", description = "The user name for login", required = true, in = ParameterIn.QUERY) @Valid @RequestParam(value = "username", required = true) String username, @NotNull @Parameter(name = "password", description = "The password for login in clear text", required = true, in = ParameterIn.QUERY) @Valid @RequestParam(value = "password", required = true) String password - ) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); String PATH_LOGOUT_USER = "/user/logout"; @@ -287,12 +248,9 @@ default ResponseEntity loginUser( method = RequestMethod.GET, value = UserApi.PATH_LOGOUT_USER ) - default ResponseEntity logoutUser( + ResponseEntity logoutUser( - ) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); String PATH_UPDATE_USER = "/user/{username}"; @@ -323,12 +281,9 @@ default ResponseEntity logoutUser( value = UserApi.PATH_UPDATE_USER, consumes = { "application/json" } ) - default ResponseEntity updateUser( + ResponseEntity updateUser( @NotNull @Parameter(name = "username", description = "name that need to be deleted", required = true, in = ParameterIn.PATH) @PathVariable("username") String username, @Parameter(name = "User", description = "Updated user object", required = true) @Valid @RequestBody User user - ) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - - } + ); } diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/configuration/HomeController.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/configuration/HomeController.java deleted file mode 100644 index 9aa29284ab5f..000000000000 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/configuration/HomeController.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.openapitools.configuration; - -import org.springframework.context.annotation.Bean; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.GetMapping; - -/** - * Home redirection to OpenAPI api documentation - */ -@Controller -public class HomeController { - - @RequestMapping("/") - public String index() { - return "redirect:swagger-ui.html"; - } - -} \ No newline at end of file diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/configuration/SpringDocConfiguration.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/configuration/SpringDocConfiguration.java deleted file mode 100644 index 2ea502c445ae..000000000000 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/configuration/SpringDocConfiguration.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.openapitools.configuration; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.oas.models.info.Info; -import io.swagger.v3.oas.models.info.Contact; -import io.swagger.v3.oas.models.info.License; -import io.swagger.v3.oas.models.Components; -import io.swagger.v3.oas.models.security.SecurityScheme; - -@Configuration -public class SpringDocConfiguration { - - @Bean(name = "org.openapitools.configuration.SpringDocConfiguration.apiInfo") - OpenAPI apiInfo() { - return new OpenAPI() - .info( - new Info() - .title("OpenAPI Petstore") - .description("This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.") - .license( - new License() - .name("Apache-2.0") - .url("https://www.apache.org/licenses/LICENSE-2.0.html") - ) - .version("1.0.0") - ) - .components( - new Components() - .addSecuritySchemes("petstore_auth", new SecurityScheme() - .type(SecurityScheme.Type.OAUTH2) - ) - .addSecuritySchemes("api_key", new SecurityScheme() - .type(SecurityScheme.Type.APIKEY) - .in(SecurityScheme.In.HEADER) - .name("api_key") - ) - ) - ; - } -} \ No newline at end of file diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java index 0754bcc4bf93..5a0296bb50fe 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java @@ -7,13 +7,13 @@ import org.springframework.lang.Nullable; import org.openapitools.jackson.nullable.JsonNullable; import java.time.OffsetDateTime; -import javax.validation.Valid; -import javax.validation.constraints.*; +import jakarta.validation.Valid; +import jakarta.validation.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; import java.util.*; -import javax.annotation.Generated; +import jakarta.annotation.Generated; /** * A category for a pet @@ -27,8 +27,14 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class Category { + + @Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("id") private @Nullable Long id; + @Pattern(regexp = "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") + @Schema(name = "name", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("name") private @Nullable String name; } diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java index f7d904b5ab7e..56f7f0aa0d36 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java @@ -8,13 +8,13 @@ import org.springframework.lang.Nullable; import org.openapitools.jackson.nullable.JsonNullable; import java.time.OffsetDateTime; -import javax.validation.Valid; -import javax.validation.constraints.*; +import jakarta.validation.Valid; +import jakarta.validation.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; import java.util.*; -import javax.annotation.Generated; +import jakarta.annotation.Generated; /** * Describes the result of uploading an image resource @@ -29,10 +29,19 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class ModelApiResponse { + + @Schema(name = "code", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("code") private @Nullable Integer code; + + @Schema(name = "type", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("type") private @Nullable String type; + + @Schema(name = "message", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("message") private @Nullable String message; } diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java index 8d0e03943b2a..ac6acb4d125f 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java @@ -10,13 +10,13 @@ import org.springframework.lang.Nullable; import org.openapitools.jackson.nullable.JsonNullable; import java.time.OffsetDateTime; -import javax.validation.Valid; -import javax.validation.constraints.*; +import jakarta.validation.Valid; +import jakarta.validation.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; import java.util.*; -import javax.annotation.Generated; +import jakarta.annotation.Generated; /** * An order for a pets from the pet store @@ -30,12 +30,24 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class Order { + + @Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("id") private @Nullable Long id; + + @Schema(name = "petId", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("petId") private @Nullable Long petId; + + @Schema(name = "quantity", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("quantity") private @Nullable Integer quantity; + @Valid + @Schema(name = "shipDate", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("shipDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) private @Nullable OffsetDateTime shipDate; @@ -76,9 +88,15 @@ public static StatusEnum fromValue(String value) { } } + + @Schema(name = "status", description = "Order Status", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("status") private @Nullable StatusEnum status; - @lombok.Builder.Default + + @Schema(name = "complete", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("complete") + @lombok.Builder.Default private Boolean complete = false; } diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java index 9a26f6e1e673..b917589cc5d6 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java @@ -13,13 +13,13 @@ import org.springframework.lang.Nullable; import org.openapitools.jackson.nullable.JsonNullable; import java.time.OffsetDateTime; -import javax.validation.Valid; -import javax.validation.constraints.*; +import jakarta.validation.Valid; +import jakarta.validation.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; import java.util.*; -import javax.annotation.Generated; +import jakarta.annotation.Generated; /** * A pet for sale in the pet store @@ -33,17 +33,32 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class Pet { + + @Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("id") private @Nullable Long id; + @Valid + @Schema(name = "category", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("category") private @Nullable Category category; + @NotNull + @Schema(name = "name", example = "doggie", requiredMode = Schema.RequiredMode.REQUIRED) + @JsonProperty("name") private String name; - @lombok.Builder.Default + @NotNull + @Schema(name = "photoUrls", requiredMode = Schema.RequiredMode.REQUIRED) + @JsonProperty("photoUrls") + @lombok.Builder.Default @Valid private List photoUrls = new ArrayList<>(); - @lombok.Builder.Default + @Valid + @Schema(name = "tags", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("tags") + @lombok.Builder.Default @Valid private List<@Valid Tag> tags = new ArrayList<>(); @@ -84,6 +99,9 @@ public static StatusEnum fromValue(String value) { } } + + @Schema(name = "status", description = "pet status in the store", deprecated = true, requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("status") @Deprecated private @Nullable StatusEnum status; diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java index 451eeec83700..0ef4183891bc 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java @@ -7,13 +7,13 @@ import org.springframework.lang.Nullable; import org.openapitools.jackson.nullable.JsonNullable; import java.time.OffsetDateTime; -import javax.validation.Valid; -import javax.validation.constraints.*; +import jakarta.validation.Valid; +import jakarta.validation.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; import java.util.*; -import javax.annotation.Generated; +import jakarta.annotation.Generated; /** * A tag for a pet @@ -27,8 +27,14 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class Tag { + + @Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("id") private @Nullable Long id; + + @Schema(name = "name", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("name") private @Nullable String name; } diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java index c1211bd95476..34ff814880e3 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java @@ -7,13 +7,13 @@ import org.springframework.lang.Nullable; import org.openapitools.jackson.nullable.JsonNullable; import java.time.OffsetDateTime; -import javax.validation.Valid; -import javax.validation.constraints.*; +import jakarta.validation.Valid; +import jakarta.validation.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; import java.util.*; -import javax.annotation.Generated; +import jakarta.annotation.Generated; /** * A User who is purchasing from the pet store @@ -27,20 +27,44 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class User { + + @Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("id") private @Nullable Long id; + + @Schema(name = "username", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("username") private @Nullable String username; + + @Schema(name = "firstName", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("firstName") private @Nullable String firstName; + + @Schema(name = "lastName", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("lastName") private @Nullable String lastName; + + @Schema(name = "email", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("email") private @Nullable String email; + + @Schema(name = "password", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("password") private @Nullable String password; + + @Schema(name = "phone", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("phone") private @Nullable String phone; + + @Schema(name = "userStatus", description = "User Status", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("userStatus") private @Nullable Integer userStatus; } diff --git a/samples/server/petstore/springboot-lombok-data/src/main/resources/application.properties b/samples/server/petstore/springboot-lombok-data/src/main/resources/application.properties deleted file mode 100644 index 7e90813e59b2..000000000000 --- a/samples/server/petstore/springboot-lombok-data/src/main/resources/application.properties +++ /dev/null @@ -1,3 +0,0 @@ -server.port=8080 -spring.jackson.date-format=org.openapitools.RFC3339DateFormat -spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false diff --git a/samples/server/petstore/springboot-lombok-data/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-lombok-data/src/main/resources/openapi.yaml deleted file mode 100644 index 31074771d9fb..000000000000 --- a/samples/server/petstore/springboot-lombok-data/src/main/resources/openapi.yaml +++ /dev/null @@ -1,909 +0,0 @@ -openapi: 3.0.0 -info: - description: "This is a sample server Petstore server. For this sample, you can\ - \ use the api key `special-key` to test the authorization filters." - license: - name: Apache-2.0 - url: https://www.apache.org/licenses/LICENSE-2.0.html - title: OpenAPI Petstore - version: 1.0.0 -externalDocs: - description: Find out more about Swagger - url: http://swagger.io -servers: -- url: http://petstore.swagger.io/v2 -tags: -- description: Everything about your Pets - name: pet -- description: Access to Petstore orders - name: store -- description: Operations about user - name: user -paths: - /pet: - post: - description: "" - operationId: addPet - requestBody: - $ref: "#/components/requestBodies/Pet" - responses: - "200": - content: - application/xml: - schema: - $ref: "#/components/schemas/Pet" - application/json: - schema: - $ref: "#/components/schemas/Pet" - description: successful operation - "405": - description: Invalid input - security: - - petstore_auth: - - write:pets - - read:pets - summary: Add a new pet to the store - tags: - - pet - x-content-type: application/json - x-accepts: - - application/json - - application/xml - x-tags: - - tag: pet - put: - description: "" - externalDocs: - description: API documentation for the updatePet operation - url: http://petstore.swagger.io/v2/doc/updatePet - operationId: updatePet - requestBody: - $ref: "#/components/requestBodies/Pet" - responses: - "200": - content: - application/xml: - schema: - $ref: "#/components/schemas/Pet" - application/json: - schema: - $ref: "#/components/schemas/Pet" - description: successful operation - "400": - description: Invalid ID supplied - "404": - description: Pet not found - "405": - description: Validation exception - security: - - petstore_auth: - - write:pets - - read:pets - summary: Update an existing pet - tags: - - pet - x-content-type: application/json - x-accepts: - - application/json - - application/xml - x-tags: - - tag: pet - /pet/findByStatus: - get: - description: Multiple status values can be provided with comma separated strings - operationId: findPetsByStatus - parameters: - - deprecated: true - description: Status values that need to be considered for filter - explode: false - in: query - name: status - required: true - schema: - items: - default: available - enum: - - available - - pending - - sold - type: string - type: array - style: form - responses: - "200": - content: - application/xml: - schema: - items: - $ref: "#/components/schemas/Pet" - type: array - application/json: - schema: - items: - $ref: "#/components/schemas/Pet" - type: array - description: successful operation - "400": - description: Invalid status value - security: - - petstore_auth: - - read:pets - summary: Finds Pets by status - tags: - - pet - x-accepts: - - application/json - - application/xml - x-tags: - - tag: pet - /pet/findByTags: - get: - deprecated: true - description: "Multiple tags can be provided with comma separated strings. Use\ - \ tag1, tag2, tag3 for testing." - operationId: findPetsByTags - parameters: - - description: Tags to filter by - explode: false - in: query - name: tags - required: true - schema: - items: - type: string - type: array - style: form - responses: - "200": - content: - application/xml: - schema: - items: - $ref: "#/components/schemas/Pet" - type: array - application/json: - schema: - items: - $ref: "#/components/schemas/Pet" - type: array - description: successful operation - "400": - description: Invalid tag value - security: - - petstore_auth: - - read:pets - summary: Finds Pets by tags - tags: - - pet - x-accepts: - - application/json - - application/xml - x-tags: - - tag: pet - /pet/{petId}: - delete: - description: "" - operationId: deletePet - parameters: - - explode: false - in: header - name: api_key - required: false - schema: - type: string - style: simple - - description: Pet id to delete - explode: false - in: path - name: petId - required: true - schema: - format: int64 - type: integer - style: simple - responses: - "400": - description: Invalid pet value - security: - - petstore_auth: - - write:pets - - read:pets - summary: Deletes a pet - tags: - - pet - x-accepts: - - application/json - x-tags: - - tag: pet - get: - description: Returns a single pet - operationId: getPetById - parameters: - - description: ID of pet to return - explode: false - in: path - name: petId - required: true - schema: - format: int64 - type: integer - style: simple - responses: - "200": - content: - application/xml: - schema: - $ref: "#/components/schemas/Pet" - application/json: - schema: - $ref: "#/components/schemas/Pet" - description: successful operation - "400": - description: Invalid ID supplied - "404": - description: Pet not found - security: - - api_key: [] - summary: Find pet by ID - tags: - - pet - x-accepts: - - application/json - - application/xml - x-tags: - - tag: pet - post: - description: "" - operationId: updatePetWithForm - parameters: - - description: ID of pet that needs to be updated - explode: false - in: path - name: petId - required: true - schema: - format: int64 - type: integer - style: simple - requestBody: - content: - application/x-www-form-urlencoded: - schema: - $ref: "#/components/schemas/updatePetWithForm_request" - responses: - "405": - description: Invalid input - security: - - petstore_auth: - - write:pets - - read:pets - summary: Updates a pet in the store with form data - tags: - - pet - x-content-type: application/x-www-form-urlencoded - x-accepts: - - application/json - x-tags: - - tag: pet - /pet/{petId}/uploadImage: - post: - description: "" - operationId: uploadFile - parameters: - - description: ID of pet to update - explode: false - in: path - name: petId - required: true - schema: - format: int64 - type: integer - style: simple - requestBody: - content: - multipart/form-data: - schema: - $ref: "#/components/schemas/uploadFile_request" - responses: - "200": - content: - application/json: - schema: - $ref: "#/components/schemas/ApiResponse" - description: successful operation - security: - - petstore_auth: - - write:pets - - read:pets - summary: uploads an image - tags: - - pet - x-content-type: multipart/form-data - x-accepts: - - application/json - x-tags: - - tag: pet - /store/inventory: - get: - description: Returns a map of status codes to quantities - operationId: getInventory - responses: - "200": - content: - application/json: - schema: - additionalProperties: - format: int32 - type: integer - type: object - description: successful operation - security: - - api_key: [] - summary: Returns pet inventories by status - tags: - - store - x-accepts: - - application/json - x-tags: - - tag: store - /store/order: - post: - description: "" - operationId: placeOrder - requestBody: - content: - application/json: - schema: - $ref: "#/components/schemas/Order" - description: order placed for purchasing the pet - required: true - responses: - "200": - content: - application/xml: - schema: - $ref: "#/components/schemas/Order" - application/json: - schema: - $ref: "#/components/schemas/Order" - description: successful operation - "400": - description: Invalid Order - summary: Place an order for a pet - tags: - - store - x-content-type: application/json - x-accepts: - - application/json - - application/xml - x-tags: - - tag: store - /store/order/{orderId}: - delete: - description: For valid response try integer IDs with value < 1000. Anything - above 1000 or nonintegers will generate API errors - operationId: deleteOrder - parameters: - - description: ID of the order that needs to be deleted - explode: false - in: path - name: orderId - required: true - schema: - type: string - style: simple - responses: - "400": - description: Invalid ID supplied - "404": - description: Order not found - summary: Delete purchase order by ID - tags: - - store - x-accepts: - - application/json - x-tags: - - tag: store - get: - description: For valid response try integer IDs with value <= 5 or > 10. Other - values will generate exceptions - operationId: getOrderById - parameters: - - description: ID of pet that needs to be fetched - explode: false - in: path - name: orderId - required: true - schema: - format: int64 - maximum: 5 - minimum: 1 - type: integer - style: simple - responses: - "200": - content: - application/xml: - schema: - $ref: "#/components/schemas/Order" - application/json: - schema: - $ref: "#/components/schemas/Order" - description: successful operation - "400": - description: Invalid ID supplied - "404": - description: Order not found - summary: Find purchase order by ID - tags: - - store - x-accepts: - - application/json - - application/xml - x-tags: - - tag: store - /user: - post: - description: This can only be done by the logged in user. - operationId: createUser - requestBody: - content: - application/json: - schema: - $ref: "#/components/schemas/User" - description: Created user object - required: true - responses: - default: - description: successful operation - security: - - api_key: [] - summary: Create user - tags: - - user - x-content-type: application/json - x-accepts: - - application/json - x-tags: - - tag: user - /user/createWithArray: - post: - description: "" - operationId: createUsersWithArrayInput - requestBody: - $ref: "#/components/requestBodies/UserArray" - responses: - default: - description: successful operation - security: - - api_key: [] - summary: Creates list of users with given input array - tags: - - user - x-content-type: application/json - x-accepts: - - application/json - x-tags: - - tag: user - /user/createWithList: - post: - description: "" - operationId: createUsersWithListInput - requestBody: - $ref: "#/components/requestBodies/UserArray" - responses: - default: - description: successful operation - security: - - api_key: [] - summary: Creates list of users with given input array - tags: - - user - x-content-type: application/json - x-accepts: - - application/json - x-tags: - - tag: user - /user/login: - get: - description: "" - operationId: loginUser - parameters: - - description: The user name for login - explode: true - in: query - name: username - required: true - schema: - pattern: "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$" - type: string - style: form - - description: The password for login in clear text - explode: true - in: query - name: password - required: true - schema: - type: string - style: form - responses: - "200": - content: - application/xml: - schema: - type: string - application/json: - schema: - type: string - description: successful operation - headers: - Set-Cookie: - description: Cookie authentication key for use with the `api_key` apiKey - authentication. - explode: false - schema: - example: AUTH_KEY=abcde12345; Path=/; HttpOnly - type: string - style: simple - X-Rate-Limit: - description: calls per hour allowed by the user - explode: false - schema: - format: int32 - type: integer - style: simple - X-Expires-After: - description: date in UTC when token expires - explode: false - schema: - format: date-time - type: string - style: simple - "400": - description: Invalid username/password supplied - summary: Logs user into the system - tags: - - user - x-accepts: - - application/json - - application/xml - x-tags: - - tag: user - /user/logout: - get: - description: "" - operationId: logoutUser - responses: - default: - description: successful operation - security: - - api_key: [] - summary: Logs out current logged in user session - tags: - - user - x-accepts: - - application/json - x-tags: - - tag: user - /user/{username}: - delete: - description: This can only be done by the logged in user. - operationId: deleteUser - parameters: - - description: The name that needs to be deleted - explode: false - in: path - name: username - required: true - schema: - type: string - style: simple - responses: - "400": - description: Invalid username supplied - "404": - description: User not found - security: - - api_key: [] - summary: Delete user - tags: - - user - x-accepts: - - application/json - x-tags: - - tag: user - get: - description: "" - operationId: getUserByName - parameters: - - description: The name that needs to be fetched. Use user1 for testing. - explode: false - in: path - name: username - required: true - schema: - type: string - style: simple - responses: - "200": - content: - application/xml: - schema: - $ref: "#/components/schemas/User" - application/json: - schema: - $ref: "#/components/schemas/User" - description: successful operation - "400": - description: Invalid username supplied - "404": - description: User not found - summary: Get user by user name - tags: - - user - x-accepts: - - application/json - - application/xml - x-tags: - - tag: user - put: - description: This can only be done by the logged in user. - operationId: updateUser - parameters: - - description: name that need to be deleted - explode: false - in: path - name: username - required: true - schema: - type: string - style: simple - requestBody: - content: - application/json: - schema: - $ref: "#/components/schemas/User" - description: Updated user object - required: true - responses: - "400": - description: Invalid user supplied - "404": - description: User not found - security: - - api_key: [] - summary: Updated user - tags: - - user - x-content-type: application/json - x-accepts: - - application/json - x-tags: - - tag: user -components: - requestBodies: - UserArray: - content: - application/json: - schema: - items: - $ref: "#/components/schemas/User" - type: array - description: List of user object - required: true - Pet: - content: - application/json: - schema: - $ref: "#/components/schemas/Pet" - application/xml: - schema: - $ref: "#/components/schemas/Pet" - description: Pet object that needs to be added to the store - required: true - schemas: - Order: - description: An order for a pets from the pet store - example: - petId: 6 - quantity: 1 - id: 0 - shipDate: 2000-01-23T04:56:07.000+00:00 - complete: false - status: placed - properties: - id: - format: int64 - type: integer - petId: - format: int64 - type: integer - quantity: - format: int32 - type: integer - shipDate: - format: date-time - type: string - status: - description: Order Status - enum: - - placed - - approved - - delivered - type: string - complete: - default: false - type: boolean - title: Pet Order - type: object - xml: - name: Order - Category: - description: A category for a pet - example: - name: name - id: 6 - properties: - id: - format: int64 - type: integer - name: - pattern: "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$" - type: string - title: Pet category - type: object - xml: - name: Category - User: - description: A User who is purchasing from the pet store - example: - firstName: firstName - lastName: lastName - password: password - userStatus: 6 - phone: phone - id: 0 - email: email - username: username - properties: - id: - format: int64 - type: integer - username: - type: string - firstName: - type: string - lastName: - type: string - email: - type: string - password: - type: string - phone: - type: string - userStatus: - description: User Status - format: int32 - type: integer - title: a User - type: object - xml: - name: User - Tag: - description: A tag for a pet - example: - name: name - id: 1 - properties: - id: - format: int64 - type: integer - name: - type: string - title: Pet Tag - type: object - xml: - name: Tag - Pet: - description: A pet for sale in the pet store - example: - photoUrls: - - photoUrls - - photoUrls - name: doggie - id: 0 - category: - name: name - id: 6 - tags: - - name: name - id: 1 - - name: name - id: 1 - status: available - properties: - id: - format: int64 - type: integer - category: - $ref: "#/components/schemas/Category" - name: - example: doggie - type: string - photoUrls: - items: - type: string - type: array - xml: - name: photoUrl - wrapped: true - tags: - items: - $ref: "#/components/schemas/Tag" - type: array - xml: - name: tag - wrapped: true - status: - deprecated: true - description: pet status in the store - enum: - - available - - pending - - sold - type: string - required: - - name - - photoUrls - title: a Pet - type: object - xml: - name: Pet - ApiResponse: - description: Describes the result of uploading an image resource - example: - code: 0 - type: type - message: message - properties: - code: - format: int32 - type: integer - type: - type: string - message: - type: string - title: An uploaded response - type: object - updatePetWithForm_request: - properties: - name: - description: Updated name of the pet - type: string - status: - description: Updated status of the pet - type: string - type: object - uploadFile_request: - properties: - additionalMetadata: - description: Additional data to pass to server - type: string - file: - description: file to upload - format: binary - type: string - type: object - securitySchemes: - petstore_auth: - flows: - implicit: - authorizationUrl: http://petstore.swagger.io/api/oauth/dialog - scopes: - write:pets: modify pets in your account - read:pets: read your pets - type: oauth2 - api_key: - in: header - name: api_key - type: apiKey From b4197eff4448ec4b6774c22d268a7b2eab9fd2ee Mon Sep 17 00:00:00 2001 From: dabdirb Date: Tue, 16 Dec 2025 17:54:04 +0800 Subject: [PATCH 2/6] fix #22492 [BUG][JAVA][MAVEN] Lombok @Getter disables validation and #19743 #18794 #17793 #17606 --- bin/configs/spring-boot-lombok-data.yaml | 2 +- .../resources/JavaSpring/lombokAnnotation.mustache | 11 ++++++----- .../main/java/org/openapitools/model/Category.java | 1 + .../java/org/openapitools/model/ModelApiResponse.java | 1 + .../src/main/java/org/openapitools/model/Order.java | 3 ++- .../src/main/java/org/openapitools/model/Pet.java | 5 +++-- .../src/main/java/org/openapitools/model/Tag.java | 1 + .../src/main/java/org/openapitools/model/User.java | 1 + 8 files changed, 16 insertions(+), 9 deletions(-) diff --git a/bin/configs/spring-boot-lombok-data.yaml b/bin/configs/spring-boot-lombok-data.yaml index 53b18feb535f..64976d6f9ea5 100644 --- a/bin/configs/spring-boot-lombok-data.yaml +++ b/bin/configs/spring-boot-lombok-data.yaml @@ -12,4 +12,4 @@ additionalProperties: useSpringBoot3: true skipDefaultInterface: true interfaceOnly: true - performBeanValidation: true, + performBeanValidation: true diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache index 78e6a99613c7..58dae14f8e2d 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache @@ -1,18 +1,18 @@ {{#lombok.RequiredArgsConstructor}} {{^useBeanValidation}} {{#required}} - @lombok.NonNull + @lombok.NonNull {{/required}} {{/useBeanValidation}} {{/lombok.RequiredArgsConstructor}} {{#lombok.ToString}} {{#isPassword}} - @lombok.ToString.Exclude + @lombok.ToString.Exclude {{/isPassword}} {{/lombok.ToString}} {{#lombok.Data}} {{#isPassword}} - @lombok.ToString.Exclude + @lombok.ToString.Exclude {{/isPassword}} {{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} {{^useBeanValidation}} @@ -20,7 +20,8 @@ @lombok.NonNull {{/required}} {{/useBeanValidation}} - {{#swagger2AnnotationLibrary}}@Schema(name = "{{{baseName}}}"{{#isReadOnly}}, accessMode = Schema.AccessMode.READ_ONLY{{/isReadOnly}}{{#example}}, example = "{{{.}}}"{{/example}}{{#description}}, description = "{{{.}}}"{{/description}}{{#deprecated}}, deprecated = true{{/deprecated}}, requiredMode = {{#required}}Schema.RequiredMode.REQUIRED{{/required}}{{^required}}Schema.RequiredMode.NOT_REQUIRED{{/required}}) + {{#swagger2AnnotationLibrary}} + @Schema(name = "{{{baseName}}}"{{#isReadOnly}}, accessMode = Schema.AccessMode.READ_ONLY{{/isReadOnly}}{{#example}}, example = "{{{.}}}"{{/example}}{{#description}}, description = "{{{.}}}"{{/description}}{{#deprecated}}, deprecated = true{{/deprecated}}, requiredMode = {{#required}}Schema.RequiredMode.REQUIRED{{/required}}{{^required}}Schema.RequiredMode.NOT_REQUIRED{{/required}}) {{/swagger2AnnotationLibrary}} {{#jackson}}@JsonProperty("{{baseName}}") {{#withXml}} @@ -33,6 +34,6 @@ {{/lombok.Data}} {{#lombok.Builder}} {{#defaultValue}} - @lombok.Builder.Default + @lombok.Builder.Default {{/defaultValue}} {{/lombok.Builder}} \ No newline at end of file diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java index 5a0296bb50fe..93935622f896 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java @@ -9,6 +9,7 @@ import java.time.OffsetDateTime; import jakarta.validation.Valid; import jakarta.validation.constraints.*; +import org.hibernate.validator.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java index 56f7f0aa0d36..782b39918bd8 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java @@ -10,6 +10,7 @@ import java.time.OffsetDateTime; import jakarta.validation.Valid; import jakarta.validation.constraints.*; +import org.hibernate.validator.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java index ac6acb4d125f..75348cfa6dc5 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java @@ -12,6 +12,7 @@ import java.time.OffsetDateTime; import jakarta.validation.Valid; import jakarta.validation.constraints.*; +import org.hibernate.validator.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; @@ -96,7 +97,7 @@ public static StatusEnum fromValue(String value) { @Schema(name = "complete", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("complete") - @lombok.Builder.Default + @lombok.Builder.Default private Boolean complete = false; } diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java index b917589cc5d6..0cd0484ce22e 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java @@ -15,6 +15,7 @@ import java.time.OffsetDateTime; import jakarta.validation.Valid; import jakarta.validation.constraints.*; +import org.hibernate.validator.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; @@ -51,14 +52,14 @@ public class Pet { @NotNull @Schema(name = "photoUrls", requiredMode = Schema.RequiredMode.REQUIRED) @JsonProperty("photoUrls") - @lombok.Builder.Default + @lombok.Builder.Default @Valid private List photoUrls = new ArrayList<>(); @Valid @Schema(name = "tags", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("tags") - @lombok.Builder.Default + @lombok.Builder.Default @Valid private List<@Valid Tag> tags = new ArrayList<>(); diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java index 0ef4183891bc..5200889f0f4e 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java @@ -9,6 +9,7 @@ import java.time.OffsetDateTime; import jakarta.validation.Valid; import jakarta.validation.constraints.*; +import org.hibernate.validator.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java index 34ff814880e3..7599d3b65d5a 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java @@ -9,6 +9,7 @@ import java.time.OffsetDateTime; import jakarta.validation.Valid; import jakarta.validation.constraints.*; +import org.hibernate.validator.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; From ece9cfe9783b628854fb86a998ddaedee3ae4dd3 Mon Sep 17 00:00:00 2001 From: dabdirb Date: Wed, 17 Dec 2025 10:17:22 +0800 Subject: [PATCH 3/6] fix #22492 [BUG][JAVA][MAVEN] Lombok @Getter disables validation and #19743 #18794 #17793 #17606 --- .../JavaSpring/lombokAnnotation.mustache | 4 +- .../openapitools/api/PetApiController.java | 47 ------------------- .../openapitools/api/StoreApiController.java | 47 ------------------- .../openapitools/api/UserApiController.java | 47 ------------------- .../java/org/openapitools/model/Category.java | 4 +- .../openapitools/model/ModelApiResponse.java | 6 +-- .../java/org/openapitools/model/Order.java | 12 ++--- .../main/java/org/openapitools/model/Pet.java | 10 ++-- .../main/java/org/openapitools/model/Tag.java | 4 +- .../java/org/openapitools/model/User.java | 16 +++---- .../OpenApiGeneratorApplicationTests.java | 13 ----- 11 files changed, 28 insertions(+), 182 deletions(-) delete mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApiController.java delete mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApiController.java delete mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApiController.java delete mode 100644 samples/server/petstore/springboot-lombok-data/src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache index 58dae14f8e2d..54cc3a52e6fc 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache @@ -14,7 +14,9 @@ {{#isPassword}} @lombok.ToString.Exclude {{/isPassword}} - {{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} + {{^isContainer}} + {{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} + {{/isContainer}} {{^useBeanValidation}} {{#required}} @lombok.NonNull diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApiController.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApiController.java deleted file mode 100644 index b8fa3720a211..000000000000 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApiController.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.openapitools.api; - -import org.openapitools.model.ModelApiResponse; -import org.openapitools.model.Pet; - - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.CookieValue; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.context.request.NativeWebRequest; - -import javax.validation.constraints.*; -import javax.validation.Valid; - -import java.util.List; -import java.util.Map; -import java.util.Optional; -import javax.annotation.Generated; - -@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") -@Controller -@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") -public class PetApiController implements PetApi { - - private final NativeWebRequest request; - - @Autowired - public PetApiController(NativeWebRequest request) { - this.request = request; - } - - @Override - public Optional getRequest() { - return Optional.ofNullable(request); - } - -} diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApiController.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApiController.java deleted file mode 100644 index 1292dc0b721d..000000000000 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApiController.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.openapitools.api; - -import java.util.Map; -import org.openapitools.model.Order; - - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.CookieValue; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.context.request.NativeWebRequest; - -import javax.validation.constraints.*; -import javax.validation.Valid; - -import java.util.List; -import java.util.Map; -import java.util.Optional; -import javax.annotation.Generated; - -@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") -@Controller -@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") -public class StoreApiController implements StoreApi { - - private final NativeWebRequest request; - - @Autowired - public StoreApiController(NativeWebRequest request) { - this.request = request; - } - - @Override - public Optional getRequest() { - return Optional.ofNullable(request); - } - -} diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApiController.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApiController.java deleted file mode 100644 index 2067b64b6fcb..000000000000 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApiController.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.openapitools.api; - -import java.time.OffsetDateTime; -import org.openapitools.model.User; - - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.CookieValue; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.context.request.NativeWebRequest; - -import javax.validation.constraints.*; -import javax.validation.Valid; - -import java.util.List; -import java.util.Map; -import java.util.Optional; -import javax.annotation.Generated; - -@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") -@Controller -@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") -public class UserApiController implements UserApi { - - private final NativeWebRequest request; - - @Autowired - public UserApiController(NativeWebRequest request) { - this.request = request; - } - - @Override - public Optional getRequest() { - return Optional.ofNullable(request); - } - -} diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java index 93935622f896..2d96e171891d 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java @@ -28,12 +28,12 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class Category { - + @Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("id") private @Nullable Long id; - @Pattern(regexp = "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") + @Pattern(regexp = "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Schema(name = "name", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("name") private @Nullable String name; diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java index 782b39918bd8..aa3f4c6c48e9 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java @@ -30,17 +30,17 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class ModelApiResponse { - + @Schema(name = "code", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("code") private @Nullable Integer code; - + @Schema(name = "type", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("type") private @Nullable String type; - + @Schema(name = "message", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("message") private @Nullable String message; diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java index 75348cfa6dc5..fe22d0bb6274 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java @@ -31,22 +31,22 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class Order { - + @Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("id") private @Nullable Long id; - + @Schema(name = "petId", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("petId") private @Nullable Long petId; - + @Schema(name = "quantity", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("quantity") private @Nullable Integer quantity; - @Valid + @Valid @Schema(name = "shipDate", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("shipDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) @@ -89,12 +89,12 @@ public static StatusEnum fromValue(String value) { } } - + @Schema(name = "status", description = "Order Status", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("status") private @Nullable StatusEnum status; - + @Schema(name = "complete", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("complete") @lombok.Builder.Default diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java index 0cd0484ce22e..f0a76b0fbba6 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java @@ -34,29 +34,27 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class Pet { - + @Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("id") private @Nullable Long id; - @Valid + @Valid @Schema(name = "category", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("category") private @Nullable Category category; - @NotNull + @NotNull @Schema(name = "name", example = "doggie", requiredMode = Schema.RequiredMode.REQUIRED) @JsonProperty("name") private String name; - @NotNull @Schema(name = "photoUrls", requiredMode = Schema.RequiredMode.REQUIRED) @JsonProperty("photoUrls") @lombok.Builder.Default @Valid private List photoUrls = new ArrayList<>(); - @Valid @Schema(name = "tags", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("tags") @lombok.Builder.Default @@ -100,7 +98,7 @@ public static StatusEnum fromValue(String value) { } } - + @Schema(name = "status", description = "pet status in the store", deprecated = true, requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("status") @Deprecated diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java index 5200889f0f4e..54818a99921c 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java @@ -28,12 +28,12 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class Tag { - + @Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("id") private @Nullable Long id; - + @Schema(name = "name", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("name") private @Nullable String name; diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java index 7599d3b65d5a..b26a236a663d 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java @@ -28,42 +28,42 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class User { - + @Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("id") private @Nullable Long id; - + @Schema(name = "username", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("username") private @Nullable String username; - + @Schema(name = "firstName", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("firstName") private @Nullable String firstName; - + @Schema(name = "lastName", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("lastName") private @Nullable String lastName; - + @Schema(name = "email", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("email") private @Nullable String email; - + @Schema(name = "password", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("password") private @Nullable String password; - + @Schema(name = "phone", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("phone") private @Nullable String phone; - + @Schema(name = "userStatus", description = "User Status", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("userStatus") private @Nullable Integer userStatus; diff --git a/samples/server/petstore/springboot-lombok-data/src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java b/samples/server/petstore/springboot-lombok-data/src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java deleted file mode 100644 index 3681f67e7705..000000000000 --- a/samples/server/petstore/springboot-lombok-data/src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.openapitools; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class OpenApiGeneratorApplicationTests { - - @Test - void contextLoads() { - } - -} \ No newline at end of file From f36b834d22d900248caf7bcf87035a48e3715ae2 Mon Sep 17 00:00:00 2001 From: dabdirb Date: Wed, 17 Dec 2025 10:24:02 +0800 Subject: [PATCH 4/6] fix #22492 [BUG][JAVA][MAVEN] Lombok @Getter disables validation and #19743 #18794 #17793 #17606 --- bin/configs/spring-boot-lombok-data.yaml | 4 - .../.openapi-generator/FILES | 10 + .../petstore/springboot-lombok-data/README.md | 34 +- .../petstore/springboot-lombok-data/pom.xml | 45 +- .../OpenApiGeneratorApplication.java | 30 + .../org/openapitools/RFC3339DateFormat.java | 38 + .../java/org/openapitools/api/ApiUtil.java | 2 +- .../java/org/openapitools/api/PetApi.java | 148 ++- .../openapitools/api/PetApiController.java | 48 + .../java/org/openapitools/api/StoreApi.java | 69 +- .../openapitools/api/StoreApiController.java | 47 + .../java/org/openapitools/api/UserApi.java | 83 +- .../openapitools/api/UserApiController.java | 47 + .../configuration/HomeController.java | 20 + .../configuration/SpringDocConfiguration.java | 43 + .../java/org/openapitools/model/Category.java | 7 +- .../openapitools/model/ModelApiResponse.java | 7 +- .../java/org/openapitools/model/Order.java | 7 +- .../main/java/org/openapitools/model/Pet.java | 7 +- .../main/java/org/openapitools/model/Tag.java | 7 +- .../java/org/openapitools/model/User.java | 7 +- .../src/main/resources/application.properties | 3 + .../src/main/resources/openapi.yaml | 909 ++++++++++++++++++ .../OpenApiGeneratorApplicationTests.java | 13 + 24 files changed, 1507 insertions(+), 128 deletions(-) create mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/OpenApiGeneratorApplication.java create mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/RFC3339DateFormat.java create mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApiController.java create mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApiController.java create mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApiController.java create mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/configuration/HomeController.java create mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/configuration/SpringDocConfiguration.java create mode 100644 samples/server/petstore/springboot-lombok-data/src/main/resources/application.properties create mode 100644 samples/server/petstore/springboot-lombok-data/src/main/resources/openapi.yaml create mode 100644 samples/server/petstore/springboot-lombok-data/src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java diff --git a/bin/configs/spring-boot-lombok-data.yaml b/bin/configs/spring-boot-lombok-data.yaml index 64976d6f9ea5..57f54d71d3db 100644 --- a/bin/configs/spring-boot-lombok-data.yaml +++ b/bin/configs/spring-boot-lombok-data.yaml @@ -9,7 +9,3 @@ additionalProperties: additionalModelTypeAnnotations: "@lombok.Data;@lombok.Builder;@lombok.NoArgsConstructor;@lombok.AllArgsConstructor" generateConstructorWithAllArgs: true generateBuilders: true - useSpringBoot3: true - skipDefaultInterface: true - interfaceOnly: true - performBeanValidation: true diff --git a/samples/server/petstore/springboot-lombok-data/.openapi-generator/FILES b/samples/server/petstore/springboot-lombok-data/.openapi-generator/FILES index 87837793235c..48cc81960647 100644 --- a/samples/server/petstore/springboot-lombok-data/.openapi-generator/FILES +++ b/samples/server/petstore/springboot-lombok-data/.openapi-generator/FILES @@ -1,12 +1,22 @@ README.md pom.xml +src/main/java/org/openapitools/OpenApiGeneratorApplication.java +src/main/java/org/openapitools/RFC3339DateFormat.java src/main/java/org/openapitools/api/ApiUtil.java src/main/java/org/openapitools/api/PetApi.java +src/main/java/org/openapitools/api/PetApiController.java src/main/java/org/openapitools/api/StoreApi.java +src/main/java/org/openapitools/api/StoreApiController.java src/main/java/org/openapitools/api/UserApi.java +src/main/java/org/openapitools/api/UserApiController.java +src/main/java/org/openapitools/configuration/HomeController.java +src/main/java/org/openapitools/configuration/SpringDocConfiguration.java src/main/java/org/openapitools/model/Category.java src/main/java/org/openapitools/model/ModelApiResponse.java src/main/java/org/openapitools/model/Order.java src/main/java/org/openapitools/model/Pet.java src/main/java/org/openapitools/model/Tag.java src/main/java/org/openapitools/model/User.java +src/main/resources/application.properties +src/main/resources/openapi.yaml +src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java diff --git a/samples/server/petstore/springboot-lombok-data/README.md b/samples/server/petstore/springboot-lombok-data/README.md index d43a1de307df..5cd22b6081a2 100644 --- a/samples/server/petstore/springboot-lombok-data/README.md +++ b/samples/server/petstore/springboot-lombok-data/README.md @@ -1,27 +1,21 @@ +# OpenAPI generated server -# OpenAPI generated API stub +Spring Boot Server -Spring Framework stub +## Overview +This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. +By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub. +This is an example of building a OpenAPI-enabled server in Java using the SpringBoot framework. -## Overview -This code was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. -By using the [OpenAPI-Spec](https://openapis.org), you can easily generate an API stub. -This is an example of building API stub interfaces in Java using the Spring framework. +The underlying library integrating OpenAPI to Spring Boot is [springdoc](https://springdoc.org). +Springdoc will generate an OpenAPI v3 specification based on the generated Controller and Model classes. +The specification is available to download using the following url: +http://localhost:8080/v3/api-docs/ -The stubs generated can be used in your existing Spring-MVC or Spring-Boot application to create controller endpoints -by adding ```@Controller``` classes that implement the interface. Eg: -```java -@Controller -public class PetController implements PetApi { -// implement all PetApi methods -} -``` +Start your server as a simple java application -You can also use the interface to create [Spring-Cloud Feign clients](http://projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-feign-inheritance).Eg: -```java -@FeignClient(name="pet", url="http://petstore.swagger.io/v2") -public interface PetClient extends PetApi { +You can view the api documentation in swagger-ui by pointing to +http://localhost:8080/swagger-ui.html -} -``` +Change default port value in application.properties \ No newline at end of file diff --git a/samples/server/petstore/springboot-lombok-data/pom.xml b/samples/server/petstore/springboot-lombok-data/pom.xml index 5ab5b9e5b37a..654fff511ba1 100644 --- a/samples/server/petstore/springboot-lombok-data/pom.xml +++ b/samples/server/petstore/springboot-lombok-data/pom.xml @@ -6,48 +6,33 @@ springboot-lombok-data 1.0.0 - 17 + 1.8 ${java.version} ${java.version} UTF-8 - 2.6.0 - 5.17.14 + 1.6.14 + 5.3.1 org.springframework.boot spring-boot-starter-parent - 3.1.3 + 2.7.15 - - - - repository.spring.milestone - Spring Milestone Repository - https://repo.spring.io/milestone - - - - - spring-milestones - https://repo.spring.io/milestone - - - src/main/java - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + @@ -63,7 +48,7 @@ org.springdoc - springdoc-openapi-starter-webmvc-ui + springdoc-openapi-ui ${springdoc.version} diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/OpenApiGeneratorApplication.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/OpenApiGeneratorApplication.java new file mode 100644 index 000000000000..97252a8a9402 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/OpenApiGeneratorApplication.java @@ -0,0 +1,30 @@ +package org.openapitools; + +import com.fasterxml.jackson.databind.Module; +import org.openapitools.jackson.nullable.JsonNullableModule; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.FilterType; +import org.springframework.context.annotation.FullyQualifiedAnnotationBeanNameGenerator; + +@SpringBootApplication( + nameGenerator = FullyQualifiedAnnotationBeanNameGenerator.class +) +@ComponentScan( + basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"}, + nameGenerator = FullyQualifiedAnnotationBeanNameGenerator.class +) +public class OpenApiGeneratorApplication { + + public static void main(String[] args) { + SpringApplication.run(OpenApiGeneratorApplication.class, args); + } + + @Bean(name = "org.openapitools.OpenApiGeneratorApplication.jsonNullableModule") + public Module jsonNullableModule() { + return new JsonNullableModule(); + } + +} \ No newline at end of file diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/RFC3339DateFormat.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/RFC3339DateFormat.java new file mode 100644 index 000000000000..bcd3936d8b34 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/RFC3339DateFormat.java @@ -0,0 +1,38 @@ +package org.openapitools; + +import com.fasterxml.jackson.databind.util.StdDateFormat; + +import java.text.DateFormat; +import java.text.FieldPosition; +import java.text.ParsePosition; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.TimeZone; + +public class RFC3339DateFormat extends DateFormat { + private static final long serialVersionUID = 1L; + private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC"); + + private final StdDateFormat fmt = new StdDateFormat() + .withTimeZone(TIMEZONE_Z) + .withColonInTimeZone(true); + + public RFC3339DateFormat() { + this.calendar = new GregorianCalendar(); + } + + @Override + public Date parse(String source, ParsePosition pos) { + return fmt.parse(source, pos); + } + + @Override + public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { + return fmt.format(date, toAppendTo, fieldPosition); + } + + @Override + public Object clone() { + return this; + } +} \ No newline at end of file diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/ApiUtil.java index 9bcd4f230ed3..1245b1dd0ccf 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/ApiUtil.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/ApiUtil.java @@ -2,7 +2,7 @@ import org.springframework.web.context.request.NativeWebRequest; -import jakarta.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletResponse; import java.io.IOException; public class ApiUtil { diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApi.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApi.java index 4491ffd52138..b621137c4a58 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApi.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApi.java @@ -20,23 +20,30 @@ import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.media.ExampleObject; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.multipart.MultipartFile; -import jakarta.validation.Valid; -import jakarta.validation.constraints.*; +import javax.validation.Valid; +import javax.validation.constraints.*; import java.util.List; import java.util.Map; import java.util.Optional; -import jakarta.annotation.Generated; +import javax.annotation.Generated; @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") @Validated @Tag(name = "pet", description = "Everything about your Pets") public interface PetApi { + default Optional getRequest() { + return Optional.empty(); + } + String PATH_ADD_PET = "/pet"; /** * POST /pet : Add a new pet to the store @@ -68,9 +75,26 @@ public interface PetApi { produces = { "application/xml", "application/json" }, consumes = { "application/json", "application/xml" } ) - ResponseEntity addPet( + default ResponseEntity addPet( @Parameter(name = "Pet", description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody Pet pet - ); + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + String exampleString = " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou "; + ApiUtil.setExampleResponse(request, "application/xml", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } String PATH_DELETE_PET = "/pet/{petId}"; @@ -98,10 +122,13 @@ ResponseEntity addPet( method = RequestMethod.DELETE, value = PetApi.PATH_DELETE_PET ) - ResponseEntity deletePet( + default ResponseEntity deletePet( @NotNull @Parameter(name = "petId", description = "Pet id to delete", required = true, in = ParameterIn.PATH) @PathVariable("petId") Long petId, @Parameter(name = "api_key", description = "", in = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) @Nullable String apiKey - ); + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } String PATH_FIND_PETS_BY_STATUS = "/pet/findByStatus"; @@ -134,9 +161,26 @@ ResponseEntity deletePet( value = PetApi.PATH_FIND_PETS_BY_STATUS, produces = { "application/xml", "application/json" } ) - ResponseEntity> findPetsByStatus( + default ResponseEntity> findPetsByStatus( @NotNull @Parameter(name = "status", deprecated = true, description = "Status values that need to be considered for filter", required = true, in = ParameterIn.QUERY) @Valid @RequestParam(value = "status", required = true) @Deprecated List status - ); + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "[ { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }, { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" } ]"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + String exampleString = " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou "; + ApiUtil.setExampleResponse(request, "application/xml", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } String PATH_FIND_PETS_BY_TAGS = "/pet/findByTags"; @@ -172,9 +216,26 @@ ResponseEntity> findPetsByStatus( value = PetApi.PATH_FIND_PETS_BY_TAGS, produces = { "application/xml", "application/json" } ) - ResponseEntity> findPetsByTags( + default ResponseEntity> findPetsByTags( @NotNull @Parameter(name = "tags", description = "Tags to filter by", required = true, in = ParameterIn.QUERY) @Valid @RequestParam(value = "tags", required = true) List tags - ); + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "[ { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }, { \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" } ]"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + String exampleString = " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou "; + ApiUtil.setExampleResponse(request, "application/xml", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } String PATH_GET_PET_BY_ID = "/pet/{petId}"; @@ -209,9 +270,26 @@ ResponseEntity> findPetsByTags( value = PetApi.PATH_GET_PET_BY_ID, produces = { "application/xml", "application/json" } ) - ResponseEntity getPetById( + default ResponseEntity getPetById( @NotNull @Parameter(name = "petId", description = "ID of pet to return", required = true, in = ParameterIn.PATH) @PathVariable("petId") Long petId - ); + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + String exampleString = " 123456789 123456789 aeiou doggie aeiou 123456789 aeiou aeiou "; + ApiUtil.setExampleResponse(request, "application/xml", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } String PATH_UPDATE_PET = "/pet"; @@ -252,9 +330,26 @@ ResponseEntity getPetById( produces = { "application/xml", "application/json" }, consumes = { "application/json", "application/xml" } ) - ResponseEntity updatePet( + default ResponseEntity updatePet( @Parameter(name = "Pet", description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody Pet pet - ); + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"photoUrls\" : [ \"photoUrls\", \"photoUrls\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"name\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"name\", \"id\" : 1 }, { \"name\" : \"name\", \"id\" : 1 } ], \"status\" : \"available\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + String exampleString = " 123456789 doggie aeiou aeiou "; + ApiUtil.setExampleResponse(request, "application/xml", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } String PATH_UPDATE_PET_WITH_FORM = "/pet/{petId}"; @@ -284,11 +379,14 @@ ResponseEntity updatePet( value = PetApi.PATH_UPDATE_PET_WITH_FORM, consumes = { "application/x-www-form-urlencoded" } ) - ResponseEntity updatePetWithForm( + default ResponseEntity updatePetWithForm( @NotNull @Parameter(name = "petId", description = "ID of pet that needs to be updated", required = true, in = ParameterIn.PATH) @PathVariable("petId") Long petId, @Parameter(name = "name", description = "Updated name of the pet") @Valid @RequestParam(value = "name", required = false) String name, @Parameter(name = "status", description = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) String status - ); + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } String PATH_UPLOAD_FILE = "/pet/{petId}/uploadImage"; @@ -321,10 +419,22 @@ ResponseEntity updatePetWithForm( produces = { "application/json" }, consumes = { "multipart/form-data" } ) - ResponseEntity uploadFile( + default ResponseEntity uploadFile( @NotNull @Parameter(name = "petId", description = "ID of pet to update", required = true, in = ParameterIn.PATH) @PathVariable("petId") Long petId, @Parameter(name = "additionalMetadata", description = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) String additionalMetadata, @Parameter(name = "file", description = "file to upload") @RequestPart(value = "file", required = false) MultipartFile file - ); + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"code\" : 0, \"type\" : \"type\", \"message\" : \"message\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } } diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApiController.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApiController.java new file mode 100644 index 000000000000..c20d64de1fc1 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApiController.java @@ -0,0 +1,48 @@ +package org.openapitools.api; + +import org.openapitools.model.ModelApiResponse; +import org.springframework.lang.Nullable; +import org.openapitools.model.Pet; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.CookieValue; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.context.request.NativeWebRequest; + +import javax.validation.constraints.*; +import javax.validation.Valid; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") +@Controller +@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") +public class PetApiController implements PetApi { + + private final NativeWebRequest request; + + @Autowired + public PetApiController(NativeWebRequest request) { + this.request = request; + } + + @Override + public Optional getRequest() { + return Optional.ofNullable(request); + } + +} diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApi.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApi.java index 86fc7be9efa0..9940dd598cd0 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApi.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApi.java @@ -19,23 +19,30 @@ import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.media.ExampleObject; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.multipart.MultipartFile; -import jakarta.validation.Valid; -import jakarta.validation.constraints.*; +import javax.validation.Valid; +import javax.validation.constraints.*; import java.util.List; import java.util.Map; import java.util.Optional; -import jakarta.annotation.Generated; +import javax.annotation.Generated; @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") @Validated @Tag(name = "store", description = "Access to Petstore orders") public interface StoreApi { + default Optional getRequest() { + return Optional.empty(); + } + String PATH_DELETE_ORDER = "/store/order/{orderId}"; /** * DELETE /store/order/{orderId} : Delete purchase order by ID @@ -59,9 +66,12 @@ public interface StoreApi { method = RequestMethod.DELETE, value = StoreApi.PATH_DELETE_ORDER ) - ResponseEntity deleteOrder( + default ResponseEntity deleteOrder( @NotNull @Parameter(name = "orderId", description = "ID of the order that needs to be deleted", required = true, in = ParameterIn.PATH) @PathVariable("orderId") String orderId - ); + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } String PATH_GET_INVENTORY = "/store/inventory"; @@ -90,9 +100,12 @@ ResponseEntity deleteOrder( value = StoreApi.PATH_GET_INVENTORY, produces = { "application/json" } ) - ResponseEntity> getInventory( + default ResponseEntity> getInventory( - ); + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } String PATH_GET_ORDER_BY_ID = "/store/order/{orderId}"; @@ -124,9 +137,26 @@ ResponseEntity> getInventory( value = StoreApi.PATH_GET_ORDER_BY_ID, produces = { "application/xml", "application/json" } ) - ResponseEntity getOrderById( + default ResponseEntity getOrderById( @NotNull @Min(value = 1L) @Max(value = 5L) @Parameter(name = "orderId", description = "ID of pet that needs to be fetched", required = true, in = ParameterIn.PATH) @PathVariable("orderId") Long orderId - ); + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + String exampleString = " 123456789 123456789 123 2000-01-23T04:56:07.000Z aeiou true "; + ApiUtil.setExampleResponse(request, "application/xml", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } String PATH_PLACE_ORDER = "/store/order"; @@ -157,8 +187,25 @@ ResponseEntity getOrderById( produces = { "application/xml", "application/json" }, consumes = { "application/json" } ) - ResponseEntity placeOrder( + default ResponseEntity placeOrder( @Parameter(name = "Order", description = "order placed for purchasing the pet", required = true) @Valid @RequestBody Order order - ); + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + String exampleString = " 123456789 123456789 123 2000-01-23T04:56:07.000Z aeiou true "; + ApiUtil.setExampleResponse(request, "application/xml", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } } diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApiController.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApiController.java new file mode 100644 index 000000000000..d71cbcd7ade5 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApiController.java @@ -0,0 +1,47 @@ +package org.openapitools.api; + +import java.util.Map; +import org.openapitools.model.Order; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.CookieValue; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.context.request.NativeWebRequest; + +import javax.validation.constraints.*; +import javax.validation.Valid; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") +@Controller +@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") +public class StoreApiController implements StoreApi { + + private final NativeWebRequest request; + + @Autowired + public StoreApiController(NativeWebRequest request) { + this.request = request; + } + + @Override + public Optional getRequest() { + return Optional.ofNullable(request); + } + +} diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApi.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApi.java index c43fd8747c42..533c83ec756c 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApi.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApi.java @@ -19,23 +19,30 @@ import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.enums.ParameterIn; import io.swagger.v3.oas.annotations.media.ExampleObject; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.multipart.MultipartFile; -import jakarta.validation.Valid; -import jakarta.validation.constraints.*; +import javax.validation.Valid; +import javax.validation.constraints.*; import java.util.List; import java.util.Map; import java.util.Optional; -import jakarta.annotation.Generated; +import javax.annotation.Generated; @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") @Validated @Tag(name = "user", description = "Operations about user") public interface UserApi { + default Optional getRequest() { + return Optional.empty(); + } + String PATH_CREATE_USER = "/user"; /** * POST /user : Create user @@ -61,9 +68,12 @@ public interface UserApi { value = UserApi.PATH_CREATE_USER, consumes = { "application/json" } ) - ResponseEntity createUser( + default ResponseEntity createUser( @Parameter(name = "User", description = "Created user object", required = true) @Valid @RequestBody User user - ); + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } String PATH_CREATE_USERS_WITH_ARRAY_INPUT = "/user/createWithArray"; @@ -91,9 +101,12 @@ ResponseEntity createUser( value = UserApi.PATH_CREATE_USERS_WITH_ARRAY_INPUT, consumes = { "application/json" } ) - ResponseEntity createUsersWithArrayInput( + default ResponseEntity createUsersWithArrayInput( @Parameter(name = "User", description = "List of user object", required = true) @Valid @RequestBody List<@Valid User> user - ); + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } String PATH_CREATE_USERS_WITH_LIST_INPUT = "/user/createWithList"; @@ -121,9 +134,12 @@ ResponseEntity createUsersWithArrayInput( value = UserApi.PATH_CREATE_USERS_WITH_LIST_INPUT, consumes = { "application/json" } ) - ResponseEntity createUsersWithListInput( + default ResponseEntity createUsersWithListInput( @Parameter(name = "User", description = "List of user object", required = true) @Valid @RequestBody List<@Valid User> user - ); + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } String PATH_DELETE_USER = "/user/{username}"; @@ -152,9 +168,12 @@ ResponseEntity createUsersWithListInput( method = RequestMethod.DELETE, value = UserApi.PATH_DELETE_USER ) - ResponseEntity deleteUser( + default ResponseEntity deleteUser( @NotNull @Parameter(name = "username", description = "The name that needs to be deleted", required = true, in = ParameterIn.PATH) @PathVariable("username") String username - ); + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } String PATH_GET_USER_BY_NAME = "/user/{username}"; @@ -186,9 +205,26 @@ ResponseEntity deleteUser( value = UserApi.PATH_GET_USER_BY_NAME, produces = { "application/xml", "application/json" } ) - ResponseEntity getUserByName( + default ResponseEntity getUserByName( @NotNull @Parameter(name = "username", description = "The name that needs to be fetched. Use user1 for testing.", required = true, in = ParameterIn.PATH) @PathVariable("username") String username - ); + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"firstName\" : \"firstName\", \"lastName\" : \"lastName\", \"password\" : \"password\", \"userStatus\" : 6, \"phone\" : \"phone\", \"id\" : 0, \"email\" : \"email\", \"username\" : \"username\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + if (mediaType.isCompatibleWith(MediaType.valueOf("application/xml"))) { + String exampleString = " 123456789 aeiou aeiou aeiou aeiou aeiou aeiou 123 "; + ApiUtil.setExampleResponse(request, "application/xml", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } String PATH_LOGIN_USER = "/user/login"; @@ -219,10 +255,13 @@ ResponseEntity getUserByName( value = UserApi.PATH_LOGIN_USER, produces = { "application/xml", "application/json" } ) - ResponseEntity loginUser( + default ResponseEntity loginUser( @NotNull @Pattern(regexp = "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Parameter(name = "username", description = "The user name for login", required = true, in = ParameterIn.QUERY) @Valid @RequestParam(value = "username", required = true) String username, @NotNull @Parameter(name = "password", description = "The password for login in clear text", required = true, in = ParameterIn.QUERY) @Valid @RequestParam(value = "password", required = true) String password - ); + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } String PATH_LOGOUT_USER = "/user/logout"; @@ -248,9 +287,12 @@ ResponseEntity loginUser( method = RequestMethod.GET, value = UserApi.PATH_LOGOUT_USER ) - ResponseEntity logoutUser( + default ResponseEntity logoutUser( - ); + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } String PATH_UPDATE_USER = "/user/{username}"; @@ -281,9 +323,12 @@ ResponseEntity logoutUser( value = UserApi.PATH_UPDATE_USER, consumes = { "application/json" } ) - ResponseEntity updateUser( + default ResponseEntity updateUser( @NotNull @Parameter(name = "username", description = "name that need to be deleted", required = true, in = ParameterIn.PATH) @PathVariable("username") String username, @Parameter(name = "User", description = "Updated user object", required = true) @Valid @RequestBody User user - ); + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } } diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApiController.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApiController.java new file mode 100644 index 000000000000..2e7d70f16d3b --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApiController.java @@ -0,0 +1,47 @@ +package org.openapitools.api; + +import java.time.OffsetDateTime; +import org.openapitools.model.User; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.CookieValue; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.context.request.NativeWebRequest; + +import javax.validation.constraints.*; +import javax.validation.Valid; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") +@Controller +@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") +public class UserApiController implements UserApi { + + private final NativeWebRequest request; + + @Autowired + public UserApiController(NativeWebRequest request) { + this.request = request; + } + + @Override + public Optional getRequest() { + return Optional.ofNullable(request); + } + +} diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/configuration/HomeController.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/configuration/HomeController.java new file mode 100644 index 000000000000..9aa29284ab5f --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/configuration/HomeController.java @@ -0,0 +1,20 @@ +package org.openapitools.configuration; + +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.GetMapping; + +/** + * Home redirection to OpenAPI api documentation + */ +@Controller +public class HomeController { + + @RequestMapping("/") + public String index() { + return "redirect:swagger-ui.html"; + } + +} \ No newline at end of file diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/configuration/SpringDocConfiguration.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/configuration/SpringDocConfiguration.java new file mode 100644 index 000000000000..2ea502c445ae --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/configuration/SpringDocConfiguration.java @@ -0,0 +1,43 @@ +package org.openapitools.configuration; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.security.SecurityScheme; + +@Configuration +public class SpringDocConfiguration { + + @Bean(name = "org.openapitools.configuration.SpringDocConfiguration.apiInfo") + OpenAPI apiInfo() { + return new OpenAPI() + .info( + new Info() + .title("OpenAPI Petstore") + .description("This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.") + .license( + new License() + .name("Apache-2.0") + .url("https://www.apache.org/licenses/LICENSE-2.0.html") + ) + .version("1.0.0") + ) + .components( + new Components() + .addSecuritySchemes("petstore_auth", new SecurityScheme() + .type(SecurityScheme.Type.OAUTH2) + ) + .addSecuritySchemes("api_key", new SecurityScheme() + .type(SecurityScheme.Type.APIKEY) + .in(SecurityScheme.In.HEADER) + .name("api_key") + ) + ) + ; + } +} \ No newline at end of file diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java index 2d96e171891d..b615e77eb248 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java @@ -7,14 +7,13 @@ import org.springframework.lang.Nullable; import org.openapitools.jackson.nullable.JsonNullable; import java.time.OffsetDateTime; -import jakarta.validation.Valid; -import jakarta.validation.constraints.*; -import org.hibernate.validator.constraints.*; +import javax.validation.Valid; +import javax.validation.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; import java.util.*; -import jakarta.annotation.Generated; +import javax.annotation.Generated; /** * A category for a pet diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java index aa3f4c6c48e9..4a0713442c1b 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java @@ -8,14 +8,13 @@ import org.springframework.lang.Nullable; import org.openapitools.jackson.nullable.JsonNullable; import java.time.OffsetDateTime; -import jakarta.validation.Valid; -import jakarta.validation.constraints.*; -import org.hibernate.validator.constraints.*; +import javax.validation.Valid; +import javax.validation.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; import java.util.*; -import jakarta.annotation.Generated; +import javax.annotation.Generated; /** * Describes the result of uploading an image resource diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java index fe22d0bb6274..37a3dd77c76e 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java @@ -10,14 +10,13 @@ import org.springframework.lang.Nullable; import org.openapitools.jackson.nullable.JsonNullable; import java.time.OffsetDateTime; -import jakarta.validation.Valid; -import jakarta.validation.constraints.*; -import org.hibernate.validator.constraints.*; +import javax.validation.Valid; +import javax.validation.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; import java.util.*; -import jakarta.annotation.Generated; +import javax.annotation.Generated; /** * An order for a pets from the pet store diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java index f0a76b0fbba6..5b3a66488e4c 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java @@ -13,14 +13,13 @@ import org.springframework.lang.Nullable; import org.openapitools.jackson.nullable.JsonNullable; import java.time.OffsetDateTime; -import jakarta.validation.Valid; -import jakarta.validation.constraints.*; -import org.hibernate.validator.constraints.*; +import javax.validation.Valid; +import javax.validation.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; import java.util.*; -import jakarta.annotation.Generated; +import javax.annotation.Generated; /** * A pet for sale in the pet store diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java index 54818a99921c..b00110f03232 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java @@ -7,14 +7,13 @@ import org.springframework.lang.Nullable; import org.openapitools.jackson.nullable.JsonNullable; import java.time.OffsetDateTime; -import jakarta.validation.Valid; -import jakarta.validation.constraints.*; -import org.hibernate.validator.constraints.*; +import javax.validation.Valid; +import javax.validation.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; import java.util.*; -import jakarta.annotation.Generated; +import javax.annotation.Generated; /** * A tag for a pet diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java index b26a236a663d..f1458ab0ec11 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java @@ -7,14 +7,13 @@ import org.springframework.lang.Nullable; import org.openapitools.jackson.nullable.JsonNullable; import java.time.OffsetDateTime; -import jakarta.validation.Valid; -import jakarta.validation.constraints.*; -import org.hibernate.validator.constraints.*; +import javax.validation.Valid; +import javax.validation.constraints.*; import io.swagger.v3.oas.annotations.media.Schema; import java.util.*; -import jakarta.annotation.Generated; +import javax.annotation.Generated; /** * A User who is purchasing from the pet store diff --git a/samples/server/petstore/springboot-lombok-data/src/main/resources/application.properties b/samples/server/petstore/springboot-lombok-data/src/main/resources/application.properties new file mode 100644 index 000000000000..7e90813e59b2 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/resources/application.properties @@ -0,0 +1,3 @@ +server.port=8080 +spring.jackson.date-format=org.openapitools.RFC3339DateFormat +spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false diff --git a/samples/server/petstore/springboot-lombok-data/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-lombok-data/src/main/resources/openapi.yaml new file mode 100644 index 000000000000..31074771d9fb --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/resources/openapi.yaml @@ -0,0 +1,909 @@ +openapi: 3.0.0 +info: + description: "This is a sample server Petstore server. For this sample, you can\ + \ use the api key `special-key` to test the authorization filters." + license: + name: Apache-2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html + title: OpenAPI Petstore + version: 1.0.0 +externalDocs: + description: Find out more about Swagger + url: http://swagger.io +servers: +- url: http://petstore.swagger.io/v2 +tags: +- description: Everything about your Pets + name: pet +- description: Access to Petstore orders + name: store +- description: Operations about user + name: user +paths: + /pet: + post: + description: "" + operationId: addPet + requestBody: + $ref: "#/components/requestBodies/Pet" + responses: + "200": + content: + application/xml: + schema: + $ref: "#/components/schemas/Pet" + application/json: + schema: + $ref: "#/components/schemas/Pet" + description: successful operation + "405": + description: Invalid input + security: + - petstore_auth: + - write:pets + - read:pets + summary: Add a new pet to the store + tags: + - pet + x-content-type: application/json + x-accepts: + - application/json + - application/xml + x-tags: + - tag: pet + put: + description: "" + externalDocs: + description: API documentation for the updatePet operation + url: http://petstore.swagger.io/v2/doc/updatePet + operationId: updatePet + requestBody: + $ref: "#/components/requestBodies/Pet" + responses: + "200": + content: + application/xml: + schema: + $ref: "#/components/schemas/Pet" + application/json: + schema: + $ref: "#/components/schemas/Pet" + description: successful operation + "400": + description: Invalid ID supplied + "404": + description: Pet not found + "405": + description: Validation exception + security: + - petstore_auth: + - write:pets + - read:pets + summary: Update an existing pet + tags: + - pet + x-content-type: application/json + x-accepts: + - application/json + - application/xml + x-tags: + - tag: pet + /pet/findByStatus: + get: + description: Multiple status values can be provided with comma separated strings + operationId: findPetsByStatus + parameters: + - deprecated: true + description: Status values that need to be considered for filter + explode: false + in: query + name: status + required: true + schema: + items: + default: available + enum: + - available + - pending + - sold + type: string + type: array + style: form + responses: + "200": + content: + application/xml: + schema: + items: + $ref: "#/components/schemas/Pet" + type: array + application/json: + schema: + items: + $ref: "#/components/schemas/Pet" + type: array + description: successful operation + "400": + description: Invalid status value + security: + - petstore_auth: + - read:pets + summary: Finds Pets by status + tags: + - pet + x-accepts: + - application/json + - application/xml + x-tags: + - tag: pet + /pet/findByTags: + get: + deprecated: true + description: "Multiple tags can be provided with comma separated strings. Use\ + \ tag1, tag2, tag3 for testing." + operationId: findPetsByTags + parameters: + - description: Tags to filter by + explode: false + in: query + name: tags + required: true + schema: + items: + type: string + type: array + style: form + responses: + "200": + content: + application/xml: + schema: + items: + $ref: "#/components/schemas/Pet" + type: array + application/json: + schema: + items: + $ref: "#/components/schemas/Pet" + type: array + description: successful operation + "400": + description: Invalid tag value + security: + - petstore_auth: + - read:pets + summary: Finds Pets by tags + tags: + - pet + x-accepts: + - application/json + - application/xml + x-tags: + - tag: pet + /pet/{petId}: + delete: + description: "" + operationId: deletePet + parameters: + - explode: false + in: header + name: api_key + required: false + schema: + type: string + style: simple + - description: Pet id to delete + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + responses: + "400": + description: Invalid pet value + security: + - petstore_auth: + - write:pets + - read:pets + summary: Deletes a pet + tags: + - pet + x-accepts: + - application/json + x-tags: + - tag: pet + get: + description: Returns a single pet + operationId: getPetById + parameters: + - description: ID of pet to return + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + responses: + "200": + content: + application/xml: + schema: + $ref: "#/components/schemas/Pet" + application/json: + schema: + $ref: "#/components/schemas/Pet" + description: successful operation + "400": + description: Invalid ID supplied + "404": + description: Pet not found + security: + - api_key: [] + summary: Find pet by ID + tags: + - pet + x-accepts: + - application/json + - application/xml + x-tags: + - tag: pet + post: + description: "" + operationId: updatePetWithForm + parameters: + - description: ID of pet that needs to be updated + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + application/x-www-form-urlencoded: + schema: + $ref: "#/components/schemas/updatePetWithForm_request" + responses: + "405": + description: Invalid input + security: + - petstore_auth: + - write:pets + - read:pets + summary: Updates a pet in the store with form data + tags: + - pet + x-content-type: application/x-www-form-urlencoded + x-accepts: + - application/json + x-tags: + - tag: pet + /pet/{petId}/uploadImage: + post: + description: "" + operationId: uploadFile + parameters: + - description: ID of pet to update + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + multipart/form-data: + schema: + $ref: "#/components/schemas/uploadFile_request" + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/ApiResponse" + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an image + tags: + - pet + x-content-type: multipart/form-data + x-accepts: + - application/json + x-tags: + - tag: pet + /store/inventory: + get: + description: Returns a map of status codes to quantities + operationId: getInventory + responses: + "200": + content: + application/json: + schema: + additionalProperties: + format: int32 + type: integer + type: object + description: successful operation + security: + - api_key: [] + summary: Returns pet inventories by status + tags: + - store + x-accepts: + - application/json + x-tags: + - tag: store + /store/order: + post: + description: "" + operationId: placeOrder + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/Order" + description: order placed for purchasing the pet + required: true + responses: + "200": + content: + application/xml: + schema: + $ref: "#/components/schemas/Order" + application/json: + schema: + $ref: "#/components/schemas/Order" + description: successful operation + "400": + description: Invalid Order + summary: Place an order for a pet + tags: + - store + x-content-type: application/json + x-accepts: + - application/json + - application/xml + x-tags: + - tag: store + /store/order/{orderId}: + delete: + description: For valid response try integer IDs with value < 1000. Anything + above 1000 or nonintegers will generate API errors + operationId: deleteOrder + parameters: + - description: ID of the order that needs to be deleted + explode: false + in: path + name: orderId + required: true + schema: + type: string + style: simple + responses: + "400": + description: Invalid ID supplied + "404": + description: Order not found + summary: Delete purchase order by ID + tags: + - store + x-accepts: + - application/json + x-tags: + - tag: store + get: + description: For valid response try integer IDs with value <= 5 or > 10. Other + values will generate exceptions + operationId: getOrderById + parameters: + - description: ID of pet that needs to be fetched + explode: false + in: path + name: orderId + required: true + schema: + format: int64 + maximum: 5 + minimum: 1 + type: integer + style: simple + responses: + "200": + content: + application/xml: + schema: + $ref: "#/components/schemas/Order" + application/json: + schema: + $ref: "#/components/schemas/Order" + description: successful operation + "400": + description: Invalid ID supplied + "404": + description: Order not found + summary: Find purchase order by ID + tags: + - store + x-accepts: + - application/json + - application/xml + x-tags: + - tag: store + /user: + post: + description: This can only be done by the logged in user. + operationId: createUser + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/User" + description: Created user object + required: true + responses: + default: + description: successful operation + security: + - api_key: [] + summary: Create user + tags: + - user + x-content-type: application/json + x-accepts: + - application/json + x-tags: + - tag: user + /user/createWithArray: + post: + description: "" + operationId: createUsersWithArrayInput + requestBody: + $ref: "#/components/requestBodies/UserArray" + responses: + default: + description: successful operation + security: + - api_key: [] + summary: Creates list of users with given input array + tags: + - user + x-content-type: application/json + x-accepts: + - application/json + x-tags: + - tag: user + /user/createWithList: + post: + description: "" + operationId: createUsersWithListInput + requestBody: + $ref: "#/components/requestBodies/UserArray" + responses: + default: + description: successful operation + security: + - api_key: [] + summary: Creates list of users with given input array + tags: + - user + x-content-type: application/json + x-accepts: + - application/json + x-tags: + - tag: user + /user/login: + get: + description: "" + operationId: loginUser + parameters: + - description: The user name for login + explode: true + in: query + name: username + required: true + schema: + pattern: "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$" + type: string + style: form + - description: The password for login in clear text + explode: true + in: query + name: password + required: true + schema: + type: string + style: form + responses: + "200": + content: + application/xml: + schema: + type: string + application/json: + schema: + type: string + description: successful operation + headers: + Set-Cookie: + description: Cookie authentication key for use with the `api_key` apiKey + authentication. + explode: false + schema: + example: AUTH_KEY=abcde12345; Path=/; HttpOnly + type: string + style: simple + X-Rate-Limit: + description: calls per hour allowed by the user + explode: false + schema: + format: int32 + type: integer + style: simple + X-Expires-After: + description: date in UTC when token expires + explode: false + schema: + format: date-time + type: string + style: simple + "400": + description: Invalid username/password supplied + summary: Logs user into the system + tags: + - user + x-accepts: + - application/json + - application/xml + x-tags: + - tag: user + /user/logout: + get: + description: "" + operationId: logoutUser + responses: + default: + description: successful operation + security: + - api_key: [] + summary: Logs out current logged in user session + tags: + - user + x-accepts: + - application/json + x-tags: + - tag: user + /user/{username}: + delete: + description: This can only be done by the logged in user. + operationId: deleteUser + parameters: + - description: The name that needs to be deleted + explode: false + in: path + name: username + required: true + schema: + type: string + style: simple + responses: + "400": + description: Invalid username supplied + "404": + description: User not found + security: + - api_key: [] + summary: Delete user + tags: + - user + x-accepts: + - application/json + x-tags: + - tag: user + get: + description: "" + operationId: getUserByName + parameters: + - description: The name that needs to be fetched. Use user1 for testing. + explode: false + in: path + name: username + required: true + schema: + type: string + style: simple + responses: + "200": + content: + application/xml: + schema: + $ref: "#/components/schemas/User" + application/json: + schema: + $ref: "#/components/schemas/User" + description: successful operation + "400": + description: Invalid username supplied + "404": + description: User not found + summary: Get user by user name + tags: + - user + x-accepts: + - application/json + - application/xml + x-tags: + - tag: user + put: + description: This can only be done by the logged in user. + operationId: updateUser + parameters: + - description: name that need to be deleted + explode: false + in: path + name: username + required: true + schema: + type: string + style: simple + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/User" + description: Updated user object + required: true + responses: + "400": + description: Invalid user supplied + "404": + description: User not found + security: + - api_key: [] + summary: Updated user + tags: + - user + x-content-type: application/json + x-accepts: + - application/json + x-tags: + - tag: user +components: + requestBodies: + UserArray: + content: + application/json: + schema: + items: + $ref: "#/components/schemas/User" + type: array + description: List of user object + required: true + Pet: + content: + application/json: + schema: + $ref: "#/components/schemas/Pet" + application/xml: + schema: + $ref: "#/components/schemas/Pet" + description: Pet object that needs to be added to the store + required: true + schemas: + Order: + description: An order for a pets from the pet store + example: + petId: 6 + quantity: 1 + id: 0 + shipDate: 2000-01-23T04:56:07.000+00:00 + complete: false + status: placed + properties: + id: + format: int64 + type: integer + petId: + format: int64 + type: integer + quantity: + format: int32 + type: integer + shipDate: + format: date-time + type: string + status: + description: Order Status + enum: + - placed + - approved + - delivered + type: string + complete: + default: false + type: boolean + title: Pet Order + type: object + xml: + name: Order + Category: + description: A category for a pet + example: + name: name + id: 6 + properties: + id: + format: int64 + type: integer + name: + pattern: "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$" + type: string + title: Pet category + type: object + xml: + name: Category + User: + description: A User who is purchasing from the pet store + example: + firstName: firstName + lastName: lastName + password: password + userStatus: 6 + phone: phone + id: 0 + email: email + username: username + properties: + id: + format: int64 + type: integer + username: + type: string + firstName: + type: string + lastName: + type: string + email: + type: string + password: + type: string + phone: + type: string + userStatus: + description: User Status + format: int32 + type: integer + title: a User + type: object + xml: + name: User + Tag: + description: A tag for a pet + example: + name: name + id: 1 + properties: + id: + format: int64 + type: integer + name: + type: string + title: Pet Tag + type: object + xml: + name: Tag + Pet: + description: A pet for sale in the pet store + example: + photoUrls: + - photoUrls + - photoUrls + name: doggie + id: 0 + category: + name: name + id: 6 + tags: + - name: name + id: 1 + - name: name + id: 1 + status: available + properties: + id: + format: int64 + type: integer + category: + $ref: "#/components/schemas/Category" + name: + example: doggie + type: string + photoUrls: + items: + type: string + type: array + xml: + name: photoUrl + wrapped: true + tags: + items: + $ref: "#/components/schemas/Tag" + type: array + xml: + name: tag + wrapped: true + status: + deprecated: true + description: pet status in the store + enum: + - available + - pending + - sold + type: string + required: + - name + - photoUrls + title: a Pet + type: object + xml: + name: Pet + ApiResponse: + description: Describes the result of uploading an image resource + example: + code: 0 + type: type + message: message + properties: + code: + format: int32 + type: integer + type: + type: string + message: + type: string + title: An uploaded response + type: object + updatePetWithForm_request: + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + type: object + uploadFile_request: + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + format: binary + type: string + type: object + securitySchemes: + petstore_auth: + flows: + implicit: + authorizationUrl: http://petstore.swagger.io/api/oauth/dialog + scopes: + write:pets: modify pets in your account + read:pets: read your pets + type: oauth2 + api_key: + in: header + name: api_key + type: apiKey diff --git a/samples/server/petstore/springboot-lombok-data/src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java b/samples/server/petstore/springboot-lombok-data/src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java new file mode 100644 index 000000000000..3681f67e7705 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java @@ -0,0 +1,13 @@ +package org.openapitools; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class OpenApiGeneratorApplicationTests { + + @Test + void contextLoads() { + } + +} \ No newline at end of file From b4045da1f415fb63836084fabe012cf43a804f9e Mon Sep 17 00:00:00 2001 From: dabdirb Date: Wed, 17 Dec 2025 11:05:20 +0800 Subject: [PATCH 5/6] fix #22492 [BUG][JAVA][MAVEN] Lombok @Getter disables validation and #19743 #18794 #17793 #17606 --- .../JavaSpring/lombokAnnotation.mustache | 4 +- .../.openapi-generator/FILES | 3 -- .../openapitools/api/PetApiController.java | 48 ------------------- .../openapitools/api/StoreApiController.java | 47 ------------------ .../openapitools/api/UserApiController.java | 47 ------------------ .../java/org/openapitools/model/Category.java | 4 +- .../openapitools/model/ModelApiResponse.java | 6 +-- .../java/org/openapitools/model/Order.java | 12 ++--- .../main/java/org/openapitools/model/Pet.java | 10 ++-- .../main/java/org/openapitools/model/Tag.java | 4 +- .../java/org/openapitools/model/User.java | 16 +++---- 11 files changed, 28 insertions(+), 173 deletions(-) delete mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApiController.java delete mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApiController.java delete mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApiController.java diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache index 54cc3a52e6fc..50834e202389 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/lombokAnnotation.mustache @@ -14,9 +14,7 @@ {{#isPassword}} @lombok.ToString.Exclude {{/isPassword}} - {{^isContainer}} - {{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} - {{/isContainer}} + {{^isContainer}}{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}}{{/isContainer}} {{^useBeanValidation}} {{#required}} @lombok.NonNull diff --git a/samples/server/petstore/springboot-lombok-data/.openapi-generator/FILES b/samples/server/petstore/springboot-lombok-data/.openapi-generator/FILES index 48cc81960647..b15e2c45d45d 100644 --- a/samples/server/petstore/springboot-lombok-data/.openapi-generator/FILES +++ b/samples/server/petstore/springboot-lombok-data/.openapi-generator/FILES @@ -4,11 +4,8 @@ src/main/java/org/openapitools/OpenApiGeneratorApplication.java src/main/java/org/openapitools/RFC3339DateFormat.java src/main/java/org/openapitools/api/ApiUtil.java src/main/java/org/openapitools/api/PetApi.java -src/main/java/org/openapitools/api/PetApiController.java src/main/java/org/openapitools/api/StoreApi.java -src/main/java/org/openapitools/api/StoreApiController.java src/main/java/org/openapitools/api/UserApi.java -src/main/java/org/openapitools/api/UserApiController.java src/main/java/org/openapitools/configuration/HomeController.java src/main/java/org/openapitools/configuration/SpringDocConfiguration.java src/main/java/org/openapitools/model/Category.java diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApiController.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApiController.java deleted file mode 100644 index c20d64de1fc1..000000000000 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApiController.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.openapitools.api; - -import org.openapitools.model.ModelApiResponse; -import org.springframework.lang.Nullable; -import org.openapitools.model.Pet; - - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.CookieValue; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.context.request.NativeWebRequest; - -import javax.validation.constraints.*; -import javax.validation.Valid; - -import java.util.List; -import java.util.Map; -import java.util.Optional; -import javax.annotation.Generated; - -@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") -@Controller -@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") -public class PetApiController implements PetApi { - - private final NativeWebRequest request; - - @Autowired - public PetApiController(NativeWebRequest request) { - this.request = request; - } - - @Override - public Optional getRequest() { - return Optional.ofNullable(request); - } - -} diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApiController.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApiController.java deleted file mode 100644 index d71cbcd7ade5..000000000000 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApiController.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.openapitools.api; - -import java.util.Map; -import org.openapitools.model.Order; - - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.CookieValue; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.context.request.NativeWebRequest; - -import javax.validation.constraints.*; -import javax.validation.Valid; - -import java.util.List; -import java.util.Map; -import java.util.Optional; -import javax.annotation.Generated; - -@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") -@Controller -@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") -public class StoreApiController implements StoreApi { - - private final NativeWebRequest request; - - @Autowired - public StoreApiController(NativeWebRequest request) { - this.request = request; - } - - @Override - public Optional getRequest() { - return Optional.ofNullable(request); - } - -} diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApiController.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApiController.java deleted file mode 100644 index 2e7d70f16d3b..000000000000 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApiController.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.openapitools.api; - -import java.time.OffsetDateTime; -import org.openapitools.model.User; - - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.CookieValue; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RequestPart; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.context.request.NativeWebRequest; - -import javax.validation.constraints.*; -import javax.validation.Valid; - -import java.util.List; -import java.util.Map; -import java.util.Optional; -import javax.annotation.Generated; - -@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") -@Controller -@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") -public class UserApiController implements UserApi { - - private final NativeWebRequest request; - - @Autowired - public UserApiController(NativeWebRequest request) { - this.request = request; - } - - @Override - public Optional getRequest() { - return Optional.ofNullable(request); - } - -} diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java index b615e77eb248..ab557de958a4 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java @@ -27,12 +27,12 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class Category { - + @Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("id") private @Nullable Long id; - @Pattern(regexp = "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") + @Pattern(regexp = "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Schema(name = "name", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("name") private @Nullable String name; diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java index 4a0713442c1b..369e7e317419 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java @@ -29,17 +29,17 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class ModelApiResponse { - + @Schema(name = "code", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("code") private @Nullable Integer code; - + @Schema(name = "type", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("type") private @Nullable String type; - + @Schema(name = "message", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("message") private @Nullable String message; diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java index 37a3dd77c76e..28086626f3ca 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java @@ -30,22 +30,22 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class Order { - + @Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("id") private @Nullable Long id; - + @Schema(name = "petId", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("petId") private @Nullable Long petId; - + @Schema(name = "quantity", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("quantity") private @Nullable Integer quantity; - @Valid + @Valid @Schema(name = "shipDate", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("shipDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) @@ -88,12 +88,12 @@ public static StatusEnum fromValue(String value) { } } - + @Schema(name = "status", description = "Order Status", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("status") private @Nullable StatusEnum status; - + @Schema(name = "complete", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("complete") @lombok.Builder.Default diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java index 5b3a66488e4c..47f7b7c59da9 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java @@ -33,27 +33,29 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class Pet { - + @Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("id") private @Nullable Long id; - @Valid + @Valid @Schema(name = "category", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("category") private @Nullable Category category; - @NotNull + @NotNull @Schema(name = "name", example = "doggie", requiredMode = Schema.RequiredMode.REQUIRED) @JsonProperty("name") private String name; + @Schema(name = "photoUrls", requiredMode = Schema.RequiredMode.REQUIRED) @JsonProperty("photoUrls") @lombok.Builder.Default @Valid private List photoUrls = new ArrayList<>(); + @Schema(name = "tags", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("tags") @lombok.Builder.Default @@ -97,7 +99,7 @@ public static StatusEnum fromValue(String value) { } } - + @Schema(name = "status", description = "pet status in the store", deprecated = true, requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("status") @Deprecated diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java index b00110f03232..83cc2197234e 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java @@ -27,12 +27,12 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class Tag { - + @Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("id") private @Nullable Long id; - + @Schema(name = "name", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("name") private @Nullable String name; diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java index f1458ab0ec11..7e5ee25f6b74 100644 --- a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java @@ -27,42 +27,42 @@ @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") public class User { - + @Schema(name = "id", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("id") private @Nullable Long id; - + @Schema(name = "username", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("username") private @Nullable String username; - + @Schema(name = "firstName", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("firstName") private @Nullable String firstName; - + @Schema(name = "lastName", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("lastName") private @Nullable String lastName; - + @Schema(name = "email", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("email") private @Nullable String email; - + @Schema(name = "password", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("password") private @Nullable String password; - + @Schema(name = "phone", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("phone") private @Nullable String phone; - + @Schema(name = "userStatus", description = "User Status", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @JsonProperty("userStatus") private @Nullable Integer userStatus; From f3ab7a3f2e986cefad0d36bcb7899b70b54d5ce9 Mon Sep 17 00:00:00 2001 From: dabdirb Date: Wed, 17 Dec 2025 13:03:55 +0800 Subject: [PATCH 6/6] fix #22492 [BUG][JAVA][MAVEN] Lombok @Getter disables validation and #19743 #18794 #17793 #17606 --- .../openapitools/api/PetApiController.java | 48 +++++++++++++++++++ .../openapitools/api/StoreApiController.java | 47 ++++++++++++++++++ .../openapitools/api/UserApiController.java | 47 ++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApiController.java create mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApiController.java create mode 100644 samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApiController.java diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApiController.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApiController.java new file mode 100644 index 000000000000..c20d64de1fc1 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApiController.java @@ -0,0 +1,48 @@ +package org.openapitools.api; + +import org.openapitools.model.ModelApiResponse; +import org.springframework.lang.Nullable; +import org.openapitools.model.Pet; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.CookieValue; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.context.request.NativeWebRequest; + +import javax.validation.constraints.*; +import javax.validation.Valid; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") +@Controller +@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") +public class PetApiController implements PetApi { + + private final NativeWebRequest request; + + @Autowired + public PetApiController(NativeWebRequest request) { + this.request = request; + } + + @Override + public Optional getRequest() { + return Optional.ofNullable(request); + } + +} diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApiController.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApiController.java new file mode 100644 index 000000000000..d71cbcd7ade5 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApiController.java @@ -0,0 +1,47 @@ +package org.openapitools.api; + +import java.util.Map; +import org.openapitools.model.Order; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.CookieValue; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.context.request.NativeWebRequest; + +import javax.validation.constraints.*; +import javax.validation.Valid; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") +@Controller +@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") +public class StoreApiController implements StoreApi { + + private final NativeWebRequest request; + + @Autowired + public StoreApiController(NativeWebRequest request) { + this.request = request; + } + + @Override + public Optional getRequest() { + return Optional.ofNullable(request); + } + +} diff --git a/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApiController.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApiController.java new file mode 100644 index 000000000000..2e7d70f16d3b --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApiController.java @@ -0,0 +1,47 @@ +package org.openapitools.api; + +import java.time.OffsetDateTime; +import org.openapitools.model.User; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.CookieValue; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.context.request.NativeWebRequest; + +import javax.validation.constraints.*; +import javax.validation.Valid; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.18.0-SNAPSHOT") +@Controller +@RequestMapping("${openapi.openAPIPetstore.base-path:/v2}") +public class UserApiController implements UserApi { + + private final NativeWebRequest request; + + @Autowired + public UserApiController(NativeWebRequest request) { + this.request = request; + } + + @Override + public Optional getRequest() { + return Optional.ofNullable(request); + } + +}