diff --git a/datamodel/openapi/openapi-api-sample/pom.xml b/datamodel/openapi/openapi-api-sample/pom.xml index ff16e8853..1d8d6579b 100644 --- a/datamodel/openapi/openapi-api-sample/pom.xml +++ b/datamodel/openapi/openapi-api-sample/pom.xml @@ -115,6 +115,11 @@ true ${project.basedir}/src/main/java true + + create + + protected + diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OrdersApi.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OrdersApi.java index 5ca04ef3d..1583d21d8 100644 --- a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OrdersApi.java +++ b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OrdersApi.java @@ -19,7 +19,7 @@ import com.google.common.annotations.Beta; import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; -import com.sap.cloud.sdk.datamodel.openapi.sample.model.Order; //NOPMD +import com.sap.cloud.sdk.datamodel.openapi.sample.model.Order; import com.sap.cloud.sdk.services.openapi.apiclient.ApiClient; import com.sap.cloud.sdk.services.openapi.core.AbstractOpenApiService; import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/SodasApi.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/SodasApi.java index a36bbcdd7..5c9091d22 100644 --- a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/SodasApi.java +++ b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/SodasApi.java @@ -21,8 +21,8 @@ import com.google.common.annotations.Beta; import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; -import com.sap.cloud.sdk.datamodel.openapi.sample.model.Soda; //NOPMD -import com.sap.cloud.sdk.datamodel.openapi.sample.model.SodaWithId; //NOPMD +import com.sap.cloud.sdk.datamodel.openapi.sample.model.Soda; +import com.sap.cloud.sdk.datamodel.openapi.sample.model.SodaWithId; import com.sap.cloud.sdk.services.openapi.apiclient.ApiClient; import com.sap.cloud.sdk.services.openapi.core.AbstractOpenApiService; import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/Order.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/Order.java index aee6d89be..659ba3091 100644 --- a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/Order.java +++ b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/Order.java @@ -57,6 +57,10 @@ public class Order @JsonAnyGetter private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + protected Order() + { + } + /** * Set the productId of this {@link Order} instance and return the same instance. * @@ -335,4 +339,43 @@ private String toIndentedString( final java.lang.Object o ) return o.toString().replace("\n", "\n "); } + /** + * Create a type-safe, fluent-api builder object to construct a new {@link Order} instance with all required + * arguments. + */ + public static Builder create() + { + return ( productId ) -> ( quantity ) -> new Order().productId(productId).quantity(quantity); + } + + /** + * Builder helper class. + */ + public interface Builder + { + /** + * Set the productId of this {@link Order} instance. + * + * @param productId + * The productId of this {@link Order} + * @return The Order builder. + */ + Builder1 productId( @Nonnull final Long productId ); + } + + /** + * Builder helper class. + */ + public interface Builder1 + { + /** + * Set the quantity of this {@link Order} instance. + * + * @param quantity + * The quantity of this {@link Order} + * @return The Order instance. + */ + Order quantity( @Nonnull final Integer quantity ); + } + } diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OrderWithTimestamp.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OrderWithTimestamp.java index 4182d9569..b94529b69 100644 --- a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OrderWithTimestamp.java +++ b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OrderWithTimestamp.java @@ -49,7 +49,7 @@ public class OrderWithTimestamp private Float totalPrice; @JsonProperty( "typelessProperty" ) - private Object typelessProperty = null; + private Object typelessProperty; @JsonProperty( "nullableProperty" ) private String nullableProperty; @@ -61,6 +61,10 @@ public class OrderWithTimestamp @JsonAnyGetter private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + protected OrderWithTimestamp() + { + } + /** * Set the productId of this {@link OrderWithTimestamp} instance and return the same instance. * @@ -378,4 +382,43 @@ private String toIndentedString( final java.lang.Object o ) return o.toString().replace("\n", "\n "); } + /** + * Create a type-safe, fluent-api builder object to construct a new {@link OrderWithTimestamp} instance with all + * required arguments. + */ + public static Builder create() + { + return ( productId ) -> ( quantity ) -> new OrderWithTimestamp().productId(productId).quantity(quantity); + } + + /** + * Builder helper class. + */ + public interface Builder + { + /** + * Set the productId of this {@link OrderWithTimestamp} instance. + * + * @param productId + * The productId of this {@link OrderWithTimestamp} + * @return The OrderWithTimestamp builder. + */ + Builder1 productId( @Nonnull final Long productId ); + } + + /** + * Builder helper class. + */ + public interface Builder1 + { + /** + * Set the quantity of this {@link OrderWithTimestamp} instance. + * + * @param quantity + * The quantity of this {@link OrderWithTimestamp} + * @return The OrderWithTimestamp instance. + */ + OrderWithTimestamp quantity( @Nonnull final Integer quantity ); + } + } diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/Soda.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/Soda.java index d55e51458..b9295277e 100644 --- a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/Soda.java +++ b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/Soda.java @@ -54,6 +54,10 @@ public class Soda @JsonAnyGetter private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + protected Soda() + { + } + /** * Set the name of this {@link Soda} instance and return the same instance. * @@ -294,4 +298,74 @@ private String toIndentedString( final java.lang.Object o ) return o.toString().replace("\n", "\n "); } + /** + * Create a type-safe, fluent-api builder object to construct a new {@link Soda} instance with all required + * arguments. + */ + public static Builder create() + { + return ( name ) -> ( + brand ) -> ( quantity ) -> ( price ) -> new Soda().name(name).brand(brand).quantity(quantity).price(price); + } + + /** + * Builder helper class. + */ + public interface Builder + { + /** + * Set the name of this {@link Soda} instance. + * + * @param name + * The name of this {@link Soda} + * @return The Soda builder. + */ + Builder1 name( @Nonnull final String name ); + } + + /** + * Builder helper class. + */ + public interface Builder1 + { + /** + * Set the brand of this {@link Soda} instance. + * + * @param brand + * The brand of this {@link Soda} + * @return The Soda builder. + */ + Builder2 brand( @Nonnull final String brand ); + } + + /** + * Builder helper class. + */ + public interface Builder2 + { + /** + * Set the quantity of this {@link Soda} instance. + * + * @param quantity + * The quantity of this {@link Soda} + * @return The Soda builder. + */ + Builder3 quantity( @Nonnull final Integer quantity ); + } + + /** + * Builder helper class. + */ + public interface Builder3 + { + /** + * Set the price of this {@link Soda} instance. + * + * @param price + * The price of this {@link Soda} + * @return The Soda instance. + */ + Soda price( @Nonnull final Float price ); + } + } diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/SodaWithId.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/SodaWithId.java index 7f7b803dc..fb1ff89b7 100644 --- a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/SodaWithId.java +++ b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/SodaWithId.java @@ -57,6 +57,10 @@ public class SodaWithId @JsonAnyGetter private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + protected SodaWithId() + { + } + /** * Set the name of this {@link SodaWithId} instance and return the same instance. * @@ -335,4 +339,74 @@ private String toIndentedString( final java.lang.Object o ) return o.toString().replace("\n", "\n "); } + /** + * Create a type-safe, fluent-api builder object to construct a new {@link SodaWithId} instance with all required + * arguments. + */ + public static Builder create() + { + return ( name ) -> ( brand ) -> ( + quantity ) -> ( price ) -> new SodaWithId().name(name).brand(brand).quantity(quantity).price(price); + } + + /** + * Builder helper class. + */ + public interface Builder + { + /** + * Set the name of this {@link SodaWithId} instance. + * + * @param name + * The name of this {@link SodaWithId} + * @return The SodaWithId builder. + */ + Builder1 name( @Nonnull final String name ); + } + + /** + * Builder helper class. + */ + public interface Builder1 + { + /** + * Set the brand of this {@link SodaWithId} instance. + * + * @param brand + * The brand of this {@link SodaWithId} + * @return The SodaWithId builder. + */ + Builder2 brand( @Nonnull final String brand ); + } + + /** + * Builder helper class. + */ + public interface Builder2 + { + /** + * Set the quantity of this {@link SodaWithId} instance. + * + * @param quantity + * The quantity of this {@link SodaWithId} + * @return The SodaWithId builder. + */ + Builder3 quantity( @Nonnull final Integer quantity ); + } + + /** + * Builder helper class. + */ + public interface Builder3 + { + /** + * Set the price of this {@link SodaWithId} instance. + * + * @param price + * The price of this {@link SodaWithId} + * @return The SodaWithId instance. + */ + SodaWithId price( @Nonnull final Float price ); + } + } diff --git a/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/DeserializationTest.java b/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/DeserializationTest.java index 8a368bc05..8f52104e1 100644 --- a/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/DeserializationTest.java +++ b/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/DeserializationTest.java @@ -32,19 +32,19 @@ void setUp( WireMockRuntimeInfo wmRuntimeInfo ) @Test void testFullResponse() { - responseBody = - """ - { - "name": "Cola", - "brand": "Coca-Cola", - "quantity": 100, - "price": 1.5, - "id": 0 - } - """; + responseBody = """ + { + "name": "Cola", + "brand": "Coca-Cola", + "quantity": 100, + "price": 1.5, + "id": 0 + } + """; stub(responseBody); - final SodaWithId expected = new SodaWithId().id(0L).name("Cola").brand("Coca-Cola").quantity(100).price(1.5f); + final SodaWithId expected = + SodaWithId.create().name("Cola").brand("Coca-Cola").quantity(100).price(1.5f).id(0L); final SodaWithId actual = sut.sodasIdGet(1L); @@ -54,19 +54,19 @@ void testFullResponse() @Test void testUnexpectedFieldOrder() { - responseBody = - """ - { - "name": "Cola", - "price": 1.5, - "id": 0, - "brand": "Coca-Cola", - "quantity": 100 - } - """; + responseBody = """ + { + "name": "Cola", + "price": 1.5, + "id": 0, + "brand": "Coca-Cola", + "quantity": 100 + } + """; stub(responseBody); - final SodaWithId expected = new SodaWithId().id(0L).name("Cola").brand("Coca-Cola").quantity(100).price(1.5f); + final SodaWithId expected = + SodaWithId.create().name("Cola").brand("Coca-Cola").quantity(100).price(1.5f).id(0L); final SodaWithId actual = sut.sodasIdGet(1L); @@ -79,7 +79,7 @@ void testPartialResponse() responseBody = "{\"name\": \"Cola\"}"; stub(responseBody); - final SodaWithId expected = new SodaWithId().name("Cola"); + final SodaWithId expected = SodaWithId.create().name("Cola").brand(null).quantity(null).price(null); final SodaWithId actual = sut.sodasIdGet(1L); @@ -89,13 +89,12 @@ void testPartialResponse() @Test void testUnexpectedAdditionalField() { - responseBody = - """ - { - "name": "Cola", - "unexpectedField": [] - } - """; + responseBody = """ + { + "name": "Cola", + "unexpectedField": [] + } + """; stub(responseBody); final SodaWithId actual = sut.sodasIdGet(1L); diff --git a/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/SerializationTest.java b/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/SerializationTest.java index f177fcc15..d554bcbcd 100644 --- a/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/SerializationTest.java +++ b/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/SerializationTest.java @@ -43,7 +43,7 @@ void testPutPayload() } """; - final SodaWithId obj = new SodaWithId().id(0L).name("Cola").brand("Coca-Cola").quantity(100).price(1.5f); + final SodaWithId obj = SodaWithId.create().name("Cola").brand("Coca-Cola").quantity(100).price(1.5f).id(0L); sut.sodasPut(obj); @@ -64,7 +64,7 @@ void testJacksonSerialization() } """; - final SodaWithId obj = new SodaWithId().id(0L).name("Cola").brand("Coca-Cola").quantity(100).price(1.5f); + final SodaWithId obj = SodaWithId.create().name("Cola").brand("Coca-Cola").quantity(100).price(1.5f).id(0L); assertThat(new ObjectMapper().writeValueAsString(obj)).isEqualToIgnoringWhitespace(expected); } diff --git a/datamodel/openapi/openapi-generator-maven-plugin/src/test/resources/DataModelGeneratorMojoIntegrationTest/sodastore/output/com/sap/cloud/sdk/datamodel/rest/sodastore/model/NewSoda.java b/datamodel/openapi/openapi-generator-maven-plugin/src/test/resources/DataModelGeneratorMojoIntegrationTest/sodastore/output/com/sap/cloud/sdk/datamodel/rest/sodastore/model/NewSoda.java index 85a9784d2..646dd50f2 100644 --- a/datamodel/openapi/openapi-generator-maven-plugin/src/test/resources/DataModelGeneratorMojoIntegrationTest/sodastore/output/com/sap/cloud/sdk/datamodel/rest/sodastore/model/NewSoda.java +++ b/datamodel/openapi/openapi-generator-maven-plugin/src/test/resources/DataModelGeneratorMojoIntegrationTest/sodastore/output/com/sap/cloud/sdk/datamodel/rest/sodastore/model/NewSoda.java @@ -255,5 +255,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + } diff --git a/datamodel/openapi/openapi-generator-maven-plugin/src/test/resources/DataModelGeneratorMojoIntegrationTest/sodastore/output/com/sap/cloud/sdk/datamodel/rest/sodastore/model/Soda.java b/datamodel/openapi/openapi-generator-maven-plugin/src/test/resources/DataModelGeneratorMojoIntegrationTest/sodastore/output/com/sap/cloud/sdk/datamodel/rest/sodastore/model/Soda.java index 01d83f5a2..7c7834e45 100644 --- a/datamodel/openapi/openapi-generator-maven-plugin/src/test/resources/DataModelGeneratorMojoIntegrationTest/sodastore/output/com/sap/cloud/sdk/datamodel/rest/sodastore/model/Soda.java +++ b/datamodel/openapi/openapi-generator-maven-plugin/src/test/resources/DataModelGeneratorMojoIntegrationTest/sodastore/output/com/sap/cloud/sdk/datamodel/rest/sodastore/model/Soda.java @@ -288,5 +288,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + } diff --git a/datamodel/openapi/openapi-generator-maven-plugin/src/test/resources/DataModelGeneratorMojoIntegrationTest/sodastore/output/com/sap/cloud/sdk/datamodel/rest/sodastore/model/UpdateSoda.java b/datamodel/openapi/openapi-generator-maven-plugin/src/test/resources/DataModelGeneratorMojoIntegrationTest/sodastore/output/com/sap/cloud/sdk/datamodel/rest/sodastore/model/UpdateSoda.java index 46e2b40d1..cc476c635 100644 --- a/datamodel/openapi/openapi-generator-maven-plugin/src/test/resources/DataModelGeneratorMojoIntegrationTest/sodastore/output/com/sap/cloud/sdk/datamodel/rest/sodastore/model/UpdateSoda.java +++ b/datamodel/openapi/openapi-generator-maven-plugin/src/test/resources/DataModelGeneratorMojoIntegrationTest/sodastore/output/com/sap/cloud/sdk/datamodel/rest/sodastore/model/UpdateSoda.java @@ -255,5 +255,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + } diff --git a/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/pojo.mustache b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/pojo.mustache index ac3203341..e85a3d177 100644 --- a/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/pojo.mustache +++ b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/pojo.mustache @@ -68,6 +68,11 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcela {{/parent}} } {{/parcelableModel}} + {{^parcelableModel}} + {{#pojoConstructorVisibility}} + {{pojoConstructorVisibility}} {{classname}}() { {{#parent}}super();{{/parent}} } + {{/pojoConstructorVisibility}} + {{/parcelableModel}} {{#vars}} {{^isReadOnly}} @@ -537,4 +542,5 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcela } }; {{/parcelableModel}} +{{>pojoBuilder}} } diff --git a/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/pojoBuilder.mustache b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/pojoBuilder.mustache new file mode 100644 index 000000000..654131a62 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/pojoBuilder.mustache @@ -0,0 +1,64 @@ +{{#pojoBuilderMethodName}} +{{#hasRequired}} + /** + * Create a type-safe, fluent-api builder object to construct a new {@link {{classname}}} instance with all required arguments. + */ + public static Builder {{pojoBuilderMethodName}}() { + return {{#requiredVars}}({{name}}) -> {{/requiredVars}}{{#pojoBuildMethodName}}() -> {{/pojoBuildMethodName}}new {{classname}}(){{#requiredVars}}.{{name}}({{name}}){{/requiredVars}}; + } + /** + * Builder helper class. + */ + public interface Builder { +{{#requiredVars}} + /** + * Set the {{name}} of this {@link {{classname}}} instance. + * + * @param {{name}} {{#description}}{{description}}{{/description}}{{^description}}The {{name}} of this {@link {{classname}}}{{/description}} + * @return {{^-last}}The {{classname}} builder.{{/-last}}{{#-last}}The {{classname}} instance.{{/-last}} + */ + {{^pojoBuildMethodName}}{{^-last}}Builder{{-index}}{{/-last}}{{#-last}}{{classname}}{{/-last}}{{/pojoBuildMethodName}}{{#pojoBuildMethodName}}Builder{{-index}}{{/pojoBuildMethodName}} {{name}}( {{#isNullable}}@Nullable{{/isNullable}}{{^isNullable}}@Nonnull{{/isNullable}} final {{{datatypeWithEnum}}} {{name}}); +{{#isArray}} + /** + * Set the {{name}} of this {@link {{classname}}} instance. + * + * @param {{name}} {{#description}}{{description}}{{/description}}{{^description}}The {{name}} of this {@link {{classname}}}{{/description}} + * @return {{^-last}}The {{classname}} builder.{{/-last}}{{#-last}}The {{classname}} instance.{{/-last}} + */ + default {{^pojoBuildMethodName}}{{^-last}}Builder{{-index}}{{/-last}}{{#-last}}{{classname}}{{/-last}}{{/pojoBuildMethodName}}{{#pojoBuildMethodName}}Builder{{-index}}{{/pojoBuildMethodName}} {{name}}( @Nonnull final {{{items.datatypeWithEnum}}}... {{name}}) { + return {{name}}(Arrays.asList({{name}})); + } +{{/isArray}} + } +{{^-last}} + /** + * Builder helper class. + */ + public interface Builder{{-index}} { +{{/-last}} +{{#-last}} +{{#pojoBuildMethodName}} + /** + * Builder helper class. + */ + public interface Builder{{-index}} { + /** + * Finalize the builder for new {@link {{classname}}} instance. + * + * @return The {{classname}} instance. + */ + {{classname}} {{pojoBuildMethodName}}(); + } +{{/pojoBuildMethodName}} +{{/-last}} +{{/requiredVars}} +{{/hasRequired}} +{{^hasRequired}} + /** + * Create a new {@link {{classname}}} instance. No arguments are required. + */ + public static {{classname}} {{pojoBuilderMethodName}}() { + return new {{classname}}(); + } +{{/hasRequired}} +{{/pojoBuilderMethodName}} \ No newline at end of file diff --git a/datamodel/openapi/openapi-generator/src/test/java/com/sap/cloud/sdk/datamodel/openapi/generator/DataModelGeneratorIntegrationTest.java b/datamodel/openapi/openapi-generator/src/test/java/com/sap/cloud/sdk/datamodel/openapi/generator/DataModelGeneratorIntegrationTest.java index 7c285b230..2410f22ff 100644 --- a/datamodel/openapi/openapi-generator/src/test/java/com/sap/cloud/sdk/datamodel/openapi/generator/DataModelGeneratorIntegrationTest.java +++ b/datamodel/openapi/openapi-generator/src/test/java/com/sap/cloud/sdk/datamodel/openapi/generator/DataModelGeneratorIntegrationTest.java @@ -20,12 +20,14 @@ import com.sap.cloud.sdk.datamodel.openapi.generator.model.GenerationResult; import io.vavr.control.Try; +import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; class DataModelGeneratorIntegrationTest { @RequiredArgsConstructor + @AllArgsConstructor private enum TestCase { API_CLASS_VENDOR_EXTENSION_YAML( @@ -59,7 +61,18 @@ private enum TestCase "com.sap.cloud.sdk.services.anyofoneof.model", ApiMaturity.RELEASED, true, - 7); + 7), + INPUT_SPEC_WITH_BUILDER( + "input-spec-with-builder", + "sodastore.JSON", + "com.sap.cloud.sdk.services.builder.api", + "com.sap.cloud.sdk.services.builder.model", + ApiMaturity.RELEASED, + true, + 6, + "builder", + "build", + "private"); final String testCaseName; final String inputSpecFileName; @@ -68,6 +81,9 @@ private enum TestCase final ApiMaturity apiMaturity; final boolean anyOfOneOfGenerationEnabled; final int expectedNumberOfGeneratedFiles; + String methodBuilder = null; + String methodBuild = null; + String constructorVisibility = null; } @ParameterizedTest @@ -96,6 +112,9 @@ void integrationTests( final TestCase testCase, @TempDir final Path path ) .withSapCopyrightHeader(true) .oneOfAnyOfGenerationEnabled(testCase.anyOfOneOfGenerationEnabled) .additionalProperty("useAbstractionForFiles", "true") + .additionalProperty("pojoBuilderMethodName", testCase.methodBuilder) + .additionalProperty("pojoBuildMethodName", testCase.methodBuild) + .additionalProperty("pojoConstructorVisibility", testCase.constructorVisibility) .build(); final Try maybeGenerationResult = @@ -130,6 +149,9 @@ void generateDataModelForComparison( final TestCase testCase ) .withSapCopyrightHeader(true) .oneOfAnyOfGenerationEnabled(testCase.anyOfOneOfGenerationEnabled) .additionalProperty("useAbstractionForFiles", "true") + .additionalProperty("pojoBuilderMethodName", testCase.methodBuilder) + .additionalProperty("pojoBuildMethodName", testCase.methodBuild) + .additionalProperty("pojoConstructorVisibility", testCase.constructorVisibility) .build(); new DataModelGenerator().generateDataModel(generationConfiguration); diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/NewSoda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/NewSoda.java index 37d3e8399..0b194bda5 100644 --- a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/NewSoda.java +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/NewSoda.java @@ -255,5 +255,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + } diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/Soda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/Soda.java index a3c51f65b..b8d8834f2 100644 --- a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/Soda.java +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/Soda.java @@ -288,5 +288,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + } diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java index 7d38b7a0f..661e7662c 100644 --- a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java @@ -255,5 +255,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + } diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/NewSoda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/NewSoda.java index 37d3e8399..0b194bda5 100644 --- a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/NewSoda.java +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/NewSoda.java @@ -255,5 +255,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + } diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/Soda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/Soda.java index a3c51f65b..b8d8834f2 100644 --- a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/Soda.java +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/Soda.java @@ -288,5 +288,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + } diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java index 7d38b7a0f..661e7662c 100644 --- a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java @@ -255,5 +255,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + } diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/ChildObject1.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/ChildObject1.java index 3c25b5081..cae62201d 100644 --- a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/ChildObject1.java +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/ChildObject1.java @@ -222,5 +222,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + } diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/ChildObject2.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/ChildObject2.java index ea4c3b531..cb7573323 100644 --- a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/ChildObject2.java +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/ChildObject2.java @@ -223,5 +223,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + } diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/ChildObject3.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/ChildObject3.java index 303bc6828..4e37b5a0c 100644 --- a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/ChildObject3.java +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/ChildObject3.java @@ -223,5 +223,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + } diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/NestedChildObject.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/NestedChildObject.java index dee7c1922..f22558347 100644 --- a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/NestedChildObject.java +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/NestedChildObject.java @@ -222,5 +222,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + } diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/RootObject.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/RootObject.java index e6f9313f4..3282bf14a 100644 --- a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/RootObject.java +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/RootObject.java @@ -172,5 +172,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + } diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/RootObjectQuestionsInner.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/RootObjectQuestionsInner.java index d9e37ced5..24b5dbd53 100644 --- a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/RootObjectQuestionsInner.java +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-anyof-oneof/output/com/sap/cloud/sdk/services/anyofoneof/model/RootObjectQuestionsInner.java @@ -225,5 +225,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + } diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/input/sodastore.JSON b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/input/sodastore.JSON new file mode 100644 index 000000000..5788837ca --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/input/sodastore.JSON @@ -0,0 +1,224 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "Soda Store API", + "version": "1.0.0", + "description": "API for managing sodas in a soda store" + }, + "paths": { + "/sodas": { + "get": { + "summary": "Get a list of all sodas", + "x-sap-cloud-sdk-api-name": "AwesomeSodas", + "operationId": "getSodas", + "responses": { + "200": { + "description": "A list of sodas", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Soda" + } + } + } + } + } + } + }, + "post": { + "summary": "Add a new soda to the store", + "x-sap-cloud-sdk-api-name": "AwesomeSoda", + "operationId": "addSoda", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/NewSoda" + } + } + } + }, + "responses": { + "201": { + "description": "The newly added soda", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Soda" + } + } + } + } + } + } + }, + "/sodas/{sodaId}": { + "get": { + "summary": "Get details of a specific soda", + "operationId": "getSodaById", + "parameters": [ + { + "name": "sodaId", + "in": "path", + "description": "ID of the soda to retrieve", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + } + ], + "responses": { + "200": { + "description": "The requested soda", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Soda" + } + } + } + }, + "404": { + "description": "Soda not found" + } + } + }, + "put": { + "summary": "Update details of a specific soda", + "operationId": "updateSodaById", + "parameters": [ + { + "name": "sodaId", + "in": "path", + "description": "ID of the soda to update", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UpdateSoda" + } + } + } + }, + "responses": { + "200": { + "description": "The updated soda", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Soda" + } + } + } + }, + "404": { + "description": "Soda not found" + } + } + }, + "delete": { + "summary": "Delete a specific soda from the store", + "operationId": "deleteSodaById", + "parameters": [ + { + "name": "sodaId", + "in": "path", + "description": "ID of the soda to delete", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + } + ], + "responses": { + "204": { + "description": "Soda successfully deleted" + }, + "404": { + "description": "Soda not found" + } + } + } + } + }, + "components": { + "schemas": { + "Soda": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "brand": { + "type": "string" + }, + "flavors": { + "type": "array", + "items": { + "type": "string" + } + }, + "price": { + "type": "number", + "format": "float" + } + }, + "required": ["name", "brand", "flavors", "price"] + }, + "NewSoda": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "brand": { + "type": "string" + }, + "flavor": { + "type": "string" + }, + "price": { + "type": "number", + "format": "float" + } + }, + "required": ["name", "brand", "flavor", "price"] + }, + "UpdateSoda": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "brand": { + "type": "string" + }, + "flavor": { + "type": "string" + }, + "price": { + "type": "number", + "format": "float" + } + } + } + } + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/api/AwesomeSodaApi.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/api/AwesomeSodaApi.java new file mode 100644 index 000000000..8399fe9d2 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/api/AwesomeSodaApi.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. + */ + +package com.sap.cloud.sdk.services.builder.api; + +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +import com.sap.cloud.sdk.services.openapi.core.OpenApiResponse; +import com.sap.cloud.sdk.services.openapi.core.AbstractOpenApiService; +import com.sap.cloud.sdk.services.openapi.apiclient.ApiClient; + +import com.sap.cloud.sdk.services.builder.model.NewSoda; +import com.sap.cloud.sdk.services.builder.model.Soda; + +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.util.UriComponentsBuilder; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.core.io.FileSystemResource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import com.google.common.annotations.Beta; + +import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; + +/** +* Soda Store API in version 1.0.0. +* +* API for managing sodas in a soda store +*/ + +public class AwesomeSodaApi extends AbstractOpenApiService { + /** + * Instantiates this API class to invoke operations on the Soda Store API. + * + * @param httpDestination The destination that API should be used with + */ + public AwesomeSodaApi( @Nonnull final Destination httpDestination ) + { + super(httpDestination); + } + + /** + * Instantiates this API class to invoke operations on the Soda Store API based on a given {@link ApiClient}. + * + * @param apiClient + * ApiClient to invoke the API on + */ + @Beta + public AwesomeSodaApi( @Nonnull final ApiClient apiClient ) + { + super(apiClient); + } + + /** + *

