diff --git a/.github/workflows/samples-spring-jdk17.yaml b/.github/workflows/samples-spring-jdk17.yaml index 76a6aa76cea..b78083f4e61 100644 --- a/.github/workflows/samples-spring-jdk17.yaml +++ b/.github/workflows/samples-spring-jdk17.yaml @@ -7,6 +7,8 @@ on: pull_request: paths: - samples/openapi3/client/petstore/spring-cloud-3-with-optional + - samples/server/petstore/springboot-lombok-data + - samples/server/petstore/springboot-lombok-tostring jobs: build: name: Build Java Spring (JDK17) @@ -17,6 +19,9 @@ jobs: sample: # clients - samples/openapi3/client/petstore/spring-cloud-3-with-optional + # servers + - samples/server/petstore/springboot-lombok-data + - samples/server/petstore/springboot-lombok-tostring steps: - uses: actions/checkout@v4 - uses: actions/setup-java@v4 diff --git a/.github/workflows/samples-spring.yaml b/.github/workflows/samples-spring.yaml index 063c38e566c..42c29b3eaaf 100644 --- a/.github/workflows/samples-spring.yaml +++ b/.github/workflows/samples-spring.yaml @@ -57,6 +57,7 @@ jobs: - samples/server/petstore/springboot-spring-pageable-without-j8 - samples/server/petstore/springboot-spring-pageable - samples/server/petstore/springboot-spring-provide-args + - samples/server/petstore/springboot-lombok-data steps: - uses: actions/checkout@v4 - uses: actions/setup-java@v4 diff --git a/bin/configs/spring-boot-lombok-data.yaml b/bin/configs/spring-boot-lombok-data.yaml new file mode 100644 index 00000000000..ac48f433214 --- /dev/null +++ b/bin/configs/spring-boot-lombok-data.yaml @@ -0,0 +1,9 @@ +generatorName: spring +outputDir: samples/server/petstore/springboot-lombok-data +inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml +templateDir: modules/openapi-generator/src/main/resources/JavaSpring +additionalProperties: + groupId: org.openapitools.openapi3 + artifactId: springboot-lombok-data + hideGenerationTimestamp: "true" + additionalModelTypeAnnotations: "@lombok.Data;@lombok.Builder;@lombok.NoArgsConstructor;@lombok.AllArgsConstructor" diff --git a/bin/configs/spring-boot-lombok-tostring.yaml b/bin/configs/spring-boot-lombok-tostring.yaml new file mode 100644 index 00000000000..35d4e934eb8 --- /dev/null +++ b/bin/configs/spring-boot-lombok-tostring.yaml @@ -0,0 +1,11 @@ +generatorName: spring +outputDir: samples/server/petstore/springboot-lombok-tostring +inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml +templateDir: modules/openapi-generator/src/main/resources/JavaSpring +additionalProperties: + groupId: org.openapitools.openapi3 + artifactId: springboot-lombok-tostring + hideGenerationTimestamp: "true" + performBeanValidation: "true" + useSpringBoot3: "true" + additionalModelTypeAnnotations: "@lombok.Getter;@lombok.Setter;@lombok.ToString;@lombok.EqualsAndHashCode" diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java index 6c4d06cf45d..c1ae3cc8fbb 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java @@ -53,6 +53,7 @@ import java.time.LocalDate; import java.time.ZoneId; import java.util.*; import java.util.concurrent.ConcurrentSkipListSet; +import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -89,7 +90,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code public static final String CAMEL_CASE_DOLLAR_SIGN = "camelCaseDollarSign"; public static final String USE_ONE_OF_INTERFACES = "useOneOfInterfaces"; - + public static final String LOMBOK = "lombok"; public static final String DEFAULT_TEST_FOLDER = "${project.build.directory}/generated-test-sources/openapi"; protected String dateLibrary = "java8"; @@ -128,6 +129,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code protected String parentVersion = ""; protected boolean parentOverridden = false; protected List additionalModelTypeAnnotations = new LinkedList<>(); + protected Map lombokAnnotations = null; protected List additionalOneOfTypeAnnotations = new LinkedList<>(); protected List additionalEnumTypeAnnotations = new LinkedList<>(); protected boolean openApiNullable = true; @@ -1677,6 +1679,22 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code } } + // parse lombok additional model type annotations + Map lombokOptions = new HashMap<>(); + String regexp = "@lombok.(\\w+\\.)*(?\\w+)(\\(.*?\\))?"; + Pattern pattern = Pattern.compile(regexp); + for (String annotation : additionalModelTypeAnnotations) { + Matcher matcher = pattern.matcher(annotation); + if (matcher.find()) { + String className = matcher.group("ClassName"); + lombokOptions.put(className, true); + } + } + if (!lombokOptions.isEmpty()) { + lombokAnnotations = lombokOptions; + writePropertyBack(LOMBOK, lombokOptions); + } + return postProcessModelsEnum(objs); } diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom-sb3.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom-sb3.mustache index fbaf46f7808..cc5a1e1632e 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom-sb3.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom-sb3.mustache @@ -62,11 +62,19 @@ org.springframework.boot spring-boot-maven-plugin - {{#classifier}} + {{#classifier}} {{{classifier}}} + {{/classifier}} + {{#lombok}} + + + org.projectlombok + lombok + + + {{/lombok}} - {{/classifier}} {{#apiFirst}} @@ -217,6 +225,13 @@ spring-boot-starter-hateoas {{/hateoas}} +{{#lombok}} + + org.projectlombok + lombok + true + +{{/lombok}} com.fasterxml.jackson.core jackson-databind diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache index e544c64388c..26e4aad21fa 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-boot/pom.mustache @@ -55,11 +55,19 @@ org.springframework.boot spring-boot-maven-plugin - {{#classifier}} + {{#classifier}} {{{classifier}}} - {{/classifier}} + {{#lombok}} + + + org.projectlombok + lombok + + + {{/lombok}} + {{#apiFirst}} @@ -227,6 +235,13 @@ spring-boot-starter-hateoas {{/hateoas}} +{{#lombok}} + + org.projectlombok + lombok + true + +{{/lombok}} com.fasterxml.jackson.core jackson-databind diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/pom-sb3.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/pom-sb3.mustache index 2ba39e1077a..65bf80bf1c0 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/pom-sb3.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/pom-sb3.mustache @@ -130,6 +130,13 @@ spring-boot-starter-hateoas {{/hateoas}} + {{#lombok}} + + org.projectlombok + lombok + true + + {{/lombok}} {{#useBeanValidation}} org.springframework.boot diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/pom.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/pom.mustache index 68f1b7ebbfd..41bbf5ef1b2 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/pom.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-cloud/pom.mustache @@ -146,6 +146,13 @@ spring-boot-starter-hateoas {{/hateoas}} + {{#lombok}} + + org.projectlombok + lombok + true + + {{/lombok}} {{#useBeanValidation}} org.springframework.boot diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/pom.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/pom.mustache index 680b4aa9947..55791462af0 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/pom.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/libraries/spring-http-interface/pom.mustache @@ -89,6 +89,13 @@ 0.2.6 {{/openApiNullable}} + {{#lombok}} + + org.projectlombok + lombok + true + + {{/lombok}} org.springframework.boot spring-boot-starter-test diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache index 5930383810f..4e18d922db9 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache @@ -51,6 +51,14 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}} {{#gson}} @SerializedName("{{baseName}}") {{/gson}} + {{#lombok}} + {{#required}} + @lombok.NonNull + {{/required}} + {{#isPassword}} + @lombok.ToString.Exclude + {{/isPassword}} + {{/lombok}} {{#vendorExtensions.x-field-extra-annotation}} {{{vendorExtensions.x-field-extra-annotation}}} {{/vendorExtensions.x-field-extra-annotation}} @@ -81,13 +89,17 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}} {{/openApiNullable}} {{/isContainer}} {{/vars}} + {{^lombok.Data}} + {{^lombok.RequiredArgsConstructor}} {{#generatedConstructorWithRequiredArgs}} {{#hasRequired}} + {{^lombok.NoArgsConstructor}} public {{classname}}() { super(); } + {{/lombok.NoArgsConstructor}} /** * Constructor with only required parameters */ @@ -108,7 +120,10 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}} } {{/hasRequired}} {{/generatedConstructorWithRequiredArgs}} + {{/lombok.RequiredArgsConstructor}} + {{/lombok.Data}} {{#vars}} + {{^lombok.Data}} {{! begin feature: fluent setter methods }} public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) { @@ -158,6 +173,7 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}} {{/isMap}} {{! end feature: fluent setter methods }} {{! begin feature: getter and setter }} + {{^lombok.Getter}} /** {{#description}} @@ -204,7 +220,9 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}} public {{>nullableDataTypeBeanValidation}} {{getter}}() { return {{name}}; } + {{/lombok.Getter}} + {{^lombok.Setter}} {{#deprecated}} /** * @deprecated @@ -219,11 +237,15 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}} public void {{setter}}({{>nullableDataType}} {{name}}) { this.{{name}} = {{name}}; } + {{/lombok.Setter}} + {{/lombok.Data}} {{! end feature: getter and setter }} {{/vars}} {{>additionalProperties}} + {{^lombok.Data}} {{#parentVars}} + {{^lombok.Setter}} {{! begin feature: fluent setter methods for inherited properties }} public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) { super.{{name}}({{name}}); @@ -243,8 +265,10 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}} return this; } {{/isMap}} + {{/lombok.Setter}} {{! end feature: fluent setter methods for inherited properties }} {{/parentVars}} + {{^lombok.EqualsAndHashCode}} @Override public boolean equals(Object o) { if (this == o) { @@ -276,7 +300,9 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}} } return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31; }{{/vendorExtensions.x-jackson-optional-nullable-helpers}} + {{/lombok.EqualsAndHashCode}} + {{^lombok.ToString}} @Override public String toString() { StringBuilder sb = new StringBuilder(); @@ -301,4 +327,6 @@ public class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}{{^parent}} } return o.toString().replace("\n", "\n "); } + {{/lombok.ToString}} + {{/lombok.Data}} } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java index 1ca5bc0af9d..b6d5ee64209 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java @@ -4427,4 +4427,48 @@ public class SpringCodegenTest { .hasParameter("race").toConstructor() ; } + + @Test + public void testLombokAnnotations() throws IOException { + final Map additionalProperties = new HashMap<>(); + additionalProperties.put(AbstractJavaCodegen.ADDITIONAL_MODEL_TYPE_ANNOTATIONS, "@lombok.Data;@lombok.NoArgsConstructor;@lombok.AllArgsConstructor"); + Map output = generateFromContract("src/test/resources/3_0/petstore.yaml", SPRING_BOOT, additionalProperties); + JavaFileAssert.assertThat(output.get("Pet.java")) + .assertNoConstructor() + .assertNoMethod("toString") + .assertNoMethod("hashCode") + .assertNoMethod("equals") + .assertNoMethod("getId") + .assertNoMethod("setId") + .assertNoMethod("getName") + .assertNoMethod("setName") + ; + additionalProperties.put(AbstractJavaCodegen.ADDITIONAL_MODEL_TYPE_ANNOTATIONS, "@lombok.ToString"); + output = generateFromContract("src/test/resources/3_0/petstore.yaml", SPRING_BOOT, additionalProperties); + JavaFileAssert.assertThat(output.get("Pet.java")) + .assertConstructor().toFileAssert() + .assertNoMethod("toString") + .assertMethod("hashCode") + .toFileAssert() + .assertMethod("equals") + .toFileAssert() + .assertMethod("getId") + .toFileAssert() + .assertMethod("setId") + .toFileAssert() + .assertMethod("getName") + .toFileAssert() + .assertMethod("setName") + ; + additionalProperties.put(AbstractJavaCodegen.ADDITIONAL_MODEL_TYPE_ANNOTATIONS, "@lombok.Getter;@lombok.Setter"); + output = generateFromContract("src/test/resources/3_0/petstore.yaml", SPRING_BOOT, additionalProperties); + JavaFileAssert.assertThat(output.get("Pet.java")) + .assertConstructor().toFileAssert() + .assertMethod("toString") + .toFileAssert() + .assertMethod("hashCode") + .toFileAssert() + .assertMethod("equals") + ; + } } diff --git a/samples/openapi3/server/petstore/spring-boot-oneof/pom.xml b/samples/openapi3/server/petstore/spring-boot-oneof/pom.xml index cc59c6ca908..7113913e6ca 100644 --- a/samples/openapi3/server/petstore/spring-boot-oneof/pom.xml +++ b/samples/openapi3/server/petstore/spring-boot-oneof/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/openapi3/server/petstore/spring-boot-springdoc/pom.xml b/samples/openapi3/server/petstore/spring-boot-springdoc/pom.xml index 0f3c053996f..230983b59c8 100644 --- a/samples/openapi3/server/petstore/spring-boot-springdoc/pom.xml +++ b/samples/openapi3/server/petstore/spring-boot-springdoc/pom.xml @@ -24,6 +24,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/openapi3/server/petstore/springboot-3/pom.xml b/samples/openapi3/server/petstore/springboot-3/pom.xml index 478e3a2a266..e8636ac3ca0 100644 --- a/samples/openapi3/server/petstore/springboot-3/pom.xml +++ b/samples/openapi3/server/petstore/springboot-3/pom.xml @@ -40,6 +40,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/openapi3/server/petstore/springboot-delegate/pom.xml b/samples/openapi3/server/petstore/springboot-delegate/pom.xml index 9a0cf5f2e0d..67d552b723d 100644 --- a/samples/openapi3/server/petstore/springboot-delegate/pom.xml +++ b/samples/openapi3/server/petstore/springboot-delegate/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/openapi3/server/petstore/springboot-implicitHeaders/pom.xml b/samples/openapi3/server/petstore/springboot-implicitHeaders/pom.xml index 57362ffd4e1..5b071433c60 100644 --- a/samples/openapi3/server/petstore/springboot-implicitHeaders/pom.xml +++ b/samples/openapi3/server/petstore/springboot-implicitHeaders/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/openapi3/server/petstore/springboot-source/pom.xml b/samples/openapi3/server/petstore/springboot-source/pom.xml index dd0b93df70b..3f54f4adede 100644 --- a/samples/openapi3/server/petstore/springboot-source/pom.xml +++ b/samples/openapi3/server/petstore/springboot-source/pom.xml @@ -24,6 +24,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/openapi3/server/petstore/springboot/pom.xml b/samples/openapi3/server/petstore/springboot/pom.xml index be6910515e6..d60cccd3ff1 100644 --- a/samples/openapi3/server/petstore/springboot/pom.xml +++ b/samples/openapi3/server/petstore/springboot/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/server/petstore/springboot-beanvalidation-no-nullable/pom.xml b/samples/server/petstore/springboot-beanvalidation-no-nullable/pom.xml index c90b0cdced6..6281f810cd3 100644 --- a/samples/server/petstore/springboot-beanvalidation-no-nullable/pom.xml +++ b/samples/server/petstore/springboot-beanvalidation-no-nullable/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/server/petstore/springboot-beanvalidation/pom.xml b/samples/server/petstore/springboot-beanvalidation/pom.xml index 3fbd5350ad3..f48622e7ec8 100644 --- a/samples/server/petstore/springboot-beanvalidation/pom.xml +++ b/samples/server/petstore/springboot-beanvalidation/pom.xml @@ -24,6 +24,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/server/petstore/springboot-delegate-j8/pom.xml b/samples/server/petstore/springboot-delegate-j8/pom.xml index 0cf57121a97..92bfa2cb5cb 100644 --- a/samples/server/petstore/springboot-delegate-j8/pom.xml +++ b/samples/server/petstore/springboot-delegate-j8/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/server/petstore/springboot-delegate-no-response-entity/pom.xml b/samples/server/petstore/springboot-delegate-no-response-entity/pom.xml index 5d517377233..461339353f4 100644 --- a/samples/server/petstore/springboot-delegate-no-response-entity/pom.xml +++ b/samples/server/petstore/springboot-delegate-no-response-entity/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/server/petstore/springboot-delegate/pom.xml b/samples/server/petstore/springboot-delegate/pom.xml index ef8ad938007..726f5f2dae8 100644 --- a/samples/server/petstore/springboot-delegate/pom.xml +++ b/samples/server/petstore/springboot-delegate/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/server/petstore/springboot-implicitHeaders-annotationLibrary/pom.xml b/samples/server/petstore/springboot-implicitHeaders-annotationLibrary/pom.xml index 081cc07e3af..68770011586 100644 --- a/samples/server/petstore/springboot-implicitHeaders-annotationLibrary/pom.xml +++ b/samples/server/petstore/springboot-implicitHeaders-annotationLibrary/pom.xml @@ -23,6 +23,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/server/petstore/springboot-implicitHeaders/pom.xml b/samples/server/petstore/springboot-implicitHeaders/pom.xml index a15567ffd9a..d1c4c8d6452 100644 --- a/samples/server/petstore/springboot-implicitHeaders/pom.xml +++ b/samples/server/petstore/springboot-implicitHeaders/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/server/petstore/springboot-lombok-data/.openapi-generator-ignore b/samples/server/petstore/springboot-lombok-data/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/server/petstore/springboot-lombok-data/.openapi-generator/FILES b/samples/server/petstore/springboot-lombok-data/.openapi-generator/FILES new file mode 100644 index 00000000000..b15e2c45d45 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/.openapi-generator/FILES @@ -0,0 +1,19 @@ +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/.openapi-generator/VERSION b/samples/server/petstore/springboot-lombok-data/.openapi-generator/VERSION new file mode 100644 index 00000000000..fff4bdd7ab5 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/springboot-lombok-data/README.md b/samples/server/petstore/springboot-lombok-data/README.md new file mode 100644 index 00000000000..5cd22b6081a --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/README.md @@ -0,0 +1,21 @@ +# OpenAPI generated server + +Spring Boot Server + +## 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. + + +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/ + +Start your server as a simple java application + +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 new file mode 100644 index 00000000000..16d607dab7b --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/pom.xml @@ -0,0 +1,93 @@ + + 4.0.0 + org.openapitools.openapi3 + springboot-lombok-data + jar + springboot-lombok-data + 1.0.0 + + 1.8 + ${java.version} + ${java.version} + UTF-8 + 1.6.14 + 5.3.1 + + + org.springframework.boot + spring-boot-starter-parent + 2.7.15 + + + + src/main/java + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.data + spring-data-commons + + + + org.springdoc + springdoc-openapi-ui + ${springdoc.version} + + + + com.google.code.findbugs + jsr305 + 3.0.2 + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + org.openapitools + jackson-databind-nullable + 0.2.6 + + + + org.springframework.boot + spring-boot-starter-validation + + + org.projectlombok + lombok + true + + + com.fasterxml.jackson.core + jackson-databind + + + org.springframework.boot + spring-boot-starter-test + test + + + 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 00000000000..97252a8a940 --- /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 00000000000..bcd3936d8b3 --- /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 new file mode 100644 index 00000000000..1245b1dd0cc --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/ApiUtil.java @@ -0,0 +1,19 @@ +package org.openapitools.api; + +import org.springframework.web.context.request.NativeWebRequest; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class ApiUtil { + public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { + try { + HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} 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 new file mode 100644 index 00000000000..524f05c4a8e --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApi.java @@ -0,0 +1,438 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.3.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package org.openapitools.api; + +import org.openapitools.model.ModelApiResponse; +import org.openapitools.model.Pet; +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +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 java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +@Validated +@Tag(name = "pet", description = "Everything about your Pets") +public interface PetApi { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * POST /pet : Add a new pet to the store + * + * + * @param pet Pet object that needs to be added to the store (required) + * @return successful operation (status code 200) + * or Invalid input (status code 405) + */ + @Operation( + operationId = "addPet", + summary = "Add a new pet to the store", + description = "", + tags = { "pet" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", schema = @Schema(implementation = Pet.class)), + @Content(mediaType = "application/json", schema = @Schema(implementation = Pet.class)) + }), + @ApiResponse(responseCode = "405", description = "Invalid input") + }, + security = { + @SecurityRequirement(name = "petstore_auth", scopes={ "write:pets", "read:pets" }) + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/pet", + produces = { "application/xml", "application/json" }, + consumes = { "application/json", "application/xml" } + ) + + 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); + + } + + + /** + * DELETE /pet/{petId} : Deletes a pet + * + * + * @param petId Pet id to delete (required) + * @param apiKey (optional) + * @return Invalid pet value (status code 400) + */ + @Operation( + operationId = "deletePet", + summary = "Deletes a pet", + description = "", + tags = { "pet" }, + responses = { + @ApiResponse(responseCode = "400", description = "Invalid pet value") + }, + security = { + @SecurityRequirement(name = "petstore_auth", scopes={ "write:pets", "read:pets" }) + } + ) + @RequestMapping( + method = RequestMethod.DELETE, + value = "/pet/{petId}" + ) + + default ResponseEntity deletePet( + @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) String apiKey + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + + /** + * GET /pet/findByStatus : Finds Pets by status + * Multiple status values can be provided with comma separated strings + * + * @param status Status values that need to be considered for filter (required) + * @return successful operation (status code 200) + * or Invalid status value (status code 400) + */ + @Operation( + operationId = "findPetsByStatus", + summary = "Finds Pets by status", + description = "Multiple status values can be provided with comma separated strings", + tags = { "pet" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", array = @ArraySchema(schema = @Schema(implementation = Pet.class))), + @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = Pet.class))) + }), + @ApiResponse(responseCode = "400", description = "Invalid status value") + }, + security = { + @SecurityRequirement(name = "petstore_auth", scopes={ "read:pets" }) + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/pet/findByStatus", + produces = { "application/xml", "application/json" } + ) + + 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); + + } + + + /** + * GET /pet/findByTags : Finds Pets by tags + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * + * @param tags Tags to filter by (required) + * @return successful operation (status code 200) + * or Invalid tag value (status code 400) + * @deprecated + */ + @Deprecated + @Operation( + operationId = "findPetsByTags", + summary = "Finds Pets by tags", + description = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", + deprecated = true, + tags = { "pet" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", array = @ArraySchema(schema = @Schema(implementation = Pet.class))), + @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = Pet.class))) + }), + @ApiResponse(responseCode = "400", description = "Invalid tag value") + }, + security = { + @SecurityRequirement(name = "petstore_auth", scopes={ "read:pets" }) + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/pet/findByTags", + produces = { "application/xml", "application/json" } + ) + + 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); + + } + + + /** + * GET /pet/{petId} : Find pet by ID + * Returns a single pet + * + * @param petId ID of pet to return (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Pet not found (status code 404) + */ + @Operation( + operationId = "getPetById", + summary = "Find pet by ID", + description = "Returns a single pet", + tags = { "pet" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", schema = @Schema(implementation = Pet.class)), + @Content(mediaType = "application/json", schema = @Schema(implementation = Pet.class)) + }), + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Pet not found") + }, + security = { + @SecurityRequirement(name = "api_key") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/pet/{petId}", + produces = { "application/xml", "application/json" } + ) + + default ResponseEntity getPetById( + @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); + + } + + + /** + * PUT /pet : Update an existing pet + * + * + * @param pet Pet object that needs to be added to the store (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Pet not found (status code 404) + * or Validation exception (status code 405) + * API documentation for the updatePet operation + * @see Update an existing pet Documentation + */ + @Operation( + operationId = "updatePet", + summary = "Update an existing pet", + description = "", + tags = { "pet" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", schema = @Schema(implementation = Pet.class)), + @Content(mediaType = "application/json", schema = @Schema(implementation = Pet.class)) + }), + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Pet not found"), + @ApiResponse(responseCode = "405", description = "Validation exception") + }, + security = { + @SecurityRequirement(name = "petstore_auth", scopes={ "write:pets", "read:pets" }) + }, + externalDocs = @ExternalDocumentation(description = "API documentation for the updatePet operation", url = "http://petstore.swagger.io/v2/doc/updatePet") + ) + @RequestMapping( + method = RequestMethod.PUT, + value = "/pet", + produces = { "application/xml", "application/json" }, + consumes = { "application/json", "application/xml" } + ) + + 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); + + } + + + /** + * POST /pet/{petId} : Updates a pet in the store with form data + * + * + * @param petId ID of pet that needs to be updated (required) + * @param name Updated name of the pet (optional) + * @param status Updated status of the pet (optional) + * @return Invalid input (status code 405) + */ + @Operation( + operationId = "updatePetWithForm", + summary = "Updates a pet in the store with form data", + description = "", + tags = { "pet" }, + responses = { + @ApiResponse(responseCode = "405", description = "Invalid input") + }, + security = { + @SecurityRequirement(name = "petstore_auth", scopes={ "write:pets", "read:pets" }) + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/pet/{petId}", + consumes = { "application/x-www-form-urlencoded" } + ) + + default ResponseEntity updatePetWithForm( + @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); + + } + + + /** + * POST /pet/{petId}/uploadImage : uploads an image + * + * + * @param petId ID of pet to update (required) + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return successful operation (status code 200) + */ + @Operation( + operationId = "uploadFile", + summary = "uploads an image", + description = "", + tags = { "pet" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = ModelApiResponse.class)) + }) + }, + security = { + @SecurityRequirement(name = "petstore_auth", scopes={ "write:pets", "read:pets" }) + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/pet/{petId}/uploadImage", + produces = { "application/json" }, + consumes = { "multipart/form-data" } + ) + + default ResponseEntity uploadFile( + @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 00000000000..b8fa3720a21 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/PetApiController.java @@ -0,0 +1,47 @@ +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/StoreApi.java b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApi.java new file mode 100644 index 00000000000..423acf765d1 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/StoreApi.java @@ -0,0 +1,210 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.3.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package org.openapitools.api; + +import java.util.Map; +import org.openapitools.model.Order; +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +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 java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +@Validated +@Tag(name = "store", description = "Access to Petstore orders") +public interface StoreApi { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * DELETE /store/order/{orderId} : Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * + * @param orderId ID of the order that needs to be deleted (required) + * @return Invalid ID supplied (status code 400) + * or Order not found (status code 404) + */ + @Operation( + operationId = "deleteOrder", + summary = "Delete purchase order by ID", + description = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", + tags = { "store" }, + responses = { + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Order not found") + } + ) + @RequestMapping( + method = RequestMethod.DELETE, + value = "/store/order/{orderId}" + ) + + default ResponseEntity deleteOrder( + @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); + + } + + + /** + * GET /store/inventory : Returns pet inventories by status + * Returns a map of status codes to quantities + * + * @return successful operation (status code 200) + */ + @Operation( + operationId = "getInventory", + summary = "Returns pet inventories by status", + description = "Returns a map of status codes to quantities", + tags = { "store" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = Map.class)) + }) + }, + security = { + @SecurityRequirement(name = "api_key") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/store/inventory", + produces = { "application/json" } + ) + + default ResponseEntity> getInventory( + + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + + /** + * GET /store/order/{orderId} : Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions + * + * @param orderId ID of pet that needs to be fetched (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Order not found (status code 404) + */ + @Operation( + operationId = "getOrderById", + summary = "Find purchase order by ID", + description = "For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions", + tags = { "store" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", schema = @Schema(implementation = Order.class)), + @Content(mediaType = "application/json", schema = @Schema(implementation = Order.class)) + }), + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Order not found") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/store/order/{orderId}", + produces = { "application/xml", "application/json" } + ) + + default ResponseEntity getOrderById( + @Min(1L) @Max(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); + + } + + + /** + * POST /store/order : Place an order for a pet + * + * + * @param order order placed for purchasing the pet (required) + * @return successful operation (status code 200) + * or Invalid Order (status code 400) + */ + @Operation( + operationId = "placeOrder", + summary = "Place an order for a pet", + description = "", + tags = { "store" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", schema = @Schema(implementation = Order.class)), + @Content(mediaType = "application/json", schema = @Schema(implementation = Order.class)) + }), + @ApiResponse(responseCode = "400", description = "Invalid Order") + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/store/order", + produces = { "application/xml", "application/json" }, + consumes = { "application/json" } + ) + + 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 00000000000..1292dc0b721 --- /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") +@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 new file mode 100644 index 00000000000..b216fcc084a --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/UserApi.java @@ -0,0 +1,333 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.3.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package org.openapitools.api; + +import java.time.OffsetDateTime; +import org.openapitools.model.User; +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +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 java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +@Validated +@Tag(name = "user", description = "Operations about user") +public interface UserApi { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * POST /user : Create user + * This can only be done by the logged in user. + * + * @param user Created user object (required) + * @return successful operation (status code 200) + */ + @Operation( + operationId = "createUser", + summary = "Create user", + description = "This can only be done by the logged in user.", + tags = { "user" }, + responses = { + @ApiResponse(responseCode = "default", description = "successful operation") + }, + security = { + @SecurityRequirement(name = "api_key") + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/user", + consumes = { "application/json" } + ) + + default ResponseEntity createUser( + @Parameter(name = "User", description = "Created user object", required = true) @Valid @RequestBody User user + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + + /** + * POST /user/createWithArray : Creates list of users with given input array + * + * + * @param user List of user object (required) + * @return successful operation (status code 200) + */ + @Operation( + operationId = "createUsersWithArrayInput", + summary = "Creates list of users with given input array", + description = "", + tags = { "user" }, + responses = { + @ApiResponse(responseCode = "default", description = "successful operation") + }, + security = { + @SecurityRequirement(name = "api_key") + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/user/createWithArray", + consumes = { "application/json" } + ) + + 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); + + } + + + /** + * POST /user/createWithList : Creates list of users with given input array + * + * + * @param user List of user object (required) + * @return successful operation (status code 200) + */ + @Operation( + operationId = "createUsersWithListInput", + summary = "Creates list of users with given input array", + description = "", + tags = { "user" }, + responses = { + @ApiResponse(responseCode = "default", description = "successful operation") + }, + security = { + @SecurityRequirement(name = "api_key") + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/user/createWithList", + consumes = { "application/json" } + ) + + 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); + + } + + + /** + * DELETE /user/{username} : Delete user + * This can only be done by the logged in user. + * + * @param username The name that needs to be deleted (required) + * @return Invalid username supplied (status code 400) + * or User not found (status code 404) + */ + @Operation( + operationId = "deleteUser", + summary = "Delete user", + description = "This can only be done by the logged in user.", + tags = { "user" }, + responses = { + @ApiResponse(responseCode = "400", description = "Invalid username supplied"), + @ApiResponse(responseCode = "404", description = "User not found") + }, + security = { + @SecurityRequirement(name = "api_key") + } + ) + @RequestMapping( + method = RequestMethod.DELETE, + value = "/user/{username}" + ) + + default ResponseEntity deleteUser( + @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); + + } + + + /** + * GET /user/{username} : Get user by user name + * + * + * @param username The name that needs to be fetched. Use user1 for testing. (required) + * @return successful operation (status code 200) + * or Invalid username supplied (status code 400) + * or User not found (status code 404) + */ + @Operation( + operationId = "getUserByName", + summary = "Get user by user name", + description = "", + tags = { "user" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", schema = @Schema(implementation = User.class)), + @Content(mediaType = "application/json", schema = @Schema(implementation = User.class)) + }), + @ApiResponse(responseCode = "400", description = "Invalid username supplied"), + @ApiResponse(responseCode = "404", description = "User not found") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/user/{username}", + produces = { "application/xml", "application/json" } + ) + + default ResponseEntity getUserByName( + @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); + + } + + + /** + * GET /user/login : Logs user into the system + * + * + * @param username The user name for login (required) + * @param password The password for login in clear text (required) + * @return successful operation (status code 200) + * or Invalid username/password supplied (status code 400) + */ + @Operation( + operationId = "loginUser", + summary = "Logs user into the system", + description = "", + tags = { "user" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", schema = @Schema(implementation = String.class)), + @Content(mediaType = "application/json", schema = @Schema(implementation = String.class)) + }), + @ApiResponse(responseCode = "400", description = "Invalid username/password supplied") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/user/login", + produces = { "application/xml", "application/json" } + ) + + 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); + + } + + + /** + * GET /user/logout : Logs out current logged in user session + * + * + * @return successful operation (status code 200) + */ + @Operation( + operationId = "logoutUser", + summary = "Logs out current logged in user session", + description = "", + tags = { "user" }, + responses = { + @ApiResponse(responseCode = "default", description = "successful operation") + }, + security = { + @SecurityRequirement(name = "api_key") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/user/logout" + ) + + default ResponseEntity logoutUser( + + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + + /** + * PUT /user/{username} : Updated user + * This can only be done by the logged in user. + * + * @param username name that need to be deleted (required) + * @param user Updated user object (required) + * @return Invalid user supplied (status code 400) + * or User not found (status code 404) + */ + @Operation( + operationId = "updateUser", + summary = "Updated user", + description = "This can only be done by the logged in user.", + tags = { "user" }, + responses = { + @ApiResponse(responseCode = "400", description = "Invalid user supplied"), + @ApiResponse(responseCode = "404", description = "User not found") + }, + security = { + @SecurityRequirement(name = "api_key") + } + ) + @RequestMapping( + method = RequestMethod.PUT, + value = "/user/{username}", + consumes = { "application/json" } + ) + + default ResponseEntity updateUser( + @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 00000000000..2067b64b6fc --- /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") +@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 00000000000..9aa29284ab5 --- /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 00000000000..2ea502c445a --- /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 new file mode 100644 index 00000000000..2f44827bc5b --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Category.java @@ -0,0 +1,34 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import org.openapitools.jackson.nullable.JsonNullable; +import java.time.OffsetDateTime; +import javax.validation.Valid; +import javax.validation.constraints.*; +import io.swagger.v3.oas.annotations.media.Schema; + + +import java.util.*; +import javax.annotation.Generated; + +/** + * A category for a pet + */ +@lombok.Data +@lombok.Builder +@lombok.NoArgsConstructor +@lombok.AllArgsConstructor + +@Schema(name = "Category", description = "A category for a pet") +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +public class Category { + + private Long id; + + private 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 new file mode 100644 index 00000000000..ca881151e5a --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/ModelApiResponse.java @@ -0,0 +1,38 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonTypeName; +import org.openapitools.jackson.nullable.JsonNullable; +import java.time.OffsetDateTime; +import javax.validation.Valid; +import javax.validation.constraints.*; +import io.swagger.v3.oas.annotations.media.Schema; + + +import java.util.*; +import javax.annotation.Generated; + +/** + * Describes the result of uploading an image resource + */ +@lombok.Data +@lombok.Builder +@lombok.NoArgsConstructor +@lombok.AllArgsConstructor + +@Schema(name = "ApiResponse", description = "Describes the result of uploading an image resource") +@JsonTypeName("ApiResponse") +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +public class ModelApiResponse { + + private Integer code; + + private String type; + + private 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 new file mode 100644 index 00000000000..97e87661281 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Order.java @@ -0,0 +1,83 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import java.time.OffsetDateTime; +import org.springframework.format.annotation.DateTimeFormat; +import org.openapitools.jackson.nullable.JsonNullable; +import java.time.OffsetDateTime; +import javax.validation.Valid; +import javax.validation.constraints.*; +import io.swagger.v3.oas.annotations.media.Schema; + + +import java.util.*; +import javax.annotation.Generated; + +/** + * An order for a pets from the pet store + */ +@lombok.Data +@lombok.Builder +@lombok.NoArgsConstructor +@lombok.AllArgsConstructor + +@Schema(name = "Order", description = "An order for a pets from the pet store") +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +public class Order { + + private Long id; + + private Long petId; + + private Integer quantity; + + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) + private OffsetDateTime shipDate; + + /** + * Order Status + */ + public enum StatusEnum { + PLACED("placed"), + + APPROVED("approved"), + + DELIVERED("delivered"); + + private String value; + + StatusEnum(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static StatusEnum fromValue(String value) { + for (StatusEnum b : StatusEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + private StatusEnum status; + + 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 new file mode 100644 index 00000000000..1a88a923c34 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Pet.java @@ -0,0 +1,90 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.openapitools.model.Category; +import org.openapitools.model.Tag; +import org.openapitools.jackson.nullable.JsonNullable; +import java.time.OffsetDateTime; +import javax.validation.Valid; +import javax.validation.constraints.*; +import io.swagger.v3.oas.annotations.media.Schema; + + +import java.util.*; +import javax.annotation.Generated; + +/** + * A pet for sale in the pet store + */ +@lombok.Data +@lombok.Builder +@lombok.NoArgsConstructor +@lombok.AllArgsConstructor + +@Schema(name = "Pet", description = "A pet for sale in the pet store") +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +public class Pet { + + private Long id; + + private Category category; + + @lombok.NonNull + private String name; + + @lombok.NonNull + @Valid + private List photoUrls = new ArrayList<>(); + + @Valid + private List<@Valid Tag> tags; + + /** + * pet status in the store + */ + public enum StatusEnum { + AVAILABLE("available"), + + PENDING("pending"), + + SOLD("sold"); + + private String value; + + StatusEnum(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static StatusEnum fromValue(String value) { + for (StatusEnum b : StatusEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @Deprecated + private 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 new file mode 100644 index 00000000000..7ac46323989 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/Tag.java @@ -0,0 +1,34 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import org.openapitools.jackson.nullable.JsonNullable; +import java.time.OffsetDateTime; +import javax.validation.Valid; +import javax.validation.constraints.*; +import io.swagger.v3.oas.annotations.media.Schema; + + +import java.util.*; +import javax.annotation.Generated; + +/** + * A tag for a pet + */ +@lombok.Data +@lombok.Builder +@lombok.NoArgsConstructor +@lombok.AllArgsConstructor + +@Schema(name = "Tag", description = "A tag for a pet") +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +public class Tag { + + private Long id; + + private 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 new file mode 100644 index 00000000000..112386252c2 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/model/User.java @@ -0,0 +1,46 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import org.openapitools.jackson.nullable.JsonNullable; +import java.time.OffsetDateTime; +import javax.validation.Valid; +import javax.validation.constraints.*; +import io.swagger.v3.oas.annotations.media.Schema; + + +import java.util.*; +import javax.annotation.Generated; + +/** + * A User who is purchasing from the pet store + */ +@lombok.Data +@lombok.Builder +@lombok.NoArgsConstructor +@lombok.AllArgsConstructor + +@Schema(name = "User", description = "A User who is purchasing from the pet store") +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +public class User { + + private Long id; + + private String username; + + private String firstName; + + private String lastName; + + private String email; + + private String password; + + private String phone; + + private 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 new file mode 100644 index 00000000000..7e90813e59b --- /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 00000000000..cee3307f79a --- /dev/null +++ b/samples/server/petstore/springboot-lombok-data/src/main/resources/openapi.yaml @@ -0,0 +1,880 @@ +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 00000000000..3681f67e770 --- /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 diff --git a/samples/server/petstore/springboot-lombok-tostring/.openapi-generator-ignore b/samples/server/petstore/springboot-lombok-tostring/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/server/petstore/springboot-lombok-tostring/.openapi-generator/FILES b/samples/server/petstore/springboot-lombok-tostring/.openapi-generator/FILES new file mode 100644 index 00000000000..b15e2c45d45 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/.openapi-generator/FILES @@ -0,0 +1,19 @@ +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-tostring/.openapi-generator/VERSION b/samples/server/petstore/springboot-lombok-tostring/.openapi-generator/VERSION new file mode 100644 index 00000000000..fff4bdd7ab5 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/springboot-lombok-tostring/README.md b/samples/server/petstore/springboot-lombok-tostring/README.md new file mode 100644 index 00000000000..5cd22b6081a --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/README.md @@ -0,0 +1,21 @@ +# OpenAPI generated server + +Spring Boot Server + +## 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. + + +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/ + +Start your server as a simple java application + +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-tostring/pom.xml b/samples/server/petstore/springboot-lombok-tostring/pom.xml new file mode 100644 index 00000000000..9d17fff871d --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/pom.xml @@ -0,0 +1,108 @@ + + 4.0.0 + org.openapitools.openapi3 + springboot-lombok-tostring + jar + springboot-lombok-tostring + 1.0.0 + + 17 + ${java.version} + ${java.version} + UTF-8 + 2.2.0 + 5.3.1 + + + org.springframework.boot + spring-boot-starter-parent + 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.springframework.boot + spring-boot-starter-web + + + org.springframework.data + spring-data-commons + + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + ${springdoc.version} + + + + com.google.code.findbugs + jsr305 + 3.0.2 + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + org.openapitools + jackson-databind-nullable + 0.2.6 + + + + org.springframework.boot + spring-boot-starter-validation + + + org.projectlombok + lombok + true + + + com.fasterxml.jackson.core + jackson-databind + + + org.springframework.boot + spring-boot-starter-test + test + + + diff --git a/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/OpenApiGeneratorApplication.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/OpenApiGeneratorApplication.java new file mode 100644 index 00000000000..97252a8a940 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/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-tostring/src/main/java/org/openapitools/RFC3339DateFormat.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/RFC3339DateFormat.java new file mode 100644 index 00000000000..bcd3936d8b3 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/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-tostring/src/main/java/org/openapitools/api/ApiUtil.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/api/ApiUtil.java new file mode 100644 index 00000000000..9bcd4f230ed --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/api/ApiUtil.java @@ -0,0 +1,19 @@ +package org.openapitools.api; + +import org.springframework.web.context.request.NativeWebRequest; + +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class ApiUtil { + public static void setExampleResponse(NativeWebRequest req, String contentType, String example) { + try { + HttpServletResponse res = req.getNativeResponse(HttpServletResponse.class); + res.setCharacterEncoding("UTF-8"); + res.addHeader("Content-Type", contentType); + res.getWriter().print(example); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/api/PetApi.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/api/PetApi.java new file mode 100644 index 00000000000..4315785bdb1 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/api/PetApi.java @@ -0,0 +1,438 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.3.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package org.openapitools.api; + +import org.openapitools.model.ModelApiResponse; +import org.openapitools.model.Pet; +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +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 java.util.List; +import java.util.Map; +import java.util.Optional; +import jakarta.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +@Validated +@Tag(name = "pet", description = "Everything about your Pets") +public interface PetApi { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * POST /pet : Add a new pet to the store + * + * + * @param pet Pet object that needs to be added to the store (required) + * @return successful operation (status code 200) + * or Invalid input (status code 405) + */ + @Operation( + operationId = "addPet", + summary = "Add a new pet to the store", + description = "", + tags = { "pet" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", schema = @Schema(implementation = Pet.class)), + @Content(mediaType = "application/json", schema = @Schema(implementation = Pet.class)) + }), + @ApiResponse(responseCode = "405", description = "Invalid input") + }, + security = { + @SecurityRequirement(name = "petstore_auth", scopes={ "write:pets", "read:pets" }) + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/pet", + produces = { "application/xml", "application/json" }, + consumes = { "application/json", "application/xml" } + ) + + 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); + + } + + + /** + * DELETE /pet/{petId} : Deletes a pet + * + * + * @param petId Pet id to delete (required) + * @param apiKey (optional) + * @return Invalid pet value (status code 400) + */ + @Operation( + operationId = "deletePet", + summary = "Deletes a pet", + description = "", + tags = { "pet" }, + responses = { + @ApiResponse(responseCode = "400", description = "Invalid pet value") + }, + security = { + @SecurityRequirement(name = "petstore_auth", scopes={ "write:pets", "read:pets" }) + } + ) + @RequestMapping( + method = RequestMethod.DELETE, + value = "/pet/{petId}" + ) + + default ResponseEntity deletePet( + @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) String apiKey + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + + /** + * GET /pet/findByStatus : Finds Pets by status + * Multiple status values can be provided with comma separated strings + * + * @param status Status values that need to be considered for filter (required) + * @return successful operation (status code 200) + * or Invalid status value (status code 400) + */ + @Operation( + operationId = "findPetsByStatus", + summary = "Finds Pets by status", + description = "Multiple status values can be provided with comma separated strings", + tags = { "pet" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", array = @ArraySchema(schema = @Schema(implementation = Pet.class))), + @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = Pet.class))) + }), + @ApiResponse(responseCode = "400", description = "Invalid status value") + }, + security = { + @SecurityRequirement(name = "petstore_auth", scopes={ "read:pets" }) + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/pet/findByStatus", + produces = { "application/xml", "application/json" } + ) + + 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); + + } + + + /** + * GET /pet/findByTags : Finds Pets by tags + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * + * @param tags Tags to filter by (required) + * @return successful operation (status code 200) + * or Invalid tag value (status code 400) + * @deprecated + */ + @Deprecated + @Operation( + operationId = "findPetsByTags", + summary = "Finds Pets by tags", + description = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", + deprecated = true, + tags = { "pet" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", array = @ArraySchema(schema = @Schema(implementation = Pet.class))), + @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = Pet.class))) + }), + @ApiResponse(responseCode = "400", description = "Invalid tag value") + }, + security = { + @SecurityRequirement(name = "petstore_auth", scopes={ "read:pets" }) + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/pet/findByTags", + produces = { "application/xml", "application/json" } + ) + + 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); + + } + + + /** + * GET /pet/{petId} : Find pet by ID + * Returns a single pet + * + * @param petId ID of pet to return (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Pet not found (status code 404) + */ + @Operation( + operationId = "getPetById", + summary = "Find pet by ID", + description = "Returns a single pet", + tags = { "pet" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", schema = @Schema(implementation = Pet.class)), + @Content(mediaType = "application/json", schema = @Schema(implementation = Pet.class)) + }), + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Pet not found") + }, + security = { + @SecurityRequirement(name = "api_key") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/pet/{petId}", + produces = { "application/xml", "application/json" } + ) + + default ResponseEntity getPetById( + @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); + + } + + + /** + * PUT /pet : Update an existing pet + * + * + * @param pet Pet object that needs to be added to the store (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Pet not found (status code 404) + * or Validation exception (status code 405) + * API documentation for the updatePet operation + * @see Update an existing pet Documentation + */ + @Operation( + operationId = "updatePet", + summary = "Update an existing pet", + description = "", + tags = { "pet" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", schema = @Schema(implementation = Pet.class)), + @Content(mediaType = "application/json", schema = @Schema(implementation = Pet.class)) + }), + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Pet not found"), + @ApiResponse(responseCode = "405", description = "Validation exception") + }, + security = { + @SecurityRequirement(name = "petstore_auth", scopes={ "write:pets", "read:pets" }) + }, + externalDocs = @ExternalDocumentation(description = "API documentation for the updatePet operation", url = "http://petstore.swagger.io/v2/doc/updatePet") + ) + @RequestMapping( + method = RequestMethod.PUT, + value = "/pet", + produces = { "application/xml", "application/json" }, + consumes = { "application/json", "application/xml" } + ) + + 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); + + } + + + /** + * POST /pet/{petId} : Updates a pet in the store with form data + * + * + * @param petId ID of pet that needs to be updated (required) + * @param name Updated name of the pet (optional) + * @param status Updated status of the pet (optional) + * @return Invalid input (status code 405) + */ + @Operation( + operationId = "updatePetWithForm", + summary = "Updates a pet in the store with form data", + description = "", + tags = { "pet" }, + responses = { + @ApiResponse(responseCode = "405", description = "Invalid input") + }, + security = { + @SecurityRequirement(name = "petstore_auth", scopes={ "write:pets", "read:pets" }) + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/pet/{petId}", + consumes = { "application/x-www-form-urlencoded" } + ) + + default ResponseEntity updatePetWithForm( + @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); + + } + + + /** + * POST /pet/{petId}/uploadImage : uploads an image + * + * + * @param petId ID of pet to update (required) + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return successful operation (status code 200) + */ + @Operation( + operationId = "uploadFile", + summary = "uploads an image", + description = "", + tags = { "pet" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = ModelApiResponse.class)) + }) + }, + security = { + @SecurityRequirement(name = "petstore_auth", scopes={ "write:pets", "read:pets" }) + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/pet/{petId}/uploadImage", + produces = { "application/json" }, + consumes = { "multipart/form-data" } + ) + + default ResponseEntity uploadFile( + @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-tostring/src/main/java/org/openapitools/api/PetApiController.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/api/PetApiController.java new file mode 100644 index 00000000000..87d02eed2df --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/api/PetApiController.java @@ -0,0 +1,47 @@ +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 jakarta.validation.constraints.*; +import jakarta.validation.Valid; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import jakarta.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-tostring/src/main/java/org/openapitools/api/StoreApi.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/api/StoreApi.java new file mode 100644 index 00000000000..faf96a6d4bb --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/api/StoreApi.java @@ -0,0 +1,210 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.3.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package org.openapitools.api; + +import java.util.Map; +import org.openapitools.model.Order; +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +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 java.util.List; +import java.util.Map; +import java.util.Optional; +import jakarta.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +@Validated +@Tag(name = "store", description = "Access to Petstore orders") +public interface StoreApi { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * DELETE /store/order/{orderId} : Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * + * @param orderId ID of the order that needs to be deleted (required) + * @return Invalid ID supplied (status code 400) + * or Order not found (status code 404) + */ + @Operation( + operationId = "deleteOrder", + summary = "Delete purchase order by ID", + description = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", + tags = { "store" }, + responses = { + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Order not found") + } + ) + @RequestMapping( + method = RequestMethod.DELETE, + value = "/store/order/{orderId}" + ) + + default ResponseEntity deleteOrder( + @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); + + } + + + /** + * GET /store/inventory : Returns pet inventories by status + * Returns a map of status codes to quantities + * + * @return successful operation (status code 200) + */ + @Operation( + operationId = "getInventory", + summary = "Returns pet inventories by status", + description = "Returns a map of status codes to quantities", + tags = { "store" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = Map.class)) + }) + }, + security = { + @SecurityRequirement(name = "api_key") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/store/inventory", + produces = { "application/json" } + ) + + default ResponseEntity> getInventory( + + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + + /** + * GET /store/order/{orderId} : Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions + * + * @param orderId ID of pet that needs to be fetched (required) + * @return successful operation (status code 200) + * or Invalid ID supplied (status code 400) + * or Order not found (status code 404) + */ + @Operation( + operationId = "getOrderById", + summary = "Find purchase order by ID", + description = "For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions", + tags = { "store" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", schema = @Schema(implementation = Order.class)), + @Content(mediaType = "application/json", schema = @Schema(implementation = Order.class)) + }), + @ApiResponse(responseCode = "400", description = "Invalid ID supplied"), + @ApiResponse(responseCode = "404", description = "Order not found") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/store/order/{orderId}", + produces = { "application/xml", "application/json" } + ) + + default ResponseEntity getOrderById( + @Min(1L) @Max(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); + + } + + + /** + * POST /store/order : Place an order for a pet + * + * + * @param order order placed for purchasing the pet (required) + * @return successful operation (status code 200) + * or Invalid Order (status code 400) + */ + @Operation( + operationId = "placeOrder", + summary = "Place an order for a pet", + description = "", + tags = { "store" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", schema = @Schema(implementation = Order.class)), + @Content(mediaType = "application/json", schema = @Schema(implementation = Order.class)) + }), + @ApiResponse(responseCode = "400", description = "Invalid Order") + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/store/order", + produces = { "application/xml", "application/json" }, + consumes = { "application/json" } + ) + + 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-tostring/src/main/java/org/openapitools/api/StoreApiController.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/api/StoreApiController.java new file mode 100644 index 00000000000..23187514cb8 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/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 jakarta.validation.constraints.*; +import jakarta.validation.Valid; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import jakarta.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-tostring/src/main/java/org/openapitools/api/UserApi.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/api/UserApi.java new file mode 100644 index 00000000000..72b93800877 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/api/UserApi.java @@ -0,0 +1,333 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.3.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package org.openapitools.api; + +import java.time.OffsetDateTime; +import org.openapitools.model.User; +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +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 java.util.List; +import java.util.Map; +import java.util.Optional; +import jakarta.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +@Validated +@Tag(name = "user", description = "Operations about user") +public interface UserApi { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * POST /user : Create user + * This can only be done by the logged in user. + * + * @param user Created user object (required) + * @return successful operation (status code 200) + */ + @Operation( + operationId = "createUser", + summary = "Create user", + description = "This can only be done by the logged in user.", + tags = { "user" }, + responses = { + @ApiResponse(responseCode = "default", description = "successful operation") + }, + security = { + @SecurityRequirement(name = "api_key") + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/user", + consumes = { "application/json" } + ) + + default ResponseEntity createUser( + @Parameter(name = "User", description = "Created user object", required = true) @Valid @RequestBody User user + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + + /** + * POST /user/createWithArray : Creates list of users with given input array + * + * + * @param user List of user object (required) + * @return successful operation (status code 200) + */ + @Operation( + operationId = "createUsersWithArrayInput", + summary = "Creates list of users with given input array", + description = "", + tags = { "user" }, + responses = { + @ApiResponse(responseCode = "default", description = "successful operation") + }, + security = { + @SecurityRequirement(name = "api_key") + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/user/createWithArray", + consumes = { "application/json" } + ) + + 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); + + } + + + /** + * POST /user/createWithList : Creates list of users with given input array + * + * + * @param user List of user object (required) + * @return successful operation (status code 200) + */ + @Operation( + operationId = "createUsersWithListInput", + summary = "Creates list of users with given input array", + description = "", + tags = { "user" }, + responses = { + @ApiResponse(responseCode = "default", description = "successful operation") + }, + security = { + @SecurityRequirement(name = "api_key") + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/user/createWithList", + consumes = { "application/json" } + ) + + 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); + + } + + + /** + * DELETE /user/{username} : Delete user + * This can only be done by the logged in user. + * + * @param username The name that needs to be deleted (required) + * @return Invalid username supplied (status code 400) + * or User not found (status code 404) + */ + @Operation( + operationId = "deleteUser", + summary = "Delete user", + description = "This can only be done by the logged in user.", + tags = { "user" }, + responses = { + @ApiResponse(responseCode = "400", description = "Invalid username supplied"), + @ApiResponse(responseCode = "404", description = "User not found") + }, + security = { + @SecurityRequirement(name = "api_key") + } + ) + @RequestMapping( + method = RequestMethod.DELETE, + value = "/user/{username}" + ) + + default ResponseEntity deleteUser( + @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); + + } + + + /** + * GET /user/{username} : Get user by user name + * + * + * @param username The name that needs to be fetched. Use user1 for testing. (required) + * @return successful operation (status code 200) + * or Invalid username supplied (status code 400) + * or User not found (status code 404) + */ + @Operation( + operationId = "getUserByName", + summary = "Get user by user name", + description = "", + tags = { "user" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", schema = @Schema(implementation = User.class)), + @Content(mediaType = "application/json", schema = @Schema(implementation = User.class)) + }), + @ApiResponse(responseCode = "400", description = "Invalid username supplied"), + @ApiResponse(responseCode = "404", description = "User not found") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/user/{username}", + produces = { "application/xml", "application/json" } + ) + + default ResponseEntity getUserByName( + @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); + + } + + + /** + * GET /user/login : Logs user into the system + * + * + * @param username The user name for login (required) + * @param password The password for login in clear text (required) + * @return successful operation (status code 200) + * or Invalid username/password supplied (status code 400) + */ + @Operation( + operationId = "loginUser", + summary = "Logs user into the system", + description = "", + tags = { "user" }, + responses = { + @ApiResponse(responseCode = "200", description = "successful operation", content = { + @Content(mediaType = "application/xml", schema = @Schema(implementation = String.class)), + @Content(mediaType = "application/json", schema = @Schema(implementation = String.class)) + }), + @ApiResponse(responseCode = "400", description = "Invalid username/password supplied") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/user/login", + produces = { "application/xml", "application/json" } + ) + + 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); + + } + + + /** + * GET /user/logout : Logs out current logged in user session + * + * + * @return successful operation (status code 200) + */ + @Operation( + operationId = "logoutUser", + summary = "Logs out current logged in user session", + description = "", + tags = { "user" }, + responses = { + @ApiResponse(responseCode = "default", description = "successful operation") + }, + security = { + @SecurityRequirement(name = "api_key") + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/user/logout" + ) + + default ResponseEntity logoutUser( + + ) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + + /** + * PUT /user/{username} : Updated user + * This can only be done by the logged in user. + * + * @param username name that need to be deleted (required) + * @param user Updated user object (required) + * @return Invalid user supplied (status code 400) + * or User not found (status code 404) + */ + @Operation( + operationId = "updateUser", + summary = "Updated user", + description = "This can only be done by the logged in user.", + tags = { "user" }, + responses = { + @ApiResponse(responseCode = "400", description = "Invalid user supplied"), + @ApiResponse(responseCode = "404", description = "User not found") + }, + security = { + @SecurityRequirement(name = "api_key") + } + ) + @RequestMapping( + method = RequestMethod.PUT, + value = "/user/{username}", + consumes = { "application/json" } + ) + + default ResponseEntity updateUser( + @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-tostring/src/main/java/org/openapitools/api/UserApiController.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/api/UserApiController.java new file mode 100644 index 00000000000..03d837700ff --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/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 jakarta.validation.constraints.*; +import jakarta.validation.Valid; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import jakarta.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-tostring/src/main/java/org/openapitools/configuration/HomeController.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/configuration/HomeController.java new file mode 100644 index 00000000000..9aa29284ab5 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/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-tostring/src/main/java/org/openapitools/configuration/SpringDocConfiguration.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/configuration/SpringDocConfiguration.java new file mode 100644 index 00000000000..2ea502c445a --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/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-tostring/src/main/java/org/openapitools/model/Category.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/model/Category.java new file mode 100644 index 00000000000..98f1c6d03c4 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/model/Category.java @@ -0,0 +1,48 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import org.openapitools.jackson.nullable.JsonNullable; +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; + + +import java.util.*; +import jakarta.annotation.Generated; + +/** + * A category for a pet + */ +@lombok.Getter +@lombok.Setter +@lombok.ToString +@lombok.EqualsAndHashCode + +@Schema(name = "Category", description = "A category for a pet") +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +public class Category { + + private Long id; + + private String name; + + public Category id(Long id) { + this.id = id; + return this; + } + + + public Category name(String name) { + this.name = name; + return this; + } + + + +} + diff --git a/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/model/ModelApiResponse.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/model/ModelApiResponse.java new file mode 100644 index 00000000000..1c34d5b8f70 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/model/ModelApiResponse.java @@ -0,0 +1,58 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonTypeName; +import org.openapitools.jackson.nullable.JsonNullable; +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; + + +import java.util.*; +import jakarta.annotation.Generated; + +/** + * Describes the result of uploading an image resource + */ +@lombok.Getter +@lombok.Setter +@lombok.ToString +@lombok.EqualsAndHashCode + +@Schema(name = "ApiResponse", description = "Describes the result of uploading an image resource") +@JsonTypeName("ApiResponse") +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +public class ModelApiResponse { + + private Integer code; + + private String type; + + private String message; + + public ModelApiResponse code(Integer code) { + this.code = code; + return this; + } + + + public ModelApiResponse type(String type) { + this.type = type; + return this; + } + + + public ModelApiResponse message(String message) { + this.message = message; + return this; + } + + + +} + diff --git a/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/model/Order.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/model/Order.java new file mode 100644 index 00000000000..0b6294c8746 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/model/Order.java @@ -0,0 +1,121 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import java.time.OffsetDateTime; +import org.springframework.format.annotation.DateTimeFormat; +import org.openapitools.jackson.nullable.JsonNullable; +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; + + +import java.util.*; +import jakarta.annotation.Generated; + +/** + * An order for a pets from the pet store + */ +@lombok.Getter +@lombok.Setter +@lombok.ToString +@lombok.EqualsAndHashCode + +@Schema(name = "Order", description = "An order for a pets from the pet store") +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +public class Order { + + private Long id; + + private Long petId; + + private Integer quantity; + + @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) + private OffsetDateTime shipDate; + + /** + * Order Status + */ + public enum StatusEnum { + PLACED("placed"), + + APPROVED("approved"), + + DELIVERED("delivered"); + + private String value; + + StatusEnum(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static StatusEnum fromValue(String value) { + for (StatusEnum b : StatusEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + private StatusEnum status; + + private Boolean complete = false; + + public Order id(Long id) { + this.id = id; + return this; + } + + + public Order petId(Long petId) { + this.petId = petId; + return this; + } + + + public Order quantity(Integer quantity) { + this.quantity = quantity; + return this; + } + + + public Order shipDate(OffsetDateTime shipDate) { + this.shipDate = shipDate; + return this; + } + + + public Order status(StatusEnum status) { + this.status = status; + return this; + } + + + public Order complete(Boolean complete) { + this.complete = complete; + return this; + } + + + +} + diff --git a/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/model/Pet.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/model/Pet.java new file mode 100644 index 00000000000..37b9d8ab3ba --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/model/Pet.java @@ -0,0 +1,156 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.openapitools.model.Category; +import org.openapitools.model.Tag; +import org.openapitools.jackson.nullable.JsonNullable; +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; + + +import java.util.*; +import jakarta.annotation.Generated; + +/** + * A pet for sale in the pet store + */ +@lombok.Getter +@lombok.Setter +@lombok.ToString +@lombok.EqualsAndHashCode + +@Schema(name = "Pet", description = "A pet for sale in the pet store") +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +public class Pet { + + private Long id; + + private Category category; + + @lombok.NonNull + private String name; + + @lombok.NonNull + @Valid + private List photoUrls = new ArrayList<>(); + + @Valid + private List<@Valid Tag> tags; + + /** + * pet status in the store + */ + public enum StatusEnum { + AVAILABLE("available"), + + PENDING("pending"), + + SOLD("sold"); + + private String value; + + StatusEnum(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static StatusEnum fromValue(String value) { + for (StatusEnum b : StatusEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @Deprecated + private StatusEnum status; + + public Pet() { + super(); + } + + /** + * Constructor with only required parameters + */ + public Pet(String name, List photoUrls) { + this.name = name; + this.photoUrls = photoUrls; + } + + public Pet id(Long id) { + this.id = id; + return this; + } + + + public Pet category(Category category) { + this.category = category; + return this; + } + + + public Pet name(String name) { + this.name = name; + return this; + } + + + public Pet photoUrls(List photoUrls) { + this.photoUrls = photoUrls; + return this; + } + + public Pet addPhotoUrlsItem(String photoUrlsItem) { + if (this.photoUrls == null) { + this.photoUrls = new ArrayList<>(); + } + this.photoUrls.add(photoUrlsItem); + return this; + } + + + public Pet tags(List<@Valid Tag> tags) { + this.tags = tags; + return this; + } + + public Pet addTagsItem(Tag tagsItem) { + if (this.tags == null) { + this.tags = new ArrayList<>(); + } + this.tags.add(tagsItem); + return this; + } + + + public Pet status(StatusEnum status) { + this.status = status; + return this; + } + + + +} + diff --git a/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/model/Tag.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/model/Tag.java new file mode 100644 index 00000000000..4ce816c672c --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/model/Tag.java @@ -0,0 +1,48 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import org.openapitools.jackson.nullable.JsonNullable; +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; + + +import java.util.*; +import jakarta.annotation.Generated; + +/** + * A tag for a pet + */ +@lombok.Getter +@lombok.Setter +@lombok.ToString +@lombok.EqualsAndHashCode + +@Schema(name = "Tag", description = "A tag for a pet") +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +public class Tag { + + private Long id; + + private String name; + + public Tag id(Long id) { + this.id = id; + return this; + } + + + public Tag name(String name) { + this.name = name; + return this; + } + + + +} + diff --git a/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/model/User.java b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/model/User.java new file mode 100644 index 00000000000..1e6737c9c5b --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/src/main/java/org/openapitools/model/User.java @@ -0,0 +1,96 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import org.openapitools.jackson.nullable.JsonNullable; +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; + + +import java.util.*; +import jakarta.annotation.Generated; + +/** + * A User who is purchasing from the pet store + */ +@lombok.Getter +@lombok.Setter +@lombok.ToString +@lombok.EqualsAndHashCode + +@Schema(name = "User", description = "A User who is purchasing from the pet store") +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen") +public class User { + + private Long id; + + private String username; + + private String firstName; + + private String lastName; + + private String email; + + private String password; + + private String phone; + + private Integer userStatus; + + public User id(Long id) { + this.id = id; + return this; + } + + + public User username(String username) { + this.username = username; + return this; + } + + + public User firstName(String firstName) { + this.firstName = firstName; + return this; + } + + + public User lastName(String lastName) { + this.lastName = lastName; + return this; + } + + + public User email(String email) { + this.email = email; + return this; + } + + + public User password(String password) { + this.password = password; + return this; + } + + + public User phone(String phone) { + this.phone = phone; + return this; + } + + + public User userStatus(Integer userStatus) { + this.userStatus = userStatus; + return this; + } + + + +} + diff --git a/samples/server/petstore/springboot-lombok-tostring/src/main/resources/application.properties b/samples/server/petstore/springboot-lombok-tostring/src/main/resources/application.properties new file mode 100644 index 00000000000..7e90813e59b --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/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-tostring/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-lombok-tostring/src/main/resources/openapi.yaml new file mode 100644 index 00000000000..cee3307f79a --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/src/main/resources/openapi.yaml @@ -0,0 +1,880 @@ +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-tostring/src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java b/samples/server/petstore/springboot-lombok-tostring/src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java new file mode 100644 index 00000000000..3681f67e770 --- /dev/null +++ b/samples/server/petstore/springboot-lombok-tostring/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 diff --git a/samples/server/petstore/springboot-reactive-noResponseEntity/pom.xml b/samples/server/petstore/springboot-reactive-noResponseEntity/pom.xml index 927e9b9ea7c..d445bc501aa 100644 --- a/samples/server/petstore/springboot-reactive-noResponseEntity/pom.xml +++ b/samples/server/petstore/springboot-reactive-noResponseEntity/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/server/petstore/springboot-reactive/pom.xml b/samples/server/petstore/springboot-reactive/pom.xml index 603acf9c8b4..586a1099ee6 100644 --- a/samples/server/petstore/springboot-reactive/pom.xml +++ b/samples/server/petstore/springboot-reactive/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/pom.xml b/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/pom.xml index fbc20526c98..814077ac4e1 100644 --- a/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/pom.xml +++ b/samples/server/petstore/springboot-spring-pageable-delegatePattern-without-j8/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/server/petstore/springboot-spring-pageable-delegatePattern/pom.xml b/samples/server/petstore/springboot-spring-pageable-delegatePattern/pom.xml index 8bbfb1c4048..6623444ffa3 100644 --- a/samples/server/petstore/springboot-spring-pageable-delegatePattern/pom.xml +++ b/samples/server/petstore/springboot-spring-pageable-delegatePattern/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/server/petstore/springboot-spring-pageable-without-j8/pom.xml b/samples/server/petstore/springboot-spring-pageable-without-j8/pom.xml index 86450ac82f4..b518d1dee9f 100644 --- a/samples/server/petstore/springboot-spring-pageable-without-j8/pom.xml +++ b/samples/server/petstore/springboot-spring-pageable-without-j8/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/server/petstore/springboot-spring-pageable/pom.xml b/samples/server/petstore/springboot-spring-pageable/pom.xml index 74121202b3a..fed9f1d12e1 100644 --- a/samples/server/petstore/springboot-spring-pageable/pom.xml +++ b/samples/server/petstore/springboot-spring-pageable/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/server/petstore/springboot-spring-provide-args/pom.xml b/samples/server/petstore/springboot-spring-provide-args/pom.xml index 6fcbcf29548..4057470ce3f 100644 --- a/samples/server/petstore/springboot-spring-provide-args/pom.xml +++ b/samples/server/petstore/springboot-spring-provide-args/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/server/petstore/springboot-useoptional/pom.xml b/samples/server/petstore/springboot-useoptional/pom.xml index bf8246d57d8..f4633149324 100644 --- a/samples/server/petstore/springboot-useoptional/pom.xml +++ b/samples/server/petstore/springboot-useoptional/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/server/petstore/springboot-virtualan/pom.xml b/samples/server/petstore/springboot-virtualan/pom.xml index 19450529e58..36bdd555a28 100644 --- a/samples/server/petstore/springboot-virtualan/pom.xml +++ b/samples/server/petstore/springboot-virtualan/pom.xml @@ -26,6 +26,8 @@ org.springframework.boot spring-boot-maven-plugin + + diff --git a/samples/server/petstore/springboot/pom.xml b/samples/server/petstore/springboot/pom.xml index 56d68a5efd0..dcce5e10d79 100644 --- a/samples/server/petstore/springboot/pom.xml +++ b/samples/server/petstore/springboot/pom.xml @@ -25,6 +25,8 @@ org.springframework.boot spring-boot-maven-plugin + +