From 11aed4ee20fff8c9654a6c47d68e55118191c5b9 Mon Sep 17 00:00:00 2001 From: Mattias-Sehlstedt <60173714+Mattias-Sehlstedt@users.noreply.github.com> Date: Thu, 3 Jul 2025 11:48:57 +0200 Subject: [PATCH] Fixes the formatting for sealed interfaces in the JavaSpring generator --- bin/configs/spring-boot-oneof-sealed.yaml | 13 + .../resources/JavaSpring/permits.mustache | 2 +- .../main/resources/JavaSpring/sealed.mustache | 2 +- .../java/spring/SpringCodegenTest.java | 27 +- .../.openapi-generator-ignore | 23 ++ .../.openapi-generator/FILES | 31 ++ .../.openapi-generator/VERSION | 1 + .../spring-boot-oneof-sealed/README.md | 21 ++ .../petstore/spring-boot-oneof-sealed/pom.xml | 82 +++++ .../OpenApiGeneratorApplication.java | 30 ++ .../org/openapitools/RFC3339DateFormat.java | 38 ++ .../java/org/openapitools/api/ApiUtil.java | 19 + .../java/org/openapitools/api/BarApi.java | 86 +++++ .../openapitools/api/BarApiController.java | 48 +++ .../java/org/openapitools/api/FooApi.java | 124 +++++++ .../openapitools/api/FooApiController.java | 48 +++ .../EnumConverterConfiguration.java | 22 ++ .../configuration/HomeController.java | 20 + .../configuration/SpringDocConfiguration.java | 27 ++ .../org/openapitools/model/Addressable.java | 173 +++++++++ .../java/org/openapitools/model/Apple.java | 188 ++++++++++ .../java/org/openapitools/model/Banana.java | 188 ++++++++++ .../main/java/org/openapitools/model/Bar.java | 299 +++++++++++++++ .../org/openapitools/model/BarCreate.java | 281 ++++++++++++++ .../java/org/openapitools/model/BarRef.java | 209 +++++++++++ .../org/openapitools/model/BarRefOrValue.java | 38 ++ .../java/org/openapitools/model/Entity.java | 290 +++++++++++++++ .../org/openapitools/model/EntityRef.java | 347 ++++++++++++++++++ .../org/openapitools/model/Extensible.java | 213 +++++++++++ .../main/java/org/openapitools/model/Foo.java | 248 +++++++++++++ .../java/org/openapitools/model/FooRef.java | 240 ++++++++++++ .../org/openapitools/model/FooRefOrValue.java | 37 ++ .../java/org/openapitools/model/Fruit.java | 41 +++ .../org/openapitools/model/FruitType.java | 56 +++ .../java/org/openapitools/model/Pasta.java | 218 +++++++++++ .../java/org/openapitools/model/Pizza.java | 227 ++++++++++++ .../org/openapitools/model/PizzaSpeziale.java | 230 ++++++++++++ .../src/main/resources/application.properties | 3 + .../src/main/resources/openapi.yaml | 264 +++++++++++++ .../OpenApiGeneratorApplicationTests.java | 13 + 40 files changed, 4453 insertions(+), 14 deletions(-) create mode 100644 bin/configs/spring-boot-oneof-sealed.yaml create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/.openapi-generator-ignore create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/.openapi-generator/FILES create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/.openapi-generator/VERSION create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/README.md create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/pom.xml create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/OpenApiGeneratorApplication.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/RFC3339DateFormat.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/ApiUtil.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/BarApi.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/BarApiController.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/FooApi.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/FooApiController.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/configuration/EnumConverterConfiguration.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/configuration/HomeController.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/configuration/SpringDocConfiguration.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Addressable.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Apple.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Banana.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Bar.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/BarCreate.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/BarRef.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/BarRefOrValue.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Entity.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/EntityRef.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Extensible.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Foo.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/FooRef.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/FooRefOrValue.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Fruit.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/FruitType.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Pasta.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Pizza.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/PizzaSpeziale.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/resources/application.properties create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/resources/openapi.yaml create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java diff --git a/bin/configs/spring-boot-oneof-sealed.yaml b/bin/configs/spring-boot-oneof-sealed.yaml new file mode 100644 index 000000000000..83da74dc7c01 --- /dev/null +++ b/bin/configs/spring-boot-oneof-sealed.yaml @@ -0,0 +1,13 @@ +generatorName: spring +outputDir: samples/openapi3/server/petstore/spring-boot-oneof-sealed +inputSpec: modules/openapi-generator/src/test/resources/3_0/oneof_polymorphism_and_inheritance.yaml +templateDir: modules/openapi-generator/src/main/resources/JavaSpring +additionalProperties: + groupId: org.openapitools.openapi3 + documentationProvider: springdoc + artifactId: springboot-oneof-sealed + snapshotVersion: "true" + hideGenerationTimestamp: "true" + generateBuilders: true + useOneOfInterfaces: true + useSealed: true diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/permits.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/permits.mustache index 5d92534d6555..9583d443a1d5 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/permits.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/permits.mustache @@ -1 +1 @@ -{{#useSealed}}{{#permits}}{{#-first}}permits {{/-first}}{{{.}}}{{^-last}}, {{/-last}}{{/permits}} {{/useSealed}} \ No newline at end of file +{{#useSealed}}{{#permits}}{{#-first}}permits {{/-first}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}} {{/-last}}{{/permits}}{{/useSealed}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/sealed.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/sealed.mustache index a5c0af002702..60af17ea3290 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/sealed.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/sealed.mustache @@ -1 +1 @@ -{{#useSealed}}{{#permits.0}}sealed {{/permits.0}}{{^permits.0}}{{^vendorExtensions.x-is-one-of-interface}}final {{/vendorExtensions.x-is-one-of-interface}}{{/permits.0}}{{/useSealed}} \ No newline at end of file +{{#useSealed}}{{#permits.0}}sealed {{/permits.0}}{{^permits.0}}{{^vendorExtensions.x-is-one-of-interface}}{{#vendorExtensions.x-implements}}final {{/vendorExtensions.x-implements}}{{/vendorExtensions.x-is-one-of-interface}}{{/permits.0}}{{/useSealed}} \ No newline at end of file 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 f0992bf36576..6ad3a993624c 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 @@ -2278,36 +2278,39 @@ public static Object[][] sealedScenarios() { {"oneOf_nonPrimitive.yaml", Map.of( "Example.java", "public interface Example {")}, {"oneOf_primitive.yaml", Map.of( - "Child.java", "public final class Child extends RepresentationModel implements Example {", + "Child.java", "public final class Child extends RepresentationModel implements Example {", "Example.java", "public sealed interface Example permits Child {")}, {"oneOf_primitiveAndArray.yaml", Map.of( "Example.java", "public interface Example {")}, {"oneOf_reuseRef.yaml", Map.of( "Fruit.java", "public sealed interface Fruit permits Apple, Banana {", - "Banana.java", "public final class Banana extends RepresentationModel implements Fruit {", - "Apple.java", "public final class Apple extends RepresentationModel implements Fruit {")}, + "Banana.java", "public final class Banana extends RepresentationModel implements Fruit {", + "Apple.java", "public final class Apple extends RepresentationModel implements Fruit {")}, {"oneOf_twoPrimitives.yaml", Map.of( - "MyExamplePostRequest.java", "public interface MyExamplePostRequest {")}, + "MyExamplePostRequest.java", "public interface MyExamplePostRequest {")}, {"oneOfArrayMapImport.yaml", Map.of( "Fruit.java", "public interface Fruit {", - "Grape.java", "public final class Grape extends RepresentationModel {", - "Apple.java", "public final class Apple extends RepresentationModel {")}, + "Grape.java", "public class Grape extends RepresentationModel {", + "Apple.java", "public class Apple extends RepresentationModel {")}, {"oneOfDiscriminator.yaml", Map.of( "FruitAllOfDisc.java", "public sealed interface FruitAllOfDisc permits AppleAllOfDisc, BananaAllOfDisc {", - "FruitReqDisc.java", "public sealed interface FruitReqDisc permits AppleReqDisc, BananaReqDisc {\n")} + "AppleAllOfDisc.java", "public final class AppleAllOfDisc extends RepresentationModel implements FruitAllOfDisc {", + "BananaAllOfDisc.java", "public final class BananaAllOfDisc extends RepresentationModel implements FruitAllOfDisc {", + "FruitReqDisc.java", "public sealed interface FruitReqDisc permits AppleReqDisc, BananaReqDisc {", + "AppleReqDisc.java", "public final class AppleReqDisc extends RepresentationModel implements FruitReqDisc {", + "BananaReqDisc.java", "public final class BananaReqDisc extends RepresentationModel implements FruitReqDisc {")} }; } @Test(dataProvider = "sealedScenarios", description = "sealed scenarios") - public void sealedScenarios(String apiFile, Map definitions) throws IOException { - File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); - output.deleteOnExit(); - String outputPath = output.getAbsolutePath().replace('\\', '/'); + public void sealedScenarios(String apiFile, Map definitions) { + Path output = newTempFolder(); + String outputPath = output.toString().replace('\\', '/'); OpenAPI openAPI = new OpenAPIParser() .readLocation("src/test/resources/3_0/" + apiFile, null, new ParseOptions()).getOpenAPI(); SpringCodegen codegen = new SpringCodegen(); - codegen.setOutputDir(output.getAbsolutePath()); + codegen.setOutputDir(outputPath); codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true"); codegen.setUseOneOfInterfaces(true); codegen.setUseSealed(true); diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/.openapi-generator-ignore b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/.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/openapi3/server/petstore/spring-boot-oneof-sealed/.openapi-generator/FILES b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/.openapi-generator/FILES new file mode 100644 index 000000000000..392c6ed21180 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/.openapi-generator/FILES @@ -0,0 +1,31 @@ +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/BarApi.java +src/main/java/org/openapitools/api/FooApi.java +src/main/java/org/openapitools/configuration/EnumConverterConfiguration.java +src/main/java/org/openapitools/configuration/HomeController.java +src/main/java/org/openapitools/configuration/SpringDocConfiguration.java +src/main/java/org/openapitools/model/Addressable.java +src/main/java/org/openapitools/model/Apple.java +src/main/java/org/openapitools/model/Banana.java +src/main/java/org/openapitools/model/Bar.java +src/main/java/org/openapitools/model/BarCreate.java +src/main/java/org/openapitools/model/BarRef.java +src/main/java/org/openapitools/model/BarRefOrValue.java +src/main/java/org/openapitools/model/Entity.java +src/main/java/org/openapitools/model/EntityRef.java +src/main/java/org/openapitools/model/Extensible.java +src/main/java/org/openapitools/model/Foo.java +src/main/java/org/openapitools/model/FooRef.java +src/main/java/org/openapitools/model/FooRefOrValue.java +src/main/java/org/openapitools/model/Fruit.java +src/main/java/org/openapitools/model/FruitType.java +src/main/java/org/openapitools/model/Pasta.java +src/main/java/org/openapitools/model/Pizza.java +src/main/java/org/openapitools/model/PizzaSpeziale.java +src/main/resources/application.properties +src/main/resources/openapi.yaml +src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/.openapi-generator/VERSION b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/.openapi-generator/VERSION new file mode 100644 index 000000000000..fc74d6ceba8e --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.15.0-SNAPSHOT diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/README.md b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/README.md new file mode 100644 index 000000000000..5cd22b6081a2 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/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/openapi3/server/petstore/spring-boot-oneof-sealed/pom.xml b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/pom.xml new file mode 100644 index 000000000000..9d6fc6c3d02f --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/pom.xml @@ -0,0 +1,82 @@ + + 4.0.0 + org.openapitools.openapi3 + springboot-oneof-sealed + jar + springboot-oneof-sealed + 0.0.1-SNAPSHOT + + 17 + ${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.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 + + + com.fasterxml.jackson.core + jackson-databind + + + org.springframework.boot + spring-boot-starter-test + test + + + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/OpenApiGeneratorApplication.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/OpenApiGeneratorApplication.java new file mode 100644 index 000000000000..97252a8a9402 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/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/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/RFC3339DateFormat.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/RFC3339DateFormat.java new file mode 100644 index 000000000000..bcd3936d8b34 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/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/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/ApiUtil.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/ApiUtil.java new file mode 100644 index 000000000000..1245b1dd0ccf --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/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/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/BarApi.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/BarApi.java new file mode 100644 index 000000000000..5a1d6c7b57e3 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/BarApi.java @@ -0,0 +1,86 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.15.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package org.openapitools.api; + +import org.openapitools.model.Bar; +import org.openapitools.model.BarCreate; +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 io.swagger.v3.oas.annotations.media.ExampleObject; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; +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", comments = "Generator version: 7.15.0-SNAPSHOT") +@Validated +@Tag(name = "Bar", description = "the Bar API") +public interface BarApi { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * POST /bar : Create a Bar + * + * @param barCreate (required) + * @return Bar created (status code 200) + */ + @Operation( + operationId = "createBar", + summary = "Create a Bar", + tags = { "Bar" }, + responses = { + @ApiResponse(responseCode = "200", description = "Bar created", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = Bar.class)) + }) + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/bar", + produces = { "application/json" }, + consumes = { "application/json" } + ) + + default ResponseEntity createBar( + @Parameter(name = "BarCreate", description = "", required = true) @Valid @RequestBody BarCreate barCreate + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"foo\" : { \"fooPropA\" : \"fooPropA\", \"fooPropB\" : \"fooPropB\" }, \"id\" : \"id\", \"fooPropB\" : \"fooPropB\", \"barPropA\" : \"barPropA\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + +} diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/BarApiController.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/BarApiController.java new file mode 100644 index 000000000000..3661fcc76135 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/BarApiController.java @@ -0,0 +1,48 @@ +package org.openapitools.api; + +import org.openapitools.model.Bar; +import org.openapitools.model.BarCreate; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.CookieValue; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.context.request.NativeWebRequest; + +import javax.validation.constraints.*; +import javax.validation.Valid; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +@Controller +@RequestMapping("${openapi.byRefOrValue.base-path:}") +public class BarApiController implements BarApi { + + private final NativeWebRequest request; + + @Autowired + public BarApiController(NativeWebRequest request) { + this.request = request; + } + + @Override + public Optional getRequest() { + return Optional.ofNullable(request); + } + +} diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/FooApi.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/FooApi.java new file mode 100644 index 000000000000..e0c6c57862d6 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/FooApi.java @@ -0,0 +1,124 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.15.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package org.openapitools.api; + +import org.openapitools.model.Foo; +import org.openapitools.model.FooRefOrValue; +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 io.swagger.v3.oas.annotations.media.ExampleObject; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; +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", comments = "Generator version: 7.15.0-SNAPSHOT") +@Validated +@Tag(name = "Foo", description = "the Foo API") +public interface FooApi { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * POST /foo : Create a Foo + * + * @param foo The Foo to be created (optional) + * @return Error (status code 201) + */ + @Operation( + operationId = "createFoo", + summary = "Create a Foo", + tags = { "Foo" }, + responses = { + @ApiResponse(responseCode = "201", description = "Error", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = FooRefOrValue.class)) + }) + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/foo", + produces = { "application/json" }, + consumes = { "application/json;charset=utf-8" } + ) + + default ResponseEntity createFoo( + @Parameter(name = "Foo", description = "The Foo to be created") @Valid @RequestBody(required = false) @Nullable Foo foo + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"fooPropA\" : \"fooPropA\", \"fooPropB\" : \"fooPropB\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + + /** + * GET /foo : GET all Foos + * + * @return Success (status code 200) + */ + @Operation( + operationId = "getAllFoos", + summary = "GET all Foos", + tags = { "Foo" }, + responses = { + @ApiResponse(responseCode = "200", description = "Success", content = { + @Content(mediaType = "application/json;charset=utf-8", array = @ArraySchema(schema = @Schema(implementation = FooRefOrValue.class))) + }) + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/foo", + produces = { "application/json;charset=utf-8" } + ) + + default ResponseEntity> getAllFoos( + + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json;charset=utf-8"))) { + String exampleString = "[ { \"fooPropA\" : \"fooPropA\", \"fooPropB\" : \"fooPropB\" }, { \"fooPropA\" : \"fooPropA\", \"fooPropB\" : \"fooPropB\" } ]"; + ApiUtil.setExampleResponse(request, "application/json;charset=utf-8", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + +} diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/FooApiController.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/FooApiController.java new file mode 100644 index 000000000000..3214c0b91ff5 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/api/FooApiController.java @@ -0,0 +1,48 @@ +package org.openapitools.api; + +import org.openapitools.model.Foo; +import org.openapitools.model.FooRefOrValue; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.CookieValue; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.context.request.NativeWebRequest; + +import javax.validation.constraints.*; +import javax.validation.Valid; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +@Controller +@RequestMapping("${openapi.byRefOrValue.base-path:}") +public class FooApiController implements FooApi { + + private final NativeWebRequest request; + + @Autowired + public FooApiController(NativeWebRequest request) { + this.request = request; + } + + @Override + public Optional getRequest() { + return Optional.ofNullable(request); + } + +} diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/configuration/EnumConverterConfiguration.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/configuration/EnumConverterConfiguration.java new file mode 100644 index 000000000000..638061b124c5 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/configuration/EnumConverterConfiguration.java @@ -0,0 +1,22 @@ +package org.openapitools.configuration; + +import org.openapitools.model.FruitType; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.convert.converter.Converter; + +@Configuration(value = "org.openapitools.configuration.enumConverterConfiguration") +public class EnumConverterConfiguration { + + @Bean(name = "org.openapitools.configuration.EnumConverterConfiguration.fruitTypeConverter") + Converter fruitTypeConverter() { + return new Converter() { + @Override + public FruitType convert(String source) { + return FruitType.fromValue(source); + } + }; + } + +} diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/configuration/HomeController.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/configuration/HomeController.java new file mode 100644 index 000000000000..9aa29284ab5f --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/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/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/configuration/SpringDocConfiguration.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/configuration/SpringDocConfiguration.java new file mode 100644 index 000000000000..b17dc1a44224 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/configuration/SpringDocConfiguration.java @@ -0,0 +1,27 @@ +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("ByRefOrValue") + .description("This tests for a oneOf interface representation ") + .version("0.0.1") + ) + ; + } +} \ No newline at end of file diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Addressable.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Addressable.java new file mode 100644 index 000000000000..9309147b5c05 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Addressable.java @@ -0,0 +1,173 @@ +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.springframework.lang.Nullable; +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; + +/** + * Base schema for addressable entities + */ + +@Schema(name = "Addressable", description = "Base schema for addressable entities") +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public class Addressable { + + private @Nullable String href; + + private @Nullable String id; + + public Addressable href(@Nullable String href) { + this.href = href; + return this; + } + + /** + * Hyperlink reference + * @return href + */ + + @Schema(name = "href", description = "Hyperlink reference", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("href") + public @Nullable String getHref() { + return href; + } + + public void setHref(@Nullable String href) { + this.href = href; + } + + public Addressable id(@Nullable String id) { + this.id = id; + return this; + } + + /** + * unique identifier + * @return id + */ + + @Schema(name = "id", description = "unique identifier", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("id") + public @Nullable String getId() { + return id; + } + + public void setId(@Nullable String id) { + this.id = id; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Addressable addressable = (Addressable) o; + return Objects.equals(this.href, addressable.href) && + Objects.equals(this.id, addressable.id); + } + + @Override + public int hashCode() { + return Objects.hash(href, id); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Addressable {\n"); + sb.append(" href: ").append(toIndentedString(href)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static class Builder { + + private Addressable instance; + + public Builder() { + this(new Addressable()); + } + + protected Builder(Addressable instance) { + this.instance = instance; + } + + protected Builder copyOf(Addressable value) { + this.instance.setHref(value.href); + this.instance.setId(value.id); + return this; + } + + public Addressable.Builder href(String href) { + this.instance.href(href); + return this; + } + + public Addressable.Builder id(String id) { + this.instance.id(id); + return this; + } + + /** + * returns a built Addressable instance. + * + * The builder is not reusable (NullPointerException) + */ + public Addressable build() { + try { + return this.instance; + } finally { + // ensure that this.instance is not reused + this.instance = null; + } + } + + @Override + public String toString() { + return getClass() + "=(" + instance + ")"; + } + } + + /** + * Create a builder with no initialized field (except for the default values). + */ + public static Addressable.Builder builder() { + return new Addressable.Builder(); + } + + /** + * Create a builder with a shallow copy of this instance. + */ + public Addressable.Builder toBuilder() { + Addressable.Builder builder = new Addressable.Builder(); + return builder.copyOf(this); + } + +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Apple.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Apple.java new file mode 100644 index 000000000000..1e3e35f4fc0a --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Apple.java @@ -0,0 +1,188 @@ +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.springframework.lang.Nullable; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonValue; +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; + +/** + * Apple + */ + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public final class Apple implements Fruit { + + private Integer seeds; + + private FruitType fruitType; + + public Apple() { + super(); + } + + /** + * Constructor with only required parameters + */ + public Apple(Integer seeds) { + this.seeds = seeds; + this.fruitType = fruitType; + } + + public Apple seeds(Integer seeds) { + this.seeds = seeds; + return this; + } + + /** + * Get seeds + * @return seeds + */ + @NotNull + @Schema(name = "seeds", requiredMode = Schema.RequiredMode.REQUIRED) + @JsonProperty("seeds") + public Integer getSeeds() { + return seeds; + } + + public void setSeeds(Integer seeds) { + this.seeds = seeds; + } + + public Apple fruitType(FruitType fruitType) { + this.fruitType = fruitType; + return this; + } + + /** + * Get fruitType + * @return fruitType + */ + @NotNull @Valid + @Schema(name = "fruitType", requiredMode = Schema.RequiredMode.REQUIRED) + @JsonProperty("fruitType") + public FruitType getFruitType() { + return fruitType; + } + + public void setFruitType(FruitType fruitType) { + this.fruitType = fruitType; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Apple apple = (Apple) o; + return Objects.equals(this.seeds, apple.seeds) && + Objects.equals(this.fruitType, apple.fruitType); + } + + @Override + public int hashCode() { + return Objects.hash(seeds, fruitType); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Apple {\n"); + sb.append(" seeds: ").append(toIndentedString(seeds)).append("\n"); + sb.append(" fruitType: ").append(toIndentedString(fruitType)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static class Builder { + + private Apple instance; + + public Builder() { + this(new Apple()); + } + + protected Builder(Apple instance) { + this.instance = instance; + } + + protected Builder copyOf(Apple value) { + this.instance.setSeeds(value.seeds); + this.instance.setFruitType(value.fruitType); + return this; + } + + public Apple.Builder seeds(Integer seeds) { + this.instance.seeds(seeds); + return this; + } + + public Apple.Builder fruitType(FruitType fruitType) { + this.instance.fruitType(fruitType); + return this; + } + + /** + * returns a built Apple instance. + * + * The builder is not reusable (NullPointerException) + */ + public Apple build() { + try { + return this.instance; + } finally { + // ensure that this.instance is not reused + this.instance = null; + } + } + + @Override + public String toString() { + return getClass() + "=(" + instance + ")"; + } + } + + /** + * Create a builder with no initialized field (except for the default values). + */ + public static Apple.Builder builder() { + return new Apple.Builder(); + } + + /** + * Create a builder with a shallow copy of this instance. + */ + public Apple.Builder toBuilder() { + Apple.Builder builder = new Apple.Builder(); + return builder.copyOf(this); + } + +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Banana.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Banana.java new file mode 100644 index 000000000000..140464af0635 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Banana.java @@ -0,0 +1,188 @@ +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.springframework.lang.Nullable; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonValue; +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; + +/** + * Banana + */ + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public final class Banana implements Fruit { + + private Integer length; + + private FruitType fruitType; + + public Banana() { + super(); + } + + /** + * Constructor with only required parameters + */ + public Banana(Integer length) { + this.length = length; + this.fruitType = fruitType; + } + + public Banana length(Integer length) { + this.length = length; + return this; + } + + /** + * Get length + * @return length + */ + @NotNull + @Schema(name = "length", requiredMode = Schema.RequiredMode.REQUIRED) + @JsonProperty("length") + public Integer getLength() { + return length; + } + + public void setLength(Integer length) { + this.length = length; + } + + public Banana fruitType(FruitType fruitType) { + this.fruitType = fruitType; + return this; + } + + /** + * Get fruitType + * @return fruitType + */ + @NotNull @Valid + @Schema(name = "fruitType", requiredMode = Schema.RequiredMode.REQUIRED) + @JsonProperty("fruitType") + public FruitType getFruitType() { + return fruitType; + } + + public void setFruitType(FruitType fruitType) { + this.fruitType = fruitType; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Banana banana = (Banana) o; + return Objects.equals(this.length, banana.length) && + Objects.equals(this.fruitType, banana.fruitType); + } + + @Override + public int hashCode() { + return Objects.hash(length, fruitType); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Banana {\n"); + sb.append(" length: ").append(toIndentedString(length)).append("\n"); + sb.append(" fruitType: ").append(toIndentedString(fruitType)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static class Builder { + + private Banana instance; + + public Builder() { + this(new Banana()); + } + + protected Builder(Banana instance) { + this.instance = instance; + } + + protected Builder copyOf(Banana value) { + this.instance.setLength(value.length); + this.instance.setFruitType(value.fruitType); + return this; + } + + public Banana.Builder length(Integer length) { + this.instance.length(length); + return this; + } + + public Banana.Builder fruitType(FruitType fruitType) { + this.instance.fruitType(fruitType); + return this; + } + + /** + * returns a built Banana instance. + * + * The builder is not reusable (NullPointerException) + */ + public Banana build() { + try { + return this.instance; + } finally { + // ensure that this.instance is not reused + this.instance = null; + } + } + + @Override + public String toString() { + return getClass() + "=(" + instance + ")"; + } + } + + /** + * Create a builder with no initialized field (except for the default values). + */ + public static Banana.Builder builder() { + return new Banana.Builder(); + } + + /** + * Create a builder with a shallow copy of this instance. + */ + public Banana.Builder toBuilder() { + Banana.Builder builder = new Banana.Builder(); + return builder.copyOf(this); + } + +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Bar.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Bar.java new file mode 100644 index 000000000000..cb915e3620bf --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Bar.java @@ -0,0 +1,299 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.openapitools.model.Entity; +import org.openapitools.model.FooRefOrValue; +import org.springframework.lang.Nullable; +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; + +/** + * Bar + */ + + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public final class Bar extends Entity implements BarRefOrValue { + + private String id; + + private @Nullable String barPropA; + + private @Nullable String fooPropB; + + private @Nullable FooRefOrValue foo; + + public Bar() { + super(); + } + + /** + * Constructor with only required parameters + */ + public Bar(String id, String atType) { + super(atType); + this.id = id; + } + + public Bar id(String id) { + this.id = id; + return this; + } + + /** + * Get id + * @return id + */ + @NotNull + @Schema(name = "id", requiredMode = Schema.RequiredMode.REQUIRED) + @JsonProperty("id") + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Bar barPropA(@Nullable String barPropA) { + this.barPropA = barPropA; + return this; + } + + /** + * Get barPropA + * @return barPropA + */ + + @Schema(name = "barPropA", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("barPropA") + public @Nullable String getBarPropA() { + return barPropA; + } + + public void setBarPropA(@Nullable String barPropA) { + this.barPropA = barPropA; + } + + public Bar fooPropB(@Nullable String fooPropB) { + this.fooPropB = fooPropB; + return this; + } + + /** + * Get fooPropB + * @return fooPropB + */ + + @Schema(name = "fooPropB", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("fooPropB") + public @Nullable String getFooPropB() { + return fooPropB; + } + + public void setFooPropB(@Nullable String fooPropB) { + this.fooPropB = fooPropB; + } + + public Bar foo(@Nullable FooRefOrValue foo) { + this.foo = foo; + return this; + } + + /** + * Get foo + * @return foo + */ + @Valid + @Schema(name = "foo", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("foo") + public @Nullable FooRefOrValue getFoo() { + return foo; + } + + public void setFoo(@Nullable FooRefOrValue foo) { + this.foo = foo; + } + + + public Bar href(String href) { + super.href(href); + return this; + } + + public Bar atSchemaLocation(String atSchemaLocation) { + super.atSchemaLocation(atSchemaLocation); + return this; + } + + public Bar atBaseType(String atBaseType) { + super.atBaseType(atBaseType); + return this; + } + + public Bar atType(String atType) { + super.atType(atType); + return this; + } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Bar bar = (Bar) o; + return Objects.equals(this.id, bar.id) && + Objects.equals(this.barPropA, bar.barPropA) && + Objects.equals(this.fooPropB, bar.fooPropB) && + Objects.equals(this.foo, bar.foo) && + super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(id, barPropA, fooPropB, foo, super.hashCode()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Bar {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" barPropA: ").append(toIndentedString(barPropA)).append("\n"); + sb.append(" fooPropB: ").append(toIndentedString(fooPropB)).append("\n"); + sb.append(" foo: ").append(toIndentedString(foo)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static class Builder extends Entity.Builder { + + private Bar instance; + + public Builder() { + this(new Bar()); + } + + protected Builder(Bar instance) { + super(instance); // the parent builder shares the same instance + this.instance = instance; + } + + protected Builder copyOf(Bar value) { + super.copyOf(value); + this.instance.setId(value.id); + this.instance.setBarPropA(value.barPropA); + this.instance.setFooPropB(value.fooPropB); + this.instance.setFoo(value.foo); + return this; + } + + public Bar.Builder id(String id) { + this.instance.id(id); + return this; + } + + public Bar.Builder barPropA(String barPropA) { + this.instance.barPropA(barPropA); + return this; + } + + public Bar.Builder fooPropB(String fooPropB) { + this.instance.fooPropB(fooPropB); + return this; + } + + public Bar.Builder foo(FooRefOrValue foo) { + this.instance.foo(foo); + return this; + } + + @Override + public Bar.Builder href(String href) { + this.instance.href(href); + return this; + } + + @Override + public Bar.Builder atSchemaLocation(String atSchemaLocation) { + this.instance.atSchemaLocation(atSchemaLocation); + return this; + } + + @Override + public Bar.Builder atBaseType(String atBaseType) { + this.instance.atBaseType(atBaseType); + return this; + } + + @Override + public Bar.Builder atType(String atType) { + this.instance.atType(atType); + return this; + } + + /** + * returns a built Bar instance. + * + * The builder is not reusable (NullPointerException) + */ + public Bar build() { + try { + return this.instance; + } finally { + // ensure that this.instance is not reused + super.build(); + this.instance = null; + } + } + + @Override + public String toString() { + return getClass() + "=(" + instance + ")"; + } + } + + /** + * Create a builder with no initialized field (except for the default values). + */ + public static Bar.Builder builder() { + return new Bar.Builder(); + } + + /** + * Create a builder with a shallow copy of this instance. + */ + public Bar.Builder toBuilder() { + Bar.Builder builder = new Bar.Builder(); + return builder.copyOf(this); + } + +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/BarCreate.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/BarCreate.java new file mode 100644 index 000000000000..ef6b71aeed47 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/BarCreate.java @@ -0,0 +1,281 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import org.openapitools.model.Entity; +import org.openapitools.model.FooRefOrValue; +import org.springframework.lang.Nullable; +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; + +/** + * BarCreate + */ + + +@JsonTypeName("Bar_Create") +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public class BarCreate extends Entity { + + private @Nullable String barPropA; + + private @Nullable String fooPropB; + + private @Nullable FooRefOrValue foo; + + public BarCreate() { + super(); + } + + /** + * Constructor with only required parameters + */ + public BarCreate(String atType) { + super(atType); + } + + public BarCreate barPropA(@Nullable String barPropA) { + this.barPropA = barPropA; + return this; + } + + /** + * Get barPropA + * @return barPropA + */ + + @Schema(name = "barPropA", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("barPropA") + public @Nullable String getBarPropA() { + return barPropA; + } + + public void setBarPropA(@Nullable String barPropA) { + this.barPropA = barPropA; + } + + public BarCreate fooPropB(@Nullable String fooPropB) { + this.fooPropB = fooPropB; + return this; + } + + /** + * Get fooPropB + * @return fooPropB + */ + + @Schema(name = "fooPropB", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("fooPropB") + public @Nullable String getFooPropB() { + return fooPropB; + } + + public void setFooPropB(@Nullable String fooPropB) { + this.fooPropB = fooPropB; + } + + public BarCreate foo(@Nullable FooRefOrValue foo) { + this.foo = foo; + return this; + } + + /** + * Get foo + * @return foo + */ + @Valid + @Schema(name = "foo", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("foo") + public @Nullable FooRefOrValue getFoo() { + return foo; + } + + public void setFoo(@Nullable FooRefOrValue foo) { + this.foo = foo; + } + + + public BarCreate href(String href) { + super.href(href); + return this; + } + + public BarCreate id(String id) { + super.id(id); + return this; + } + + public BarCreate atSchemaLocation(String atSchemaLocation) { + super.atSchemaLocation(atSchemaLocation); + return this; + } + + public BarCreate atBaseType(String atBaseType) { + super.atBaseType(atBaseType); + return this; + } + + public BarCreate atType(String atType) { + super.atType(atType); + return this; + } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BarCreate barCreate = (BarCreate) o; + return Objects.equals(this.barPropA, barCreate.barPropA) && + Objects.equals(this.fooPropB, barCreate.fooPropB) && + Objects.equals(this.foo, barCreate.foo) && + super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(barPropA, fooPropB, foo, super.hashCode()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class BarCreate {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append(" barPropA: ").append(toIndentedString(barPropA)).append("\n"); + sb.append(" fooPropB: ").append(toIndentedString(fooPropB)).append("\n"); + sb.append(" foo: ").append(toIndentedString(foo)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static class Builder extends Entity.Builder { + + private BarCreate instance; + + public Builder() { + this(new BarCreate()); + } + + protected Builder(BarCreate instance) { + super(instance); // the parent builder shares the same instance + this.instance = instance; + } + + protected Builder copyOf(BarCreate value) { + super.copyOf(value); + this.instance.setBarPropA(value.barPropA); + this.instance.setFooPropB(value.fooPropB); + this.instance.setFoo(value.foo); + return this; + } + + public BarCreate.Builder barPropA(String barPropA) { + this.instance.barPropA(barPropA); + return this; + } + + public BarCreate.Builder fooPropB(String fooPropB) { + this.instance.fooPropB(fooPropB); + return this; + } + + public BarCreate.Builder foo(FooRefOrValue foo) { + this.instance.foo(foo); + return this; + } + + @Override + public BarCreate.Builder href(String href) { + this.instance.href(href); + return this; + } + + @Override + public BarCreate.Builder id(String id) { + this.instance.id(id); + return this; + } + + @Override + public BarCreate.Builder atSchemaLocation(String atSchemaLocation) { + this.instance.atSchemaLocation(atSchemaLocation); + return this; + } + + @Override + public BarCreate.Builder atBaseType(String atBaseType) { + this.instance.atBaseType(atBaseType); + return this; + } + + @Override + public BarCreate.Builder atType(String atType) { + this.instance.atType(atType); + return this; + } + + /** + * returns a built BarCreate instance. + * + * The builder is not reusable (NullPointerException) + */ + public BarCreate build() { + try { + return this.instance; + } finally { + // ensure that this.instance is not reused + super.build(); + this.instance = null; + } + } + + @Override + public String toString() { + return getClass() + "=(" + instance + ")"; + } + } + + /** + * Create a builder with no initialized field (except for the default values). + */ + public static BarCreate.Builder builder() { + return new BarCreate.Builder(); + } + + /** + * Create a builder with a shallow copy of this instance. + */ + public BarCreate.Builder toBuilder() { + BarCreate.Builder builder = new BarCreate.Builder(); + return builder.copyOf(this); + } + +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/BarRef.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/BarRef.java new file mode 100644 index 000000000000..441cdb9ed4d5 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/BarRef.java @@ -0,0 +1,209 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.openapitools.model.EntityRef; +import org.springframework.lang.Nullable; +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; + +/** + * BarRef + */ + + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public final class BarRef extends EntityRef implements BarRefOrValue { + + public BarRef() { + super(); + } + + /** + * Constructor with only required parameters + */ + public BarRef(String atType) { + super(atType); + } + + + public BarRef name(String name) { + super.name(name); + return this; + } + + public BarRef atReferredType(String atReferredType) { + super.atReferredType(atReferredType); + return this; + } + + public BarRef href(String href) { + super.href(href); + return this; + } + + public BarRef id(String id) { + super.id(id); + return this; + } + + public BarRef atSchemaLocation(String atSchemaLocation) { + super.atSchemaLocation(atSchemaLocation); + return this; + } + + public BarRef atBaseType(String atBaseType) { + super.atBaseType(atBaseType); + return this; + } + + public BarRef atType(String atType) { + super.atType(atType); + return this; + } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + return super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class BarRef {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static class Builder extends EntityRef.Builder { + + private BarRef instance; + + public Builder() { + this(new BarRef()); + } + + protected Builder(BarRef instance) { + super(instance); // the parent builder shares the same instance + this.instance = instance; + } + + protected Builder copyOf(BarRef value) { + super.copyOf(value); + return this; + } + + @Override + public BarRef.Builder name(String name) { + this.instance.name(name); + return this; + } + + @Override + public BarRef.Builder atReferredType(String atReferredType) { + this.instance.atReferredType(atReferredType); + return this; + } + + @Override + public BarRef.Builder href(String href) { + this.instance.href(href); + return this; + } + + @Override + public BarRef.Builder id(String id) { + this.instance.id(id); + return this; + } + + @Override + public BarRef.Builder atSchemaLocation(String atSchemaLocation) { + this.instance.atSchemaLocation(atSchemaLocation); + return this; + } + + @Override + public BarRef.Builder atBaseType(String atBaseType) { + this.instance.atBaseType(atBaseType); + return this; + } + + @Override + public BarRef.Builder atType(String atType) { + this.instance.atType(atType); + return this; + } + + /** + * returns a built BarRef instance. + * + * The builder is not reusable (NullPointerException) + */ + public BarRef build() { + try { + return this.instance; + } finally { + // ensure that this.instance is not reused + super.build(); + this.instance = null; + } + } + + @Override + public String toString() { + return getClass() + "=(" + instance + ")"; + } + } + + /** + * Create a builder with no initialized field (except for the default values). + */ + public static BarRef.Builder builder() { + return new BarRef.Builder(); + } + + /** + * Create a builder with a shallow copy of this instance. + */ + public BarRef.Builder toBuilder() { + BarRef.Builder builder = new BarRef.Builder(); + return builder.copyOf(this); + } + +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/BarRefOrValue.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/BarRefOrValue.java new file mode 100644 index 000000000000..640bffedb909 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/BarRefOrValue.java @@ -0,0 +1,38 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.openapitools.model.Bar; +import org.openapitools.model.BarRef; +import org.openapitools.model.FooRefOrValue; +import org.springframework.lang.Nullable; +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; + + +@JsonIgnoreProperties( + value = "@type", // ignore manually set @type, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the @type to be set during deserialization +) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@type", visible = true) +@JsonSubTypes({ + @JsonSubTypes.Type(value = Bar.class, name = "Bar"), + @JsonSubTypes.Type(value = BarRef.class, name = "BarRef") +}) + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public sealed interface BarRefOrValue permits Bar, BarRef { + public String getAtType(); +} diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Entity.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Entity.java new file mode 100644 index 000000000000..09910cd3d556 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Entity.java @@ -0,0 +1,290 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.springframework.lang.Nullable; +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; + +/** + * Entity + */ + +@JsonIgnoreProperties( + value = "@type", // ignore manually set @type, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the @type to be set during deserialization +) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@type", visible = true) +@JsonSubTypes({ + @JsonSubTypes.Type(value = Bar.class, name = "Bar"), + @JsonSubTypes.Type(value = BarCreate.class, name = "Bar_Create"), + @JsonSubTypes.Type(value = Foo.class, name = "Foo"), + @JsonSubTypes.Type(value = Pasta.class, name = "Pasta"), + @JsonSubTypes.Type(value = Pizza.class, name = "Pizza"), + @JsonSubTypes.Type(value = PizzaSpeziale.class, name = "PizzaSpeziale") +}) + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public sealed class Entity permits Bar, BarCreate, Foo, Pasta, Pizza { + + private @Nullable String href; + + private @Nullable String id; + + private @Nullable String atSchemaLocation; + + private @Nullable String atBaseType; + + private String atType; + + public Entity() { + super(); + } + + /** + * Constructor with only required parameters + */ + public Entity(String atType) { + this.atType = atType; + } + + public Entity href(@Nullable String href) { + this.href = href; + return this; + } + + /** + * Hyperlink reference + * @return href + */ + + @Schema(name = "href", description = "Hyperlink reference", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("href") + public @Nullable String getHref() { + return href; + } + + public void setHref(@Nullable String href) { + this.href = href; + } + + public Entity id(@Nullable String id) { + this.id = id; + return this; + } + + /** + * unique identifier + * @return id + */ + + @Schema(name = "id", description = "unique identifier", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("id") + public @Nullable String getId() { + return id; + } + + public void setId(@Nullable String id) { + this.id = id; + } + + public Entity atSchemaLocation(@Nullable String atSchemaLocation) { + this.atSchemaLocation = atSchemaLocation; + return this; + } + + /** + * A URI to a JSON-Schema file that defines additional attributes and relationships + * @return atSchemaLocation + */ + + @Schema(name = "@schemaLocation", description = "A URI to a JSON-Schema file that defines additional attributes and relationships", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("@schemaLocation") + public @Nullable String getAtSchemaLocation() { + return atSchemaLocation; + } + + public void setAtSchemaLocation(@Nullable String atSchemaLocation) { + this.atSchemaLocation = atSchemaLocation; + } + + public Entity atBaseType(@Nullable String atBaseType) { + this.atBaseType = atBaseType; + return this; + } + + /** + * When sub-classing, this defines the super-class + * @return atBaseType + */ + + @Schema(name = "@baseType", description = "When sub-classing, this defines the super-class", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("@baseType") + public @Nullable String getAtBaseType() { + return atBaseType; + } + + public void setAtBaseType(@Nullable String atBaseType) { + this.atBaseType = atBaseType; + } + + public Entity atType(String atType) { + this.atType = atType; + return this; + } + + /** + * When sub-classing, this defines the sub-class Extensible name + * @return atType + */ + @NotNull + @Schema(name = "@type", description = "When sub-classing, this defines the sub-class Extensible name", requiredMode = Schema.RequiredMode.REQUIRED) + @JsonProperty("@type") + public String getAtType() { + return atType; + } + + public void setAtType(String atType) { + this.atType = atType; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Entity entity = (Entity) o; + return Objects.equals(this.href, entity.href) && + Objects.equals(this.id, entity.id) && + Objects.equals(this.atSchemaLocation, entity.atSchemaLocation) && + Objects.equals(this.atBaseType, entity.atBaseType) && + Objects.equals(this.atType, entity.atType); + } + + @Override + public int hashCode() { + return Objects.hash(href, id, atSchemaLocation, atBaseType, atType); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Entity {\n"); + sb.append(" href: ").append(toIndentedString(href)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" atSchemaLocation: ").append(toIndentedString(atSchemaLocation)).append("\n"); + sb.append(" atBaseType: ").append(toIndentedString(atBaseType)).append("\n"); + sb.append(" atType: ").append(toIndentedString(atType)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static class Builder { + + private Entity instance; + + public Builder() { + this(new Entity()); + } + + protected Builder(Entity instance) { + this.instance = instance; + } + + protected Builder copyOf(Entity value) { + this.instance.setHref(value.href); + this.instance.setId(value.id); + this.instance.setAtSchemaLocation(value.atSchemaLocation); + this.instance.setAtBaseType(value.atBaseType); + this.instance.setAtType(value.atType); + return this; + } + + public Entity.Builder href(String href) { + this.instance.href(href); + return this; + } + + public Entity.Builder id(String id) { + this.instance.id(id); + return this; + } + + public Entity.Builder atSchemaLocation(String atSchemaLocation) { + this.instance.atSchemaLocation(atSchemaLocation); + return this; + } + + public Entity.Builder atBaseType(String atBaseType) { + this.instance.atBaseType(atBaseType); + return this; + } + + public Entity.Builder atType(String atType) { + this.instance.atType(atType); + return this; + } + + /** + * returns a built Entity instance. + * + * The builder is not reusable (NullPointerException) + */ + public Entity build() { + try { + return this.instance; + } finally { + // ensure that this.instance is not reused + this.instance = null; + } + } + + @Override + public String toString() { + return getClass() + "=(" + instance + ")"; + } + } + + /** + * Create a builder with no initialized field (except for the default values). + */ + public static Entity.Builder builder() { + return new Entity.Builder(); + } + + /** + * Create a builder with a shallow copy of this instance. + */ + public Entity.Builder toBuilder() { + Entity.Builder builder = new Entity.Builder(); + return builder.copyOf(this); + } + +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/EntityRef.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/EntityRef.java new file mode 100644 index 000000000000..96cee851b2ad --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/EntityRef.java @@ -0,0 +1,347 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.springframework.lang.Nullable; +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; + +/** + * Entity reference schema to be use for all entityRef class. + */ + +@Schema(name = "EntityRef", description = "Entity reference schema to be use for all entityRef class.") +@JsonIgnoreProperties( + value = "@type", // ignore manually set @type, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the @type to be set during deserialization +) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@type", visible = true) +@JsonSubTypes({ + @JsonSubTypes.Type(value = BarRef.class, name = "BarRef"), + @JsonSubTypes.Type(value = FooRef.class, name = "FooRef") +}) + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public sealed class EntityRef permits BarRef, FooRef { + + private @Nullable String name; + + private @Nullable String atReferredType; + + private @Nullable String href; + + private @Nullable String id; + + private @Nullable String atSchemaLocation; + + private @Nullable String atBaseType; + + private String atType; + + public EntityRef() { + super(); + } + + /** + * Constructor with only required parameters + */ + public EntityRef(String atType) { + this.atType = atType; + } + + public EntityRef name(@Nullable String name) { + this.name = name; + return this; + } + + /** + * Name of the related entity. + * @return name + */ + + @Schema(name = "name", description = "Name of the related entity.", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("name") + public @Nullable String getName() { + return name; + } + + public void setName(@Nullable String name) { + this.name = name; + } + + public EntityRef atReferredType(@Nullable String atReferredType) { + this.atReferredType = atReferredType; + return this; + } + + /** + * The actual type of the target instance when needed for disambiguation. + * @return atReferredType + */ + + @Schema(name = "@referredType", description = "The actual type of the target instance when needed for disambiguation.", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("@referredType") + public @Nullable String getAtReferredType() { + return atReferredType; + } + + public void setAtReferredType(@Nullable String atReferredType) { + this.atReferredType = atReferredType; + } + + public EntityRef href(@Nullable String href) { + this.href = href; + return this; + } + + /** + * Hyperlink reference + * @return href + */ + + @Schema(name = "href", description = "Hyperlink reference", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("href") + public @Nullable String getHref() { + return href; + } + + public void setHref(@Nullable String href) { + this.href = href; + } + + public EntityRef id(@Nullable String id) { + this.id = id; + return this; + } + + /** + * unique identifier + * @return id + */ + + @Schema(name = "id", description = "unique identifier", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("id") + public @Nullable String getId() { + return id; + } + + public void setId(@Nullable String id) { + this.id = id; + } + + public EntityRef atSchemaLocation(@Nullable String atSchemaLocation) { + this.atSchemaLocation = atSchemaLocation; + return this; + } + + /** + * A URI to a JSON-Schema file that defines additional attributes and relationships + * @return atSchemaLocation + */ + + @Schema(name = "@schemaLocation", description = "A URI to a JSON-Schema file that defines additional attributes and relationships", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("@schemaLocation") + public @Nullable String getAtSchemaLocation() { + return atSchemaLocation; + } + + public void setAtSchemaLocation(@Nullable String atSchemaLocation) { + this.atSchemaLocation = atSchemaLocation; + } + + public EntityRef atBaseType(@Nullable String atBaseType) { + this.atBaseType = atBaseType; + return this; + } + + /** + * When sub-classing, this defines the super-class + * @return atBaseType + */ + + @Schema(name = "@baseType", description = "When sub-classing, this defines the super-class", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("@baseType") + public @Nullable String getAtBaseType() { + return atBaseType; + } + + public void setAtBaseType(@Nullable String atBaseType) { + this.atBaseType = atBaseType; + } + + public EntityRef atType(String atType) { + this.atType = atType; + return this; + } + + /** + * When sub-classing, this defines the sub-class Extensible name + * @return atType + */ + @NotNull + @Schema(name = "@type", description = "When sub-classing, this defines the sub-class Extensible name", requiredMode = Schema.RequiredMode.REQUIRED) + @JsonProperty("@type") + public String getAtType() { + return atType; + } + + public void setAtType(String atType) { + this.atType = atType; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + EntityRef entityRef = (EntityRef) o; + return Objects.equals(this.name, entityRef.name) && + Objects.equals(this.atReferredType, entityRef.atReferredType) && + Objects.equals(this.href, entityRef.href) && + Objects.equals(this.id, entityRef.id) && + Objects.equals(this.atSchemaLocation, entityRef.atSchemaLocation) && + Objects.equals(this.atBaseType, entityRef.atBaseType) && + Objects.equals(this.atType, entityRef.atType); + } + + @Override + public int hashCode() { + return Objects.hash(name, atReferredType, href, id, atSchemaLocation, atBaseType, atType); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class EntityRef {\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" atReferredType: ").append(toIndentedString(atReferredType)).append("\n"); + sb.append(" href: ").append(toIndentedString(href)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" atSchemaLocation: ").append(toIndentedString(atSchemaLocation)).append("\n"); + sb.append(" atBaseType: ").append(toIndentedString(atBaseType)).append("\n"); + sb.append(" atType: ").append(toIndentedString(atType)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static class Builder { + + private EntityRef instance; + + public Builder() { + this(new EntityRef()); + } + + protected Builder(EntityRef instance) { + this.instance = instance; + } + + protected Builder copyOf(EntityRef value) { + this.instance.setName(value.name); + this.instance.setAtReferredType(value.atReferredType); + this.instance.setHref(value.href); + this.instance.setId(value.id); + this.instance.setAtSchemaLocation(value.atSchemaLocation); + this.instance.setAtBaseType(value.atBaseType); + this.instance.setAtType(value.atType); + return this; + } + + public EntityRef.Builder name(String name) { + this.instance.name(name); + return this; + } + + public EntityRef.Builder atReferredType(String atReferredType) { + this.instance.atReferredType(atReferredType); + return this; + } + + public EntityRef.Builder href(String href) { + this.instance.href(href); + return this; + } + + public EntityRef.Builder id(String id) { + this.instance.id(id); + return this; + } + + public EntityRef.Builder atSchemaLocation(String atSchemaLocation) { + this.instance.atSchemaLocation(atSchemaLocation); + return this; + } + + public EntityRef.Builder atBaseType(String atBaseType) { + this.instance.atBaseType(atBaseType); + return this; + } + + public EntityRef.Builder atType(String atType) { + this.instance.atType(atType); + return this; + } + + /** + * returns a built EntityRef instance. + * + * The builder is not reusable (NullPointerException) + */ + public EntityRef build() { + try { + return this.instance; + } finally { + // ensure that this.instance is not reused + this.instance = null; + } + } + + @Override + public String toString() { + return getClass() + "=(" + instance + ")"; + } + } + + /** + * Create a builder with no initialized field (except for the default values). + */ + public static EntityRef.Builder builder() { + return new EntityRef.Builder(); + } + + /** + * Create a builder with a shallow copy of this instance. + */ + public EntityRef.Builder toBuilder() { + EntityRef.Builder builder = new EntityRef.Builder(); + return builder.copyOf(this); + } + +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Extensible.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Extensible.java new file mode 100644 index 000000000000..f102532d2f8d --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Extensible.java @@ -0,0 +1,213 @@ +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.springframework.lang.Nullable; +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; + +/** + * Extensible + */ + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public class Extensible { + + private @Nullable String atSchemaLocation; + + private @Nullable String atBaseType; + + private String atType; + + public Extensible() { + super(); + } + + /** + * Constructor with only required parameters + */ + public Extensible(String atType) { + this.atType = atType; + } + + public Extensible atSchemaLocation(@Nullable String atSchemaLocation) { + this.atSchemaLocation = atSchemaLocation; + return this; + } + + /** + * A URI to a JSON-Schema file that defines additional attributes and relationships + * @return atSchemaLocation + */ + + @Schema(name = "@schemaLocation", description = "A URI to a JSON-Schema file that defines additional attributes and relationships", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("@schemaLocation") + public @Nullable String getAtSchemaLocation() { + return atSchemaLocation; + } + + public void setAtSchemaLocation(@Nullable String atSchemaLocation) { + this.atSchemaLocation = atSchemaLocation; + } + + public Extensible atBaseType(@Nullable String atBaseType) { + this.atBaseType = atBaseType; + return this; + } + + /** + * When sub-classing, this defines the super-class + * @return atBaseType + */ + + @Schema(name = "@baseType", description = "When sub-classing, this defines the super-class", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("@baseType") + public @Nullable String getAtBaseType() { + return atBaseType; + } + + public void setAtBaseType(@Nullable String atBaseType) { + this.atBaseType = atBaseType; + } + + public Extensible atType(String atType) { + this.atType = atType; + return this; + } + + /** + * When sub-classing, this defines the sub-class Extensible name + * @return atType + */ + @NotNull + @Schema(name = "@type", description = "When sub-classing, this defines the sub-class Extensible name", requiredMode = Schema.RequiredMode.REQUIRED) + @JsonProperty("@type") + public String getAtType() { + return atType; + } + + public void setAtType(String atType) { + this.atType = atType; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Extensible extensible = (Extensible) o; + return Objects.equals(this.atSchemaLocation, extensible.atSchemaLocation) && + Objects.equals(this.atBaseType, extensible.atBaseType) && + Objects.equals(this.atType, extensible.atType); + } + + @Override + public int hashCode() { + return Objects.hash(atSchemaLocation, atBaseType, atType); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Extensible {\n"); + sb.append(" atSchemaLocation: ").append(toIndentedString(atSchemaLocation)).append("\n"); + sb.append(" atBaseType: ").append(toIndentedString(atBaseType)).append("\n"); + sb.append(" atType: ").append(toIndentedString(atType)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static class Builder { + + private Extensible instance; + + public Builder() { + this(new Extensible()); + } + + protected Builder(Extensible instance) { + this.instance = instance; + } + + protected Builder copyOf(Extensible value) { + this.instance.setAtSchemaLocation(value.atSchemaLocation); + this.instance.setAtBaseType(value.atBaseType); + this.instance.setAtType(value.atType); + return this; + } + + public Extensible.Builder atSchemaLocation(String atSchemaLocation) { + this.instance.atSchemaLocation(atSchemaLocation); + return this; + } + + public Extensible.Builder atBaseType(String atBaseType) { + this.instance.atBaseType(atBaseType); + return this; + } + + public Extensible.Builder atType(String atType) { + this.instance.atType(atType); + return this; + } + + /** + * returns a built Extensible instance. + * + * The builder is not reusable (NullPointerException) + */ + public Extensible build() { + try { + return this.instance; + } finally { + // ensure that this.instance is not reused + this.instance = null; + } + } + + @Override + public String toString() { + return getClass() + "=(" + instance + ")"; + } + } + + /** + * Create a builder with no initialized field (except for the default values). + */ + public static Extensible.Builder builder() { + return new Extensible.Builder(); + } + + /** + * Create a builder with a shallow copy of this instance. + */ + public Extensible.Builder toBuilder() { + Extensible.Builder builder = new Extensible.Builder(); + return builder.copyOf(this); + } + +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Foo.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Foo.java new file mode 100644 index 000000000000..2834bc3cc67d --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Foo.java @@ -0,0 +1,248 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.openapitools.model.Entity; +import org.springframework.lang.Nullable; +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; + +/** + * Foo + */ + + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public final class Foo extends Entity implements FooRefOrValue { + + private @Nullable String fooPropA; + + private @Nullable String fooPropB; + + public Foo() { + super(); + } + + /** + * Constructor with only required parameters + */ + public Foo(String atType) { + super(atType); + } + + public Foo fooPropA(@Nullable String fooPropA) { + this.fooPropA = fooPropA; + return this; + } + + /** + * Get fooPropA + * @return fooPropA + */ + + @Schema(name = "fooPropA", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("fooPropA") + public @Nullable String getFooPropA() { + return fooPropA; + } + + public void setFooPropA(@Nullable String fooPropA) { + this.fooPropA = fooPropA; + } + + public Foo fooPropB(@Nullable String fooPropB) { + this.fooPropB = fooPropB; + return this; + } + + /** + * Get fooPropB + * @return fooPropB + */ + + @Schema(name = "fooPropB", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("fooPropB") + public @Nullable String getFooPropB() { + return fooPropB; + } + + public void setFooPropB(@Nullable String fooPropB) { + this.fooPropB = fooPropB; + } + + + public Foo href(String href) { + super.href(href); + return this; + } + + public Foo id(String id) { + super.id(id); + return this; + } + + public Foo atSchemaLocation(String atSchemaLocation) { + super.atSchemaLocation(atSchemaLocation); + return this; + } + + public Foo atBaseType(String atBaseType) { + super.atBaseType(atBaseType); + return this; + } + + public Foo atType(String atType) { + super.atType(atType); + return this; + } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Foo foo = (Foo) o; + return Objects.equals(this.fooPropA, foo.fooPropA) && + Objects.equals(this.fooPropB, foo.fooPropB) && + super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(fooPropA, fooPropB, super.hashCode()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Foo {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append(" fooPropA: ").append(toIndentedString(fooPropA)).append("\n"); + sb.append(" fooPropB: ").append(toIndentedString(fooPropB)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static class Builder extends Entity.Builder { + + private Foo instance; + + public Builder() { + this(new Foo()); + } + + protected Builder(Foo instance) { + super(instance); // the parent builder shares the same instance + this.instance = instance; + } + + protected Builder copyOf(Foo value) { + super.copyOf(value); + this.instance.setFooPropA(value.fooPropA); + this.instance.setFooPropB(value.fooPropB); + return this; + } + + public Foo.Builder fooPropA(String fooPropA) { + this.instance.fooPropA(fooPropA); + return this; + } + + public Foo.Builder fooPropB(String fooPropB) { + this.instance.fooPropB(fooPropB); + return this; + } + + @Override + public Foo.Builder href(String href) { + this.instance.href(href); + return this; + } + + @Override + public Foo.Builder id(String id) { + this.instance.id(id); + return this; + } + + @Override + public Foo.Builder atSchemaLocation(String atSchemaLocation) { + this.instance.atSchemaLocation(atSchemaLocation); + return this; + } + + @Override + public Foo.Builder atBaseType(String atBaseType) { + this.instance.atBaseType(atBaseType); + return this; + } + + @Override + public Foo.Builder atType(String atType) { + this.instance.atType(atType); + return this; + } + + /** + * returns a built Foo instance. + * + * The builder is not reusable (NullPointerException) + */ + public Foo build() { + try { + return this.instance; + } finally { + // ensure that this.instance is not reused + super.build(); + this.instance = null; + } + } + + @Override + public String toString() { + return getClass() + "=(" + instance + ")"; + } + } + + /** + * Create a builder with no initialized field (except for the default values). + */ + public static Foo.Builder builder() { + return new Foo.Builder(); + } + + /** + * Create a builder with a shallow copy of this instance. + */ + public Foo.Builder toBuilder() { + Foo.Builder builder = new Foo.Builder(); + return builder.copyOf(this); + } + +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/FooRef.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/FooRef.java new file mode 100644 index 000000000000..10f0b6d583f0 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/FooRef.java @@ -0,0 +1,240 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.openapitools.model.EntityRef; +import org.springframework.lang.Nullable; +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; + +/** + * FooRef + */ + + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public final class FooRef extends EntityRef implements FooRefOrValue { + + private @Nullable String foorefPropA; + + public FooRef() { + super(); + } + + /** + * Constructor with only required parameters + */ + public FooRef(String atType) { + super(atType); + } + + public FooRef foorefPropA(@Nullable String foorefPropA) { + this.foorefPropA = foorefPropA; + return this; + } + + /** + * Get foorefPropA + * @return foorefPropA + */ + + @Schema(name = "foorefPropA", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("foorefPropA") + public @Nullable String getFoorefPropA() { + return foorefPropA; + } + + public void setFoorefPropA(@Nullable String foorefPropA) { + this.foorefPropA = foorefPropA; + } + + + public FooRef name(String name) { + super.name(name); + return this; + } + + public FooRef atReferredType(String atReferredType) { + super.atReferredType(atReferredType); + return this; + } + + public FooRef href(String href) { + super.href(href); + return this; + } + + public FooRef id(String id) { + super.id(id); + return this; + } + + public FooRef atSchemaLocation(String atSchemaLocation) { + super.atSchemaLocation(atSchemaLocation); + return this; + } + + public FooRef atBaseType(String atBaseType) { + super.atBaseType(atBaseType); + return this; + } + + public FooRef atType(String atType) { + super.atType(atType); + return this; + } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + FooRef fooRef = (FooRef) o; + return Objects.equals(this.foorefPropA, fooRef.foorefPropA) && + super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(foorefPropA, super.hashCode()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class FooRef {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append(" foorefPropA: ").append(toIndentedString(foorefPropA)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static class Builder extends EntityRef.Builder { + + private FooRef instance; + + public Builder() { + this(new FooRef()); + } + + protected Builder(FooRef instance) { + super(instance); // the parent builder shares the same instance + this.instance = instance; + } + + protected Builder copyOf(FooRef value) { + super.copyOf(value); + this.instance.setFoorefPropA(value.foorefPropA); + return this; + } + + public FooRef.Builder foorefPropA(String foorefPropA) { + this.instance.foorefPropA(foorefPropA); + return this; + } + + @Override + public FooRef.Builder name(String name) { + this.instance.name(name); + return this; + } + + @Override + public FooRef.Builder atReferredType(String atReferredType) { + this.instance.atReferredType(atReferredType); + return this; + } + + @Override + public FooRef.Builder href(String href) { + this.instance.href(href); + return this; + } + + @Override + public FooRef.Builder id(String id) { + this.instance.id(id); + return this; + } + + @Override + public FooRef.Builder atSchemaLocation(String atSchemaLocation) { + this.instance.atSchemaLocation(atSchemaLocation); + return this; + } + + @Override + public FooRef.Builder atBaseType(String atBaseType) { + this.instance.atBaseType(atBaseType); + return this; + } + + @Override + public FooRef.Builder atType(String atType) { + this.instance.atType(atType); + return this; + } + + /** + * returns a built FooRef instance. + * + * The builder is not reusable (NullPointerException) + */ + public FooRef build() { + try { + return this.instance; + } finally { + // ensure that this.instance is not reused + super.build(); + this.instance = null; + } + } + + @Override + public String toString() { + return getClass() + "=(" + instance + ")"; + } + } + + /** + * Create a builder with no initialized field (except for the default values). + */ + public static FooRef.Builder builder() { + return new FooRef.Builder(); + } + + /** + * Create a builder with a shallow copy of this instance. + */ + public FooRef.Builder toBuilder() { + FooRef.Builder builder = new FooRef.Builder(); + return builder.copyOf(this); + } + +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/FooRefOrValue.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/FooRefOrValue.java new file mode 100644 index 000000000000..786731fcc52e --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/FooRefOrValue.java @@ -0,0 +1,37 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.openapitools.model.Foo; +import org.openapitools.model.FooRef; +import org.springframework.lang.Nullable; +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; + + +@JsonIgnoreProperties( + value = "@type", // ignore manually set @type, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the @type to be set during deserialization +) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@type", visible = true) +@JsonSubTypes({ + @JsonSubTypes.Type(value = Foo.class, name = "Foo"), + @JsonSubTypes.Type(value = FooRef.class, name = "FooRef") +}) + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public sealed interface FooRefOrValue permits Foo, FooRef { + public String getAtType(); +} diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Fruit.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Fruit.java new file mode 100644 index 000000000000..5062b4c48eb1 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Fruit.java @@ -0,0 +1,41 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonValue; +import org.openapitools.model.Apple; +import org.openapitools.model.Banana; +import org.openapitools.model.FruitType; +import org.springframework.lang.Nullable; +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; + + +@JsonIgnoreProperties( + value = "fruitType", // ignore manually set fruitType, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the fruitType to be set during deserialization +) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "fruitType", visible = true) +@JsonSubTypes({ + @JsonSubTypes.Type(value = Apple.class, name = "APPLE"), + @JsonSubTypes.Type(value = Banana.class, name = "BANANA"), + @JsonSubTypes.Type(value = Apple.class, name = "Apple"), + @JsonSubTypes.Type(value = Banana.class, name = "Banana") +}) + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public sealed interface Fruit permits Apple, Banana { + public FruitType getFruitType(); +} diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/FruitType.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/FruitType.java new file mode 100644 index 000000000000..b23ab8a11701 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/FruitType.java @@ -0,0 +1,56 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonValue; +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; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Gets or Sets FruitType + */ + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public enum FruitType { + + APPLE("APPLE"), + + BANANA("BANANA"); + + private final String value; + + FruitType(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static FruitType fromValue(String value) { + for (FruitType b : FruitType.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Pasta.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Pasta.java new file mode 100644 index 000000000000..7dc9568d5006 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Pasta.java @@ -0,0 +1,218 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.openapitools.model.Entity; +import org.springframework.lang.Nullable; +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; + +/** + * Pasta + */ + + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public class Pasta extends Entity { + + private @Nullable String vendor; + + public Pasta() { + super(); + } + + /** + * Constructor with only required parameters + */ + public Pasta(String atType) { + super(atType); + } + + public Pasta vendor(@Nullable String vendor) { + this.vendor = vendor; + return this; + } + + /** + * Get vendor + * @return vendor + */ + + @Schema(name = "vendor", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("vendor") + public @Nullable String getVendor() { + return vendor; + } + + public void setVendor(@Nullable String vendor) { + this.vendor = vendor; + } + + + public Pasta href(String href) { + super.href(href); + return this; + } + + public Pasta id(String id) { + super.id(id); + return this; + } + + public Pasta atSchemaLocation(String atSchemaLocation) { + super.atSchemaLocation(atSchemaLocation); + return this; + } + + public Pasta atBaseType(String atBaseType) { + super.atBaseType(atBaseType); + return this; + } + + public Pasta atType(String atType) { + super.atType(atType); + return this; + } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Pasta pasta = (Pasta) o; + return Objects.equals(this.vendor, pasta.vendor) && + super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(vendor, super.hashCode()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Pasta {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append(" vendor: ").append(toIndentedString(vendor)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static class Builder extends Entity.Builder { + + private Pasta instance; + + public Builder() { + this(new Pasta()); + } + + protected Builder(Pasta instance) { + super(instance); // the parent builder shares the same instance + this.instance = instance; + } + + protected Builder copyOf(Pasta value) { + super.copyOf(value); + this.instance.setVendor(value.vendor); + return this; + } + + public Pasta.Builder vendor(String vendor) { + this.instance.vendor(vendor); + return this; + } + + @Override + public Pasta.Builder href(String href) { + this.instance.href(href); + return this; + } + + @Override + public Pasta.Builder id(String id) { + this.instance.id(id); + return this; + } + + @Override + public Pasta.Builder atSchemaLocation(String atSchemaLocation) { + this.instance.atSchemaLocation(atSchemaLocation); + return this; + } + + @Override + public Pasta.Builder atBaseType(String atBaseType) { + this.instance.atBaseType(atBaseType); + return this; + } + + @Override + public Pasta.Builder atType(String atType) { + this.instance.atType(atType); + return this; + } + + /** + * returns a built Pasta instance. + * + * The builder is not reusable (NullPointerException) + */ + public Pasta build() { + try { + return this.instance; + } finally { + // ensure that this.instance is not reused + super.build(); + this.instance = null; + } + } + + @Override + public String toString() { + return getClass() + "=(" + instance + ")"; + } + } + + /** + * Create a builder with no initialized field (except for the default values). + */ + public static Pasta.Builder builder() { + return new Pasta.Builder(); + } + + /** + * Create a builder with a shallow copy of this instance. + */ + public Pasta.Builder toBuilder() { + Pasta.Builder builder = new Pasta.Builder(); + return builder.copyOf(this); + } + +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Pizza.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Pizza.java new file mode 100644 index 000000000000..2f9f00d5821b --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Pizza.java @@ -0,0 +1,227 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import java.math.BigDecimal; +import org.openapitools.model.Entity; +import org.springframework.lang.Nullable; +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; + +/** + * Pizza + */ + +@JsonIgnoreProperties( + value = "@type", // ignore manually set @type, it will be automatically generated by Jackson during serialization + allowSetters = true // allows the @type to be set during deserialization +) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@type", visible = true) +@JsonSubTypes({ + @JsonSubTypes.Type(value = PizzaSpeziale.class, name = "PizzaSpeziale") +}) + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public sealed class Pizza extends Entity permits PizzaSpeziale { + + private @Nullable BigDecimal pizzaSize; + + public Pizza() { + super(); + } + + /** + * Constructor with only required parameters + */ + public Pizza(String atType) { + super(atType); + } + + public Pizza pizzaSize(@Nullable BigDecimal pizzaSize) { + this.pizzaSize = pizzaSize; + return this; + } + + /** + * Get pizzaSize + * @return pizzaSize + */ + @Valid + @Schema(name = "pizzaSize", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("pizzaSize") + public @Nullable BigDecimal getPizzaSize() { + return pizzaSize; + } + + public void setPizzaSize(@Nullable BigDecimal pizzaSize) { + this.pizzaSize = pizzaSize; + } + + + public Pizza href(String href) { + super.href(href); + return this; + } + + public Pizza id(String id) { + super.id(id); + return this; + } + + public Pizza atSchemaLocation(String atSchemaLocation) { + super.atSchemaLocation(atSchemaLocation); + return this; + } + + public Pizza atBaseType(String atBaseType) { + super.atBaseType(atBaseType); + return this; + } + + public Pizza atType(String atType) { + super.atType(atType); + return this; + } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Pizza pizza = (Pizza) o; + return Objects.equals(this.pizzaSize, pizza.pizzaSize) && + super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(pizzaSize, super.hashCode()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Pizza {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append(" pizzaSize: ").append(toIndentedString(pizzaSize)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static class Builder extends Entity.Builder { + + private Pizza instance; + + public Builder() { + this(new Pizza()); + } + + protected Builder(Pizza instance) { + super(instance); // the parent builder shares the same instance + this.instance = instance; + } + + protected Builder copyOf(Pizza value) { + super.copyOf(value); + this.instance.setPizzaSize(value.pizzaSize); + return this; + } + + public Pizza.Builder pizzaSize(BigDecimal pizzaSize) { + this.instance.pizzaSize(pizzaSize); + return this; + } + + @Override + public Pizza.Builder href(String href) { + this.instance.href(href); + return this; + } + + @Override + public Pizza.Builder id(String id) { + this.instance.id(id); + return this; + } + + @Override + public Pizza.Builder atSchemaLocation(String atSchemaLocation) { + this.instance.atSchemaLocation(atSchemaLocation); + return this; + } + + @Override + public Pizza.Builder atBaseType(String atBaseType) { + this.instance.atBaseType(atBaseType); + return this; + } + + @Override + public Pizza.Builder atType(String atType) { + this.instance.atType(atType); + return this; + } + + /** + * returns a built Pizza instance. + * + * The builder is not reusable (NullPointerException) + */ + public Pizza build() { + try { + return this.instance; + } finally { + // ensure that this.instance is not reused + super.build(); + this.instance = null; + } + } + + @Override + public String toString() { + return getClass() + "=(" + instance + ")"; + } + } + + /** + * Create a builder with no initialized field (except for the default values). + */ + public static Pizza.Builder builder() { + return new Pizza.Builder(); + } + + /** + * Create a builder with a shallow copy of this instance. + */ + public Pizza.Builder toBuilder() { + Pizza.Builder builder = new Pizza.Builder(); + return builder.copyOf(this); + } + +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/PizzaSpeziale.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/PizzaSpeziale.java new file mode 100644 index 000000000000..93510272902c --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/PizzaSpeziale.java @@ -0,0 +1,230 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import java.math.BigDecimal; +import org.openapitools.model.Pizza; +import org.springframework.lang.Nullable; +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; + +/** + * PizzaSpeziale + */ + + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +public class PizzaSpeziale extends Pizza { + + private @Nullable String toppings; + + public PizzaSpeziale() { + super(); + } + + /** + * Constructor with only required parameters + */ + public PizzaSpeziale(String atType) { + super(atType); + } + + public PizzaSpeziale toppings(@Nullable String toppings) { + this.toppings = toppings; + return this; + } + + /** + * Get toppings + * @return toppings + */ + + @Schema(name = "toppings", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("toppings") + public @Nullable String getToppings() { + return toppings; + } + + public void setToppings(@Nullable String toppings) { + this.toppings = toppings; + } + + + public PizzaSpeziale pizzaSize(BigDecimal pizzaSize) { + super.pizzaSize(pizzaSize); + return this; + } + + public PizzaSpeziale href(String href) { + super.href(href); + return this; + } + + public PizzaSpeziale id(String id) { + super.id(id); + return this; + } + + public PizzaSpeziale atSchemaLocation(String atSchemaLocation) { + super.atSchemaLocation(atSchemaLocation); + return this; + } + + public PizzaSpeziale atBaseType(String atBaseType) { + super.atBaseType(atBaseType); + return this; + } + + public PizzaSpeziale atType(String atType) { + super.atType(atType); + return this; + } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PizzaSpeziale pizzaSpeziale = (PizzaSpeziale) o; + return Objects.equals(this.toppings, pizzaSpeziale.toppings) && + super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(toppings, super.hashCode()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PizzaSpeziale {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append(" toppings: ").append(toIndentedString(toppings)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + public static class Builder extends Pizza.Builder { + + private PizzaSpeziale instance; + + public Builder() { + this(new PizzaSpeziale()); + } + + protected Builder(PizzaSpeziale instance) { + super(instance); // the parent builder shares the same instance + this.instance = instance; + } + + protected Builder copyOf(PizzaSpeziale value) { + super.copyOf(value); + this.instance.setToppings(value.toppings); + return this; + } + + public PizzaSpeziale.Builder toppings(String toppings) { + this.instance.toppings(toppings); + return this; + } + + @Override + public PizzaSpeziale.Builder pizzaSize(BigDecimal pizzaSize) { + this.instance.pizzaSize(pizzaSize); + return this; + } + + @Override + public PizzaSpeziale.Builder href(String href) { + this.instance.href(href); + return this; + } + + @Override + public PizzaSpeziale.Builder id(String id) { + this.instance.id(id); + return this; + } + + @Override + public PizzaSpeziale.Builder atSchemaLocation(String atSchemaLocation) { + this.instance.atSchemaLocation(atSchemaLocation); + return this; + } + + @Override + public PizzaSpeziale.Builder atBaseType(String atBaseType) { + this.instance.atBaseType(atBaseType); + return this; + } + + @Override + public PizzaSpeziale.Builder atType(String atType) { + this.instance.atType(atType); + return this; + } + + /** + * returns a built PizzaSpeziale instance. + * + * The builder is not reusable (NullPointerException) + */ + public PizzaSpeziale build() { + try { + return this.instance; + } finally { + // ensure that this.instance is not reused + super.build(); + this.instance = null; + } + } + + @Override + public String toString() { + return getClass() + "=(" + instance + ")"; + } + } + + /** + * Create a builder with no initialized field (except for the default values). + */ + public static PizzaSpeziale.Builder builder() { + return new PizzaSpeziale.Builder(); + } + + /** + * Create a builder with a shallow copy of this instance. + */ + public PizzaSpeziale.Builder toBuilder() { + PizzaSpeziale.Builder builder = new PizzaSpeziale.Builder(); + return builder.copyOf(this); + } + +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/resources/application.properties b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/resources/application.properties new file mode 100644 index 000000000000..7e90813e59b2 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/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/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/resources/openapi.yaml b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/resources/openapi.yaml new file mode 100644 index 000000000000..24752605bf87 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/resources/openapi.yaml @@ -0,0 +1,264 @@ +openapi: 3.0.1 +info: + description: | + This tests for a oneOf interface representation + title: ByRefOrValue + version: 0.0.1 +servers: +- url: http://localhost:8080 +tags: +- name: Foo +- name: Bar +paths: + /foo: + get: + operationId: getAllFoos + responses: + "200": + $ref: "#/components/responses/200FooArray" + summary: GET all Foos + tags: + - Foo + x-accepts: + - application/json;charset=utf-8 + x-tags: + - tag: Foo + post: + operationId: createFoo + requestBody: + $ref: "#/components/requestBodies/Foo" + responses: + "201": + $ref: "#/components/responses/201Foo" + summary: Create a Foo + tags: + - Foo + x-content-type: application/json;charset=utf-8 + x-accepts: + - application/json + x-tags: + - tag: Foo + /bar: + post: + operationId: createBar + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/Bar_Create" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/Bar" + description: Bar created + summary: Create a Bar + tags: + - Bar + x-content-type: application/json + x-accepts: + - application/json + x-tags: + - tag: Bar +components: + requestBodies: + Foo: + content: + application/json;charset=utf-8: + schema: + $ref: "#/components/schemas/Foo" + description: The Foo to be created + responses: + "204": + content: {} + description: Deleted + "201Foo": + content: + application/json: + schema: + $ref: "#/components/schemas/FooRefOrValue" + description: Error + "200FooArray": + content: + application/json;charset=utf-8: + schema: + items: + $ref: "#/components/schemas/FooRefOrValue" + type: array + description: Success + schemas: + Addressable: + description: Base schema for addressable entities + properties: + href: + description: Hyperlink reference + type: string + id: + description: unique identifier + type: string + type: object + Extensible: + properties: + '@schemaLocation': + description: A URI to a JSON-Schema file that defines additional attributes + and relationships + type: string + '@baseType': + description: "When sub-classing, this defines the super-class" + type: string + '@type': + description: "When sub-classing, this defines the sub-class Extensible name" + type: string + required: + - '@type' + type: object + Entity: + allOf: + - $ref: "#/components/schemas/Addressable" + - $ref: "#/components/schemas/Extensible" + discriminator: + propertyName: '@type' + type: object + EntityRef: + allOf: + - $ref: "#/components/schemas/Addressable" + - $ref: "#/components/schemas/Extensible" + description: Entity reference schema to be use for all entityRef class. + discriminator: + propertyName: '@type' + properties: + name: + description: Name of the related entity. + type: string + '@referredType': + description: The actual type of the target instance when needed for disambiguation. + type: string + type: object + FooRefOrValue: + discriminator: + propertyName: '@type' + oneOf: + - $ref: "#/components/schemas/Foo" + - $ref: "#/components/schemas/FooRef" + type: object + x-one-of-name: FooRefOrValue + Foo: + allOf: + - $ref: "#/components/schemas/Entity" + example: + fooPropA: fooPropA + fooPropB: fooPropB + properties: + fooPropA: + type: string + fooPropB: + type: string + type: object + FooRef: + allOf: + - $ref: "#/components/schemas/EntityRef" + properties: + foorefPropA: + type: string + type: object + BarRef: + allOf: + - $ref: "#/components/schemas/EntityRef" + type: object + Bar_Create: + allOf: + - $ref: "#/components/schemas/Entity" + properties: + barPropA: + type: string + fooPropB: + type: string + foo: + $ref: "#/components/schemas/FooRefOrValue" + type: object + Bar: + allOf: + - $ref: "#/components/schemas/Entity" + example: + foo: + fooPropA: fooPropA + fooPropB: fooPropB + id: id + fooPropB: fooPropB + barPropA: barPropA + properties: + id: + type: string + barPropA: + type: string + fooPropB: + type: string + foo: + $ref: "#/components/schemas/FooRefOrValue" + required: + - id + type: object + BarRefOrValue: + oneOf: + - $ref: "#/components/schemas/Bar" + - $ref: "#/components/schemas/BarRef" + type: object + x-one-of-name: BarRefOrValue + Pizza: + allOf: + - $ref: "#/components/schemas/Entity" + properties: + pizzaSize: + type: number + type: object + Pasta: + allOf: + - $ref: "#/components/schemas/Entity" + properties: + vendor: + type: string + type: object + PizzaSpeziale: + allOf: + - $ref: "#/components/schemas/Pizza" + properties: + toppings: + type: string + type: object + FruitType: + enum: + - APPLE + - BANANA + type: string + Fruit: + discriminator: + mapping: + APPLE: "#/components/schemas/Apple" + BANANA: "#/components/schemas/Banana" + propertyName: fruitType + oneOf: + - $ref: "#/components/schemas/Apple" + - $ref: "#/components/schemas/Banana" + properties: + fruitType: + $ref: "#/components/schemas/FruitType" + required: + - fruitType + type: object + x-one-of-name: Fruit + Apple: + properties: + seeds: + type: integer + required: + - seeds + type: object + Banana: + properties: + length: + type: integer + required: + - length + type: object diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java new file mode 100644 index 000000000000..3681f67e7705 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/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