diff --git a/.github/workflows/samples-spring-jdk17.yaml b/.github/workflows/samples-spring-jdk17.yaml index 74c71ce4e8ff..8305c1820564 100644 --- a/.github/workflows/samples-spring-jdk17.yaml +++ b/.github/workflows/samples-spring-jdk17.yaml @@ -11,6 +11,7 @@ on: - samples/server/petstore/springboot-file-delegate-optional - samples/server/petstore/springboot-petstore-with-api-response-examples - samples/server/petstore/spring-boot-oneof-sealed + - samples/openapi3/server/petstore/spring-boot-oneof-interface pull_request: paths: - samples/openapi3/client/petstore/spring-cloud-3-with-optional @@ -21,6 +22,7 @@ on: - samples/server/petstore/springboot-file-delegate-optional - samples/server/petstore/springboot-petstore-with-api-response-examples - samples/server/petstore/spring-boot-oneof-sealed + - samples/openapi3/server/petstore/spring-boot-oneof-interface jobs: build: name: Build Java Spring (JDK17) @@ -39,6 +41,7 @@ jobs: - samples/server/petstore/springboot-file-delegate-optional - samples/server/petstore/springboot-petstore-with-api-response-examples - samples/server/petstore/spring-boot-oneof-sealed + - samples/openapi3/server/petstore/spring-boot-oneof-interface steps: - uses: actions/checkout@v4 - uses: actions/setup-java@v4 diff --git a/.github/workflows/samples-spring.yaml b/.github/workflows/samples-spring.yaml index fc5bffc2a339..886b53309ed5 100644 --- a/.github/workflows/samples-spring.yaml +++ b/.github/workflows/samples-spring.yaml @@ -60,6 +60,7 @@ jobs: - samples/server/petstore/springboot-spring-provide-args - samples/server/petstore/springboot-useoptional - samples/server/petstore/springboot-virtualan + - samples/openapi3/server/petstore/spring-boot-oneof-interface steps: - uses: actions/checkout@v4 - uses: actions/setup-java@v4 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/docs/generators/java-camel.md b/docs/generators/java-camel.md index 9b1c3c37162a..b6045e5a6788 100644 --- a/docs/generators/java-camel.md +++ b/docs/generators/java-camel.md @@ -99,6 +99,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |title|server title name or client service name| |OpenAPI Spring| |unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false| |useBeanValidation|Use BeanValidation API annotations| |true| +|useDeductionForOneOfInterfaces|whether to use deduction for generated oneOf interfaces| |false| |useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false| |useFeignClientContextId|Whether to generate Feign client with contextId parameter.| |true| |useFeignClientUrl|Whether to generate Feign client with url parameter.| |true| diff --git a/docs/generators/spring.md b/docs/generators/spring.md index 54d0433256e1..cf152645e5d6 100644 --- a/docs/generators/spring.md +++ b/docs/generators/spring.md @@ -92,6 +92,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |title|server title name or client service name| |OpenAPI Spring| |unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false| |useBeanValidation|Use BeanValidation API annotations| |true| +|useDeductionForOneOfInterfaces|whether to use deduction for generated oneOf interfaces| |false| |useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false| |useFeignClientContextId|Whether to generate Feign client with contextId parameter.| |true| |useFeignClientUrl|Whether to generate Feign client with url parameter.| |true| 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 621c91bfa84f..687fd543a544 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 @@ -99,6 +99,7 @@ public class SpringCodegen extends AbstractJavaCodegen public static final String USE_SEALED = "useSealed"; public static final String OPTIONAL_ACCEPT_NULLABLE = "optionalAcceptNullable"; public static final String USE_SPRING_BUILT_IN_VALIDATION = "useSpringBuiltInValidation"; + public static final String USE_DEDUCTION_FOR_ONE_OF_INTERFACES = "useDeductionForOneOfInterfaces"; @Getter public enum RequestMappingMode { @@ -159,6 +160,8 @@ public enum RequestMappingMode { protected boolean optionalAcceptNullable = true; @Getter @Setter protected boolean useSpringBuiltInValidation = false; + @Getter @Setter + protected boolean useDeductionForOneOfInterfaces = false; public SpringCodegen() { super(); @@ -276,6 +279,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."); @@ -446,6 +450,7 @@ public void processOpts() { } convertPropertyToBooleanAndWriteBack(OPTIONAL_ACCEPT_NULLABLE, this::setOptionalAcceptNullable); convertPropertyToBooleanAndWriteBack(USE_SPRING_BUILT_IN_VALIDATION, this::setUseSpringBuiltInValidation); + convertPropertyToBooleanAndWriteBack(USE_DEDUCTION_FOR_ONE_OF_INTERFACES, this::setUseDeductionForOneOfInterfaces); additionalProperties.put("springHttpStatus", new SpringHttpStatusLambda()); 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 f8f79802bbc8..98db2c7cf4e2 100644 --- a/modules/openapi-generator/src/main/resources/JavaSpring/oneof_interface.mustache +++ b/modules/openapi-generator/src/main/resources/JavaSpring/oneof_interface.mustache @@ -6,6 +6,14 @@ {{#discriminator}} {{>typeInfoAnnotation}} +{{/discriminator}}{{^discriminator}}{{#useDeductionForOneOfInterfaces}} +@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION) +@JsonSubTypes({ + {{#interfaceModels}} + @JsonSubTypes.Type(value = {{classname}}.class){{^-last}}, {{/-last}} + {{/interfaceModels}} +}) +{{/useDeductionForOneOfInterfaces}} {{/discriminator}} {{>generatedAnnotation}} 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 0036c39ec9cc..62e6b3eae85c 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,13 @@ 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(); + // test deduction + 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..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 @@ -209,6 +209,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: diff --git a/samples/client/echo_api/java/okhttp-gson-user-defined-templates/README.md b/samples/client/echo_api/java/okhttp-gson-user-defined-templates/README.md new file mode 100644 index 000000000000..61555e362393 --- /dev/null +++ b/samples/client/echo_api/java/okhttp-gson-user-defined-templates/README.md @@ -0,0 +1,184 @@ +# openapi-java-client + +OpenAPI Petstore +- API version: 1.0.0 + - Generator version: 7.6.0-SNAPSHOT + +This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + + +*Automatically generated by the [OpenAPI Generator](https://openapi-generator.tech)* + + +## Requirements + +Building the API client library requires: +1. Java 1.8+ +2. Maven (3.8.3+)/Gradle (7.2+) + +## Installation + +To install the API client library to your local Maven repository, simply execute: + +```shell +mvn clean install +``` + +To deploy it to a remote Maven repository instead, configure the settings of the repository and execute: + +```shell +mvn clean deploy +``` + +Refer to the [OSSRH Guide](http://central.sonatype.org/pages/ossrh-guide.html) for more information. + +### Maven users + +Add this dependency to your project's POM: + +```xml + + org.openapitools + openapi-java-client + 1.0.0 + compile + +``` + +### Gradle users + +Add this dependency to your project's build file: + +```groovy + repositories { + mavenCentral() // Needed if the 'openapi-java-client' jar has been published to maven central. + mavenLocal() // Needed if the 'openapi-java-client' jar has been published to the local maven repo. + } + + dependencies { + implementation "org.openapitools:openapi-java-client:1.0.0" + } +``` + +### Others + +At first generate the JAR by executing: + +```shell +mvn clean package +``` + +Then manually install the following JARs: + +* `target/openapi-java-client-1.0.0.jar` +* `target/lib/*.jar` + +## Getting Started + +Please follow the [installation](#installation) instruction and execute the following Java code: + +```java + +// Import classes: +import org.openapitools.client.ApiClient; +import org.openapitools.client.ApiException; +import org.openapitools.client.Configuration; +import org.openapitools.client.auth.*; +import org.openapitools.client.models.*; +import org.openapitools.client.api.PetApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("http://petstore.swagger.io/v2"); + + // Configure OAuth2 access token for authorization: petstore_auth + OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth"); + petstore_auth.setAccessToken("YOUR ACCESS TOKEN"); + + PetApi apiInstance = new PetApi(defaultClient); + Pet pet = new Pet(); // Pet | Pet object that needs to be added to the store + try { + Pet result = apiInstance.addPet(pet); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling PetApi#addPet"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} + +``` + +## Documentation for API Endpoints + +All URIs are relative to *http://petstore.swagger.io/v2* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*PetApi* | [**addPet**](docs/PetApi.md#addPet) | **POST** /pet | Add a new pet to the store +*PetApi* | [**deletePet**](docs/PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet +*PetApi* | [**findPetsByStatus**](docs/PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status +*PetApi* | [**findPetsByTags**](docs/PetApi.md#findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags +*PetApi* | [**getPetById**](docs/PetApi.md#getPetById) | **GET** /pet/{petId} | Find pet by ID +*PetApi* | [**updatePet**](docs/PetApi.md#updatePet) | **PUT** /pet | Update an existing pet +*PetApi* | [**updatePetWithForm**](docs/PetApi.md#updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data +*PetApi* | [**uploadFile**](docs/PetApi.md#uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image +*StoreApi* | [**deleteOrder**](docs/StoreApi.md#deleteOrder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID +*StoreApi* | [**getInventory**](docs/StoreApi.md#getInventory) | **GET** /store/inventory | Returns pet inventories by status +*StoreApi* | [**getOrderById**](docs/StoreApi.md#getOrderById) | **GET** /store/order/{orderId} | Find purchase order by ID +*StoreApi* | [**placeOrder**](docs/StoreApi.md#placeOrder) | **POST** /store/order | Place an order for a pet +*UserApi* | [**createUser**](docs/UserApi.md#createUser) | **POST** /user | Create user +*UserApi* | [**createUsersWithArrayInput**](docs/UserApi.md#createUsersWithArrayInput) | **POST** /user/createWithArray | Creates list of users with given input array +*UserApi* | [**createUsersWithListInput**](docs/UserApi.md#createUsersWithListInput) | **POST** /user/createWithList | Creates list of users with given input array +*UserApi* | [**deleteUser**](docs/UserApi.md#deleteUser) | **DELETE** /user/{username} | Delete user +*UserApi* | [**getUserByName**](docs/UserApi.md#getUserByName) | **GET** /user/{username} | Get user by user name +*UserApi* | [**loginUser**](docs/UserApi.md#loginUser) | **GET** /user/login | Logs user into the system +*UserApi* | [**logoutUser**](docs/UserApi.md#logoutUser) | **GET** /user/logout | Logs out current logged in user session +*UserApi* | [**updateUser**](docs/UserApi.md#updateUser) | **PUT** /user/{username} | Updated user + + +## Documentation for Models + + - [Category](docs/Category.md) + - [ModelApiResponse](docs/ModelApiResponse.md) + - [Order](docs/Order.md) + - [Pet](docs/Pet.md) + - [Tag](docs/Tag.md) + - [User](docs/User.md) + + + +## Documentation for Authorization + + +Authentication schemes defined for the API: + +### petstore_auth + +- **Type**: OAuth +- **Flow**: implicit +- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog +- **Scopes**: + - write:pets: modify pets in your account + - read:pets: read your pets + + +### api_key + +- **Type**: API key +- **API key parameter name**: api_key +- **Location**: HTTP header + + +## Recommendation + +It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues. + +## Author + + + 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 7d90d194cdfe..b68376da35d7 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 e47bcfcba561..b4bbded45c30 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..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 @@ -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 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 93c267ab25c3..9b112cdb692f 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 60a5a39c4cb4..d7631230f926 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/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..fc74d6ceba8e --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.15.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..5a1d6c7b57e3 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/BarApi.java @@ -0,0 +1,86 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.15.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package org.openapitools.api; + +import org.openapitools.model.Bar; +import org.openapitools.model.BarCreate; +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.ExampleObject; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.multipart.MultipartFile; + +import javax.validation.Valid; +import javax.validation.constraints.*; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +@Validated +@Tag(name = "Bar", description = "the Bar API") +public interface BarApi { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * POST /bar : Create a Bar + * + * @param barCreate (required) + * @return Bar created (status code 200) + */ + @Operation( + operationId = "createBar", + summary = "Create a Bar", + tags = { "Bar" }, + responses = { + @ApiResponse(responseCode = "200", description = "Bar created", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = Bar.class)) + }) + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/bar", + produces = { "application/json" }, + consumes = { "application/json" } + ) + + default ResponseEntity createBar( + @Parameter(name = "BarCreate", description = "", required = true) @Valid @RequestBody BarCreate barCreate + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"foo\" : { \"fooPropA\" : \"fooPropA\", \"fooPropB\" : \"fooPropB\" }, \"id\" : \"id\", \"fooPropB\" : \"fooPropB\", \"barPropA\" : \"barPropA\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + +} diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-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..e0c6c57862d6 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/api/FooApi.java @@ -0,0 +1,124 @@ +/** + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.15.0-SNAPSHOT). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package org.openapitools.api; + +import org.openapitools.model.Foo; +import org.openapitools.model.FooRefOrValue; +import io.swagger.v3.oas.annotations.ExternalDocumentation; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import io.swagger.v3.oas.annotations.media.ExampleObject; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.lang.Nullable; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.multipart.MultipartFile; + +import javax.validation.Valid; +import javax.validation.constraints.*; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.annotation.Generated; + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") +@Validated +@Tag(name = "Foo", description = "the Foo API") +public interface FooApi { + + default Optional getRequest() { + return Optional.empty(); + } + + /** + * POST /foo : Create a Foo + * + * @param foo The Foo to be created (optional) + * @return Error (status code 201) + */ + @Operation( + operationId = "createFoo", + summary = "Create a Foo", + tags = { "Foo" }, + responses = { + @ApiResponse(responseCode = "201", description = "Error", content = { + @Content(mediaType = "application/json", schema = @Schema(implementation = FooRefOrValue.class)) + }) + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/foo", + produces = { "application/json" }, + consumes = { "application/json;charset=utf-8" } + ) + + default ResponseEntity createFoo( + @Parameter(name = "Foo", description = "The Foo to be created") @Valid @RequestBody(required = false) @Nullable Foo foo + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) { + String exampleString = "{ \"fooPropA\" : \"fooPropA\", \"fooPropB\" : \"fooPropB\" }"; + ApiUtil.setExampleResponse(request, "application/json", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + + + /** + * GET /foo : GET all Foos + * + * @return Success (status code 200) + */ + @Operation( + operationId = "getAllFoos", + summary = "GET all Foos", + tags = { "Foo" }, + responses = { + @ApiResponse(responseCode = "200", description = "Success", content = { + @Content(mediaType = "application/json;charset=utf-8", array = @ArraySchema(schema = @Schema(implementation = FooRefOrValue.class))) + }) + } + ) + @RequestMapping( + method = RequestMethod.GET, + value = "/foo", + produces = { "application/json;charset=utf-8" } + ) + + default ResponseEntity> getAllFoos( + + ) { + getRequest().ifPresent(request -> { + for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) { + if (mediaType.isCompatibleWith(MediaType.valueOf("application/json;charset=utf-8"))) { + String exampleString = "[ { \"fooPropA\" : \"fooPropA\", \"fooPropB\" : \"fooPropB\" }, { \"fooPropA\" : \"fooPropA\", \"fooPropB\" : \"fooPropB\" } ]"; + ApiUtil.setExampleResponse(request, "application/json;charset=utf-8", exampleString); + break; + } + } + }); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + + } + +} diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-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..638061b124c5 --- /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(value = "org.openapitools.configuration.enumConverterConfiguration") +public class EnumConverterConfiguration { + + @Bean(name = "org.openapitools.configuration.EnumConverterConfiguration.fruitTypeConverter") + Converter fruitTypeConverter() { + return new Converter() { + @Override + public FruitType convert(String source) { + return FruitType.fromValue(source); + } + }; + } + +} diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-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..cc1faa7f02f9 --- /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.15.0-SNAPSHOT") +public class Addressable { + + private @Nullable String href; + + private @Nullable String id; + + public Addressable href(@Nullable String href) { + this.href = href; + return this; + } + + /** + * Hyperlink reference + * @return href + */ + + @Schema(name = "href", description = "Hyperlink reference", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("href") + public @Nullable String getHref() { + return href; + } + + public void setHref(@Nullable String href) { + this.href = href; + } + + public Addressable id(@Nullable String id) { + this.id = id; + return this; + } + + /** + * unique identifier + * @return id + */ + + @Schema(name = "id", description = "unique identifier", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("id") + public @Nullable String getId() { + return id; + } + + public void setId(@Nullable String id) { + this.id = id; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Addressable addressable = (Addressable) o; + return Objects.equals(this.href, addressable.href) && + Objects.equals(this.id, addressable.id); + } + + @Override + public int hashCode() { + return Objects.hash(href, id); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Addressable {\n"); + sb.append(" href: ").append(toIndentedString(href)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + 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..71497d6c7192 --- /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.15.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..98f9bc20637e --- /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.15.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..7ddd5c8eef1a --- /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.15.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..7ef793d7b0c4 --- /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.15.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(@Nullable String barPropA) { + this.barPropA = barPropA; + return this; + } + + /** + * Get barPropA + * @return barPropA + */ + + @Schema(name = "barPropA", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("barPropA") + public @Nullable String getBarPropA() { + return barPropA; + } + + public void setBarPropA(@Nullable String barPropA) { + this.barPropA = barPropA; + } + + public Bar fooPropB(@Nullable String fooPropB) { + this.fooPropB = fooPropB; + return this; + } + + /** + * Get fooPropB + * @return fooPropB + */ + + @Schema(name = "fooPropB", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("fooPropB") + public @Nullable String getFooPropB() { + return fooPropB; + } + + public void setFooPropB(@Nullable String fooPropB) { + this.fooPropB = fooPropB; + } + + public Bar foo(@Nullable FooRefOrValue foo) { + this.foo = foo; + return this; + } + + /** + * Get foo + * @return foo + */ + @Valid + @Schema(name = "foo", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("foo") + public @Nullable FooRefOrValue getFoo() { + return foo; + } + + public void setFoo(@Nullable FooRefOrValue foo) { + this.foo = foo; + } + + + public Bar href(String href) { + super.href(href); + return this; + } + + public Bar atSchemaLocation(String atSchemaLocation) { + super.atSchemaLocation(atSchemaLocation); + return this; + } + + public Bar atBaseType(String atBaseType) { + super.atBaseType(atBaseType); + return this; + } + + public Bar atType(String atType) { + super.atType(atType); + return this; + } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Bar bar = (Bar) o; + return Objects.equals(this.id, bar.id) && + Objects.equals(this.barPropA, bar.barPropA) && + Objects.equals(this.fooPropB, bar.fooPropB) && + Objects.equals(this.foo, bar.foo) && + super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(id, barPropA, fooPropB, foo, super.hashCode()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Bar {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" barPropA: ").append(toIndentedString(barPropA)).append("\n"); + sb.append(" fooPropB: ").append(toIndentedString(fooPropB)).append("\n"); + sb.append(" foo: ").append(toIndentedString(foo)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + 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..4ff8623f2cd1 --- /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.15.0-SNAPSHOT") +public class BarCreate extends Entity { + + private @Nullable String barPropA; + + private @Nullable String fooPropB; + + private @Nullable FooRefOrValue foo; + + public BarCreate() { + super(); + } + + /** + * Constructor with only required parameters + */ + public BarCreate(String atType) { + super(atType); + } + + public BarCreate barPropA(@Nullable String barPropA) { + this.barPropA = barPropA; + return this; + } + + /** + * Get barPropA + * @return barPropA + */ + + @Schema(name = "barPropA", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("barPropA") + public @Nullable String getBarPropA() { + return barPropA; + } + + public void setBarPropA(@Nullable String barPropA) { + this.barPropA = barPropA; + } + + public BarCreate fooPropB(@Nullable String fooPropB) { + this.fooPropB = fooPropB; + return this; + } + + /** + * Get fooPropB + * @return fooPropB + */ + + @Schema(name = "fooPropB", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("fooPropB") + public @Nullable String getFooPropB() { + return fooPropB; + } + + public void setFooPropB(@Nullable String fooPropB) { + this.fooPropB = fooPropB; + } + + public BarCreate foo(@Nullable FooRefOrValue foo) { + this.foo = foo; + return this; + } + + /** + * Get foo + * @return foo + */ + @Valid + @Schema(name = "foo", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("foo") + public @Nullable FooRefOrValue getFoo() { + return foo; + } + + public void setFoo(@Nullable FooRefOrValue foo) { + this.foo = foo; + } + + + public BarCreate href(String href) { + super.href(href); + return this; + } + + public BarCreate id(String id) { + super.id(id); + return this; + } + + public BarCreate atSchemaLocation(String atSchemaLocation) { + super.atSchemaLocation(atSchemaLocation); + return this; + } + + public BarCreate atBaseType(String atBaseType) { + super.atBaseType(atBaseType); + return this; + } + + public BarCreate atType(String atType) { + super.atType(atType); + return this; + } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BarCreate barCreate = (BarCreate) o; + return Objects.equals(this.barPropA, barCreate.barPropA) && + Objects.equals(this.fooPropB, barCreate.fooPropB) && + Objects.equals(this.foo, barCreate.foo) && + super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(barPropA, fooPropB, foo, super.hashCode()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class BarCreate {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append(" barPropA: ").append(toIndentedString(barPropA)).append("\n"); + sb.append(" fooPropB: ").append(toIndentedString(fooPropB)).append("\n"); + sb.append(" foo: ").append(toIndentedString(foo)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + 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..9e693220631e --- /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.15.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..231127081847 --- /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.15.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..690ed47b4bc9 --- /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.15.0-SNAPSHOT") +public class Cat implements Animal { + + private @Nullable Boolean declawed; + + public Cat declawed(@Nullable Boolean declawed) { + this.declawed = declawed; + return this; + } + + /** + * Get declawed + * @return declawed + */ + + @Schema(name = "declawed", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("declawed") + public @Nullable Boolean getDeclawed() { + return declawed; + } + + public void setDeclawed(@Nullable 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..385ffd6ab3c8 --- /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.15.0-SNAPSHOT") +public class Dog implements Animal { + + private @Nullable Boolean bark; + + public Dog bark(@Nullable Boolean bark) { + this.bark = bark; + return this; + } + + /** + * Get bark + * @return bark + */ + + @Schema(name = "bark", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("bark") + public @Nullable Boolean getBark() { + return bark; + } + + public void setBark(@Nullable 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..312c1480e7c6 --- /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.15.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(@Nullable String href) { + this.href = href; + return this; + } + + /** + * Hyperlink reference + * @return href + */ + + @Schema(name = "href", description = "Hyperlink reference", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("href") + public @Nullable String getHref() { + return href; + } + + public void setHref(@Nullable String href) { + this.href = href; + } + + public Entity id(@Nullable String id) { + this.id = id; + return this; + } + + /** + * unique identifier + * @return id + */ + + @Schema(name = "id", description = "unique identifier", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("id") + public @Nullable String getId() { + return id; + } + + public void setId(@Nullable String id) { + this.id = id; + } + + public Entity atSchemaLocation(@Nullable String atSchemaLocation) { + this.atSchemaLocation = atSchemaLocation; + return this; + } + + /** + * A URI to a JSON-Schema file that defines additional attributes and relationships + * @return atSchemaLocation + */ + + @Schema(name = "@schemaLocation", description = "A URI to a JSON-Schema file that defines additional attributes and relationships", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("@schemaLocation") + public @Nullable String getAtSchemaLocation() { + return atSchemaLocation; + } + + public void setAtSchemaLocation(@Nullable String atSchemaLocation) { + this.atSchemaLocation = atSchemaLocation; + } + + public Entity atBaseType(@Nullable String atBaseType) { + this.atBaseType = atBaseType; + return this; + } + + /** + * When sub-classing, this defines the super-class + * @return atBaseType + */ + + @Schema(name = "@baseType", description = "When sub-classing, this defines the super-class", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("@baseType") + public @Nullable String getAtBaseType() { + return atBaseType; + } + + public void setAtBaseType(@Nullable String atBaseType) { + this.atBaseType = atBaseType; + } + + public Entity atType(String atType) { + this.atType = atType; + return this; + } + + /** + * When sub-classing, this defines the sub-class Extensible name + * @return atType + */ + @NotNull + @Schema(name = "@type", description = "When sub-classing, this defines the sub-class Extensible name", requiredMode = Schema.RequiredMode.REQUIRED) + @JsonProperty("@type") + public String getAtType() { + return atType; + } + + public void setAtType(String atType) { + this.atType = atType; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Entity entity = (Entity) o; + return Objects.equals(this.href, entity.href) && + Objects.equals(this.id, entity.id) && + Objects.equals(this.atSchemaLocation, entity.atSchemaLocation) && + Objects.equals(this.atBaseType, entity.atBaseType) && + Objects.equals(this.atType, entity.atType); + } + + @Override + public int hashCode() { + return Objects.hash(href, id, atSchemaLocation, atBaseType, atType); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Entity {\n"); + sb.append(" href: ").append(toIndentedString(href)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" atSchemaLocation: ").append(toIndentedString(atSchemaLocation)).append("\n"); + sb.append(" atBaseType: ").append(toIndentedString(atBaseType)).append("\n"); + sb.append(" atType: ").append(toIndentedString(atType)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + 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..e350803a8aa3 --- /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.15.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(@Nullable String name) { + this.name = name; + return this; + } + + /** + * Name of the related entity. + * @return name + */ + + @Schema(name = "name", description = "Name of the related entity.", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("name") + public @Nullable String getName() { + return name; + } + + public void setName(@Nullable String name) { + this.name = name; + } + + public EntityRef atReferredType(@Nullable String atReferredType) { + this.atReferredType = atReferredType; + return this; + } + + /** + * The actual type of the target instance when needed for disambiguation. + * @return atReferredType + */ + + @Schema(name = "@referredType", description = "The actual type of the target instance when needed for disambiguation.", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("@referredType") + public @Nullable String getAtReferredType() { + return atReferredType; + } + + public void setAtReferredType(@Nullable String atReferredType) { + this.atReferredType = atReferredType; + } + + public EntityRef href(@Nullable String href) { + this.href = href; + return this; + } + + /** + * Hyperlink reference + * @return href + */ + + @Schema(name = "href", description = "Hyperlink reference", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("href") + public @Nullable String getHref() { + return href; + } + + public void setHref(@Nullable String href) { + this.href = href; + } + + public EntityRef id(@Nullable String id) { + this.id = id; + return this; + } + + /** + * unique identifier + * @return id + */ + + @Schema(name = "id", description = "unique identifier", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("id") + public @Nullable String getId() { + return id; + } + + public void setId(@Nullable String id) { + this.id = id; + } + + public EntityRef atSchemaLocation(@Nullable String atSchemaLocation) { + this.atSchemaLocation = atSchemaLocation; + return this; + } + + /** + * A URI to a JSON-Schema file that defines additional attributes and relationships + * @return atSchemaLocation + */ + + @Schema(name = "@schemaLocation", description = "A URI to a JSON-Schema file that defines additional attributes and relationships", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("@schemaLocation") + public @Nullable String getAtSchemaLocation() { + return atSchemaLocation; + } + + public void setAtSchemaLocation(@Nullable String atSchemaLocation) { + this.atSchemaLocation = atSchemaLocation; + } + + public EntityRef atBaseType(@Nullable String atBaseType) { + this.atBaseType = atBaseType; + return this; + } + + /** + * When sub-classing, this defines the super-class + * @return atBaseType + */ + + @Schema(name = "@baseType", description = "When sub-classing, this defines the super-class", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("@baseType") + public @Nullable String getAtBaseType() { + return atBaseType; + } + + public void setAtBaseType(@Nullable String atBaseType) { + this.atBaseType = atBaseType; + } + + public EntityRef atType(String atType) { + this.atType = atType; + return this; + } + + /** + * When sub-classing, this defines the sub-class Extensible name + * @return atType + */ + @NotNull + @Schema(name = "@type", description = "When sub-classing, this defines the sub-class Extensible name", requiredMode = Schema.RequiredMode.REQUIRED) + @JsonProperty("@type") + public String getAtType() { + return atType; + } + + public void setAtType(String atType) { + this.atType = atType; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + EntityRef entityRef = (EntityRef) o; + return Objects.equals(this.name, entityRef.name) && + Objects.equals(this.atReferredType, entityRef.atReferredType) && + Objects.equals(this.href, entityRef.href) && + Objects.equals(this.id, entityRef.id) && + Objects.equals(this.atSchemaLocation, entityRef.atSchemaLocation) && + Objects.equals(this.atBaseType, entityRef.atBaseType) && + Objects.equals(this.atType, entityRef.atType); + } + + @Override + public int hashCode() { + return Objects.hash(name, atReferredType, href, id, atSchemaLocation, atBaseType, atType); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class EntityRef {\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" atReferredType: ").append(toIndentedString(atReferredType)).append("\n"); + sb.append(" href: ").append(toIndentedString(href)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" atSchemaLocation: ").append(toIndentedString(atSchemaLocation)).append("\n"); + sb.append(" atBaseType: ").append(toIndentedString(atBaseType)).append("\n"); + sb.append(" atType: ").append(toIndentedString(atType)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + 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..c0324216c73d --- /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.15.0-SNAPSHOT") +public class Extensible { + + private @Nullable String atSchemaLocation; + + private @Nullable String atBaseType; + + private String atType; + + public Extensible() { + super(); + } + + /** + * Constructor with only required parameters + */ + public Extensible(String atType) { + this.atType = atType; + } + + public Extensible atSchemaLocation(@Nullable String atSchemaLocation) { + this.atSchemaLocation = atSchemaLocation; + return this; + } + + /** + * A URI to a JSON-Schema file that defines additional attributes and relationships + * @return atSchemaLocation + */ + + @Schema(name = "@schemaLocation", description = "A URI to a JSON-Schema file that defines additional attributes and relationships", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("@schemaLocation") + public @Nullable String getAtSchemaLocation() { + return atSchemaLocation; + } + + public void setAtSchemaLocation(@Nullable String atSchemaLocation) { + this.atSchemaLocation = atSchemaLocation; + } + + public Extensible atBaseType(@Nullable String atBaseType) { + this.atBaseType = atBaseType; + return this; + } + + /** + * When sub-classing, this defines the super-class + * @return atBaseType + */ + + @Schema(name = "@baseType", description = "When sub-classing, this defines the super-class", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("@baseType") + public @Nullable String getAtBaseType() { + return atBaseType; + } + + public void setAtBaseType(@Nullable String atBaseType) { + this.atBaseType = atBaseType; + } + + public Extensible atType(String atType) { + this.atType = atType; + return this; + } + + /** + * When sub-classing, this defines the sub-class Extensible name + * @return atType + */ + @NotNull + @Schema(name = "@type", description = "When sub-classing, this defines the sub-class Extensible name", requiredMode = Schema.RequiredMode.REQUIRED) + @JsonProperty("@type") + public String getAtType() { + return atType; + } + + public void setAtType(String atType) { + this.atType = atType; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Extensible extensible = (Extensible) o; + return Objects.equals(this.atSchemaLocation, extensible.atSchemaLocation) && + Objects.equals(this.atBaseType, extensible.atBaseType) && + Objects.equals(this.atType, extensible.atType); + } + + @Override + public int hashCode() { + return Objects.hash(atSchemaLocation, atBaseType, atType); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Extensible {\n"); + sb.append(" atSchemaLocation: ").append(toIndentedString(atSchemaLocation)).append("\n"); + sb.append(" atBaseType: ").append(toIndentedString(atBaseType)).append("\n"); + sb.append(" atType: ").append(toIndentedString(atType)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + 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..b3fd833b8eac --- /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.15.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(@Nullable String fooPropA) { + this.fooPropA = fooPropA; + return this; + } + + /** + * Get fooPropA + * @return fooPropA + */ + + @Schema(name = "fooPropA", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("fooPropA") + public @Nullable String getFooPropA() { + return fooPropA; + } + + public void setFooPropA(@Nullable String fooPropA) { + this.fooPropA = fooPropA; + } + + public Foo fooPropB(@Nullable String fooPropB) { + this.fooPropB = fooPropB; + return this; + } + + /** + * Get fooPropB + * @return fooPropB + */ + + @Schema(name = "fooPropB", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("fooPropB") + public @Nullable String getFooPropB() { + return fooPropB; + } + + public void setFooPropB(@Nullable String fooPropB) { + this.fooPropB = fooPropB; + } + + + public Foo href(String href) { + super.href(href); + return this; + } + + public Foo id(String id) { + super.id(id); + return this; + } + + public Foo atSchemaLocation(String atSchemaLocation) { + super.atSchemaLocation(atSchemaLocation); + return this; + } + + public Foo atBaseType(String atBaseType) { + super.atBaseType(atBaseType); + return this; + } + + public Foo atType(String atType) { + super.atType(atType); + return this; + } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Foo foo = (Foo) o; + return Objects.equals(this.fooPropA, foo.fooPropA) && + Objects.equals(this.fooPropB, foo.fooPropB) && + super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(fooPropA, fooPropB, super.hashCode()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Foo {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append(" fooPropA: ").append(toIndentedString(fooPropA)).append("\n"); + sb.append(" fooPropB: ").append(toIndentedString(fooPropB)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + 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..ba4d64626c90 --- /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.15.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(@Nullable String foorefPropA) { + this.foorefPropA = foorefPropA; + return this; + } + + /** + * Get foorefPropA + * @return foorefPropA + */ + + @Schema(name = "foorefPropA", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("foorefPropA") + public @Nullable String getFoorefPropA() { + return foorefPropA; + } + + public void setFoorefPropA(@Nullable String foorefPropA) { + this.foorefPropA = foorefPropA; + } + + + public FooRef name(String name) { + super.name(name); + return this; + } + + public FooRef atReferredType(String atReferredType) { + super.atReferredType(atReferredType); + return this; + } + + public FooRef href(String href) { + super.href(href); + return this; + } + + public FooRef id(String id) { + super.id(id); + return this; + } + + public FooRef atSchemaLocation(String atSchemaLocation) { + super.atSchemaLocation(atSchemaLocation); + return this; + } + + public FooRef atBaseType(String atBaseType) { + super.atBaseType(atBaseType); + return this; + } + + public FooRef atType(String atType) { + super.atType(atType); + return this; + } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + FooRef fooRef = (FooRef) o; + return Objects.equals(this.foorefPropA, fooRef.foorefPropA) && + super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(foorefPropA, super.hashCode()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class FooRef {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append(" foorefPropA: ").append(toIndentedString(foorefPropA)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + 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..21f35dee14a6 --- /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.15.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..0313fa6de3e3 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/java/org/openapitools/model/Fruit.java @@ -0,0 +1,39 @@ +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") +}) + +@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.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..b23ab8a11701 --- /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.15.0-SNAPSHOT") +public enum FruitType { + + APPLE("APPLE"), + + BANANA("BANANA"); + + private final String value; + + FruitType(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static FruitType fromValue(String value) { + for (FruitType b : FruitType.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } +} + diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-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..262f1386da46 --- /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.15.0-SNAPSHOT") +public class Pasta extends Entity { + + private @Nullable String vendor; + + public Pasta() { + super(); + } + + /** + * Constructor with only required parameters + */ + public Pasta(String atType) { + super(atType); + } + + public Pasta vendor(@Nullable String vendor) { + this.vendor = vendor; + return this; + } + + /** + * Get vendor + * @return vendor + */ + + @Schema(name = "vendor", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("vendor") + public @Nullable String getVendor() { + return vendor; + } + + public void setVendor(@Nullable String vendor) { + this.vendor = vendor; + } + + + public Pasta href(String href) { + super.href(href); + return this; + } + + public Pasta id(String id) { + super.id(id); + return this; + } + + public Pasta atSchemaLocation(String atSchemaLocation) { + super.atSchemaLocation(atSchemaLocation); + return this; + } + + public Pasta atBaseType(String atBaseType) { + super.atBaseType(atBaseType); + return this; + } + + public Pasta atType(String atType) { + super.atType(atType); + return this; + } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Pasta pasta = (Pasta) o; + return Objects.equals(this.vendor, pasta.vendor) && + super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(vendor, super.hashCode()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Pasta {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append(" vendor: ").append(toIndentedString(vendor)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + 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..53979cecbafd --- /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.15.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(@Nullable BigDecimal pizzaSize) { + this.pizzaSize = pizzaSize; + return this; + } + + /** + * Get pizzaSize + * @return pizzaSize + */ + @Valid + @Schema(name = "pizzaSize", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("pizzaSize") + public @Nullable BigDecimal getPizzaSize() { + return pizzaSize; + } + + public void setPizzaSize(@Nullable BigDecimal pizzaSize) { + this.pizzaSize = pizzaSize; + } + + + public Pizza href(String href) { + super.href(href); + return this; + } + + public Pizza id(String id) { + super.id(id); + return this; + } + + public Pizza atSchemaLocation(String atSchemaLocation) { + super.atSchemaLocation(atSchemaLocation); + return this; + } + + public Pizza atBaseType(String atBaseType) { + super.atBaseType(atBaseType); + return this; + } + + public Pizza atType(String atType) { + super.atType(atType); + return this; + } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Pizza pizza = (Pizza) o; + return Objects.equals(this.pizzaSize, pizza.pizzaSize) && + super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(pizzaSize, super.hashCode()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Pizza {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append(" pizzaSize: ").append(toIndentedString(pizzaSize)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + 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..c52c56041e7d --- /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.15.0-SNAPSHOT") +public class PizzaSpeziale extends Pizza { + + private @Nullable String toppings; + + public PizzaSpeziale() { + super(); + } + + /** + * Constructor with only required parameters + */ + public PizzaSpeziale(String atType) { + super(atType); + } + + public PizzaSpeziale toppings(@Nullable String toppings) { + this.toppings = toppings; + return this; + } + + /** + * Get toppings + * @return toppings + */ + + @Schema(name = "toppings", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("toppings") + public @Nullable String getToppings() { + return toppings; + } + + public void setToppings(@Nullable String toppings) { + this.toppings = toppings; + } + + + public PizzaSpeziale pizzaSize(BigDecimal pizzaSize) { + super.pizzaSize(pizzaSize); + return this; + } + + public PizzaSpeziale href(String href) { + super.href(href); + return this; + } + + public PizzaSpeziale id(String id) { + super.id(id); + return this; + } + + public PizzaSpeziale atSchemaLocation(String atSchemaLocation) { + super.atSchemaLocation(atSchemaLocation); + return this; + } + + public PizzaSpeziale atBaseType(String atBaseType) { + super.atBaseType(atBaseType); + return this; + } + + public PizzaSpeziale atType(String atType) { + super.atType(atType); + return this; + } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PizzaSpeziale pizzaSpeziale = (PizzaSpeziale) o; + return Objects.equals(this.toppings, pizzaSpeziale.toppings) && + super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(toppings, super.hashCode()); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PizzaSpeziale {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); + sb.append(" toppings: ").append(toIndentedString(toppings)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + 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..df48b1fe6ba5 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-interface/src/main/resources/openapi.yaml @@ -0,0 +1,279 @@ +openapi: 3.0.1 +info: + description: | + This tests for a oneOf interface representation + title: ByRefOrValue + version: 0.0.1 +servers: +- url: http://localhost:8080 +tags: +- name: Foo +- name: Bar +paths: + /foo: + get: + operationId: getAllFoos + responses: + "200": + $ref: "#/components/responses/200FooArray" + summary: GET all Foos + tags: + - Foo + x-accepts: + - application/json;charset=utf-8 + x-tags: + - tag: Foo + post: + operationId: createFoo + requestBody: + $ref: "#/components/requestBodies/Foo" + responses: + "201": + $ref: "#/components/responses/201Foo" + summary: Create a Foo + tags: + - Foo + x-content-type: application/json;charset=utf-8 + x-accepts: + - application/json + x-tags: + - tag: Foo + /bar: + post: + operationId: createBar + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/Bar_Create" + required: true + responses: + "200": + content: + application/json: + schema: + $ref: "#/components/schemas/Bar" + description: Bar created + summary: Create a Bar + tags: + - Bar + x-content-type: application/json + x-accepts: + - application/json + x-tags: + - tag: Bar +components: + requestBodies: + Foo: + content: + application/json;charset=utf-8: + schema: + $ref: "#/components/schemas/Foo" + description: The Foo to be created + responses: + "204": + content: {} + description: Deleted + "201Foo": + content: + application/json: + schema: + $ref: "#/components/schemas/FooRefOrValue" + description: Error + "200FooArray": + content: + application/json;charset=utf-8: + schema: + items: + $ref: "#/components/schemas/FooRefOrValue" + type: array + description: Success + schemas: + Addressable: + description: Base schema for addressable entities + properties: + href: + description: Hyperlink reference + type: string + id: + description: unique identifier + type: string + type: object + Extensible: + properties: + '@schemaLocation': + description: A URI to a JSON-Schema file that defines additional attributes + and relationships + type: string + '@baseType': + description: "When sub-classing, this defines the super-class" + type: string + '@type': + description: "When sub-classing, this defines the sub-class Extensible name" + type: string + required: + - '@type' + type: object + Entity: + allOf: + - $ref: "#/components/schemas/Addressable" + - $ref: "#/components/schemas/Extensible" + discriminator: + propertyName: '@type' + type: object + EntityRef: + allOf: + - $ref: "#/components/schemas/Addressable" + - $ref: "#/components/schemas/Extensible" + description: Entity reference schema to be use for all entityRef class. + discriminator: + propertyName: '@type' + properties: + name: + description: Name of the related entity. + type: string + '@referredType': + description: The actual type of the target instance when needed for disambiguation. + type: string + type: object + FooRefOrValue: + discriminator: + propertyName: '@type' + oneOf: + - $ref: "#/components/schemas/Foo" + - $ref: "#/components/schemas/FooRef" + type: object + x-one-of-name: FooRefOrValue + Foo: + allOf: + - $ref: "#/components/schemas/Entity" + example: + fooPropA: fooPropA + fooPropB: fooPropB + properties: + fooPropA: + type: string + fooPropB: + type: string + type: object + FooRef: + allOf: + - $ref: "#/components/schemas/EntityRef" + properties: + foorefPropA: + type: string + type: object + BarRef: + allOf: + - $ref: "#/components/schemas/EntityRef" + type: object + Bar_Create: + allOf: + - $ref: "#/components/schemas/Entity" + properties: + barPropA: + type: string + fooPropB: + type: string + foo: + $ref: "#/components/schemas/FooRefOrValue" + type: object + Bar: + allOf: + - $ref: "#/components/schemas/Entity" + example: + foo: + fooPropA: fooPropA + fooPropB: fooPropB + id: id + fooPropB: fooPropB + barPropA: barPropA + properties: + id: + type: string + barPropA: + type: string + fooPropB: + type: string + foo: + $ref: "#/components/schemas/FooRefOrValue" + required: + - id + type: object + BarRefOrValue: + oneOf: + - $ref: "#/components/schemas/Bar" + - $ref: "#/components/schemas/BarRef" + type: object + x-one-of-name: BarRefOrValue + Pizza: + allOf: + - $ref: "#/components/schemas/Entity" + properties: + pizzaSize: + type: number + type: object + Pasta: + allOf: + - $ref: "#/components/schemas/Entity" + properties: + vendor: + type: string + type: object + PizzaSpeziale: + allOf: + - $ref: "#/components/schemas/Pizza" + properties: + toppings: + type: string + type: object + FruitType: + enum: + - APPLE + - BANANA + type: string + Fruit: + discriminator: + mapping: + APPLE: "#/components/schemas/Apple" + BANANA: "#/components/schemas/Banana" + propertyName: fruitType + oneOf: + - $ref: "#/components/schemas/Apple" + - $ref: "#/components/schemas/Banana" + properties: + fruitType: + $ref: "#/components/schemas/FruitType" + required: + - fruitType + type: object + x-one-of-name: Fruit + Apple: + properties: + seeds: + type: integer + required: + - seeds + type: object + Banana: + properties: + length: + type: integer + required: + - length + type: object + 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 diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/.openapi-generator/FILES b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/.openapi-generator/FILES index 392c6ed21180..cdd9c1c00a22 100644 --- a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/.openapi-generator/FILES +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/.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/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Animal.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Animal.java new file mode 100644 index 000000000000..30731ad0d1eb --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/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.15.0-SNAPSHOT") +public sealed interface Animal permits Dog, Cat { +} diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Cat.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Cat.java new file mode 100644 index 000000000000..3082c00bd925 --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/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.15.0-SNAPSHOT") +public final class Cat implements Animal { + + private @Nullable Boolean declawed; + + public Cat declawed(@Nullable Boolean declawed) { + this.declawed = declawed; + return this; + } + + /** + * Get declawed + * @return declawed + */ + + @Schema(name = "declawed", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("declawed") + public @Nullable Boolean getDeclawed() { + return declawed; + } + + public void setDeclawed(@Nullable 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-sealed/src/main/java/org/openapitools/model/Dog.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Dog.java new file mode 100644 index 000000000000..4ee53035790d --- /dev/null +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/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.15.0-SNAPSHOT") +public final class Dog implements Animal { + + private @Nullable Boolean bark; + + public Dog bark(@Nullable Boolean bark) { + this.bark = bark; + return this; + } + + /** + * Get bark + * @return bark + */ + + @Schema(name = "bark", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("bark") + public @Nullable Boolean getBark() { + return bark; + } + + public void setBark(@Nullable 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-sealed/src/main/java/org/openapitools/model/Fruit.java b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Fruit.java index 5062b4c48eb1..86be74c431b0 100644 --- a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Fruit.java +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/java/org/openapitools/model/Fruit.java @@ -30,9 +30,7 @@ @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") + @JsonSubTypes.Type(value = Banana.class, name = "BANANA") }) @Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.15.0-SNAPSHOT") diff --git a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/resources/openapi.yaml b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/resources/openapi.yaml index 24752605bf87..df48b1fe6ba5 100644 --- a/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/resources/openapi.yaml +++ b/samples/openapi3/server/petstore/spring-boot-oneof-sealed/src/main/resources/openapi.yaml @@ -262,3 +262,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 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/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..53d04fdcc39f --- /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.15.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..5c22cba14724 --- /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.15.0-SNAPSHOT") +public class Cat implements Animal { + + private @Nullable Boolean declawed; + + public Cat declawed(@Nullable Boolean declawed) { + this.declawed = declawed; + return this; + } + + /** + * Get declawed + * @return declawed + */ + + @Schema(name = "declawed", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("declawed") + public @Nullable Boolean getDeclawed() { + return declawed; + } + + public void setDeclawed(@Nullable 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..d3b99c1f9d97 --- /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.15.0-SNAPSHOT") +public class Dog implements Animal { + + private @Nullable Boolean bark; + + public Dog bark(@Nullable Boolean bark) { + this.bark = bark; + return this; + } + + /** + * Get bark + * @return bark + */ + + @Schema(name = "bark", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @JsonProperty("bark") + public @Nullable Boolean getBark() { + return bark; + } + + public void setBark(@Nullable 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 24752605bf87..df48b1fe6ba5 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 @@ -262,3 +262,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