From 717360afe4399fe22b410cc8fe50649fcbeaa470 Mon Sep 17 00:00:00 2001 From: jpfinne Date: Fri, 14 Mar 2025 17:14:58 +0100 Subject: [PATCH 1/6] Use deduction configOptions for oneOfInterfaces --- docs/generators/java-camel.md | 1 + docs/generators/spring.md | 1 + .../codegen/languages/SpringCodegen.java | 5 ++++- .../JavaSpring/oneof_interface.mustache | 8 ++++++++ .../codegen/java/spring/SpringCodegenTest.java | 2 ++ .../3_0/oneof_polymorphism_and_inheritance.yaml | 16 ++++++++++++++++ 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/docs/generators/java-camel.md b/docs/generators/java-camel.md index f2714febe563..52ae4809ad41 100644 --- a/docs/generators/java-camel.md +++ b/docs/generators/java-camel.md @@ -102,6 +102,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useFeignClientUrl|Whether to generate Feign client with url parameter.| |true| |useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false| |useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false| +|useOneOfInterfacesDeduction|whether to use deduction for generated oneOf interfaces| |false| |useOptional|Use Optional container for optional parameters| |false| |useResponseEntity|Use the `ResponseEntity` type to wrap return values of generated API methods. If disabled, method are annotated using a `@ResponseStatus` annotation, which has the status of the first response declared in the Api definition| |true| |useSealed|Whether to generate sealed model interfaces and classes| |false| diff --git a/docs/generators/spring.md b/docs/generators/spring.md index 954b786ebd13..efcc8098e4e3 100644 --- a/docs/generators/spring.md +++ b/docs/generators/spring.md @@ -95,6 +95,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useFeignClientUrl|Whether to generate Feign client with url parameter.| |true| |useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false| |useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false| +|useOneOfInterfacesDeduction|whether to use deduction for generated oneOf interfaces| |false| |useOptional|Use Optional container for optional parameters| |false| |useResponseEntity|Use the `ResponseEntity` type to wrap return values of generated API methods. If disabled, method are annotated using a `@ResponseStatus` annotation, which has the status of the first response declared in the Api definition| |true| |useSealed|Whether to generate sealed model interfaces and classes| |false| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java index 5b28553854b2..072979481285 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java @@ -96,7 +96,7 @@ public class SpringCodegen extends AbstractJavaCodegen public static final String USE_REQUEST_MAPPING_ON_INTERFACE = "useRequestMappingOnInterface"; public static final String USE_SEALED = "useSealed"; public static final String OPTIONAL_ACCEPT_NULLABLE = "optionalAcceptNullable"; - + public static final String USE_DEDUCTION_FOR_ONE_OF_INTERFACES = "oneOfInterfacesDeduction"; @Getter public enum RequestMappingMode { api_interface("Generate the @RequestMapping annotation on the generated Api Interface."), @@ -152,6 +152,8 @@ public enum RequestMappingMode { protected RequestMappingMode requestMappingMode = RequestMappingMode.controller; @Getter @Setter protected boolean optionalAcceptNullable = true; + @Getter @Setter + protected boolean useDeductionForOneOfInterfaces = false; public SpringCodegen() { super(); @@ -260,6 +262,7 @@ public SpringCodegen() { "Use `ofNullable` instead of just `of` to accept null values when using Optional.", optionalAcceptNullable)); + cliOptions.add(CliOption.newBoolean(USE_DEDUCTION_FOR_ONE_OF_INTERFACES, "whether to use deduction for generated oneOf interfaces", useDeductionForOneOfInterfaces)); supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application."); supportedLibraries.put(SPRING_CLOUD_LIBRARY, "Spring-Cloud-Feign client with Spring-Boot auto-configured settings."); diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/oneof_interface.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/oneof_interface.mustache index e83ac99867f5..5ba289914e85 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/oneof_interface.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/oneof_interface.mustache @@ -5,6 +5,14 @@ {{#discriminator}} {{>typeInfoAnnotation}} {{/discriminator}} +{{^discriminator}}{{#useDeductionForOneOfInterfaces}} +@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION) +@JsonSubTypes({ + {{#interfaceModels}} + @JsonSubTypes.Type(value = {{classname}}.class){{^-last}}, {{/-last}} + {{/interfaceModels}} +}) +{{/useDeductionForOneOfInterfaces}}{{/discriminator}} {{>generatedAnnotation}} public {{>sealed}}interface {{classname}}{{#vendorExtensions.x-implements}}{{#-first}} extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {{>permits}}{ {{#discriminator}} 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 a7ccd9d369e3..4e8d9967f5b4 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 @@ -1702,10 +1702,12 @@ public void testOneOfAndAllOf() throws IOException { generator.setGeneratorPropertyDefault(CodegenConstants.LEGACY_DISCRIMINATOR_BEHAVIOR, "false"); codegen.setUseOneOfInterfaces(true); + codegen.setUseDeductionForOneOfInterfaces(true); codegen.setLegacyDiscriminatorBehavior(false); generator.opts(input).generate(); + assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/model/Animal.java"), "@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)", "@JsonSubTypes.Type(value = Dog.class),", "@JsonSubTypes.Type(value = Cat.class)"); assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/model/Foo.java"), "public class Foo extends Entity implements FooRefOrValue"); assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/model/FooRef.java"), "public class FooRef extends EntityRef implements FooRefOrValue"); assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/model/FooRefOrValue.java"), "public interface FooRefOrValue"); diff --git a/modules/openapi-generator/src/test/resources/3_0/oneof_polymorphism_and_inheritance.yaml b/modules/openapi-generator/src/test/resources/3_0/oneof_polymorphism_and_inheritance.yaml index d890e5fbfd5a..2eed77fef5eb 100644 --- a/modules/openapi-generator/src/test/resources/3_0/oneof_polymorphism_and_inheritance.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/oneof_polymorphism_and_inheritance.yaml @@ -108,6 +108,8 @@ components: Foo: type: object properties: + dog: + $ref: "#/components/schemas/Dog" fooPropA: type: string fooPropB: @@ -209,6 +211,20 @@ components: properties: length: type: integer + Animal: + oneOf: + - $ref: '#/components/schemas/Dog' + - $ref: '#/components/schemas/Cat' + Cat: + type: object + properties: + declawed: + type: boolean + Dog: + type: object + properties: + bark: + type: boolean requestBodies: Foo: From a2a21d33ab9623b1dc310b9198fc6cca1638cff6 Mon Sep 17 00:00:00 2001 From: jpfinne Date: Sat, 15 Mar 2025 18:46:44 +0100 Subject: [PATCH 2/6] generate samples and doc --- docs/generators/java-camel.md | 2 +- docs/generators/spring.md | 2 +- .../JavaSpring/oneof_interface.mustache | 6 +- .../oneof_polymorphism_and_inheritance.yaml | 2 - .../java/org/openapitools/model/Animal.java | 25 +++ .../main/java/org/openapitools/model/Cat.java | 142 ++++++++++++++++++ .../main/java/org/openapitools/model/Dog.java | 142 ++++++++++++++++++ .../src/main/resources/openapi.yaml | 15 ++ 8 files changed, 329 insertions(+), 7 deletions(-) create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof/src/main/java/org/openapitools/model/Animal.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof/src/main/java/org/openapitools/model/Cat.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof/src/main/java/org/openapitools/model/Dog.java diff --git a/docs/generators/java-camel.md b/docs/generators/java-camel.md index 52ae4809ad41..df38b63908be 100644 --- a/docs/generators/java-camel.md +++ b/docs/generators/java-camel.md @@ -72,6 +72,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |licenseName|The name of the license| |Unlicense| |licenseUrl|The URL of the license| |http://unlicense.org| |modelPackage|package for generated models| |org.openapitools.model| +|oneOfInterfacesDeduction|whether to use deduction for generated oneOf interfaces| |false| |openApiNullable|Enable OpenAPI Jackson Nullable library. Not supported by `microprofile` library.| |true| |optionalAcceptNullable|Use `ofNullable` instead of just `of` to accept null values when using Optional.| |true| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| @@ -102,7 +103,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useFeignClientUrl|Whether to generate Feign client with url parameter.| |true| |useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false| |useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false| -|useOneOfInterfacesDeduction|whether to use deduction for generated oneOf interfaces| |false| |useOptional|Use Optional container for optional parameters| |false| |useResponseEntity|Use the `ResponseEntity` type to wrap return values of generated API methods. If disabled, method are annotated using a `@ResponseStatus` annotation, which has the status of the first response declared in the Api definition| |true| |useSealed|Whether to generate sealed model interfaces and classes| |false| diff --git a/docs/generators/spring.md b/docs/generators/spring.md index efcc8098e4e3..92a78ea5c443 100644 --- a/docs/generators/spring.md +++ b/docs/generators/spring.md @@ -65,6 +65,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |licenseName|The name of the license| |Unlicense| |licenseUrl|The URL of the license| |http://unlicense.org| |modelPackage|package for generated models| |org.openapitools.model| +|oneOfInterfacesDeduction|whether to use deduction for generated oneOf interfaces| |false| |openApiNullable|Enable OpenAPI Jackson Nullable library. Not supported by `microprofile` library.| |true| |optionalAcceptNullable|Use `ofNullable` instead of just `of` to accept null values when using Optional.| |true| |parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null| @@ -95,7 +96,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl |useFeignClientUrl|Whether to generate Feign client with url parameter.| |true| |useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false| |useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false| -|useOneOfInterfacesDeduction|whether to use deduction for generated oneOf interfaces| |false| |useOptional|Use Optional container for optional parameters| |false| |useResponseEntity|Use the `ResponseEntity` type to wrap return values of generated API methods. If disabled, method are annotated using a `@ResponseStatus` annotation, which has the status of the first response declared in the Api definition| |true| |useSealed|Whether to generate sealed model interfaces and classes| |false| diff --git a/modules/openapi-generator/src/main/resources/JavaSpring/oneof_interface.mustache b/modules/openapi-generator/src/main/resources/JavaSpring/oneof_interface.mustache index 5ba289914e85..5934368ebb27 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/oneof_interface.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/oneof_interface.mustache @@ -4,15 +4,15 @@ {{/withXml}} {{#discriminator}} {{>typeInfoAnnotation}} -{{/discriminator}} -{{^discriminator}}{{#useDeductionForOneOfInterfaces}} +{{/discriminator}}{{^discriminator}}{{#useDeductionForOneOfInterfaces}} @JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION) @JsonSubTypes({ {{#interfaceModels}} @JsonSubTypes.Type(value = {{classname}}.class){{^-last}}, {{/-last}} {{/interfaceModels}} }) -{{/useDeductionForOneOfInterfaces}}{{/discriminator}} +{{/useDeductionForOneOfInterfaces}} +{{/discriminator}} {{>generatedAnnotation}} public {{>sealed}}interface {{classname}}{{#vendorExtensions.x-implements}}{{#-first}} extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {{>permits}}{ {{#discriminator}} diff --git a/modules/openapi-generator/src/test/resources/3_0/oneof_polymorphism_and_inheritance.yaml b/modules/openapi-generator/src/test/resources/3_0/oneof_polymorphism_and_inheritance.yaml index 2eed77fef5eb..ad65b8921f73 100644 --- a/modules/openapi-generator/src/test/resources/3_0/oneof_polymorphism_and_inheritance.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/oneof_polymorphism_and_inheritance.yaml @@ -108,8 +108,6 @@ components: Foo: type: object properties: - dog: - $ref: "#/components/schemas/Dog" fooPropA: type: string fooPropB: diff --git a/samples/openapi3/server/petstore/spring-boot-oneof/src/main/java/org/openapitools/model/Animal.java b/samples/openapi3/server/petstore/spring-boot-oneof/src/main/java/org/openapitools/model/Animal.java new file mode 100644 index 000000000000..ac8d823a301a --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof/src/main/java/org/openapitools/model/Animal.java @@ -0,0 +1,25 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import org.openapitools.model.Cat; +import org.openapitools.model.Dog; +import org.springframework.lang.Nullable; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +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; + + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.13.0-SNAPSHOT") +public interface Animal { +} diff --git a/samples/openapi3/server/petstore/spring-boot-oneof/src/main/java/org/openapitools/model/Cat.java b/samples/openapi3/server/petstore/spring-boot-oneof/src/main/java/org/openapitools/model/Cat.java new file mode 100644 index 000000000000..c09bf9f8e2c8 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof/src/main/java/org/openapitools/model/Cat.java @@ -0,0 +1,142 @@ +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; + +/** + * Cat + */ + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.13.0-SNAPSHOT") +public class Cat implements Animal { + + private @Nullable Boolean declawed; + + public Cat declawed(Boolean declawed) { + this.declawed = declawed; + return this; + } + + /** + * Get declawed + * @return declawed + */ + + @Schema(name = "declawed", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("declawed") + public Boolean getDeclawed() { + return declawed; + } + + public void setDeclawed(Boolean declawed) { + this.declawed = declawed; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Cat cat = (Cat) o; + return Objects.equals(this.declawed, cat.declawed); + } + + @Override + public int hashCode() { + return Objects.hash(declawed); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Cat {\n"); + sb.append(" declawed: ").append(toIndentedString(declawed)).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 Cat instance; + + public Builder() { + this(new Cat()); + } + + protected Builder(Cat instance) { + this.instance = instance; + } + + protected Builder copyOf(Cat value) { + this.instance.setDeclawed(value.declawed); + return this; + } + + public Cat.Builder declawed(Boolean declawed) { + this.instance.declawed(declawed); + return this; + } + + /** + * returns a built Cat instance. + * + * The builder is not reusable (NullPointerException) + */ + public Cat 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 Cat.Builder builder() { + return new Cat.Builder(); + } + + /** + * Create a builder with a shallow copy of this instance. + */ + public Cat.Builder toBuilder() { + Cat.Builder builder = new Cat.Builder(); + return builder.copyOf(this); + } + +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof/src/main/java/org/openapitools/model/Dog.java b/samples/openapi3/server/petstore/spring-boot-oneof/src/main/java/org/openapitools/model/Dog.java new file mode 100644 index 000000000000..cc9ee40a8b16 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof/src/main/java/org/openapitools/model/Dog.java @@ -0,0 +1,142 @@ +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; + +/** + * Dog + */ + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.13.0-SNAPSHOT") +public class Dog implements Animal { + + private @Nullable Boolean bark; + + public Dog bark(Boolean bark) { + this.bark = bark; + return this; + } + + /** + * Get bark + * @return bark + */ + + @Schema(name = "bark", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("bark") + public Boolean getBark() { + return bark; + } + + public void setBark(Boolean bark) { + this.bark = bark; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Dog dog = (Dog) o; + return Objects.equals(this.bark, dog.bark); + } + + @Override + public int hashCode() { + return Objects.hash(bark); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Dog {\n"); + sb.append(" bark: ").append(toIndentedString(bark)).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 Dog instance; + + public Builder() { + this(new Dog()); + } + + protected Builder(Dog instance) { + this.instance = instance; + } + + protected Builder copyOf(Dog value) { + this.instance.setBark(value.bark); + return this; + } + + public Dog.Builder bark(Boolean bark) { + this.instance.bark(bark); + return this; + } + + /** + * returns a built Dog instance. + * + * The builder is not reusable (NullPointerException) + */ + public Dog 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 Dog.Builder builder() { + return new Dog.Builder(); + } + + /** + * Create a builder with a shallow copy of this instance. + */ + public Dog.Builder toBuilder() { + Dog.Builder builder = new Dog.Builder(); + return builder.copyOf(this); + } + +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof/src/main/resources/openapi.yaml b/samples/openapi3/server/petstore/spring-boot-oneof/src/main/resources/openapi.yaml index 50a9730c4e73..f2d068cdbb3e 100644 --- a/samples/openapi3/server/petstore/spring-boot-oneof/src/main/resources/openapi.yaml +++ b/samples/openapi3/server/petstore/spring-boot-oneof/src/main/resources/openapi.yaml @@ -272,3 +272,18 @@ components: required: - length type: object + Animal: + oneOf: + - $ref: '#/components/schemas/Dog' + - $ref: '#/components/schemas/Cat' + x-one-of-name: Animal + Cat: + properties: + declawed: + type: boolean + type: object + Dog: + properties: + bark: + type: boolean + type: object From e04f4abcbe60f6d80422e09fa6a8a89f92415b52 Mon Sep 17 00:00:00 2001 From: jpfinne Date: Sat, 15 Mar 2025 19:07:12 +0100 Subject: [PATCH 3/6] generate samples for rust and dart --- .../rust/hyper/oneOf/.openapi-generator/FILES | 6 + .../client/others/rust/hyper/oneOf/README.md | 3 + .../others/rust/hyper/oneOf/docs/Animal.md | 12 ++ .../others/rust/hyper/oneOf/docs/Cat.md | 11 ++ .../others/rust/hyper/oneOf/docs/Dog.md | 11 ++ .../rust/hyper/oneOf/src/models/animal.rs | 26 +++++ .../others/rust/hyper/oneOf/src/models/cat.rs | 27 +++++ .../others/rust/hyper/oneOf/src/models/dog.rs | 27 +++++ .../others/rust/hyper/oneOf/src/models/mod.rs | 6 + .../reqwest/oneOf/.openapi-generator/FILES | 6 + .../others/rust/reqwest/oneOf/README.md | 3 + .../others/rust/reqwest/oneOf/docs/Animal.md | 12 ++ .../others/rust/reqwest/oneOf/docs/Cat.md | 11 ++ .../others/rust/reqwest/oneOf/docs/Dog.md | 11 ++ .../rust/reqwest/oneOf/src/models/animal.rs | 26 +++++ .../rust/reqwest/oneOf/src/models/cat.rs | 27 +++++ .../rust/reqwest/oneOf/src/models/dog.rs | 27 +++++ .../rust/reqwest/oneOf/src/models/mod.rs | 6 + .../.openapi-generator/FILES | 9 ++ .../README.md | 3 + .../doc/Animal.md | 16 +++ .../doc/Cat.md | 15 +++ .../doc/Dog.md | 15 +++ .../lib/openapi.dart | 3 + .../lib/src/model/animal.dart | 73 ++++++++++++ .../lib/src/model/cat.dart | 108 ++++++++++++++++++ .../lib/src/model/dog.dart | 108 ++++++++++++++++++ .../lib/src/serializers.dart | 6 + .../test/animal_test.dart | 21 ++++ .../test/cat_test.dart | 16 +++ .../test/dog_test.dart | 16 +++ .../main/java/org/openapitools/model/Tag.java | 105 ----------------- .../.openapi-generator/FILES | 3 + .../.openapi-generator/FILES | 12 -- 34 files changed, 670 insertions(+), 117 deletions(-) create mode 100644 samples/client/others/rust/hyper/oneOf/docs/Animal.md create mode 100644 samples/client/others/rust/hyper/oneOf/docs/Cat.md create mode 100644 samples/client/others/rust/hyper/oneOf/docs/Dog.md create mode 100644 samples/client/others/rust/hyper/oneOf/src/models/animal.rs create mode 100644 samples/client/others/rust/hyper/oneOf/src/models/cat.rs create mode 100644 samples/client/others/rust/hyper/oneOf/src/models/dog.rs create mode 100644 samples/client/others/rust/reqwest/oneOf/docs/Animal.md create mode 100644 samples/client/others/rust/reqwest/oneOf/docs/Cat.md create mode 100644 samples/client/others/rust/reqwest/oneOf/docs/Dog.md create mode 100644 samples/client/others/rust/reqwest/oneOf/src/models/animal.rs create mode 100644 samples/client/others/rust/reqwest/oneOf/src/models/cat.rs create mode 100644 samples/client/others/rust/reqwest/oneOf/src/models/dog.rs create mode 100644 samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Animal.md create mode 100644 samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Cat.md create mode 100644 samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Dog.md create mode 100644 samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/animal.dart create mode 100644 samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/cat.dart create mode 100644 samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/dog.dart create mode 100644 samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/animal_test.dart create mode 100644 samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/cat_test.dart create mode 100644 samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/dog_test.dart delete mode 100644 samples/server/petstore/springboot-file-delegate-optional/.openapi-generator/FILES diff --git a/samples/client/others/rust/hyper/oneOf/.openapi-generator/FILES b/samples/client/others/rust/hyper/oneOf/.openapi-generator/FILES index 7452a306cce2..f1727840902e 100644 --- a/samples/client/others/rust/hyper/oneOf/.openapi-generator/FILES +++ b/samples/client/others/rust/hyper/oneOf/.openapi-generator/FILES @@ -3,6 +3,7 @@ Cargo.toml README.md docs/Addressable.md +docs/Animal.md docs/Apple.md docs/Banana.md docs/Bar.md @@ -10,6 +11,8 @@ docs/BarApi.md docs/BarCreate.md docs/BarRef.md docs/BarRefOrValue.md +docs/Cat.md +docs/Dog.md docs/Entity.md docs/EntityRef.md docs/Extensible.md @@ -31,12 +34,15 @@ src/apis/mod.rs src/apis/request.rs src/lib.rs src/models/addressable.rs +src/models/animal.rs src/models/apple.rs src/models/banana.rs src/models/bar.rs src/models/bar_create.rs src/models/bar_ref.rs src/models/bar_ref_or_value.rs +src/models/cat.rs +src/models/dog.rs src/models/entity.rs src/models/entity_ref.rs src/models/extensible.rs diff --git a/samples/client/others/rust/hyper/oneOf/README.md b/samples/client/others/rust/hyper/oneOf/README.md index 2513a0e125e9..259c6c63a4ac 100644 --- a/samples/client/others/rust/hyper/oneOf/README.md +++ b/samples/client/others/rust/hyper/oneOf/README.md @@ -35,12 +35,15 @@ Class | Method | HTTP request | Description ## Documentation For Models - [Addressable](docs/Addressable.md) + - [Animal](docs/Animal.md) - [Apple](docs/Apple.md) - [Banana](docs/Banana.md) - [Bar](docs/Bar.md) - [BarCreate](docs/BarCreate.md) - [BarRef](docs/BarRef.md) - [BarRefOrValue](docs/BarRefOrValue.md) + - [Cat](docs/Cat.md) + - [Dog](docs/Dog.md) - [Entity](docs/Entity.md) - [EntityRef](docs/EntityRef.md) - [Extensible](docs/Extensible.md) diff --git a/samples/client/others/rust/hyper/oneOf/docs/Animal.md b/samples/client/others/rust/hyper/oneOf/docs/Animal.md new file mode 100644 index 000000000000..7288082ea0b1 --- /dev/null +++ b/samples/client/others/rust/hyper/oneOf/docs/Animal.md @@ -0,0 +1,12 @@ +# Animal + +## Enum Variants + +| Name | Description | +|---- | -----| +| Cat | | +| Dog | | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/others/rust/hyper/oneOf/docs/Cat.md b/samples/client/others/rust/hyper/oneOf/docs/Cat.md new file mode 100644 index 000000000000..29a32acc867f --- /dev/null +++ b/samples/client/others/rust/hyper/oneOf/docs/Cat.md @@ -0,0 +1,11 @@ +# Cat + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**declawed** | Option<**bool**> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/others/rust/hyper/oneOf/docs/Dog.md b/samples/client/others/rust/hyper/oneOf/docs/Dog.md new file mode 100644 index 000000000000..8cc581d43d6e --- /dev/null +++ b/samples/client/others/rust/hyper/oneOf/docs/Dog.md @@ -0,0 +1,11 @@ +# Dog + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**bark** | Option<**bool**> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/others/rust/hyper/oneOf/src/models/animal.rs b/samples/client/others/rust/hyper/oneOf/src/models/animal.rs new file mode 100644 index 000000000000..4973966941e4 --- /dev/null +++ b/samples/client/others/rust/hyper/oneOf/src/models/animal.rs @@ -0,0 +1,26 @@ +/* + * ByRefOrValue + * + * This tests for a oneOf interface representation + * + * The version of the OpenAPI document: 0.0.1 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(untagged)] +pub enum Animal { + Dog(Box), + Cat(Box), +} + +impl Default for Animal { + fn default() -> Self { + Self::Dog(Default::default()) + } +} + diff --git a/samples/client/others/rust/hyper/oneOf/src/models/cat.rs b/samples/client/others/rust/hyper/oneOf/src/models/cat.rs new file mode 100644 index 000000000000..3e06691828af --- /dev/null +++ b/samples/client/others/rust/hyper/oneOf/src/models/cat.rs @@ -0,0 +1,27 @@ +/* + * ByRefOrValue + * + * This tests for a oneOf interface representation + * + * The version of the OpenAPI document: 0.0.1 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct Cat { + #[serde(rename = "declawed", skip_serializing_if = "Option::is_none")] + pub declawed: Option, +} + +impl Cat { + pub fn new() -> Cat { + Cat { + declawed: None, + } + } +} + diff --git a/samples/client/others/rust/hyper/oneOf/src/models/dog.rs b/samples/client/others/rust/hyper/oneOf/src/models/dog.rs new file mode 100644 index 000000000000..59c0321282df --- /dev/null +++ b/samples/client/others/rust/hyper/oneOf/src/models/dog.rs @@ -0,0 +1,27 @@ +/* + * ByRefOrValue + * + * This tests for a oneOf interface representation + * + * The version of the OpenAPI document: 0.0.1 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct Dog { + #[serde(rename = "bark", skip_serializing_if = "Option::is_none")] + pub bark: Option, +} + +impl Dog { + pub fn new() -> Dog { + Dog { + bark: None, + } + } +} + diff --git a/samples/client/others/rust/hyper/oneOf/src/models/mod.rs b/samples/client/others/rust/hyper/oneOf/src/models/mod.rs index 581d09587bcc..8fc7bc4efe19 100644 --- a/samples/client/others/rust/hyper/oneOf/src/models/mod.rs +++ b/samples/client/others/rust/hyper/oneOf/src/models/mod.rs @@ -1,5 +1,7 @@ pub mod addressable; pub use self::addressable::Addressable; +pub mod animal; +pub use self::animal::Animal; pub mod apple; pub use self::apple::Apple; pub mod banana; @@ -12,6 +14,10 @@ pub mod bar_ref; pub use self::bar_ref::BarRef; pub mod bar_ref_or_value; pub use self::bar_ref_or_value::BarRefOrValue; +pub mod cat; +pub use self::cat::Cat; +pub mod dog; +pub use self::dog::Dog; pub mod entity; pub use self::entity::Entity; pub mod entity_ref; diff --git a/samples/client/others/rust/reqwest/oneOf/.openapi-generator/FILES b/samples/client/others/rust/reqwest/oneOf/.openapi-generator/FILES index a24a8ab7271b..e5d1837cbf99 100644 --- a/samples/client/others/rust/reqwest/oneOf/.openapi-generator/FILES +++ b/samples/client/others/rust/reqwest/oneOf/.openapi-generator/FILES @@ -3,6 +3,7 @@ Cargo.toml README.md docs/Addressable.md +docs/Animal.md docs/Apple.md docs/Banana.md docs/Bar.md @@ -10,6 +11,8 @@ docs/BarApi.md docs/BarCreate.md docs/BarRef.md docs/BarRefOrValue.md +docs/Cat.md +docs/Dog.md docs/Entity.md docs/EntityRef.md docs/Extensible.md @@ -29,12 +32,15 @@ src/apis/foo_api.rs src/apis/mod.rs src/lib.rs src/models/addressable.rs +src/models/animal.rs src/models/apple.rs src/models/banana.rs src/models/bar.rs src/models/bar_create.rs src/models/bar_ref.rs src/models/bar_ref_or_value.rs +src/models/cat.rs +src/models/dog.rs src/models/entity.rs src/models/entity_ref.rs src/models/extensible.rs diff --git a/samples/client/others/rust/reqwest/oneOf/README.md b/samples/client/others/rust/reqwest/oneOf/README.md index 29531be95b23..762f200975a9 100644 --- a/samples/client/others/rust/reqwest/oneOf/README.md +++ b/samples/client/others/rust/reqwest/oneOf/README.md @@ -35,12 +35,15 @@ Class | Method | HTTP request | Description ## Documentation For Models - [Addressable](docs/Addressable.md) + - [Animal](docs/Animal.md) - [Apple](docs/Apple.md) - [Banana](docs/Banana.md) - [Bar](docs/Bar.md) - [BarCreate](docs/BarCreate.md) - [BarRef](docs/BarRef.md) - [BarRefOrValue](docs/BarRefOrValue.md) + - [Cat](docs/Cat.md) + - [Dog](docs/Dog.md) - [Entity](docs/Entity.md) - [EntityRef](docs/EntityRef.md) - [Extensible](docs/Extensible.md) diff --git a/samples/client/others/rust/reqwest/oneOf/docs/Animal.md b/samples/client/others/rust/reqwest/oneOf/docs/Animal.md new file mode 100644 index 000000000000..7288082ea0b1 --- /dev/null +++ b/samples/client/others/rust/reqwest/oneOf/docs/Animal.md @@ -0,0 +1,12 @@ +# Animal + +## Enum Variants + +| Name | Description | +|---- | -----| +| Cat | | +| Dog | | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/others/rust/reqwest/oneOf/docs/Cat.md b/samples/client/others/rust/reqwest/oneOf/docs/Cat.md new file mode 100644 index 000000000000..29a32acc867f --- /dev/null +++ b/samples/client/others/rust/reqwest/oneOf/docs/Cat.md @@ -0,0 +1,11 @@ +# Cat + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**declawed** | Option<**bool**> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/others/rust/reqwest/oneOf/docs/Dog.md b/samples/client/others/rust/reqwest/oneOf/docs/Dog.md new file mode 100644 index 000000000000..8cc581d43d6e --- /dev/null +++ b/samples/client/others/rust/reqwest/oneOf/docs/Dog.md @@ -0,0 +1,11 @@ +# Dog + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**bark** | Option<**bool**> | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/others/rust/reqwest/oneOf/src/models/animal.rs b/samples/client/others/rust/reqwest/oneOf/src/models/animal.rs new file mode 100644 index 000000000000..4973966941e4 --- /dev/null +++ b/samples/client/others/rust/reqwest/oneOf/src/models/animal.rs @@ -0,0 +1,26 @@ +/* + * ByRefOrValue + * + * This tests for a oneOf interface representation + * + * The version of the OpenAPI document: 0.0.1 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(untagged)] +pub enum Animal { + Dog(Box), + Cat(Box), +} + +impl Default for Animal { + fn default() -> Self { + Self::Dog(Default::default()) + } +} + diff --git a/samples/client/others/rust/reqwest/oneOf/src/models/cat.rs b/samples/client/others/rust/reqwest/oneOf/src/models/cat.rs new file mode 100644 index 000000000000..3e06691828af --- /dev/null +++ b/samples/client/others/rust/reqwest/oneOf/src/models/cat.rs @@ -0,0 +1,27 @@ +/* + * ByRefOrValue + * + * This tests for a oneOf interface representation + * + * The version of the OpenAPI document: 0.0.1 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct Cat { + #[serde(rename = "declawed", skip_serializing_if = "Option::is_none")] + pub declawed: Option, +} + +impl Cat { + pub fn new() -> Cat { + Cat { + declawed: None, + } + } +} + diff --git a/samples/client/others/rust/reqwest/oneOf/src/models/dog.rs b/samples/client/others/rust/reqwest/oneOf/src/models/dog.rs new file mode 100644 index 000000000000..59c0321282df --- /dev/null +++ b/samples/client/others/rust/reqwest/oneOf/src/models/dog.rs @@ -0,0 +1,27 @@ +/* + * ByRefOrValue + * + * This tests for a oneOf interface representation + * + * The version of the OpenAPI document: 0.0.1 + * + * Generated by: https://openapi-generator.tech + */ + +use crate::models; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)] +pub struct Dog { + #[serde(rename = "bark", skip_serializing_if = "Option::is_none")] + pub bark: Option, +} + +impl Dog { + pub fn new() -> Dog { + Dog { + bark: None, + } + } +} + diff --git a/samples/client/others/rust/reqwest/oneOf/src/models/mod.rs b/samples/client/others/rust/reqwest/oneOf/src/models/mod.rs index 581d09587bcc..8fc7bc4efe19 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/models/mod.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/models/mod.rs @@ -1,5 +1,7 @@ pub mod addressable; pub use self::addressable::Addressable; +pub mod animal; +pub use self::animal::Animal; pub mod apple; pub use self::apple::Apple; pub mod banana; @@ -12,6 +14,10 @@ pub mod bar_ref; pub use self::bar_ref::BarRef; pub mod bar_ref_or_value; pub use self::bar_ref_or_value::BarRefOrValue; +pub mod cat; +pub use self::cat::Cat; +pub mod dog; +pub use self::dog::Dog; pub mod entity; pub use self::entity::Entity; pub mod entity_ref; diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.openapi-generator/FILES b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.openapi-generator/FILES index 5e9dbd5a0777..522e794179cc 100644 --- a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.openapi-generator/FILES @@ -2,6 +2,7 @@ README.md analysis_options.yaml doc/Addressable.md +doc/Animal.md doc/Apple.md doc/Banana.md doc/Bar.md @@ -9,6 +10,8 @@ doc/BarApi.md doc/BarCreate.md doc/BarRef.md doc/BarRefOrValue.md +doc/Cat.md +doc/Dog.md doc/Entity.md doc/EntityRef.md doc/Extensible.md @@ -33,13 +36,16 @@ lib/src/auth/bearer_auth.dart lib/src/auth/oauth.dart lib/src/date_serializer.dart lib/src/model/addressable.dart +lib/src/model/animal.dart lib/src/model/apple.dart lib/src/model/banana.dart lib/src/model/bar.dart lib/src/model/bar_create.dart lib/src/model/bar_ref.dart lib/src/model/bar_ref_or_value.dart +lib/src/model/cat.dart lib/src/model/date.dart +lib/src/model/dog.dart lib/src/model/entity.dart lib/src/model/entity_ref.dart lib/src/model/extensible.dart @@ -53,3 +59,6 @@ lib/src/model/pizza.dart lib/src/model/pizza_speziale.dart lib/src/serializers.dart pubspec.yaml +test/animal_test.dart +test/cat_test.dart +test/dog_test.dart diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/README.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/README.md index a73efc0a7a3b..5f8932d1f4fa 100644 --- a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/README.md +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/README.md @@ -74,12 +74,15 @@ Class | Method | HTTP request | Description ## Documentation For Models - [Addressable](doc/Addressable.md) + - [Animal](doc/Animal.md) - [Apple](doc/Apple.md) - [Banana](doc/Banana.md) - [Bar](doc/Bar.md) - [BarCreate](doc/BarCreate.md) - [BarRef](doc/BarRef.md) - [BarRefOrValue](doc/BarRefOrValue.md) + - [Cat](doc/Cat.md) + - [Dog](doc/Dog.md) - [Entity](doc/Entity.md) - [EntityRef](doc/EntityRef.md) - [Extensible](doc/Extensible.md) diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Animal.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Animal.md new file mode 100644 index 000000000000..b30398312c77 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Animal.md @@ -0,0 +1,16 @@ +# openapi.model.Animal + +## Load the model package +```dart +import 'package:openapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**bark** | **bool** | | [optional] +**declawed** | **bool** | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Cat.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Cat.md new file mode 100644 index 000000000000..c1c078d2b65e --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Cat.md @@ -0,0 +1,15 @@ +# openapi.model.Cat + +## Load the model package +```dart +import 'package:openapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**declawed** | **bool** | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Dog.md b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Dog.md new file mode 100644 index 000000000000..c6cc069e2563 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/doc/Dog.md @@ -0,0 +1,15 @@ +# openapi.model.Dog + +## Load the model package +```dart +import 'package:openapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**bark** | **bool** | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/openapi.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/openapi.dart index 80b852dd0d54..62792ee50e05 100644 --- a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/openapi.dart +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/openapi.dart @@ -14,12 +14,15 @@ export 'package:openapi/src/api/bar_api.dart'; export 'package:openapi/src/api/foo_api.dart'; export 'package:openapi/src/model/addressable.dart'; +export 'package:openapi/src/model/animal.dart'; export 'package:openapi/src/model/apple.dart'; export 'package:openapi/src/model/banana.dart'; export 'package:openapi/src/model/bar.dart'; export 'package:openapi/src/model/bar_create.dart'; export 'package:openapi/src/model/bar_ref.dart'; export 'package:openapi/src/model/bar_ref_or_value.dart'; +export 'package:openapi/src/model/cat.dart'; +export 'package:openapi/src/model/dog.dart'; export 'package:openapi/src/model/entity.dart'; export 'package:openapi/src/model/entity_ref.dart'; export 'package:openapi/src/model/extensible.dart'; diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/animal.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/animal.dart new file mode 100644 index 000000000000..78030696e949 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/animal.dart @@ -0,0 +1,73 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// + +// ignore_for_file: unused_element +import 'package:openapi/src/model/dog.dart'; +import 'package:openapi/src/model/cat.dart'; +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; +import 'package:one_of/one_of.dart'; + +part 'animal.g.dart'; + +/// Animal +/// +/// Properties: +/// * [bark] +/// * [declawed] +@BuiltValue() +abstract class Animal implements Built { + /// One Of [Cat], [Dog] + OneOf get oneOf; + + Animal._(); + + factory Animal([void updates(AnimalBuilder b)]) = _$Animal; + + @BuiltValueHook(initializeBuilder: true) + static void _defaults(AnimalBuilder b) => b; + + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$AnimalSerializer(); +} + +class _$AnimalSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Animal, _$Animal]; + + @override + final String wireName = r'Animal'; + + Iterable _serializeProperties( + Serializers serializers, + Animal object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + } + + @override + Object serialize( + Serializers serializers, + Animal object, { + FullType specifiedType = FullType.unspecified, + }) { + final oneOf = object.oneOf; + return serializers.serialize(oneOf.value, specifiedType: FullType(oneOf.valueType))!; + } + + @override + Animal deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = AnimalBuilder(); + Object? oneOfDataSrc; + final targetType = const FullType(OneOf, [FullType(Dog), FullType(Cat), ]); + oneOfDataSrc = serialized; + result.oneOf = serializers.deserialize(oneOfDataSrc, specifiedType: targetType) as OneOf; + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/cat.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/cat.dart new file mode 100644 index 000000000000..49dcb76828c3 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/cat.dart @@ -0,0 +1,108 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// + +// ignore_for_file: unused_element +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; + +part 'cat.g.dart'; + +/// Cat +/// +/// Properties: +/// * [declawed] +@BuiltValue() +abstract class Cat implements Built { + @BuiltValueField(wireName: r'declawed') + bool? get declawed; + + Cat._(); + + factory Cat([void updates(CatBuilder b)]) = _$Cat; + + @BuiltValueHook(initializeBuilder: true) + static void _defaults(CatBuilder b) => b; + + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$CatSerializer(); +} + +class _$CatSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Cat, _$Cat]; + + @override + final String wireName = r'Cat'; + + Iterable _serializeProperties( + Serializers serializers, + Cat object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.declawed != null) { + yield r'declawed'; + yield serializers.serialize( + object.declawed, + specifiedType: const FullType(bool), + ); + } + } + + @override + Object serialize( + Serializers serializers, + Cat object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required CatBuilder result, + required List unhandled, + }) { + for (var i = 0; i < serializedList.length; i += 2) { + final key = serializedList[i] as String; + final value = serializedList[i + 1]; + switch (key) { + case r'declawed': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(bool), + ) as bool; + result.declawed = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + Cat deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = CatBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/dog.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/dog.dart new file mode 100644 index 000000000000..d6a1d27c5b3c --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/model/dog.dart @@ -0,0 +1,108 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// + +// ignore_for_file: unused_element +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; + +part 'dog.g.dart'; + +/// Dog +/// +/// Properties: +/// * [bark] +@BuiltValue() +abstract class Dog implements Built { + @BuiltValueField(wireName: r'bark') + bool? get bark; + + Dog._(); + + factory Dog([void updates(DogBuilder b)]) = _$Dog; + + @BuiltValueHook(initializeBuilder: true) + static void _defaults(DogBuilder b) => b; + + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$DogSerializer(); +} + +class _$DogSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [Dog, _$Dog]; + + @override + final String wireName = r'Dog'; + + Iterable _serializeProperties( + Serializers serializers, + Dog object, { + FullType specifiedType = FullType.unspecified, + }) sync* { + if (object.bark != null) { + yield r'bark'; + yield serializers.serialize( + object.bark, + specifiedType: const FullType(bool), + ); + } + } + + @override + Object serialize( + Serializers serializers, + Dog object, { + FullType specifiedType = FullType.unspecified, + }) { + return _serializeProperties(serializers, object, specifiedType: specifiedType).toList(); + } + + void _deserializeProperties( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + required List serializedList, + required DogBuilder result, + required List unhandled, + }) { + for (var i = 0; i < serializedList.length; i += 2) { + final key = serializedList[i] as String; + final value = serializedList[i + 1]; + switch (key) { + case r'bark': + final valueDes = serializers.deserialize( + value, + specifiedType: const FullType(bool), + ) as bool; + result.bark = valueDes; + break; + default: + unhandled.add(key); + unhandled.add(value); + break; + } + } + } + + @override + Dog deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) { + final result = DogBuilder(); + final serializedList = (serialized as Iterable).toList(); + final unhandled = []; + _deserializeProperties( + serializers, + serialized, + specifiedType: specifiedType, + serializedList: serializedList, + unhandled: unhandled, + result: result, + ); + return result.build(); + } +} + diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/serializers.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/serializers.dart index 14964c349ade..3a70150ef9ab 100644 --- a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/serializers.dart +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/lib/src/serializers.dart @@ -15,12 +15,15 @@ import 'package:openapi/src/date_serializer.dart'; import 'package:openapi/src/model/date.dart'; import 'package:openapi/src/model/addressable.dart'; +import 'package:openapi/src/model/animal.dart'; import 'package:openapi/src/model/apple.dart'; import 'package:openapi/src/model/banana.dart'; import 'package:openapi/src/model/bar.dart'; import 'package:openapi/src/model/bar_create.dart'; import 'package:openapi/src/model/bar_ref.dart'; import 'package:openapi/src/model/bar_ref_or_value.dart'; +import 'package:openapi/src/model/cat.dart'; +import 'package:openapi/src/model/dog.dart'; import 'package:openapi/src/model/entity.dart'; import 'package:openapi/src/model/entity_ref.dart'; import 'package:openapi/src/model/extensible.dart'; @@ -37,12 +40,15 @@ part 'serializers.g.dart'; @SerializersFor([ Addressable,$Addressable, + Animal, Apple, Banana, Bar, BarCreate, BarRef, BarRefOrValue, + Cat, + Dog, Entity,$Entity, EntityRef,$EntityRef, Extensible,$Extensible, diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/animal_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/animal_test.dart new file mode 100644 index 000000000000..c45f20e17613 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/animal_test.dart @@ -0,0 +1,21 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for Animal +void main() { + final instance = AnimalBuilder(); + // TODO add properties to the builder and call build() + + group(Animal, () { + // bool bark + test('to test the property `bark`', () async { + // TODO + }); + + // bool declawed + test('to test the property `declawed`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/cat_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/cat_test.dart new file mode 100644 index 000000000000..889ceb416aa7 --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/cat_test.dart @@ -0,0 +1,16 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for Cat +void main() { + final instance = CatBuilder(); + // TODO add properties to the builder and call build() + + group(Cat, () { + // bool declawed + test('to test the property `declawed`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/dog_test.dart b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/dog_test.dart new file mode 100644 index 000000000000..6fa7a01b3bef --- /dev/null +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/test/dog_test.dart @@ -0,0 +1,16 @@ +import 'package:test/test.dart'; +import 'package:openapi/openapi.dart'; + +// tests for Dog +void main() { + final instance = DogBuilder(); + // TODO add properties to the builder and call build() + + group(Dog, () { + // bool bark + test('to test the property `bark`', () async { + // TODO + }); + + }); +} diff --git a/samples/openapi3/client/petstore/spring-cloud-3-with-optional/src/main/java/org/openapitools/model/Tag.java b/samples/openapi3/client/petstore/spring-cloud-3-with-optional/src/main/java/org/openapitools/model/Tag.java index 1b1d2db4f55f..e69de29bb2d1 100644 --- a/samples/openapi3/client/petstore/spring-cloud-3-with-optional/src/main/java/org/openapitools/model/Tag.java +++ b/samples/openapi3/client/petstore/spring-cloud-3-with-optional/src/main/java/org/openapitools/model/Tag.java @@ -1,105 +0,0 @@ -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 jakarta.validation.Valid; -import jakarta.validation.constraints.*; - - -import java.util.*; -import jakarta.annotation.Generated; - -/** - * A tag for a pet - */ - -@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.13.0-SNAPSHOT") -public class Tag { - - private Optional id = Optional.empty(); - - private Optional name = Optional.empty(); - - public Tag id(Long id) { - this.id = Optional.ofNullable(id); - return this; - } - - /** - * Get id - * @return id - */ - - @JsonProperty("id") - public Optional getId() { - return id; - } - - public void setId(Optional id) { - this.id = id; - } - - public Tag name(String name) { - this.name = Optional.ofNullable(name); - return this; - } - - /** - * Get name - * @return name - */ - - @JsonProperty("name") - public Optional getName() { - return name; - } - - public void setName(Optional name) { - this.name = name; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - Tag tag = (Tag) o; - return Objects.equals(this.id, tag.id) && - Objects.equals(this.name, tag.name); - } - - @Override - public int hashCode() { - return Objects.hash(id, name); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("class Tag {\n"); - sb.append(" id: ").append(toIndentedString(id)).append("\n"); - sb.append(" name: ").append(toIndentedString(name)).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 "); - } -} - diff --git a/samples/openapi3/server/petstore/spring-boot-oneof/.openapi-generator/FILES b/samples/openapi3/server/petstore/spring-boot-oneof/.openapi-generator/FILES index 392c6ed21180..cdd9c1c00a22 100644 --- a/samples/openapi3/server/petstore/spring-boot-oneof/.openapi-generator/FILES +++ b/samples/openapi3/server/petstore/spring-boot-oneof/.openapi-generator/FILES @@ -9,12 +9,15 @@ 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/Animal.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/Cat.java +src/main/java/org/openapitools/model/Dog.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 diff --git a/samples/server/petstore/springboot-file-delegate-optional/.openapi-generator/FILES b/samples/server/petstore/springboot-file-delegate-optional/.openapi-generator/FILES deleted file mode 100644 index a0c2e31c8865..000000000000 --- a/samples/server/petstore/springboot-file-delegate-optional/.openapi-generator/FILES +++ /dev/null @@ -1,12 +0,0 @@ -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/DummyApi.java -src/main/java/org/openapitools/api/DummyApiDelegate.java -src/main/java/org/openapitools/configuration/HomeController.java -src/main/java/org/openapitools/configuration/SpringDocConfiguration.java -src/main/resources/application.properties -src/main/resources/openapi.yaml -src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java From 602ea9c4bab562c0abc7b9c001f2612ab3e17b55 Mon Sep 17 00:00:00 2001 From: jpfinne Date: Sun, 16 Mar 2025 09:17:55 +0100 Subject: [PATCH 4/6] generate samples for rust and dart --- .../.openapi-generator/FILES | 3 - .../main/java/org/openapitools/model/Tag.java | 105 ++++++++++++++++++ 2 files changed, 105 insertions(+), 3 deletions(-) diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.openapi-generator/FILES b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.openapi-generator/FILES index 522e794179cc..1c42b39a4554 100644 --- a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/.openapi-generator/FILES @@ -59,6 +59,3 @@ lib/src/model/pizza.dart lib/src/model/pizza_speziale.dart lib/src/serializers.dart pubspec.yaml -test/animal_test.dart -test/cat_test.dart -test/dog_test.dart diff --git a/samples/openapi3/client/petstore/spring-cloud-3-with-optional/src/main/java/org/openapitools/model/Tag.java b/samples/openapi3/client/petstore/spring-cloud-3-with-optional/src/main/java/org/openapitools/model/Tag.java index e69de29bb2d1..1b1d2db4f55f 100644 --- a/samples/openapi3/client/petstore/spring-cloud-3-with-optional/src/main/java/org/openapitools/model/Tag.java +++ b/samples/openapi3/client/petstore/spring-cloud-3-with-optional/src/main/java/org/openapitools/model/Tag.java @@ -0,0 +1,105 @@ +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 jakarta.validation.Valid; +import jakarta.validation.constraints.*; + + +import java.util.*; +import jakarta.annotation.Generated; + +/** + * A tag for a pet + */ + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.13.0-SNAPSHOT") +public class Tag { + + private Optional id = Optional.empty(); + + private Optional name = Optional.empty(); + + public Tag id(Long id) { + this.id = Optional.ofNullable(id); + return this; + } + + /** + * Get id + * @return id + */ + + @JsonProperty("id") + public Optional getId() { + return id; + } + + public void setId(Optional id) { + this.id = id; + } + + public Tag name(String name) { + this.name = Optional.ofNullable(name); + return this; + } + + /** + * Get name + * @return name + */ + + @JsonProperty("name") + public Optional getName() { + return name; + } + + public void setName(Optional name) { + this.name = name; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Tag tag = (Tag) o; + return Objects.equals(this.id, tag.id) && + Objects.equals(this.name, tag.name); + } + + @Override + public int hashCode() { + return Objects.hash(id, name); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Tag {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).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 "); + } +} + From 09a00b6361704d50aa220d682ea482dcaf80e987 Mon Sep 17 00:00:00 2001 From: jpfinne Date: Sun, 16 Mar 2025 09:27:54 +0100 Subject: [PATCH 5/6] add spring-boot-file-delegate-optional FILES --- .../.openapi-generator/FILES | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 samples/server/petstore/springboot-file-delegate-optional/.openapi-generator/FILES diff --git a/samples/server/petstore/springboot-file-delegate-optional/.openapi-generator/FILES b/samples/server/petstore/springboot-file-delegate-optional/.openapi-generator/FILES new file mode 100644 index 000000000000..a0c2e31c8865 --- /dev/null +++ b/samples/server/petstore/springboot-file-delegate-optional/.openapi-generator/FILES @@ -0,0 +1,12 @@ +README.md +pom.xml +src/main/java/org/openapitools/OpenApiGeneratorApplication.java +src/main/java/org/openapitools/RFC3339DateFormat.java +src/main/java/org/openapitools/api/ApiUtil.java +src/main/java/org/openapitools/api/DummyApi.java +src/main/java/org/openapitools/api/DummyApiDelegate.java +src/main/java/org/openapitools/configuration/HomeController.java +src/main/java/org/openapitools/configuration/SpringDocConfiguration.java +src/main/resources/application.properties +src/main/resources/openapi.yaml +src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java From 2e40e82144ebd51908f8c7243e81a5fd579d1418 Mon Sep 17 00:00:00 2001 From: jpfinne Date: Tue, 18 Mar 2025 09:11:57 +0100 Subject: [PATCH 6/6] Add sample for useDeductionForOneOfInterfaces=true --- bin/configs/spring-boot-oneof-interface.yaml | 12 + .../.openapi-generator-ignore | 23 ++ .../.openapi-generator/FILES | 34 +++ .../.openapi-generator/VERSION | 1 + .../spring-boot-oneof-interface/README.md | 21 ++ .../spring-boot-oneof-interface/pom.xml | 82 +++++ .../OpenApiGeneratorApplication.java | 30 ++ .../org/openapitools/RFC3339DateFormat.java | 38 +++ .../java/org/openapitools/api/ApiUtil.java | 19 ++ .../java/org/openapitools/api/BarApi.java | 84 +++++ .../openapitools/api/BarApiController.java | 47 +++ .../java/org/openapitools/api/FooApi.java | 122 ++++++++ .../openapitools/api/FooApiController.java | 47 +++ .../EnumConverterConfiguration.java | 22 ++ .../configuration/HomeController.java | 20 ++ .../configuration/SpringDocConfiguration.java | 27 ++ .../org/openapitools/model/Addressable.java | 109 +++++++ .../java/org/openapitools/model/Animal.java | 31 ++ .../java/org/openapitools/model/Apple.java | 124 ++++++++ .../java/org/openapitools/model/Banana.java | 124 ++++++++ .../main/java/org/openapitools/model/Bar.java | 196 ++++++++++++ .../org/openapitools/model/BarCreate.java | 178 +++++++++++ .../java/org/openapitools/model/BarRef.java | 112 +++++++ .../org/openapitools/model/BarRefOrValue.java | 38 +++ .../main/java/org/openapitools/model/Cat.java | 84 +++++ .../main/java/org/openapitools/model/Dog.java | 84 +++++ .../java/org/openapitools/model/Entity.java | 208 +++++++++++++ .../org/openapitools/model/EntityRef.java | 253 +++++++++++++++ .../org/openapitools/model/Extensible.java | 143 +++++++++ .../main/java/org/openapitools/model/Foo.java | 151 +++++++++ .../java/org/openapitools/model/FooRef.java | 137 +++++++++ .../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 | 127 ++++++++ .../java/org/openapitools/model/Pizza.java | 136 +++++++++ .../org/openapitools/model/PizzaSpeziale.java | 133 ++++++++ .../src/main/resources/application.properties | 3 + .../src/main/resources/openapi.yaml | 289 ++++++++++++++++++ .../OpenApiGeneratorApplicationTests.java | 13 + 40 files changed, 3436 insertions(+) create mode 100644 bin/configs/spring-boot-oneof-interface.yaml create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/.openapi-generator-ignore create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/.openapi-generator/FILES create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/.openapi-generator/VERSION create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/README.md create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/pom.xml create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/OpenApiGeneratorApplication.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/RFC3339DateFormat.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/ApiUtil.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/BarApi.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/BarApiController.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/FooApi.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/FooApiController.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/configuration/EnumConverterConfiguration.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/configuration/HomeController.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/configuration/SpringDocConfiguration.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Addressable.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Animal.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Apple.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Banana.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Bar.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/BarCreate.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/BarRef.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/BarRefOrValue.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Cat.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Dog.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Entity.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/EntityRef.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Extensible.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Foo.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/FooRef.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/FooRefOrValue.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Fruit.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/FruitType.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Pasta.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Pizza.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/PizzaSpeziale.java create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/resources/application.properties create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/resources/openapi.yaml create mode 100644 samples/openapi3/server/petstore/spring-boot-oneof-interface/src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java diff --git a/bin/configs/spring-boot-oneof-interface.yaml b/bin/configs/spring-boot-oneof-interface.yaml new file mode 100644 index 000000000000..a66a2c4bfc97 --- /dev/null +++ b/bin/configs/spring-boot-oneof-interface.yaml @@ -0,0 +1,12 @@ +generatorName: spring +outputDir: samples/openapi3/server/petstore/spring-boot-oneof-interface +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 + snapshotVersion: "true" + hideGenerationTimestamp: "true" + useOneOfInterfaces: "true" + useDeductionForOneOfInterfaces: "true" diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/.openapi-generator-ignore b/samples/openapi3/server/petstore/spring-boot-oneof-interface/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/.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-interface/.openapi-generator/FILES b/samples/openapi3/server/petstore/spring-boot-oneof-interface/.openapi-generator/FILES new file mode 100644 index 000000000000..cdd9c1c00a22 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/.openapi-generator/FILES @@ -0,0 +1,34 @@ +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/Animal.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/Cat.java +src/main/java/org/openapitools/model/Dog.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-interface/.openapi-generator/VERSION b/samples/openapi3/server/petstore/spring-boot-oneof-interface/.openapi-generator/VERSION new file mode 100644 index 000000000000..96cfbb19ae28 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.13.0-SNAPSHOT diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/README.md b/samples/openapi3/server/petstore/spring-boot-oneof-interface/README.md new file mode 100644 index 000000000000..5cd22b6081a2 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/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-interface/pom.xml b/samples/openapi3/server/petstore/spring-boot-oneof-interface/pom.xml new file mode 100644 index 000000000000..7113913e6ca0 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/pom.xml @@ -0,0 +1,82 @@ + + 4.0.0 + org.openapitools.openapi3 + springboot-oneof + jar + springboot-oneof + 0.0.1-SNAPSHOT + + 1.8 + ${java.version} + ${java.version} + UTF-8 + 1.6.14 + 5.3.1 + + + org.springframework.boot + spring-boot-starter-parent + 2.7.15 + + + + src/main/java + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + + org.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-interface/src/main/java/org/openapitools/OpenApiGeneratorApplication.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/OpenApiGeneratorApplication.java new file mode 100644 index 000000000000..97252a8a9402 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/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-interface/src/main/java/org/openapitools/RFC3339DateFormat.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/RFC3339DateFormat.java new file mode 100644 index 000000000000..bcd3936d8b34 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/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-interface/src/main/java/org/openapitools/api/ApiUtil.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/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-interface/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-interface/src/main/java/org/openapitools/api/BarApi.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/BarApi.java new file mode 100644 index 000000000000..e6177d62794f --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/BarApi.java @@ -0,0 +1,84 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.13.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 org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.multipart.MultipartFile; + +import javax.validation.Valid; +import javax.validation.constraints.*; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.13.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-interface/src/main/java/org/openapitools/api/BarApiController.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/BarApiController.java new file mode 100644 index 000000000000..d3de8c18b7ca --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/BarApiController.java @@ -0,0 +1,47 @@ +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.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.13.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-interface/src/main/java/org/openapitools/api/FooApi.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/FooApi.java new file mode 100644 index 000000000000..5bced8b80937 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/FooApi.java @@ -0,0 +1,122 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.13.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 org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.multipart.MultipartFile; + +import javax.validation.Valid; +import javax.validation.constraints.*; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.13.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) 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-interface/src/main/java/org/openapitools/api/FooApiController.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/FooApiController.java new file mode 100644 index 000000000000..60b92f06dfee --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/FooApiController.java @@ -0,0 +1,47 @@ +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.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.13.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-interface/src/main/java/org/openapitools/configuration/EnumConverterConfiguration.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/configuration/EnumConverterConfiguration.java new file mode 100644 index 000000000000..dc5bf376b0f3 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/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 +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-interface/src/main/java/org/openapitools/configuration/HomeController.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/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-interface/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-interface/src/main/java/org/openapitools/configuration/SpringDocConfiguration.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/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-interface/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-interface/src/main/java/org/openapitools/model/Addressable.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Addressable.java new file mode 100644 index 000000000000..60a8c6bac969 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Addressable.java @@ -0,0 +1,109 @@ +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.13.0-SNAPSHOT") +public class Addressable { + + private @Nullable String href; + + private @Nullable String id; + + public Addressable href(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 String getHref() { + return href; + } + + public void setHref(String href) { + this.href = href; + } + + public Addressable id(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 String getId() { + return id; + } + + public void setId(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 "); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Animal.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Animal.java new file mode 100644 index 000000000000..93da1acbeb0b --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Animal.java @@ -0,0 +1,31 @@ +package org.openapitools.model; + +import java.net.URI; +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import org.openapitools.model.Cat; +import org.openapitools.model.Dog; +import org.springframework.lang.Nullable; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +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; + + + +@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION) +@JsonSubTypes({ + @JsonSubTypes.Type(value = Dog.class), + @JsonSubTypes.Type(value = Cat.class) +}) +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.13.0-SNAPSHOT") +public interface Animal { +} diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Apple.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Apple.java new file mode 100644 index 000000000000..bbf15e4e1343 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Apple.java @@ -0,0 +1,124 @@ +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.13.0-SNAPSHOT") +public 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 "); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Banana.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Banana.java new file mode 100644 index 000000000000..a66b9b34797a --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Banana.java @@ -0,0 +1,124 @@ +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.13.0-SNAPSHOT") +public 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 "); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Bar.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Bar.java new file mode 100644 index 000000000000..9502cb3b45c8 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Bar.java @@ -0,0 +1,196 @@ +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.13.0-SNAPSHOT") +public 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(String barPropA) { + this.barPropA = barPropA; + return this; + } + + /** + * Get barPropA + * @return barPropA + */ + + @Schema(name = "barPropA", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("barPropA") + public String getBarPropA() { + return barPropA; + } + + public void setBarPropA(String barPropA) { + this.barPropA = barPropA; + } + + public Bar fooPropB(String fooPropB) { + this.fooPropB = fooPropB; + return this; + } + + /** + * Get fooPropB + * @return fooPropB + */ + + @Schema(name = "fooPropB", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("fooPropB") + public String getFooPropB() { + return fooPropB; + } + + public void setFooPropB(String fooPropB) { + this.fooPropB = fooPropB; + } + + public Bar foo(FooRefOrValue foo) { + this.foo = foo; + return this; + } + + /** + * Get foo + * @return foo + */ + @Valid + @Schema(name = "foo", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("foo") + public FooRefOrValue getFoo() { + return foo; + } + + public void setFoo(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 "); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/BarCreate.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/BarCreate.java new file mode 100644 index 000000000000..33d6bf56e598 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/BarCreate.java @@ -0,0 +1,178 @@ +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.13.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(String barPropA) { + this.barPropA = barPropA; + return this; + } + + /** + * Get barPropA + * @return barPropA + */ + + @Schema(name = "barPropA", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("barPropA") + public String getBarPropA() { + return barPropA; + } + + public void setBarPropA(String barPropA) { + this.barPropA = barPropA; + } + + public BarCreate fooPropB(String fooPropB) { + this.fooPropB = fooPropB; + return this; + } + + /** + * Get fooPropB + * @return fooPropB + */ + + @Schema(name = "fooPropB", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("fooPropB") + public String getFooPropB() { + return fooPropB; + } + + public void setFooPropB(String fooPropB) { + this.fooPropB = fooPropB; + } + + public BarCreate foo(FooRefOrValue foo) { + this.foo = foo; + return this; + } + + /** + * Get foo + * @return foo + */ + @Valid + @Schema(name = "foo", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("foo") + public FooRefOrValue getFoo() { + return foo; + } + + public void setFoo(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 "); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/BarRef.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/BarRef.java new file mode 100644 index 000000000000..82d01db89bfd --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/BarRef.java @@ -0,0 +1,112 @@ +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.13.0-SNAPSHOT") +public 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 "); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/BarRefOrValue.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/BarRefOrValue.java new file mode 100644 index 000000000000..c7c74e43859d --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/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.13.0-SNAPSHOT") +public interface BarRefOrValue { + public String getAtType(); +} diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Cat.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Cat.java new file mode 100644 index 000000000000..c8aac77d5c34 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Cat.java @@ -0,0 +1,84 @@ +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; + +/** + * Cat + */ + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.13.0-SNAPSHOT") +public class Cat implements Animal { + + private @Nullable Boolean declawed; + + public Cat declawed(Boolean declawed) { + this.declawed = declawed; + return this; + } + + /** + * Get declawed + * @return declawed + */ + + @Schema(name = "declawed", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("declawed") + public Boolean getDeclawed() { + return declawed; + } + + public void setDeclawed(Boolean declawed) { + this.declawed = declawed; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Cat cat = (Cat) o; + return Objects.equals(this.declawed, cat.declawed); + } + + @Override + public int hashCode() { + return Objects.hash(declawed); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Cat {\n"); + sb.append(" declawed: ").append(toIndentedString(declawed)).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 "); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Dog.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Dog.java new file mode 100644 index 000000000000..7b7b19ecd763 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Dog.java @@ -0,0 +1,84 @@ +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; + +/** + * Dog + */ + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.13.0-SNAPSHOT") +public class Dog implements Animal { + + private @Nullable Boolean bark; + + public Dog bark(Boolean bark) { + this.bark = bark; + return this; + } + + /** + * Get bark + * @return bark + */ + + @Schema(name = "bark", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("bark") + public Boolean getBark() { + return bark; + } + + public void setBark(Boolean bark) { + this.bark = bark; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Dog dog = (Dog) o; + return Objects.equals(this.bark, dog.bark); + } + + @Override + public int hashCode() { + return Objects.hash(bark); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Dog {\n"); + sb.append(" bark: ").append(toIndentedString(bark)).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 "); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Entity.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Entity.java new file mode 100644 index 000000000000..99eff4b61623 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Entity.java @@ -0,0 +1,208 @@ +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.13.0-SNAPSHOT") +public class Entity { + + 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(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 String getHref() { + return href; + } + + public void setHref(String href) { + this.href = href; + } + + public Entity id(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 String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Entity atSchemaLocation(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 String getAtSchemaLocation() { + return atSchemaLocation; + } + + public void setAtSchemaLocation(String atSchemaLocation) { + this.atSchemaLocation = atSchemaLocation; + } + + public Entity atBaseType(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 String getAtBaseType() { + return atBaseType; + } + + public void setAtBaseType(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 "); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/EntityRef.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/EntityRef.java new file mode 100644 index 000000000000..cf27227dbaa7 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/EntityRef.java @@ -0,0 +1,253 @@ +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.13.0-SNAPSHOT") +public class EntityRef { + + 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(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 String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public EntityRef atReferredType(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 String getAtReferredType() { + return atReferredType; + } + + public void setAtReferredType(String atReferredType) { + this.atReferredType = atReferredType; + } + + public EntityRef href(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 String getHref() { + return href; + } + + public void setHref(String href) { + this.href = href; + } + + public EntityRef id(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 String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public EntityRef atSchemaLocation(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 String getAtSchemaLocation() { + return atSchemaLocation; + } + + public void setAtSchemaLocation(String atSchemaLocation) { + this.atSchemaLocation = atSchemaLocation; + } + + public EntityRef atBaseType(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 String getAtBaseType() { + return atBaseType; + } + + public void setAtBaseType(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 "); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Extensible.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Extensible.java new file mode 100644 index 000000000000..a2838492d7a0 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Extensible.java @@ -0,0 +1,143 @@ +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.13.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(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 String getAtSchemaLocation() { + return atSchemaLocation; + } + + public void setAtSchemaLocation(String atSchemaLocation) { + this.atSchemaLocation = atSchemaLocation; + } + + public Extensible atBaseType(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 String getAtBaseType() { + return atBaseType; + } + + public void setAtBaseType(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 "); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Foo.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Foo.java new file mode 100644 index 000000000000..0878c1fff4cb --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Foo.java @@ -0,0 +1,151 @@ +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.13.0-SNAPSHOT") +public 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(String fooPropA) { + this.fooPropA = fooPropA; + return this; + } + + /** + * Get fooPropA + * @return fooPropA + */ + + @Schema(name = "fooPropA", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("fooPropA") + public String getFooPropA() { + return fooPropA; + } + + public void setFooPropA(String fooPropA) { + this.fooPropA = fooPropA; + } + + public Foo fooPropB(String fooPropB) { + this.fooPropB = fooPropB; + return this; + } + + /** + * Get fooPropB + * @return fooPropB + */ + + @Schema(name = "fooPropB", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("fooPropB") + public String getFooPropB() { + return fooPropB; + } + + public void setFooPropB(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 "); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/FooRef.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/FooRef.java new file mode 100644 index 000000000000..e7409ab9ecbc --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/FooRef.java @@ -0,0 +1,137 @@ +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.13.0-SNAPSHOT") +public 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(String foorefPropA) { + this.foorefPropA = foorefPropA; + return this; + } + + /** + * Get foorefPropA + * @return foorefPropA + */ + + @Schema(name = "foorefPropA", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("foorefPropA") + public String getFoorefPropA() { + return foorefPropA; + } + + public void setFoorefPropA(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 "); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/FooRefOrValue.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/FooRefOrValue.java new file mode 100644 index 000000000000..7a2f6982f9e7 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/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.13.0-SNAPSHOT") +public interface FooRefOrValue { + public String getAtType(); +} diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Fruit.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Fruit.java new file mode 100644 index 000000000000..f64169c99d3c --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/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.13.0-SNAPSHOT") +public interface Fruit { + public FruitType getFruitType(); +} diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/FruitType.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/FruitType.java new file mode 100644 index 000000000000..0083b22f8fe2 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/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.13.0-SNAPSHOT") +public enum FruitType { + + APPLE("APPLE"), + + BANANA("BANANA"); + + private 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-interface/src/main/java/org/openapitools/model/Pasta.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Pasta.java new file mode 100644 index 000000000000..7eb08b229c4b --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Pasta.java @@ -0,0 +1,127 @@ +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.13.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(String vendor) { + this.vendor = vendor; + return this; + } + + /** + * Get vendor + * @return vendor + */ + + @Schema(name = "vendor", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("vendor") + public String getVendor() { + return vendor; + } + + public void setVendor(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 "); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Pizza.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Pizza.java new file mode 100644 index 000000000000..d82dd9869e66 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Pizza.java @@ -0,0 +1,136 @@ +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.13.0-SNAPSHOT") +public class Pizza extends Entity { + + private @Nullable BigDecimal pizzaSize; + + public Pizza() { + super(); + } + + /** + * Constructor with only required parameters + */ + public Pizza(String atType) { + super(atType); + } + + public Pizza pizzaSize(BigDecimal pizzaSize) { + this.pizzaSize = pizzaSize; + return this; + } + + /** + * Get pizzaSize + * @return pizzaSize + */ + @Valid + @Schema(name = "pizzaSize", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("pizzaSize") + public BigDecimal getPizzaSize() { + return pizzaSize; + } + + public void setPizzaSize(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 "); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/PizzaSpeziale.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/PizzaSpeziale.java new file mode 100644 index 000000000000..12675ef03091 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/PizzaSpeziale.java @@ -0,0 +1,133 @@ +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.13.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(String toppings) { + this.toppings = toppings; + return this; + } + + /** + * Get toppings + * @return toppings + */ + + @Schema(name = "toppings", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("toppings") + public String getToppings() { + return toppings; + } + + public void setToppings(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 "); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/resources/application.properties b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/resources/application.properties new file mode 100644 index 000000000000..7e90813e59b2 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/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-interface/src/main/resources/openapi.yaml b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/resources/openapi.yaml new file mode 100644 index 000000000000..f2d068cdbb3e --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/resources/openapi.yaml @@ -0,0 +1,289 @@ +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": + content: + application/json;charset=utf-8: + schema: + items: + $ref: '#/components/schemas/FooRefOrValue' + type: array + description: Success + 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": + content: + application/json: + schema: + $ref: '#/components/schemas/FooRefOrValue' + description: Error + 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 + Animal: + oneOf: + - $ref: '#/components/schemas/Dog' + - $ref: '#/components/schemas/Cat' + x-one-of-name: Animal + Cat: + properties: + declawed: + type: boolean + type: object + Dog: + properties: + bark: + type: boolean + type: object diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java new file mode 100644 index 000000000000..3681f67e7705 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/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