Add a new soda to the store

+ *

+ *

201 - The newly added soda +* @param newSoda + The value for the parameter newSoda +* @return Soda +* @throws OpenApiRequestException if an error occurs while attempting to invoke the API + */ + @Nullable public Soda addSoda( @Nonnull final NewSoda newSoda) throws OpenApiRequestException { + final Object localVarPostBody = newSoda; + + // verify the required parameter 'newSoda' is set + if (newSoda == null) { + throw new OpenApiRequestException("Missing the required parameter 'newSoda' when calling addSoda"); + } + + final String localVarPath = UriComponentsBuilder.fromPath("/sodas").build().toUriString(); + + final MultiValueMap localVarQueryParams = new LinkedMultiValueMap(); + final HttpHeaders localVarHeaderParams = new HttpHeaders(); + final MultiValueMap localVarFormParams = new LinkedMultiValueMap(); + + final String[] localVarAccepts = { + "application/json" + }; + final List localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + "application/json" + }; + final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); + + final String[] localVarAuthNames = new String[] { }; + + final ParameterizedTypeReference localVarReturnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(localVarPath, HttpMethod.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType); + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/api/AwesomeSodasApi.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/api/AwesomeSodasApi.java new file mode 100644 index 000000000..5074247a7 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/api/AwesomeSodasApi.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. + */ + +package com.sap.cloud.sdk.services.builder.api; + +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +import com.sap.cloud.sdk.services.openapi.core.OpenApiResponse; +import com.sap.cloud.sdk.services.openapi.core.AbstractOpenApiService; +import com.sap.cloud.sdk.services.openapi.apiclient.ApiClient; + +import com.sap.cloud.sdk.services.builder.model.Soda; + +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.util.UriComponentsBuilder; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.core.io.FileSystemResource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import com.google.common.annotations.Beta; + +import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; + +/** +* Soda Store API in version 1.0.0. +* +* API for managing sodas in a soda store +*/ + +public class AwesomeSodasApi extends AbstractOpenApiService { + /** + * Instantiates this API class to invoke operations on the Soda Store API. + * + * @param httpDestination The destination that API should be used with + */ + public AwesomeSodasApi( @Nonnull final Destination httpDestination ) + { + super(httpDestination); + } + + /** + * Instantiates this API class to invoke operations on the Soda Store API based on a given {@link ApiClient}. + * + * @param apiClient + * ApiClient to invoke the API on + */ + @Beta + public AwesomeSodasApi( @Nonnull final ApiClient apiClient ) + { + super(apiClient); + } + + /** + *

Get a list of all sodas

+ *

+ *

200 - A list of sodas +* @return List<Soda> +* @throws OpenApiRequestException if an error occurs while attempting to invoke the API + */ + @Nullable public List getSodas() throws OpenApiRequestException { + final Object localVarPostBody = null; + + final String localVarPath = UriComponentsBuilder.fromPath("/sodas").build().toUriString(); + + final MultiValueMap localVarQueryParams = new LinkedMultiValueMap(); + final HttpHeaders localVarHeaderParams = new HttpHeaders(); + final MultiValueMap localVarFormParams = new LinkedMultiValueMap(); + + final String[] localVarAccepts = { + "application/json" + }; + final List localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { }; + final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); + + final String[] localVarAuthNames = new String[] { }; + + final ParameterizedTypeReference> localVarReturnType = new ParameterizedTypeReference>() {}; + return apiClient.invokeAPI(localVarPath, HttpMethod.GET, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType); + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/api/DefaultApi.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/api/DefaultApi.java new file mode 100644 index 000000000..4fb038a36 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/api/DefaultApi.java @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. + */ + +package com.sap.cloud.sdk.services.builder.api; + +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +import com.sap.cloud.sdk.services.openapi.core.OpenApiResponse; +import com.sap.cloud.sdk.services.openapi.core.AbstractOpenApiService; +import com.sap.cloud.sdk.services.openapi.apiclient.ApiClient; + +import com.sap.cloud.sdk.services.builder.model.Soda; +import com.sap.cloud.sdk.services.builder.model.UpdateSoda; + +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.util.UriComponentsBuilder; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.core.io.FileSystemResource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import com.google.common.annotations.Beta; + +import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; + +/** +* Soda Store API in version 1.0.0. +* +* API for managing sodas in a soda store +*/ + +public class DefaultApi extends AbstractOpenApiService { + /** + * Instantiates this API class to invoke operations on the Soda Store API. + * + * @param httpDestination The destination that API should be used with + */ + public DefaultApi( @Nonnull final Destination httpDestination ) + { + super(httpDestination); + } + + /** + * Instantiates this API class to invoke operations on the Soda Store API based on a given {@link ApiClient}. + * + * @param apiClient + * ApiClient to invoke the API on + */ + @Beta + public DefaultApi( @Nonnull final ApiClient apiClient ) + { + super(apiClient); + } + + /** + *

Delete a specific soda from the store

+ *

+ *

204 - Soda successfully deleted + *

404 - Soda not found +* @param sodaId + ID of the soda to delete +* @return An OpenApiResponse containing the status code of the HttpResponse. +* @throws OpenApiRequestException if an error occurs while attempting to invoke the API + */ + @Nonnull public OpenApiResponse deleteSodaById( @Nonnull final Long sodaId) throws OpenApiRequestException { + final Object localVarPostBody = null; + + // verify the required parameter 'sodaId' is set + if (sodaId == null) { + throw new OpenApiRequestException("Missing the required parameter 'sodaId' when calling deleteSodaById"); + } + + // create path and map variables + final Map localVarPathParams = new HashMap(); + localVarPathParams.put("sodaId", sodaId); + final String localVarPath = UriComponentsBuilder.fromPath("/sodas/{sodaId}").buildAndExpand(localVarPathParams).toUriString(); + + final MultiValueMap localVarQueryParams = new LinkedMultiValueMap(); + final HttpHeaders localVarHeaderParams = new HttpHeaders(); + final MultiValueMap localVarFormParams = new LinkedMultiValueMap(); + + final String[] localVarAccepts = { }; + final List localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { }; + final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); + + final String[] localVarAuthNames = new String[] { }; + + final ParameterizedTypeReference localVarReturnType = new ParameterizedTypeReference() {}; + apiClient.invokeAPI(localVarPath, HttpMethod.DELETE, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType); + return new OpenApiResponse(apiClient); + } + /** + *

Get details of a specific soda

+ *

+ *

200 - The requested soda + *

404 - Soda not found +* @param sodaId + ID of the soda to retrieve +* @return Soda +* @throws OpenApiRequestException if an error occurs while attempting to invoke the API + */ + @Nullable public Soda getSodaById( @Nonnull final Long sodaId) throws OpenApiRequestException { + final Object localVarPostBody = null; + + // verify the required parameter 'sodaId' is set + if (sodaId == null) { + throw new OpenApiRequestException("Missing the required parameter 'sodaId' when calling getSodaById"); + } + + // create path and map variables + final Map localVarPathParams = new HashMap(); + localVarPathParams.put("sodaId", sodaId); + final String localVarPath = UriComponentsBuilder.fromPath("/sodas/{sodaId}").buildAndExpand(localVarPathParams).toUriString(); + + final MultiValueMap localVarQueryParams = new LinkedMultiValueMap(); + final HttpHeaders localVarHeaderParams = new HttpHeaders(); + final MultiValueMap localVarFormParams = new LinkedMultiValueMap(); + + final String[] localVarAccepts = { + "application/json" + }; + final List localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { }; + final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); + + final String[] localVarAuthNames = new String[] { }; + + final ParameterizedTypeReference localVarReturnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(localVarPath, HttpMethod.GET, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType); + } + /** + *

Update details of a specific soda

+ *

+ *

200 - The updated soda + *

404 - Soda not found +* @param sodaId + ID of the soda to update +* @param updateSoda + The value for the parameter updateSoda +* @return Soda +* @throws OpenApiRequestException if an error occurs while attempting to invoke the API + */ + @Nullable public Soda updateSodaById( @Nonnull final Long sodaId, @Nonnull final UpdateSoda updateSoda) throws OpenApiRequestException { + final Object localVarPostBody = updateSoda; + + // verify the required parameter 'sodaId' is set + if (sodaId == null) { + throw new OpenApiRequestException("Missing the required parameter 'sodaId' when calling updateSodaById"); + } + + // verify the required parameter 'updateSoda' is set + if (updateSoda == null) { + throw new OpenApiRequestException("Missing the required parameter 'updateSoda' when calling updateSodaById"); + } + + // create path and map variables + final Map localVarPathParams = new HashMap(); + localVarPathParams.put("sodaId", sodaId); + final String localVarPath = UriComponentsBuilder.fromPath("/sodas/{sodaId}").buildAndExpand(localVarPathParams).toUriString(); + + final MultiValueMap localVarQueryParams = new LinkedMultiValueMap(); + final HttpHeaders localVarHeaderParams = new HttpHeaders(); + final MultiValueMap localVarFormParams = new LinkedMultiValueMap(); + + final String[] localVarAccepts = { + "application/json" + }; + final List localVarAccept = apiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + "application/json" + }; + final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes); + + final String[] localVarAuthNames = new String[] { }; + + final ParameterizedTypeReference localVarReturnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(localVarPath, HttpMethod.PUT, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType); + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/model/NewSoda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/model/NewSoda.java new file mode 100644 index 000000000..5436584f0 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/model/NewSoda.java @@ -0,0 +1,326 @@ +/* + * Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.cloud.sdk.services.builder.model; + +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonValue; +import java.io.Serializable; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.annotation.JsonTypeName; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * NewSoda + */ + +// CHECKSTYLE:OFF +public class NewSoda +// CHECKSTYLE:ON +{ + @JsonProperty("name") + private String name; + + @JsonProperty("brand") + private String brand; + + @JsonProperty("flavor") + private String flavor; + + @JsonProperty("price") + private Float price; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + private NewSoda() { } + + /** + * Set the name of this {@link NewSoda} instance and return the same instance. + * + * @param name The name of this {@link NewSoda} + * @return The same instance of this {@link NewSoda} class + */ + @Nonnull public NewSoda name(@Nonnull final String name) { + this.name = name; + return this; + } + + /** + * Get name + * @return name The name of this {@link NewSoda} instance. + **/ + @Nonnull public String getName() { + return name; + } + + /** + * Set the name of this {@link NewSoda} instance. + * + * @param name The name of this {@link NewSoda} + */ + public void setName( @Nonnull final String name) { + this.name = name; + } + + /** + * Set the brand of this {@link NewSoda} instance and return the same instance. + * + * @param brand The brand of this {@link NewSoda} + * @return The same instance of this {@link NewSoda} class + */ + @Nonnull public NewSoda brand(@Nonnull final String brand) { + this.brand = brand; + return this; + } + + /** + * Get brand + * @return brand The brand of this {@link NewSoda} instance. + **/ + @Nonnull public String getBrand() { + return brand; + } + + /** + * Set the brand of this {@link NewSoda} instance. + * + * @param brand The brand of this {@link NewSoda} + */ + public void setBrand( @Nonnull final String brand) { + this.brand = brand; + } + + /** + * Set the flavor of this {@link NewSoda} instance and return the same instance. + * + * @param flavor The flavor of this {@link NewSoda} + * @return The same instance of this {@link NewSoda} class + */ + @Nonnull public NewSoda flavor(@Nonnull final String flavor) { + this.flavor = flavor; + return this; + } + + /** + * Get flavor + * @return flavor The flavor of this {@link NewSoda} instance. + **/ + @Nonnull public String getFlavor() { + return flavor; + } + + /** + * Set the flavor of this {@link NewSoda} instance. + * + * @param flavor The flavor of this {@link NewSoda} + */ + public void setFlavor( @Nonnull final String flavor) { + this.flavor = flavor; + } + + /** + * Set the price of this {@link NewSoda} instance and return the same instance. + * + * @param price The price of this {@link NewSoda} + * @return The same instance of this {@link NewSoda} class + */ + @Nonnull public NewSoda price(@Nonnull final Float price) { + this.price = price; + return this; + } + + /** + * Get price + * @return price The price of this {@link NewSoda} instance. + **/ + @Nonnull public Float getPrice() { + return price; + } + + /** + * Set the price of this {@link NewSoda} instance. + * + * @param price The price of this {@link NewSoda} + */ + public void setPrice( @Nonnull final Float price) { + this.price = price; + } + + /** + * Get the names of the unrecognizable properties of the {@link NewSoda}. + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link NewSoda} instance. + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if( !cloudSdkCustomFields.containsKey(name) ) { + throw new NoSuchElementException("NewSoda has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link NewSoda} instance. If the map previously contained a mapping + * for the key, the old value is replaced by the specified value. + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField( @Nonnull String customFieldName, @Nullable Object customFieldValue ) + { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + + @Override + public boolean equals(@Nullable final java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final NewSoda newSoda = (NewSoda) o; + return Objects.equals(this.cloudSdkCustomFields, newSoda.cloudSdkCustomFields) && + Objects.equals(this.name, newSoda.name) && + Objects.equals(this.brand, newSoda.brand) && + Objects.equals(this.flavor, newSoda.flavor) && + Objects.equals(this.price, newSoda.price); + } + + @Override + public int hashCode() { + return Objects.hash(name, brand, flavor, price, cloudSdkCustomFields); + } + + @Override + @Nonnull public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class NewSoda {\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" brand: ").append(toIndentedString(brand)).append("\n"); + sb.append(" flavor: ").append(toIndentedString(flavor)).append("\n"); + sb.append(" price: ").append(toIndentedString(price)).append("\n"); + cloudSdkCustomFields.forEach((k,v) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).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(final java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + /** + * Create a type-safe, fluent-api builder object to construct a new {@link NewSoda} instance with all required arguments. + */ + public static Builder builder() { + return (name) -> (brand) -> (flavor) -> (price) -> () -> new NewSoda().name(name).brand(brand).flavor(flavor).price(price); + } + /** + * Builder helper class. + */ + public interface Builder { + /** + * Set the name of this {@link NewSoda} instance. + * + * @param name The name of this {@link NewSoda} + * @return The NewSoda builder. + */ + Builder1 name( @Nonnull final String name); + } + /** + * Builder helper class. + */ + public interface Builder1 { + /** + * Set the brand of this {@link NewSoda} instance. + * + * @param brand The brand of this {@link NewSoda} + * @return The NewSoda builder. + */ + Builder2 brand( @Nonnull final String brand); + } + /** + * Builder helper class. + */ + public interface Builder2 { + /** + * Set the flavor of this {@link NewSoda} instance. + * + * @param flavor The flavor of this {@link NewSoda} + * @return The NewSoda builder. + */ + Builder3 flavor( @Nonnull final String flavor); + } + /** + * Builder helper class. + */ + public interface Builder3 { + /** + * Set the price of this {@link NewSoda} instance. + * + * @param price The price of this {@link NewSoda} + * @return The NewSoda instance. + */ + Builder4 price( @Nonnull final Float price); + } + /** + * Builder helper class. + */ + public interface Builder4 { + /** + * Finalize the builder for new {@link NewSoda} instance. + * + * @return The NewSoda instance. + */ + NewSoda build(); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/model/Soda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/model/Soda.java new file mode 100644 index 000000000..c7e6d84ea --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/model/Soda.java @@ -0,0 +1,383 @@ +/* + * Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.cloud.sdk.services.builder.model; + +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.io.Serializable; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.annotation.JsonTypeName; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Soda + */ + +// CHECKSTYLE:OFF +public class Soda +// CHECKSTYLE:ON +{ + @JsonProperty("id") + private Long id; + + @JsonProperty("name") + private String name; + + @JsonProperty("brand") + private String brand; + + @JsonProperty("flavors") + private List flavors = new ArrayList<>(); + + @JsonProperty("price") + private Float price; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + private Soda() { } + + /** + * Set the id of this {@link Soda} instance and return the same instance. + * + * @param id The id of this {@link Soda} + * @return The same instance of this {@link Soda} class + */ + @Nonnull public Soda id(@Nonnull final Long id) { + this.id = id; + return this; + } + + /** + * Get id + * @return id The id of this {@link Soda} instance. + **/ + @Nonnull public Long getId() { + return id; + } + + /** + * Set the id of this {@link Soda} instance. + * + * @param id The id of this {@link Soda} + */ + public void setId( @Nonnull final Long id) { + this.id = id; + } + + /** + * Set the name of this {@link Soda} instance and return the same instance. + * + * @param name The name of this {@link Soda} + * @return The same instance of this {@link Soda} class + */ + @Nonnull public Soda name(@Nonnull final String name) { + this.name = name; + return this; + } + + /** + * Get name + * @return name The name of this {@link Soda} instance. + **/ + @Nonnull public String getName() { + return name; + } + + /** + * Set the name of this {@link Soda} instance. + * + * @param name The name of this {@link Soda} + */ + public void setName( @Nonnull final String name) { + this.name = name; + } + + /** + * Set the brand of this {@link Soda} instance and return the same instance. + * + * @param brand The brand of this {@link Soda} + * @return The same instance of this {@link Soda} class + */ + @Nonnull public Soda brand(@Nonnull final String brand) { + this.brand = brand; + return this; + } + + /** + * Get brand + * @return brand The brand of this {@link Soda} instance. + **/ + @Nonnull public String getBrand() { + return brand; + } + + /** + * Set the brand of this {@link Soda} instance. + * + * @param brand The brand of this {@link Soda} + */ + public void setBrand( @Nonnull final String brand) { + this.brand = brand; + } + + /** + * Set the flavors of this {@link Soda} instance and return the same instance. + * + * @param flavors The flavors of this {@link Soda} + * @return The same instance of this {@link Soda} class + */ + @Nonnull public Soda flavors(@Nonnull final List flavors) { + this.flavors = flavors; + return this; + } + /** + * Add one flavors instance to this {@link Soda}. + * @param flavorsItem The flavors that should be added + * @return The same instance of type {@link Soda} + */ + @Nonnull public Soda addFlavorsItem( @Nonnull final String flavorsItem) { + if (this.flavors == null) { + this.flavors = new ArrayList<>(); + } + this.flavors.add(flavorsItem); + return this; + } + + /** + * Get flavors + * @return flavors The flavors of this {@link Soda} instance. + **/ + @Nonnull public List getFlavors() { + return flavors; + } + + /** + * Set the flavors of this {@link Soda} instance. + * + * @param flavors The flavors of this {@link Soda} + */ + public void setFlavors( @Nonnull final List flavors) { + this.flavors = flavors; + } + + /** + * Set the price of this {@link Soda} instance and return the same instance. + * + * @param price The price of this {@link Soda} + * @return The same instance of this {@link Soda} class + */ + @Nonnull public Soda price(@Nonnull final Float price) { + this.price = price; + return this; + } + + /** + * Get price + * @return price The price of this {@link Soda} instance. + **/ + @Nonnull public Float getPrice() { + return price; + } + + /** + * Set the price of this {@link Soda} instance. + * + * @param price The price of this {@link Soda} + */ + public void setPrice( @Nonnull final Float price) { + this.price = price; + } + + /** + * Get the names of the unrecognizable properties of the {@link Soda}. + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link Soda} instance. + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if( !cloudSdkCustomFields.containsKey(name) ) { + throw new NoSuchElementException("Soda has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link Soda} instance. If the map previously contained a mapping + * for the key, the old value is replaced by the specified value. + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField( @Nonnull String customFieldName, @Nullable Object customFieldValue ) + { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + + @Override + public boolean equals(@Nullable final java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final Soda soda = (Soda) o; + return Objects.equals(this.cloudSdkCustomFields, soda.cloudSdkCustomFields) && + Objects.equals(this.id, soda.id) && + Objects.equals(this.name, soda.name) && + Objects.equals(this.brand, soda.brand) && + Objects.equals(this.flavors, soda.flavors) && + Objects.equals(this.price, soda.price); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, brand, flavors, price, cloudSdkCustomFields); + } + + @Override + @Nonnull public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class Soda {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" brand: ").append(toIndentedString(brand)).append("\n"); + sb.append(" flavors: ").append(toIndentedString(flavors)).append("\n"); + sb.append(" price: ").append(toIndentedString(price)).append("\n"); + cloudSdkCustomFields.forEach((k,v) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).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(final java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + /** + * Create a type-safe, fluent-api builder object to construct a new {@link Soda} instance with all required arguments. + */ + public static Builder builder() { + return (name) -> (brand) -> (flavors) -> (price) -> () -> new Soda().name(name).brand(brand).flavors(flavors).price(price); + } + /** + * Builder helper class. + */ + public interface Builder { + /** + * Set the name of this {@link Soda} instance. + * + * @param name The name of this {@link Soda} + * @return The Soda builder. + */ + Builder1 name( @Nonnull final String name); + } + /** + * Builder helper class. + */ + public interface Builder1 { + /** + * Set the brand of this {@link Soda} instance. + * + * @param brand The brand of this {@link Soda} + * @return The Soda builder. + */ + Builder2 brand( @Nonnull final String brand); + } + /** + * Builder helper class. + */ + public interface Builder2 { + /** + * Set the flavors of this {@link Soda} instance. + * + * @param flavors The flavors of this {@link Soda} + * @return The Soda builder. + */ + Builder3 flavors( @Nonnull final List flavors); + /** + * Set the flavors of this {@link Soda} instance. + * + * @param flavors The flavors of this {@link Soda} + * @return The Soda builder. + */ + default Builder3 flavors( @Nonnull final String... flavors) { + return flavors(Arrays.asList(flavors)); + } + } + /** + * Builder helper class. + */ + public interface Builder3 { + /** + * Set the price of this {@link Soda} instance. + * + * @param price The price of this {@link Soda} + * @return The Soda instance. + */ + Builder4 price( @Nonnull final Float price); + } + /** + * Builder helper class. + */ + public interface Builder4 { + /** + * Finalize the builder for new {@link Soda} instance. + * + * @return The Soda instance. + */ + Soda build(); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/model/UpdateSoda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/model/UpdateSoda.java new file mode 100644 index 000000000..b80a805c9 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-builder/output/com/sap/cloud/sdk/services/builder/model/UpdateSoda.java @@ -0,0 +1,267 @@ +/* + * Copyright (c) 2024 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.cloud.sdk.services.builder.model; + +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonValue; +import java.io.Serializable; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.annotation.JsonTypeName; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * UpdateSoda + */ + +// CHECKSTYLE:OFF +public class UpdateSoda +// CHECKSTYLE:ON +{ + @JsonProperty("name") + private String name; + + @JsonProperty("brand") + private String brand; + + @JsonProperty("flavor") + private String flavor; + + @JsonProperty("price") + private Float price; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + private UpdateSoda() { } + + /** + * Set the name of this {@link UpdateSoda} instance and return the same instance. + * + * @param name The name of this {@link UpdateSoda} + * @return The same instance of this {@link UpdateSoda} class + */ + @Nonnull public UpdateSoda name(@Nonnull final String name) { + this.name = name; + return this; + } + + /** + * Get name + * @return name The name of this {@link UpdateSoda} instance. + **/ + @Nonnull public String getName() { + return name; + } + + /** + * Set the name of this {@link UpdateSoda} instance. + * + * @param name The name of this {@link UpdateSoda} + */ + public void setName( @Nonnull final String name) { + this.name = name; + } + + /** + * Set the brand of this {@link UpdateSoda} instance and return the same instance. + * + * @param brand The brand of this {@link UpdateSoda} + * @return The same instance of this {@link UpdateSoda} class + */ + @Nonnull public UpdateSoda brand(@Nonnull final String brand) { + this.brand = brand; + return this; + } + + /** + * Get brand + * @return brand The brand of this {@link UpdateSoda} instance. + **/ + @Nonnull public String getBrand() { + return brand; + } + + /** + * Set the brand of this {@link UpdateSoda} instance. + * + * @param brand The brand of this {@link UpdateSoda} + */ + public void setBrand( @Nonnull final String brand) { + this.brand = brand; + } + + /** + * Set the flavor of this {@link UpdateSoda} instance and return the same instance. + * + * @param flavor The flavor of this {@link UpdateSoda} + * @return The same instance of this {@link UpdateSoda} class + */ + @Nonnull public UpdateSoda flavor(@Nonnull final String flavor) { + this.flavor = flavor; + return this; + } + + /** + * Get flavor + * @return flavor The flavor of this {@link UpdateSoda} instance. + **/ + @Nonnull public String getFlavor() { + return flavor; + } + + /** + * Set the flavor of this {@link UpdateSoda} instance. + * + * @param flavor The flavor of this {@link UpdateSoda} + */ + public void setFlavor( @Nonnull final String flavor) { + this.flavor = flavor; + } + + /** + * Set the price of this {@link UpdateSoda} instance and return the same instance. + * + * @param price The price of this {@link UpdateSoda} + * @return The same instance of this {@link UpdateSoda} class + */ + @Nonnull public UpdateSoda price(@Nonnull final Float price) { + this.price = price; + return this; + } + + /** + * Get price + * @return price The price of this {@link UpdateSoda} instance. + **/ + @Nonnull public Float getPrice() { + return price; + } + + /** + * Set the price of this {@link UpdateSoda} instance. + * + * @param price The price of this {@link UpdateSoda} + */ + public void setPrice( @Nonnull final Float price) { + this.price = price; + } + + /** + * Get the names of the unrecognizable properties of the {@link UpdateSoda}. + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link UpdateSoda} instance. + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if( !cloudSdkCustomFields.containsKey(name) ) { + throw new NoSuchElementException("UpdateSoda has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link UpdateSoda} instance. If the map previously contained a mapping + * for the key, the old value is replaced by the specified value. + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField( @Nonnull String customFieldName, @Nullable Object customFieldValue ) + { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + + @Override + public boolean equals(@Nullable final java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final UpdateSoda updateSoda = (UpdateSoda) o; + return Objects.equals(this.cloudSdkCustomFields, updateSoda.cloudSdkCustomFields) && + Objects.equals(this.name, updateSoda.name) && + Objects.equals(this.brand, updateSoda.brand) && + Objects.equals(this.flavor, updateSoda.flavor) && + Objects.equals(this.price, updateSoda.price); + } + + @Override + public int hashCode() { + return Objects.hash(name, brand, flavor, price, cloudSdkCustomFields); + } + + @Override + @Nonnull public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class UpdateSoda {\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" brand: ").append(toIndentedString(brand)).append("\n"); + sb.append(" flavor: ").append(toIndentedString(flavor)).append("\n"); + sb.append(" price: ").append(toIndentedString(price)).append("\n"); + cloudSdkCustomFields.forEach((k,v) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).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(final java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + /** + * Create a new {@link UpdateSoda} instance. No arguments are required. + */ + public static UpdateSoda builder() { + return new UpdateSoda(); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-uppercase-file-extension/output/com/sap/cloud/sdk/services/uppercasefileextension/model/NewSoda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-uppercase-file-extension/output/com/sap/cloud/sdk/services/uppercasefileextension/model/NewSoda.java index fd191dfa0..601a5fc78 100644 --- a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-uppercase-file-extension/output/com/sap/cloud/sdk/services/uppercasefileextension/model/NewSoda.java +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-uppercase-file-extension/output/com/sap/cloud/sdk/services/uppercasefileextension/model/NewSoda.java @@ -255,5 +255,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + } diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-uppercase-file-extension/output/com/sap/cloud/sdk/services/uppercasefileextension/model/Soda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-uppercase-file-extension/output/com/sap/cloud/sdk/services/uppercasefileextension/model/Soda.java index 124f984e2..b16001383 100644 --- a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-uppercase-file-extension/output/com/sap/cloud/sdk/services/uppercasefileextension/model/Soda.java +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-uppercase-file-extension/output/com/sap/cloud/sdk/services/uppercasefileextension/model/Soda.java @@ -288,5 +288,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + } diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-uppercase-file-extension/output/com/sap/cloud/sdk/services/uppercasefileextension/model/UpdateSoda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-uppercase-file-extension/output/com/sap/cloud/sdk/services/uppercasefileextension/model/UpdateSoda.java index 63cab69b1..07ff63082 100644 --- a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-uppercase-file-extension/output/com/sap/cloud/sdk/services/uppercasefileextension/model/UpdateSoda.java +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/input-spec-with-uppercase-file-extension/output/com/sap/cloud/sdk/services/uppercasefileextension/model/UpdateSoda.java @@ -255,5 +255,6 @@ private String toIndentedString(final java.lang.Object o) { return o.toString().replace("\n", "\n "); } + }