diff --git a/datamodel/openapi/openapi-api-apache-sample/pom.xml b/datamodel/openapi/openapi-api-apache-sample/pom.xml index 4e08b5835..0b646fc69 100644 --- a/datamodel/openapi/openapi-api-apache-sample/pom.xml +++ b/datamodel/openapi/openapi-api-apache-sample/pom.xml @@ -47,6 +47,36 @@ com.fasterxml.jackson.core jackson-annotations + + + org.junit.jupiter + junit-jupiter-api + test + + + org.wiremock + wiremock + test + + + org.assertj + assertj-core + test + + + org.junit.jupiter + junit-jupiter-params + + + com.fasterxml.jackson.core + jackson-databind + test + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + test + @@ -82,11 +112,10 @@ generate-sources ${project.basedir}/src/main/resources/sodastore.yaml - com.sap.cloud.sdk.datamodel.openapi.apache.sample.api - com.sap.cloud.sdk.datamodel.openapi.apache.sample.model + com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.api + com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model apache-httpclient - false create protected true diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/api/DefaultApi.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/api/DefaultApi.java index af9d5c541..75b3fe7c0 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/api/DefaultApi.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/api/DefaultApi.java @@ -99,13 +99,13 @@ public Pet addPet( @Nonnull final PetInput pet ) final String[] localVarAccepts = { "application/json" }; final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); - final String[] localVarContentTypes = { "application/json" }; final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); final TypeReference localVarReturnType = new TypeReference() { }; + return apiClient .invokeAPI( localVarPath, @@ -161,7 +161,6 @@ public OpenApiResponse deletePet( @Nonnull final Long id ) final String[] localVarAccepts = { "application/json" }; final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); - final String[] localVarContentTypes = { }; @@ -170,6 +169,7 @@ public OpenApiResponse deletePet( @Nonnull final Long id ) final TypeReference localVarReturnType = new TypeReference() { }; + return apiClient .invokeAPI( localVarPath, @@ -225,7 +225,6 @@ public Pet findPetById( @Nonnull final Long id ) final String[] localVarAccepts = { "application/json", "application/xml", "text/xml", "text/html" }; final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); - final String[] localVarContentTypes = { }; @@ -234,6 +233,7 @@ public Pet findPetById( @Nonnull final Long id ) final TypeReference localVarReturnType = new TypeReference() { }; + return apiClient .invokeAPI( localVarPath, @@ -287,7 +287,6 @@ public List findPets( @Nullable final List tags, @Nullable final In final String[] localVarAccepts = { "application/json", "application/xml", "text/xml", "text/html" }; final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); - final String[] localVarContentTypes = { }; @@ -296,6 +295,7 @@ public List findPets( @Nullable final List tags, @Nullable final In final TypeReference> localVarReturnType = new TypeReference>() { }; + return apiClient .invokeAPI( localVarPath, diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/model/ErrorModel.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/model/ErrorModel.java index c9739e71d..046e744f0 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/model/ErrorModel.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/model/ErrorModel.java @@ -15,14 +15,11 @@ package com.sap.cloud.sdk.datamodel.openapi.apache.petstore.model; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; import java.util.LinkedHashMap; import java.util.Map; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Set; -import java.util.StringJoiner; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -232,78 +229,4 @@ private String toIndentedString( final java.lang.Object o ) return o.toString().replace("\n", "\n "); } - /** - * Convert the instance into URL query string. - * - * @return URL query string - */ - public String toUrlQueryString() - { - return toUrlQueryString(null); - } - - /** - * Convert the instance into URL query string. - * - * @param prefix - * prefix of the query string - * @return URL query string - */ - public String toUrlQueryString( String prefix ) - { - String suffix = ""; - String containerSuffix = ""; - String containerPrefix = ""; - if( prefix == null ) { - // style=form, explode=true, e.g. /pet?name=cat&type=manx - prefix = ""; - } else { - // deepObject style e.g. /pet?id[name]=cat&id[type]=manx - prefix = prefix + "["; - suffix = "]"; - containerSuffix = "]"; - containerPrefix = "["; - } - - StringJoiner joiner = new StringJoiner("&"); - - // add `code` to the URL query string - if( getCode() != null ) { - try { - joiner - .add( - String - .format( - "%scode%s=%s", - prefix, - suffix, - URLEncoder.encode(String.valueOf(getCode()), "UTF-8").replaceAll("\\+", "%20"))); - } - catch( UnsupportedEncodingException e ) { - // Should never happen, UTF-8 is always supported - throw new RuntimeException(e); - } - } - - // add `message` to the URL query string - if( getMessage() != null ) { - try { - joiner - .add( - String - .format( - "%smessage%s=%s", - prefix, - suffix, - URLEncoder.encode(String.valueOf(getMessage()), "UTF-8").replaceAll("\\+", "%20"))); - } - catch( UnsupportedEncodingException e ) { - // Should never happen, UTF-8 is always supported - throw new RuntimeException(e); - } - } - - return joiner.toString(); - } - } diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/model/Pet.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/model/Pet.java index 1a6d2654a..d86916dfb 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/model/Pet.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/model/Pet.java @@ -15,14 +15,11 @@ package com.sap.cloud.sdk.datamodel.openapi.apache.petstore.model; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; import java.util.LinkedHashMap; import java.util.Map; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Set; -import java.util.StringJoiner; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -275,96 +272,4 @@ private String toIndentedString( final java.lang.Object o ) return o.toString().replace("\n", "\n "); } - /** - * Convert the instance into URL query string. - * - * @return URL query string - */ - public String toUrlQueryString() - { - return toUrlQueryString(null); - } - - /** - * Convert the instance into URL query string. - * - * @param prefix - * prefix of the query string - * @return URL query string - */ - public String toUrlQueryString( String prefix ) - { - String suffix = ""; - String containerSuffix = ""; - String containerPrefix = ""; - if( prefix == null ) { - // style=form, explode=true, e.g. /pet?name=cat&type=manx - prefix = ""; - } else { - // deepObject style e.g. /pet?id[name]=cat&id[type]=manx - prefix = prefix + "["; - suffix = "]"; - containerSuffix = "]"; - containerPrefix = "["; - } - - StringJoiner joiner = new StringJoiner("&"); - - // add `id` to the URL query string - if( getId() != null ) { - try { - joiner - .add( - String - .format( - "%sid%s=%s", - prefix, - suffix, - URLEncoder.encode(String.valueOf(getId()), "UTF-8").replaceAll("\\+", "%20"))); - } - catch( UnsupportedEncodingException e ) { - // Should never happen, UTF-8 is always supported - throw new RuntimeException(e); - } - } - - // add `name` to the URL query string - if( getName() != null ) { - try { - joiner - .add( - String - .format( - "%sname%s=%s", - prefix, - suffix, - URLEncoder.encode(String.valueOf(getName()), "UTF-8").replaceAll("\\+", "%20"))); - } - catch( UnsupportedEncodingException e ) { - // Should never happen, UTF-8 is always supported - throw new RuntimeException(e); - } - } - - // add `tag` to the URL query string - if( getTag() != null ) { - try { - joiner - .add( - String - .format( - "%stag%s=%s", - prefix, - suffix, - URLEncoder.encode(String.valueOf(getTag()), "UTF-8").replaceAll("\\+", "%20"))); - } - catch( UnsupportedEncodingException e ) { - // Should never happen, UTF-8 is always supported - throw new RuntimeException(e); - } - } - - return joiner.toString(); - } - } diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/model/PetInput.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/model/PetInput.java index 7f6ea7be2..3d458b782 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/model/PetInput.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/petstore/model/PetInput.java @@ -15,14 +15,11 @@ package com.sap.cloud.sdk.datamodel.openapi.apache.petstore.model; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; import java.util.LinkedHashMap; import java.util.Map; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Set; -import java.util.StringJoiner; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -275,96 +272,4 @@ private String toIndentedString( final java.lang.Object o ) return o.toString().replace("\n", "\n "); } - /** - * Convert the instance into URL query string. - * - * @return URL query string - */ - public String toUrlQueryString() - { - return toUrlQueryString(null); - } - - /** - * Convert the instance into URL query string. - * - * @param prefix - * prefix of the query string - * @return URL query string - */ - public String toUrlQueryString( String prefix ) - { - String suffix = ""; - String containerSuffix = ""; - String containerPrefix = ""; - if( prefix == null ) { - // style=form, explode=true, e.g. /pet?name=cat&type=manx - prefix = ""; - } else { - // deepObject style e.g. /pet?id[name]=cat&id[type]=manx - prefix = prefix + "["; - suffix = "]"; - containerSuffix = "]"; - containerPrefix = "["; - } - - StringJoiner joiner = new StringJoiner("&"); - - // add `id` to the URL query string - if( getId() != null ) { - try { - joiner - .add( - String - .format( - "%sid%s=%s", - prefix, - suffix, - URLEncoder.encode(String.valueOf(getId()), "UTF-8").replaceAll("\\+", "%20"))); - } - catch( UnsupportedEncodingException e ) { - // Should never happen, UTF-8 is always supported - throw new RuntimeException(e); - } - } - - // add `name` to the URL query string - if( getName() != null ) { - try { - joiner - .add( - String - .format( - "%sname%s=%s", - prefix, - suffix, - URLEncoder.encode(String.valueOf(getName()), "UTF-8").replaceAll("\\+", "%20"))); - } - catch( UnsupportedEncodingException e ) { - // Should never happen, UTF-8 is always supported - throw new RuntimeException(e); - } - } - - // add `tag` to the URL query string - if( getTag() != null ) { - try { - joiner - .add( - String - .format( - "%stag%s=%s", - prefix, - suffix, - URLEncoder.encode(String.valueOf(getTag()), "UTF-8").replaceAll("\\+", "%20"))); - } - catch( UnsupportedEncodingException e ) { - // Should never happen, UTF-8 is always supported - throw new RuntimeException(e); - } - } - - return joiner.toString(); - } - } diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/api/OrdersApi.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/api/OrdersApi.java similarity index 96% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/api/OrdersApi.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/api/OrdersApi.java index d3f5d7f00..102b092a1 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/api/OrdersApi.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/api/OrdersApi.java @@ -2,7 +2,7 @@ * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.api; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.api; import java.util.ArrayList; import java.util.HashMap; @@ -14,7 +14,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; -import com.sap.cloud.sdk.datamodel.openapi.apache.sample.model.Order; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.Order; import com.sap.cloud.sdk.services.openapi.apache.ApiClient; import com.sap.cloud.sdk.services.openapi.apache.BaseApi; import com.sap.cloud.sdk.services.openapi.apache.Pair; @@ -94,13 +94,13 @@ public Order ordersPost( @Nonnull final Order order ) final String[] localVarAccepts = { "application/json" }; final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); - final String[] localVarContentTypes = { "application/json" }; final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); final TypeReference localVarReturnType = new TypeReference() { }; + return apiClient .invokeAPI( localVarPath, diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/api/SodasApi.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/api/SodasApi.java similarity index 97% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/api/SodasApi.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/api/SodasApi.java index 80d852f1c..ae5a60760 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/api/SodasApi.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/api/SodasApi.java @@ -2,7 +2,7 @@ * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.api; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.api; import java.io.File; import java.util.ArrayList; @@ -16,8 +16,8 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; -import com.sap.cloud.sdk.datamodel.openapi.apache.sample.model.Soda; -import com.sap.cloud.sdk.datamodel.openapi.apache.sample.model.SodaWithId; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.Soda; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.SodaWithId; import com.sap.cloud.sdk.services.openapi.apache.ApiClient; import com.sap.cloud.sdk.services.openapi.apache.BaseApi; import com.sap.cloud.sdk.services.openapi.apache.Pair; @@ -101,7 +101,6 @@ public File sodasDownloadIdGet( @Nonnull final Long id ) final String[] localVarAccepts = { "application/octet-stream" }; final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); - final String[] localVarContentTypes = { }; @@ -110,6 +109,7 @@ public File sodasDownloadIdGet( @Nonnull final Long id ) final TypeReference localVarReturnType = new TypeReference() { }; + return apiClient .invokeAPI( localVarPath, @@ -154,7 +154,6 @@ public List sodasGet() final String[] localVarAccepts = { "application/json" }; final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); - final String[] localVarContentTypes = { }; @@ -163,6 +162,7 @@ public List sodasGet() final TypeReference> localVarReturnType = new TypeReference>() { }; + return apiClient .invokeAPI( localVarPath, @@ -218,7 +218,6 @@ public SodaWithId sodasIdGet( @Nonnull final Long id ) final String[] localVarAccepts = { "application/json" }; final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); - final String[] localVarContentTypes = { }; @@ -227,6 +226,7 @@ public SodaWithId sodasIdGet( @Nonnull final Long id ) final TypeReference localVarReturnType = new TypeReference() { }; + return apiClient .invokeAPI( localVarPath, @@ -283,13 +283,13 @@ public Soda sodasPut( @Nonnull final SodaWithId sodaWithId ) final String[] localVarAccepts = { "application/json" }; final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); - final String[] localVarContentTypes = { "application/json" }; final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); final TypeReference localVarReturnType = new TypeReference() { }; + return apiClient .invokeAPI( localVarPath, diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/AllOf.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/AllOf.java similarity index 99% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/AllOf.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/AllOf.java index 234145720..4314271a4 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/AllOf.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/AllOf.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import java.util.LinkedHashMap; import java.util.Map; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/AnyOf.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/AnyOf.java similarity index 99% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/AnyOf.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/AnyOf.java index 797cdcfc5..7a52c6b68 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/AnyOf.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/AnyOf.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import java.util.LinkedHashMap; import java.util.Map; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Bar.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Bar.java similarity index 99% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Bar.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Bar.java index 33bbf6e19..b08fd7d21 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Bar.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Bar.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import java.util.LinkedHashMap; import java.util.Map; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Cola.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Cola.java similarity index 99% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Cola.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Cola.java index 5f4f95861..e5065f83b 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Cola.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Cola.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import java.util.LinkedHashMap; import java.util.Map; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/ColaBarCode.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/ColaBarCode.java similarity index 95% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/ColaBarCode.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/ColaBarCode.java index 967a74c58..1643ab004 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/ColaBarCode.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/ColaBarCode.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import javax.annotation.Nonnull; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/ColaLogo.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/ColaLogo.java similarity index 96% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/ColaLogo.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/ColaLogo.java index 72ea29bbd..c757ceca1 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/ColaLogo.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/ColaLogo.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import java.util.List; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Fanta.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Fanta.java similarity index 99% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Fanta.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Fanta.java index 27d1ac103..10ec15000 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Fanta.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Fanta.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import java.util.LinkedHashMap; import java.util.Map; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/FantaFlavor.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/FantaFlavor.java similarity index 97% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/FantaFlavor.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/FantaFlavor.java index d295a9cca..41738c868 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/FantaFlavor.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/FantaFlavor.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import java.util.List; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/FlavorType.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/FlavorType.java similarity index 98% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/FlavorType.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/FlavorType.java index 67e1ab5d7..22c389044 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/FlavorType.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/FlavorType.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import java.util.LinkedHashMap; import java.util.Map; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Foo.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Foo.java similarity index 99% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Foo.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Foo.java index 68a350cf7..1b07e9411 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Foo.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Foo.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import java.util.LinkedHashMap; import java.util.Map; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOf.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/OneOf.java similarity index 90% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOf.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/OneOf.java index 177f45b3d..08460550c 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOf.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/OneOf.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithDiscriminator.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/OneOfWithDiscriminator.java similarity index 92% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithDiscriminator.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/OneOfWithDiscriminator.java index 781c5501f..c360e6957 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithDiscriminator.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/OneOfWithDiscriminator.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithDiscriminatorAndMapping.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/OneOfWithDiscriminatorAndMapping.java similarity index 92% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithDiscriminatorAndMapping.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/OneOfWithDiscriminatorAndMapping.java index 459ac2c5c..b5bd9540f 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithDiscriminatorAndMapping.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/OneOfWithDiscriminatorAndMapping.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithEnumDiscriminator.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/OneOfWithEnumDiscriminator.java similarity index 92% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithEnumDiscriminator.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/OneOfWithEnumDiscriminator.java index 0152e120e..60c6bafc6 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OneOfWithEnumDiscriminator.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/OneOfWithEnumDiscriminator.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Order.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Order.java similarity index 99% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Order.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Order.java index cc37812ee..722bfd26a 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Order.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Order.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import java.util.LinkedHashMap; import java.util.Map; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OrderWithTimestamp.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/OrderWithTimestamp.java similarity index 99% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OrderWithTimestamp.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/OrderWithTimestamp.java index 9a24b5710..7a37e6995 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/OrderWithTimestamp.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/OrderWithTimestamp.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import java.time.OffsetDateTime; import java.util.LinkedHashMap; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Soda.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Soda.java similarity index 99% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Soda.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Soda.java index dfaa4d01d..d114bfac9 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/Soda.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/Soda.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import java.util.LinkedHashMap; import java.util.Map; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/SodaWithId.java b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/SodaWithId.java similarity index 99% rename from datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/SodaWithId.java rename to datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/SodaWithId.java index c7763d4a9..3bac8d0f2 100644 --- a/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sample/model/SodaWithId.java +++ b/datamodel/openapi/openapi-api-apache-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/apache/sodastore/model/SodaWithId.java @@ -13,7 +13,7 @@ * Do not edit the class manually. */ -package com.sap.cloud.sdk.datamodel.openapi.apache.sample.model; +package com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model; import java.util.LinkedHashMap; import java.util.Map; diff --git a/datamodel/openapi/openapi-api-apache-sample/src/test/java/com/sap/cloud/sdk/services/openapi/apache/DeserializationTest.java b/datamodel/openapi/openapi-api-apache-sample/src/test/java/com/sap/cloud/sdk/services/openapi/apache/DeserializationTest.java new file mode 100644 index 000000000..cfd345dc4 --- /dev/null +++ b/datamodel/openapi/openapi-api-apache-sample/src/test/java/com/sap/cloud/sdk/services/openapi/apache/DeserializationTest.java @@ -0,0 +1,144 @@ +package com.sap.cloud.sdk.services.openapi.apache; + +import static com.github.tomakehurst.wiremock.client.WireMock.okJson; +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; +import java.util.Map; + +import org.assertj.core.api.InstanceOfAssertFactories; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.github.tomakehurst.wiremock.client.WireMock; +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; +import com.github.tomakehurst.wiremock.junit5.WireMockTest; +import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.api.SodasApi; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.SodaWithId; + +@WireMockTest +class DeserializationTest +{ + + private SodasApi sut; + private String responseBody; + + @BeforeEach + void setUp( WireMockRuntimeInfo wmRuntimeInfo ) + { + sut = new SodasApi(DefaultHttpDestination.builder(wmRuntimeInfo.getHttpBaseUrl()).build()); + } + + @Test + void testFullResponse() + { + responseBody = """ + { + "name": "Cola", + "brand": "Coca-Cola", + "quantity": 100, + "packaging" : "new-value", + "price": 1.5, + "id": 0 + } + """; + stub(responseBody); + + final SodaWithId expected = + SodaWithId + .create() + .name("Cola") + .brand("Coca-Cola") + .quantity(100) + .price(1.5f) + .id(0L) + .packaging(SodaWithId.PackagingEnum.UNKNOWN_DEFAULT_OPEN_API); + + final SodaWithId actual = sut.sodasIdGet(1L); + + assertThat(actual).isEqualTo(expected); + } + + @Test + void testUnexpectedFieldOrder() + { + responseBody = """ + { + "name": "Cola", + "price": 1.5, + "id": 0, + "brand": "Coca-Cola", + "quantity": 100 + } + """; + stub(responseBody); + + final SodaWithId expected = + SodaWithId.create().name("Cola").brand("Coca-Cola").quantity(100).price(1.5f).id(0L); + + final SodaWithId actual = sut.sodasIdGet(1L); + + assertThat(actual).isEqualTo(expected); + } + + @Test + void testPartialResponse() + { + responseBody = "{\"name\": \"Cola\"}"; + stub(responseBody); + + final SodaWithId expected = SodaWithId.create().name("Cola").brand(null).quantity(null).price(null); + + final SodaWithId actual = sut.sodasIdGet(1L); + + assertThat(actual).isEqualTo(expected); + } + + @Test + @SuppressWarnings( "deprecation" ) + void testUnexpectedAdditionalField() + { + responseBody = """ + { + "name": "Cola", + "unexpectedField": [] + } + """; + stub(responseBody); + + final SodaWithId actual = sut.sodasIdGet(1L); + + assertThat(actual.getName()).isEqualTo("Cola"); + assertThat(actual.toMap()) + .containsExactlyInAnyOrderEntriesOf(Map.of("name", "Cola", "unexpectedField", List.of())); + assertThat(actual.toMap().get("doesNotExist")).isNull(); + assertThat(actual.getCustomFieldNames()).containsExactly("unexpectedField"); + assertThat(actual.getCustomField("unexpectedField")).asInstanceOf(InstanceOfAssertFactories.LIST).isEmpty(); + } + + @Test + void testBinaryResponse() + { + final byte[] binaryData = "binary file content".getBytes(); + WireMock + .stubFor( + WireMock + .get(WireMock.urlMatching("/sodas/download/\\d+")) + .willReturn( + WireMock + .aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/octet-stream") + .withBody(binaryData))); + //TODO: support byte[] for files? Do via review + // final byte[] result = sut.sodasDownloadIdGet(1L); + // assertThat(result).isNotNull(); + // assertThat(result).isEqualTo(binaryData); + } + + private void stub( String responseBody ) + { + WireMock.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(okJson(responseBody))); + } +} diff --git a/datamodel/openapi/openapi-api-apache-sample/src/test/java/com/sap/cloud/sdk/services/openapi/apache/OneOfDeserializationTest.java b/datamodel/openapi/openapi-api-apache-sample/src/test/java/com/sap/cloud/sdk/services/openapi/apache/OneOfDeserializationTest.java new file mode 100644 index 000000000..fb48b5b15 --- /dev/null +++ b/datamodel/openapi/openapi-api-apache-sample/src/test/java/com/sap/cloud/sdk/services/openapi/apache/OneOfDeserializationTest.java @@ -0,0 +1,316 @@ +package com.sap.cloud.sdk.services.openapi.apache; + +import static com.fasterxml.jackson.annotation.PropertyAccessor.GETTER; +import static com.fasterxml.jackson.annotation.PropertyAccessor.SETTER; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.util.List; +import java.util.stream.Stream; + +import javax.annotation.Nonnull; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.AllOf; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.AnyOf; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.Bar; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.Cola; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.ColaBarCode; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.ColaLogo; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.Fanta; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.FantaFlavor; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.FlavorType; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.Foo; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.OneOf; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.OneOfWithDiscriminator; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.OneOfWithDiscriminatorAndMapping; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.OneOfWithEnumDiscriminator; + +class OneOfDeserializationTest +{ + private static final ObjectMapper objectMapper = newDefaultObjectMapper(); + + private static final Cola COLA_OBJECT = Cola.create().caffeine(true).sodaType("Cola"); + private static final Fanta FANTA_OBJECT = + Fanta + .create() + .color("orange") + .sodaType("Fanta") + .flavor(new FantaFlavor.InnerFlavorType(FlavorType.create().intensity(3).nuance("wood"))); + private static final String COLA_JSON = """ + { + "sodaType": "Cola", + "caffeine": true + }"""; + private static final String FANTA_JSON = """ + { + "sodaType": "Fanta", + "color": "orange", + "flavor": {"intensity":3,"nuance":"wood"} + }"""; + private static final String FANTA_FLAVOR_ARRAY_JSON = """ + { + "sodaType": "Fanta", + "color": "orange", + "flavor": [ + {"intensity":3,"nuance":"wood"}, + {"intensity":5,"nuance":"citrus"} + ] + }"""; + private static final String COLA_LOGO_MATRIX_JSON = """ + { + "sodaType": "Cola", + "caffeine": true, + "logo": [[255, 0, 0], [0, 255, 0], [0, 0, 255]] + }"""; + private static final String UNKNOWN_JSON = """ + { + "sodaType": "Sprite", + "someProperty": "someValue" + }"""; + + private static final String COLA_BARCODE_FLOAT_ARRAY_JSON = """ + { + "sodaType": "Cola", + "caffeine": true, + "barCode": [1.1, 2.2, 3.3] + }"""; + + @Test + void oneOf() + throws JsonProcessingException + { + var actual = objectMapper.readValue(COLA_JSON, OneOf.class); + assertThat(actual) + .describedAs("Object should automatically be deserialized as Cola with JSON subtype deduction") + .isInstanceOf(Cola.class) + .isEqualTo(COLA_OBJECT); + + actual = objectMapper.readValue(FANTA_JSON, OneOf.class); + assertThat(actual) + .describedAs("Object should automatically be deserialized as Fanta with JSON subtype deduction") + .isInstanceOf(Fanta.class) + .isEqualTo(FANTA_OBJECT); + + assertThatThrownBy(() -> objectMapper.readValue(UNKNOWN_JSON, OneOf.class)) + .isInstanceOf(JsonProcessingException.class); + } + + @Test + void oneOfWithDiscriminator() + throws JsonProcessingException + { + var actual = objectMapper.readValue(COLA_JSON, OneOfWithDiscriminator.class); + assertThat(actual) + .describedAs( + "Object should automatically be deserialized as Cola using the class names as discriminator mapping values") + .isInstanceOf(Cola.class) + .isEqualTo(COLA_OBJECT); + + actual = objectMapper.readValue(FANTA_JSON, OneOfWithDiscriminator.class); + assertThat(actual) + .describedAs( + "Object should automatically be deserialized as Fanta using the class names as discriminator mapping values") + .isInstanceOf(Fanta.class) + .isEqualTo(FANTA_OBJECT); + + assertThatThrownBy(() -> objectMapper.readValue(UNKNOWN_JSON, OneOfWithDiscriminator.class)) + .isInstanceOf(JsonProcessingException.class); + } + + @Test + void oneOfWithDiscriminatorAndMapping() + throws JsonProcessingException + { + var jsonWithCustomMapping = """ + { + "sodaType": "cool_cola", + "caffeine": true + }"""; + var actual = objectMapper.readValue(jsonWithCustomMapping, OneOfWithDiscriminatorAndMapping.class); + assertThat(actual) + .describedAs( + "Object should automatically be deserialized as Cola using the explicit discriminator mapping values") + .isInstanceOf(Cola.class) + .isEqualTo(Cola.create().caffeine(true).sodaType("cool_cola")); + + jsonWithCustomMapping = """ + { + "sodaType": "fancy_fanta", + "color": "orange" + }"""; + actual = objectMapper.readValue(jsonWithCustomMapping, OneOfWithDiscriminatorAndMapping.class); + assertThat(actual) + .describedAs( + "Object should automatically be deserialized as Fanta using the explicit discriminator mapping values") + .isInstanceOf(Fanta.class) + .isEqualTo(Fanta.create().color("orange").sodaType("fancy_fanta")); + + assertThatThrownBy(() -> objectMapper.readValue(UNKNOWN_JSON, OneOfWithDiscriminatorAndMapping.class)) + .isInstanceOf(JsonProcessingException.class); + } + + static Stream> oneOfStrategiesProvider() + { + return Stream.of(OneOf.class, OneOfWithDiscriminator.class); + } + + @ParameterizedTest( name = "Deserialization with strategy: {0}" ) + @MethodSource( "oneOfStrategiesProvider" ) + void oneOfWithNestedArrayOfObjects( Class strategy ) + throws JsonProcessingException + { + var payload = FANTA_FLAVOR_ARRAY_JSON; + if( strategy == OneOfWithDiscriminatorAndMapping.class ) { + payload.replace("Fanta", "fancy_fanta").replace("Cola", "cool_cola"); + } + + Object actual = objectMapper.readValue(payload, strategy); + + assertThat(actual) + .describedAs("Object should automatically be deserialized as Fanta with JSON subtype deduction") + .isInstanceOf(Fanta.class); + var fanta = (Fanta) actual; + assertThat(fanta.getFlavor()) + .describedAs("Flavor should be deserialized as wrapper class for a list of FlavorType instances") + .isInstanceOf(FantaFlavor.ListOfFlavorTypes.class); + var flavorTypes = (FantaFlavor.ListOfFlavorTypes) fanta.getFlavor(); + assertThat(flavorTypes.values()) + .describedAs("Flavor should be deserialized as a list of FlavorType instances") + .isNotEmpty() + .allMatch(FlavorType.class::isInstance); + + actual = objectMapper.readValue(COLA_LOGO_MATRIX_JSON, strategy); + + assertThat(actual) + .describedAs("Object should automatically be deserialized as Cola with JSON subtype deduction") + .isInstanceOf(Cola.class); + var cola = (Cola) actual; + assertThat(cola.isCaffeine()).isTrue(); + assertThat(cola.getLogo()).isInstanceOf(ColaLogo.ListOfListOfIntegers.class); + var logo = (ColaLogo.ListOfListOfIntegers) cola.getLogo(); + assertThat(logo.values()) + .describedAs("Logo should be deserialized as a list of list of integers") + .isInstanceOf(List.class) + .containsExactly(List.of(255, 0, 0), List.of(0, 255, 0), List.of(0, 0, 255)); + + actual = objectMapper.readValue(COLA_BARCODE_FLOAT_ARRAY_JSON, strategy); + assertThat(actual) + .describedAs("Object should automatically be deserialized as Cola with JSON subtype deduction") + .isInstanceOf(Cola.class); + cola = (Cola) actual; + assertThat(cola.isCaffeine()).isTrue(); + assertThat(cola.getBarCode()).isInstanceOf(ColaBarCode.ArrayOfFloats.class); + var barCode = (ColaBarCode.ArrayOfFloats) cola.getBarCode(); + assertThat(barCode.values()) + .describedAs("BarCode should be deserialized as an array of floats") + .isInstanceOf(float[].class) + .containsExactly(1.1f, 2.2f, 3.3f); + } + + @Test + void anyOf() + throws JsonProcessingException + { + AnyOf anyOfCola = objectMapper.readValue(COLA_JSON, AnyOf.class); + assertThat(anyOfCola.getSodaType()).isEqualTo("Cola"); + assertThat(anyOfCola.isCaffeine()).isTrue(); + assertThat(anyOfCola.getColor()).isNull(); + + AnyOf anyOfFanta = objectMapper.readValue(FANTA_JSON, AnyOf.class); + assertThat(anyOfFanta.getSodaType()).isEqualTo("Fanta"); + assertThat(anyOfFanta.getColor()).isEqualTo("orange"); + assertThat(anyOfFanta.isCaffeine()).isNull(); + + AnyOf actual = objectMapper.readValue(FANTA_FLAVOR_ARRAY_JSON, AnyOf.class); + + assertThat(actual.getSodaType()).isEqualTo("Fanta"); + assertThat(actual.getColor()).isEqualTo("orange"); + assertThat(actual.getFlavor()).isInstanceOf(FantaFlavor.ListOfFlavorTypes.class); + assertThat(((FantaFlavor.ListOfFlavorTypes) actual.getFlavor()).values()) + .allMatch(FlavorType.class::isInstance); + } + + @Test + void allOf() + throws JsonProcessingException + { + AllOf allOfCola = objectMapper.readValue(COLA_JSON, AllOf.class); + assertThat(allOfCola.getSodaType()).isEqualTo("Cola"); + assertThat(allOfCola.isCaffeine()).isTrue(); + assertThat(allOfCola.getColor()).isNull(); + + AllOf allOfFanta = objectMapper.readValue(FANTA_JSON, AllOf.class); + assertThat(allOfFanta.getSodaType()).isEqualTo("Fanta"); + assertThat(allOfFanta.getColor()).isEqualTo("orange"); + assertThat(allOfFanta.isCaffeine()).isNull(); + } + + @Test + void testColaSerialization() + throws JsonProcessingException + { + var expected = objectMapper.readValue(COLA_JSON, JsonNode.class); + var actual = objectMapper.valueToTree(expected); + + assertThat(actual).isEqualTo(expected); + } + + @Test + void testFantaSerialization() + throws JsonProcessingException + { + var expected = objectMapper.readValue(FANTA_JSON, JsonNode.class); + var actual = objectMapper.valueToTree(expected); + + assertThat(actual).isEqualTo(expected); + } + + @Test + void testDeserializationWithEnumDiscriminator() + throws JsonProcessingException + { + var json = """ + { + "foo": "asdf", + "disc": "disc_foo" + }"""; + assertThat(objectMapper.readValue(json, OneOfWithEnumDiscriminator.class)) + .isInstanceOf(Foo.class) + .isEqualTo(Foo.create().foo("asdf").disc(Foo.DiscEnum.DISC_FOO)); + json = """ + { + "bar": "asdf", + "disc": "disc_bar" + }"""; + assertThat(objectMapper.readValue(json, OneOfWithEnumDiscriminator.class)) + .isInstanceOf(Bar.class) + .isEqualTo(Bar.create().bar("asdf").disc(Bar.DiscEnum.DISC_BAR)); + + assertThatThrownBy(() -> objectMapper.readValue("{ \"type\": \"unknown\" }", OneOfWithEnumDiscriminator.class)) + .isInstanceOf(JsonProcessingException.class); + } + + /** + * Taken from {@link com.sap.cloud.sdk.services.openapi.apiclient.ApiClient} + */ + @Nonnull + private static ObjectMapper newDefaultObjectMapper() + { + return JsonMapper + .builder() + .addModule(new JavaTimeModule()) + .visibility(GETTER, JsonAutoDetect.Visibility.NONE) + .visibility(SETTER, JsonAutoDetect.Visibility.NONE) + .build(); + } +} diff --git a/datamodel/openapi/openapi-api-apache-sample/src/test/java/com/sap/cloud/sdk/services/openapi/apache/SerializationTest.java b/datamodel/openapi/openapi-api-apache-sample/src/test/java/com/sap/cloud/sdk/services/openapi/apache/SerializationTest.java new file mode 100644 index 000000000..ce00661a0 --- /dev/null +++ b/datamodel/openapi/openapi-api-apache-sample/src/test/java/com/sap/cloud/sdk/services/openapi/apache/SerializationTest.java @@ -0,0 +1,112 @@ +package com.sap.cloud.sdk.services.openapi.apache; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.tomakehurst.wiremock.client.WireMock; +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; +import com.github.tomakehurst.wiremock.junit5.WireMockTest; +import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.api.SodasApi; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.Order; +import com.sap.cloud.sdk.datamodel.openapi.apache.sodastore.model.SodaWithId; + +@WireMockTest +class SerializationTest +{ + + private SodasApi sut; + private String expected; + + @BeforeEach + void setUp( WireMockRuntimeInfo wmRuntimeInfo ) + { + sut = new SodasApi(DefaultHttpDestination.builder(wmRuntimeInfo.getHttpBaseUrl()).build()); + WireMock.stubFor(WireMock.put("/sodas").willReturn(WireMock.created())); + } + + @Test + void testPutPayload() + { + // TODO: discuss whether to ignore null on serialization? Do via review + expected = """ + { + "name": "Cola", + "brand": "Coca-Cola", + "quantity": 100, + "packaging" : null, + "price": 1.5, + "id": 0 + } + """; + + final SodaWithId obj = SodaWithId.create().name("Cola").brand("Coca-Cola").quantity(100).price(1.5f).id(0L); + + sut.sodasPut(obj); + + verify(expected); + } + + @Test + void testJacksonSerializeSodaWithId() + throws JsonProcessingException + { + expected = """ + { + "name": "Cola", + "brand": "Coca-Cola", + "quantity": 100, + "packaging" : "can", + "price": 1.5, + "id": 0 + } + """; + + final SodaWithId obj = + SodaWithId + .create() + .name("Cola") + .brand("Coca-Cola") + .quantity(100) + .price(1.5f) + .id(0L) + .packaging(SodaWithId.PackagingEnum.CAN); + + assertThat(new ObjectMapper().writeValueAsString(obj)).isEqualToIgnoringWhitespace(expected); + } + + @Test + void testJacksonSerializeOrder() + throws JsonProcessingException + { + expected = """ + { + "productId": 100, + "quantity": 5, + "totalPrice": 6.0, + "typelessProperty":null, + "nullableProperty":null, + "shoesize": 44 + } + """; + final Order order = Order.create().productId(100L).quantity(5).totalPrice(6.0f); + order.setCustomField("shoesize", 44); + assertThat(new ObjectMapper().writeValueAsString(order)).isEqualToIgnoringWhitespace(expected); + assertThat(new ObjectMapper().readValue(expected, Order.class)).isEqualTo(order); + } + + private void verify( String requestBody ) + { + WireMock + .verify( + WireMock + .putRequestedFor(WireMock.urlEqualTo("/sodas")) + .withHeader("Content-Type", WireMock.equalTo("application/json; charset=UTF-8")) + .withRequestBody(WireMock.equalToJson(requestBody))); + } + +} diff --git a/datamodel/openapi/openapi-core/pom.xml b/datamodel/openapi/openapi-core/pom.xml index ce7787da4..5c43b2765 100644 --- a/datamodel/openapi/openapi-core/pom.xml +++ b/datamodel/openapi/openapi-core/pom.xml @@ -105,7 +105,12 @@ org.apache.httpcomponents.core5 httpcore5 - + + org.junit.jupiter + junit-jupiter-params + test + + diff --git a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ApiClient.java b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ApiClient.java index c4f1506f1..f27cee8de 100644 --- a/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ApiClient.java +++ b/datamodel/openapi/openapi-core/src/main/java/com/sap/cloud/sdk/services/openapi/apache/ApiClient.java @@ -47,7 +47,6 @@ import org.apache.hc.core5.http.message.BasicNameValuePair; import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; @@ -145,8 +144,6 @@ private static ObjectMapper createDefaultObjectMapper() .defaultDateFormat(new RFC3339DateFormat()) .visibility(PropertyAccessor.GETTER, Visibility.NONE) .visibility(PropertyAccessor.SETTER, Visibility.NONE) - .defaultPropertyInclusion( - JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.NON_NULL)) .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .disable(MapperFeature.DEFAULT_VIEW_INCLUSION) .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) diff --git a/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/apiclient/ApacheApiClientViaConstructorTest.java b/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/apiclient/ApacheApiClientViaConstructorTest.java new file mode 100644 index 000000000..604e6467f --- /dev/null +++ b/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/apiclient/ApacheApiClientViaConstructorTest.java @@ -0,0 +1,194 @@ +package com.sap.cloud.sdk.services.openapi.apiclient; + +import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor; +import static com.github.tomakehurst.wiremock.client.WireMock.ok; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.verify; +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; +import java.util.Map; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.type.TypeReference; +import com.github.tomakehurst.wiremock.client.WireMock; +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; +import com.github.tomakehurst.wiremock.junit5.WireMockTest; +import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5FactoryBuilder; +import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5FactoryBuilder.TlsUpgrade; +import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination; +import com.sap.cloud.sdk.services.openapi.apache.ApiClient; +import com.sap.cloud.sdk.services.openapi.apache.BaseApi; +import com.sap.cloud.sdk.services.openapi.apache.Pair; + +import jdk.jfr.Description; + +@WireMockTest +class ApacheApiClientViaConstructorTest +{ + + private static final String RELATIVE_PATH = "/apiEndpoint"; + private static final String SUCCESS_BODY = "success"; + private static final String BASE_PATH = "http://localhost:8080"; + + @Test + @Description( "Verify ApiClient's ObjectMapper ignores getters to avoid duplicate JSON properties." ) + void testApiClientDefaultObjectMapperIgnoresGetters( WireMockRuntimeInfo wm ) + { + final String baseUrl = wm.getHttpBaseUrl(); + final String requestBody = "{\"Return\":\"Hello, World!\"}"; + WireMock + .stubFor( + post(urlEqualTo(RELATIVE_PATH)) + .withRequestBody(equalTo(requestBody)) + .willReturn(ok().withHeader("Content-Type", "text/plain").withBody(SUCCESS_BODY))); + + final MyDto myTestDto = new MyDto(); + myTestDto.setReturn("Hello, World!"); + + final var apiClient = ApiClient.create().withBasePath(baseUrl); + final var testApi = new MyTestApacheOpenApiService(apiClient, baseUrl); + testApi.invokeApiEndpoint(myTestDto); + + WireMock.verify(1, postRequestedFor(urlEqualTo(RELATIVE_PATH)).withRequestBody(equalTo(requestBody))); + } + + @Test + void testApiClientWithQueryParams( WireMockRuntimeInfo wm ) + { + final String baseUrl = wm.getHttpBaseUrl(); + final String filterQueryValue = "emails.value eq \"my.email@test.com\""; + final String filterQueryParam = "filter"; + + List queryParams = ApiClient.parameterToPair(filterQueryParam, filterQueryValue); + + WireMock + .stubFor( + get(urlPathEqualTo(RELATIVE_PATH)) + .withQueryParam(filterQueryParam, equalTo(filterQueryValue)) + .willReturn(ok().withHeader("Content-Type", "text/plain").withBody(SUCCESS_BODY))); + + final var apiClient = ApiClient.create().withBasePath(baseUrl); + final var testApi = new MyTestApacheOpenApiService(apiClient, baseUrl); + testApi.invokeApiEndpoint("GET", null, queryParams); + + WireMock + .verify( + 1, + getRequestedFor(urlPathEqualTo(RELATIVE_PATH)) + .withQueryParam(filterQueryParam, equalTo(filterQueryValue))); + } + + @Test + @Description( "Verify that the TlsUpgrade configuration is transmitted in HTTP requests." ) + void testHttpRequestConfigIsTransmitted( WireMockRuntimeInfo wm ) + { + httpRequest(TlsUpgrade.DISABLED, wm.getHttpBaseUrl()); + verify(getRequestedFor(anyUrl()).withoutHeader("Upgrade")); + + httpRequest(TlsUpgrade.AUTOMATIC, wm.getHttpBaseUrl()); + verify(getRequestedFor(anyUrl()).withoutHeader("Upgrade")); + } + + private static void httpRequest( TlsUpgrade toggle, String url ) + { + var httpClientFactory = new ApacheHttpClient5FactoryBuilder().tlsUpgrade(toggle).build(); + var httpClient = httpClientFactory.createHttpClient(DefaultHttpDestination.builder(url).build()); + var apiClient = ApiClient.fromHttpClient((CloseableHttpClient) httpClient); + apiClient = apiClient.withBasePath(url); + + stubFor(get(anyUrl()).willReturn(ok().withHeader("Content-Type", "text/plain").withBody(SUCCESS_BODY))); + + assertThat( + apiClient + .invokeAPI( + RELATIVE_PATH, + "GET", + null, + null, + "", + null, + Map.of(), + Map.of(), + "text/plain", + "text/plain", + new TypeReference() + { + })) + .isEqualTo(SUCCESS_BODY); + } + + private static class MyDto + { + @JsonProperty( "Return" ) + private String _return; + + public String getReturn() + { + return _return; + } + + public void setReturn( String _return ) + { + this._return = _return; + } + } + + private static class MyTestApacheOpenApiService extends BaseApi + { + private final String expectedBasePath; + + MyTestApacheOpenApiService( + @Nonnull final com.sap.cloud.sdk.services.openapi.apache.ApiClient apiClient, + String expectedBasePath ) + { + super(apiClient); + this.expectedBasePath = expectedBasePath; + } + + void invokeApiEndpoint( @Nullable Object body ) + { + invokeApiEndpoint("POST", body, null); + } + + //make it apache reliant + void invokeApiEndpoint( String method, @Nullable Object body, @Nullable List queryParams ) + { + assertThat(apiClient.getBasePath()).isEqualTo(expectedBasePath); + + final TypeReference returnType = new TypeReference() + { + }; + + final String s = + apiClient + .invokeAPI( + RELATIVE_PATH, + method, + queryParams, + null, + "", + body, + Map.of(), + Map.of(), + "application/json", + "application/json", + returnType); + + assertThat(s).isEqualTo(SUCCESS_BODY); + } + } +} diff --git a/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/apiclient/ApiClientExtensionsDeserializationTest.java b/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/apiclient/ApiClientExtensionsDeserializationTest.java index 599ce214c..e4e27e010 100644 --- a/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/apiclient/ApiClientExtensionsDeserializationTest.java +++ b/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/apiclient/ApiClientExtensionsDeserializationTest.java @@ -5,12 +5,14 @@ import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; +import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; +import java.util.StringJoiner; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -31,17 +33,57 @@ import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.type.TypeReference; +import com.github.tomakehurst.wiremock.client.WireMock; +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; +import com.github.tomakehurst.wiremock.junit5.WireMockTest; +import com.sap.cloud.sdk.services.openapi.apache.BaseApi; +import com.sap.cloud.sdk.services.openapi.apache.Pair; import com.sap.cloud.sdk.services.openapi.core.AbstractOpenApiService; +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +import jdk.jfr.Description; import lombok.Getter; import lombok.Setter; +@WireMockTest class ApiClientExtensionsDeserializationTest { @Nonnull private static final String BASE_PATH = "http://localhost:8080"; @Nonnull private static final String RELATIVE_PATH = "/outer"; + @Nonnull + private static final String RESPONSE = """ + { + "message": "Hello from the outer level.", + "code": 1337, + "inner": { + "message": "Hello from the inner level.", + "code": 7331, + "innerComplexExtension": { + "innerString": "inner", + "innerInteger": 24 + }, + "innerListExtension": [ + "oof", + "rab", + "zab" + ], + "innerPrimitiveExtension": "additionalInnerValue" + }, + "outerComplexExtension": { + "outerString": "outer", + "outerInteger": 42 + }, + "outerListExtension": [ + "foo", + "bar", + "baz" + ], + "outerPrimitiveExtension": "additionalOuterValue" + } + """; @Test void testDeserializeResponseWithNestedExtensions() @@ -53,42 +95,33 @@ void testDeserializeResponseWithNestedExtensions() server .expect(ExpectedCount.once(), requestTo(BASE_PATH + RELATIVE_PATH)) .andExpect(method(HttpMethod.GET)) - .andRespond(MockRestResponseCreators.withSuccess(""" - { - "message": "Hello from the outer level.", - "code": 1337, - "inner": { - "message": "Hello from the inner level.", - "code": 7331, - "innerComplexExtension": { - "innerString": "inner", - "innerInteger": 24 - }, - "innerListExtension": [ - "oof", - "rab", - "zab" - ], - "innerPrimitiveExtension": "additionalInnerValue" - }, - "outerComplexExtension": { - "outerString": "outer", - "outerInteger": 42 - }, - "outerListExtension": [ - "foo", - "bar", - "baz" - ], - "outerPrimitiveExtension": "additionalOuterValue" - } - """, MediaType.APPLICATION_JSON)); - - final TestApi api = new TestApi(apiClient); + .andRespond(MockRestResponseCreators.withSuccess(RESPONSE, MediaType.APPLICATION_JSON)); + + final TestSpringApi api = new TestSpringApi(apiClient); final Outer result = api.getOuter(); server.verify(); + assertResult(result); + } + + @Test + @Description( "Tests deserialization of responses with nested extensions using the Apache HTTP client based ApiClient." ) + void testDeserializeResponseWithNestedExtensionsApache( WireMockRuntimeInfo wmInfo ) + { + + WireMock.stubFor(WireMock.get(WireMock.urlEqualTo(RELATIVE_PATH)).willReturn(WireMock.okJson(RESPONSE))); + final var apiClient = + com.sap.cloud.sdk.services.openapi.apache.ApiClient.create().withBasePath(wmInfo.getHttpBaseUrl()); + + final TestApacheApi api = new TestApacheApi(apiClient); + final Outer result = api.getOuter(); + + WireMock.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo(RELATIVE_PATH))); + assertResult(result); + } + private static void assertResult( Outer result ) + { assertThat(result.getMessage()).isEqualTo("Hello from the outer level."); assertThat(result.getCode()).isEqualTo(1337); assertThat(result.getCustomFieldNames()) @@ -128,9 +161,61 @@ void testDeserializeResponseWithNestedExtensions() }); } - private static class TestApi extends AbstractOpenApiService + private static class TestApacheApi extends BaseApi + { + public TestApacheApi( final com.sap.cloud.sdk.services.openapi.apache.ApiClient apiClient ) + { + super(apiClient); + } + + @Nonnull + public Outer getOuter() + throws OpenApiRequestException + { + final Object localVarPostBody = null; + + // create path and map variables + final String localVarPath = RELATIVE_PATH; + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + final String[] localVarAccepts = { "application/json" }; + final String localVarAccept = + com.sap.cloud.sdk.services.openapi.apache.ApiClient.selectHeaderAccept(localVarAccepts); + + final String[] localVarContentTypes = { + + }; + final String localVarContentType = + com.sap.cloud.sdk.services.openapi.apache.ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() + { + }; + return apiClient + .invokeAPI( + localVarPath, + "GET", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType); + } + } + + private static class TestSpringApi extends AbstractOpenApiService { - public TestApi( final ApiClient apiClient ) + public TestSpringApi( final ApiClient apiClient ) { super(apiClient); } diff --git a/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/apiclient/ApiClientFromDestinationTest.java b/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/apiclient/ApiClientFromDestinationTest.java index faa905633..6ebd2a7c8 100644 --- a/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/apiclient/ApiClientFromDestinationTest.java +++ b/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/apiclient/ApiClientFromDestinationTest.java @@ -24,9 +24,12 @@ void testServiceInvocation() { final HttpDestination testDestination = DefaultHttpDestination.builder(SERVER.baseUrl()).build(); - final MyTestAbstractOpenApiService service = new MyTestAbstractOpenApiService(testDestination); + final MyTestAbstractOpenApiService springService = new MyTestAbstractOpenApiService(testDestination); + final MyTestAbstractApacheOpenApiService apacheService = + new MyTestAbstractApacheOpenApiService(testDestination); - service.foo(); + springService.foo(); + apacheService.foo(); } @Test @@ -34,9 +37,13 @@ void testExceptionIsThrown() { final HttpDestination testDestination = DefaultHttpDestination.builder(SERVER.baseUrl()).build(); - final MyExceptionThrowingServiceAbstract service = new MyExceptionThrowingServiceAbstract(testDestination); + final MyExceptionThrowingServiceAbstract springService = + new MyExceptionThrowingServiceAbstract(testDestination); + final MyExceptionThrowingApacheServiceAbstract apacheService = + new MyExceptionThrowingApacheServiceAbstract(testDestination); - assertThatExceptionOfType(IllegalAccessException.class).isThrownBy(service::foo); + assertThatExceptionOfType(IllegalAccessException.class).isThrownBy(springService::foo); + assertThatExceptionOfType(IllegalAccessException.class).isThrownBy(apacheService::foo); } private class MyTestAbstractOpenApiService extends AbstractOpenApiService @@ -65,4 +72,33 @@ void foo() throw new IllegalAccessException("Something went horribly wrong"); } } + + private static class MyTestAbstractApacheOpenApiService extends com.sap.cloud.sdk.services.openapi.apache.BaseApi + { + public MyTestAbstractApacheOpenApiService( final Destination destination ) + { + super(destination); + } + + void foo() + { + assertThat(apiClient.getBasePath()).isEqualTo(SERVER.baseUrl()); + } + } + + private static class MyExceptionThrowingApacheServiceAbstract + extends + com.sap.cloud.sdk.services.openapi.apache.BaseApi + { + public MyExceptionThrowingApacheServiceAbstract( final Destination destination ) + { + super(destination); + } + + void foo() + throws IllegalAccessException + { + throw new IllegalAccessException("Something went horribly wrong"); + } + } } diff --git a/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/genericparameter/GenericParameterTest.java b/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/genericparameter/GenericParameterTest.java index f50df180f..035effa39 100644 --- a/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/genericparameter/GenericParameterTest.java +++ b/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/genericparameter/GenericParameterTest.java @@ -7,7 +7,11 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.verify; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.StringJoiner; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -25,6 +29,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonRawValue; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.tomakehurst.wiremock.client.WireMock; @@ -32,6 +37,9 @@ import com.github.tomakehurst.wiremock.junit5.WireMockTest; import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination; import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; +import com.sap.cloud.sdk.services.openapi.apache.ApiClient; +import com.sap.cloud.sdk.services.openapi.apache.BaseApi; +import com.sap.cloud.sdk.services.openapi.apache.Pair; import com.sap.cloud.sdk.services.openapi.core.AbstractOpenApiService; import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; @@ -41,23 +49,24 @@ @WireMockTest class GenericParameterTest { + final static String EXPECTED_BODY = """ + {\ + "id":"foo",\ + "fieldPopulatedAsStringWithAnnotation":{"foo": "bar"},\ + "fieldPopulatedAsStringWithoutAnnotation":"{\\"foo\\": \\"bar\\"}",\ + "fieldPopulatedAsJacksonJsonNode":{"foo":"bar"}\ + }\ + """; + @Test void testInvocationWithGenericParameter( @Nonnull final WireMockRuntimeInfo wm ) throws JsonProcessingException { - final String expectedBody = """ - {\ - "id":"foo",\ - "fieldPopulatedAsStringWithAnnotation":{"foo": "bar"},\ - "fieldPopulatedAsStringWithoutAnnotation":"{\\"foo\\": \\"bar\\"}",\ - "fieldPopulatedAsJacksonJsonNode":{"foo":"bar"}\ - }\ - """; WireMock .stubFor( post(urlEqualTo("/api")) - .withRequestBody(equalTo(expectedBody)) + .withRequestBody(equalTo(EXPECTED_BODY)) .willReturn(aResponse().withStatus(HttpStatus.SC_OK))); final DefaultHttpDestination httpDestination = DefaultHttpDestination.builder(wm.getHttpBaseUrl()).build(); @@ -67,16 +76,18 @@ void testInvocationWithGenericParameter( @Nonnull final WireMockRuntimeInfo wm ) //this is how you pass a JSON representation into a parameter of type Object final JsonNode jacksonJsonNode = new ObjectMapper().readTree(jsonString); - new TestApi(httpDestination) - .testMethod( - TestModelPOST - .builder() - .id("foo") - .fieldPopulatedAsStringWithAnnotation(jsonString) - .fieldPopulatedAsStringWithoutAnnotation(jsonString) - .fieldPopulatedAsJacksonJsonNode(jacksonJsonNode) - .build()); - verify(postRequestedFor(urlEqualTo("/api")).withRequestBody(equalTo(expectedBody))); + final TestModelPOST testModelPOST = + TestModelPOST + .builder() + .id("foo") + .fieldPopulatedAsStringWithAnnotation(jsonString) + .fieldPopulatedAsStringWithoutAnnotation(jsonString) + .fieldPopulatedAsJacksonJsonNode(jacksonJsonNode) + .build(); + + new TestSpringApi(httpDestination).testMethod(testModelPOST); + new TestApacheApi(httpDestination).testMethod(testModelPOST); + verify(2, postRequestedFor(urlEqualTo("/api")).withRequestBody(equalTo(EXPECTED_BODY))); } @Value @@ -97,9 +108,64 @@ private static class TestModelPOST Object fieldPopulatedAsJacksonJsonNode; } - private static class TestApi extends AbstractOpenApiService + private static class TestApacheApi extends BaseApi + { + public TestApacheApi( @Nonnull final Destination destination ) + { + super(destination); + } + + @Nullable + public TestModel testMethod( @Nonnull final TestModelPOST body ) + throws OpenApiRequestException + { + final Object localVarPostBody = body; + + // verify the required parameter 'pet' is set + if( body == null ) { + throw new OpenApiRequestException("Missing the required parameter 'pet' when calling addPet") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/api"; + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + final String[] localVarAccepts = { "application/json" }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + + final String[] localVarContentTypes = { "application/json" }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() + { + }; + return apiClient + .invokeAPI( + localVarPath, + "POST", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType); + } + + } + + private static class TestSpringApi extends AbstractOpenApiService { - public TestApi( @Nonnull final Destination httpDestination ) + public TestSpringApi( @Nonnull final Destination httpDestination ) { super(httpDestination); } diff --git a/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/genericreturntype/GenericReturnTypeTest.java b/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/genericreturntype/GenericReturnTypeTest.java index 0a7b3f87d..4d909438b 100644 --- a/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/genericreturntype/GenericReturnTypeTest.java +++ b/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/genericreturntype/GenericReturnTypeTest.java @@ -8,10 +8,15 @@ import java.util.LinkedHashMap; import java.util.List; +import java.util.function.Function; +import java.util.stream.Stream; import javax.annotation.Nonnull; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; import com.github.tomakehurst.wiremock.junit5.WireMockTest; @@ -42,16 +47,31 @@ @WireMockTest class GenericReturnTypeTest { - @Test - void testGenericAccessToNonNestedJsonObject( @Nonnull final WireMockRuntimeInfo wm ) + + HttpDestination httpDestination; + + @BeforeEach + void setUp( @Nonnull final WireMockRuntimeInfo wm ) { - final String responseBody = "{\"firstname\":\"John\",\"lastname\":\"Doe\"}"; + httpDestination = DefaultHttpDestination.builder(wm.getHttpBaseUrl()).build(); + } - final HttpDestination httpDestination = DefaultHttpDestination.builder(wm.getHttpBaseUrl()).build(); + static Stream provideContext() + { + return Stream + .of( + Arguments.of((Function) ( des ) -> new TestSpringApi(des).testMethod()), + Arguments.of((Function) ( des ) -> new TestApacheApi(des).testMethod())); + } + @MethodSource( "provideContext" ) + @ParameterizedTest + void testGenericAccessToNonNestedJsonObject( @Nonnull final Function contextFactory ) + { + final String responseBody = "{\"firstname\":\"John\",\"lastname\":\"Doe\"}"; stubFor(get(urlEqualTo("/endpoint")).willReturn(okJson(responseBody))); - final Object context = new TestApi(httpDestination).testMethod(); + final Object context = contextFactory.apply(httpDestination); @SuppressWarnings( "unchecked" ) final LinkedHashMap castedReturnObject = (LinkedHashMap) context; @@ -60,16 +80,15 @@ void testGenericAccessToNonNestedJsonObject( @Nonnull final WireMockRuntimeInfo assertThat(castedReturnObject.get("lastname")).isEqualTo("Doe"); } - @Test - void testGenericAccessToNestedJsonObject( @Nonnull final WireMockRuntimeInfo wm ) + @MethodSource( "provideContext" ) + @ParameterizedTest + void testGenericAccessToNestedJsonObject( @Nonnull final Function contextFactory ) { final String responseBody = "{" + "\"foo\": \"bar\"," + "\"bar\": {" + "\"foobar\": \"barfoo\"" + "}" + "}"; - final HttpDestination httpDestination = DefaultHttpDestination.builder(wm.getHttpBaseUrl()).build(); - stubFor(get(urlEqualTo("/endpoint")).willReturn(okJson(responseBody))); - final Object context = new TestApi(httpDestination).testMethod(); + final Object context = contextFactory.apply(httpDestination); @SuppressWarnings( "unchecked" ) final LinkedHashMap castedReturnObject = (LinkedHashMap) context; @@ -83,16 +102,15 @@ void testGenericAccessToNestedJsonObject( @Nonnull final WireMockRuntimeInfo wm assertThat(castedNestedReturnObject.get("foobar")).isEqualTo("barfoo"); } - @Test - void testGenericAccessToArray( @Nonnull final WireMockRuntimeInfo wm ) + @MethodSource( "provideContext" ) + @ParameterizedTest + void testGenericAccessToArray( @Nonnull final Function contextFactory ) { final String responseBody = "[\"foo\", \"bar\", \"foo\", \"bar\"]"; - final HttpDestination httpDestination = DefaultHttpDestination.builder(wm.getHttpBaseUrl()).build(); - stubFor(get(urlEqualTo("/endpoint")).willReturn(okJson(responseBody))); - final Object context = new TestApi(httpDestination).testMethod(); + final Object context = contextFactory.apply(httpDestination); @SuppressWarnings( "unchecked" ) final List castedReturnObject = (List) context; diff --git a/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/genericreturntype/TestApacheApi.java b/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/genericreturntype/TestApacheApi.java new file mode 100644 index 000000000..6e3f10aca --- /dev/null +++ b/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/genericreturntype/TestApacheApi.java @@ -0,0 +1,65 @@ +package com.sap.cloud.sdk.services.openapi.genericreturntype; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.StringJoiner; + +import javax.annotation.Nonnull; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; +import com.sap.cloud.sdk.services.openapi.apache.BaseApi; +import com.sap.cloud.sdk.services.openapi.apache.Pair; + +class TestApacheApi extends BaseApi +{ + + TestApacheApi( @Nonnull final Destination destination ) + { + super(destination); + } + + Object testMethod() + { + final Object localVarPostBody = null; + + // create path and map variables + final String localVarPath = "/endpoint"; + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + final String[] localVarAccepts = { "application/json" }; + final String localVarAccept = + com.sap.cloud.sdk.services.openapi.apache.ApiClient.selectHeaderAccept(localVarAccepts); + + final String[] localVarContentTypes = { + + }; + final String localVarContentType = + com.sap.cloud.sdk.services.openapi.apache.ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() + { + }; + return apiClient + .invokeAPI( + localVarPath, + "GET", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType); + } +} diff --git a/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/genericreturntype/TestApi.java b/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/genericreturntype/TestSpringApi.java similarity index 94% rename from datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/genericreturntype/TestApi.java rename to datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/genericreturntype/TestSpringApi.java index 900b83373..c670b1271 100644 --- a/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/genericreturntype/TestApi.java +++ b/datamodel/openapi/openapi-core/src/test/java/com/sap/cloud/sdk/services/openapi/genericreturntype/TestSpringApi.java @@ -18,9 +18,9 @@ import com.sap.cloud.sdk.services.openapi.core.AbstractOpenApiService; import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; -class TestApi extends AbstractOpenApiService +class TestSpringApi extends AbstractOpenApiService { - TestApi( @Nonnull final Destination httpDestination ) + TestSpringApi( @Nonnull final Destination httpDestination ) { super(httpDestination); } diff --git a/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/GenerationConfigurationConverter.java b/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/GenerationConfigurationConverter.java index 596d8545c..999398f32 100644 --- a/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/GenerationConfigurationConverter.java +++ b/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/GenerationConfigurationConverter.java @@ -49,6 +49,7 @@ class GenerationConfigurationConverter "Copyright (c) " + Year.now() + " SAP SE or an SAP affiliate company. All rights reserved."; static final String TEMPLATE_DIRECTORY = Paths.get("openapi-generator").resolve("mustache-templates").toString(); static final String LIBRARY_NAME = JavaClientCodegen.RESTTEMPLATE; + static final String SUPPORT_URL_QUERY = "supportUrlQuery"; @Nonnull static ClientOptInput convertGenerationConfiguration( @@ -190,6 +191,10 @@ private static Map getAdditionalProperties( @Nonnull final Gener } result.put(k, v); }); + + // Always disable supportUrlQuery as it's not compatible with interface generation + result.put(SUPPORT_URL_QUERY, "false"); + return result; } } diff --git a/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/libraries/apache-httpclient/api.mustache b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/libraries/apache-httpclient/api.mustache index e6a5a6b92..1d05d9202 100644 --- a/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/libraries/apache-httpclient/api.mustache +++ b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/libraries/apache-httpclient/api.mustache @@ -99,88 +99,88 @@ public class {{classname}} extends BaseApi { {{/aiSdkConstructor}} {{#operation}} - {{#hasOptionalParams}} - /** - *

{{summary}} - *

{{notes}} - {{#responses}} - *

{{code}}{{#message}} - {{message}}{{/message}} - {{/responses}} - {{#allParams}} - * @param {{paramName}} {{#required}} (required){{/required}}{{^required}} (optional{{^isContainer}}{{#defaultValue}}, default to {{.}}{{/defaultValue}}{{/isContainer}}){{/required}} - {{#description}} - * {{description}} - {{/description}} - {{^description}} - * The value for the parameter {{paramName}} - {{/description}} - {{/allParams}} - {{#returnType}} - * @return {{returnType}} - {{/returnType}} - {{^returnType}} - * @return An OpenApiResponse containing the status code of the HttpResponse. - {{/returnType}} - * @throws OpenApiRequestException if an error occurs while attempting to invoke the API - {{#externalDocs}} - * {{description}} - * @see {{summary}} Documentation - {{/externalDocs}} - {{#isDeprecated}} - * @deprecated - {{/isDeprecated}} - */ - {{#isDeprecated}} - @Deprecated - {{/isDeprecated}} - {{#vendorExtensions.x-return-nullable}}@Nullable{{/vendorExtensions.x-return-nullable}}{{^vendorExtensions.x-return-nullable}}@Nonnull{{/vendorExtensions.x-return-nullable}} - public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}OpenApiResponse {{/returnType}}{{#vendorExtensions.x-sap-cloud-sdk-operation-name}}{{vendorExtensions.x-sap-cloud-sdk-operation-name}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}{{^vendorExtensions.x-sap-cloud-sdk-operation-name}}{{operationId}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}({{#allParams}}{{>nullable_var_annotations}} final {{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) throws OpenApiRequestException { - {{>operationBody}} - } - {{/hasOptionalParams}} - - /** - *

{{summary}} - *

{{notes}} - {{#responses}} - *

{{code}}{{#message}} - {{message}}{{/message}} - {{/responses}} - {{#requiredParams}} - * @param {{paramName}} - {{#description}} - * {{description}} - {{/description}} - {{^description}} - * The value for the parameter {{paramName}} - {{/description}} - {{/requiredParams}} - {{#returnType}} - * @return {{returnType}} - {{/returnType}} - {{^returnType}} - * @return An OpenApiResponse containing the status code of the HttpResponse. - {{/returnType}} - * @throws OpenApiRequestException if an error occurs while attempting to invoke the API - {{#externalDocs}} - * {{description}} - * @see {{summary}} Documentation - {{/externalDocs}} - {{#isDeprecated}} - * @deprecated - {{/isDeprecated}} - */ - {{#isDeprecated}} - @Deprecated - {{/isDeprecated}} - {{#vendorExtensions.x-return-nullable}}@Nullable{{/vendorExtensions.x-return-nullable}}{{^vendorExtensions.x-return-nullable}}@Nonnull{{/vendorExtensions.x-return-nullable}} - public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}OpenApiResponse {{/returnType}}{{#vendorExtensions.x-sap-cloud-sdk-operation-name}}{{vendorExtensions.x-sap-cloud-sdk-operation-name}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}{{^vendorExtensions.x-sap-cloud-sdk-operation-name}}{{operationId}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}({{#requiredParams}}{{>nullable_var_annotations}} final {{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/requiredParams}}) throws OpenApiRequestException { - {{#hasOptionalParams}} - {{#returnType}}return {{/returnType}}{{#vendorExtensions.x-sap-cloud-sdk-operation-name}}{{vendorExtensions.x-sap-cloud-sdk-operation-name}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}{{^vendorExtensions.x-sap-cloud-sdk-operation-name}}{{operationId}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}({{#hasRequiredParams}}{{#requiredParams}}{{paramName}}{{^-last}}, {{/-last}}{{/requiredParams}}, {{/hasRequiredParams}}{{#optionalParams}}null{{^-last}}, {{/-last}}{{/optionalParams}}); - {{/hasOptionalParams}} - {{^hasOptionalParams}} - {{>operationBody}} - {{/hasOptionalParams}} - } + {{#hasOptionalParams}} + /** + *

{{summary}} + *

{{notes}} + {{#responses}} + *

{{code}}{{#message}} - {{message}}{{/message}} + {{/responses}} + {{#allParams}} + * @param {{paramName}} {{#required}} (required){{/required}}{{^required}} (optional{{^isContainer}}{{#defaultValue}}, default to {{.}}{{/defaultValue}}{{/isContainer}}){{/required}} + {{#description}} + * {{description}} + {{/description}} + {{^description}} + * The value for the parameter {{paramName}} + {{/description}} + {{/allParams}} + {{#returnType}} + * @return {{returnType}} + {{/returnType}} + {{^returnType}} + * @return An OpenApiResponse containing the status code of the HttpResponse. + {{/returnType}} + * @throws OpenApiRequestException if an error occurs while attempting to invoke the API + {{#externalDocs}} + * {{description}} + * @see {{summary}} Documentation + {{/externalDocs}} + {{#isDeprecated}} + * @deprecated + {{/isDeprecated}} + */ + {{#isDeprecated}} + @Deprecated + {{/isDeprecated}} + {{#vendorExtensions.x-return-nullable}}@Nullable{{/vendorExtensions.x-return-nullable}}{{^vendorExtensions.x-return-nullable}}@Nonnull{{/vendorExtensions.x-return-nullable}} + public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}OpenApiResponse {{/returnType}}{{#vendorExtensions.x-sap-cloud-sdk-operation-name}}{{vendorExtensions.x-sap-cloud-sdk-operation-name}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}{{^vendorExtensions.x-sap-cloud-sdk-operation-name}}{{operationId}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}({{#allParams}}{{>nullable_var_annotations}} final {{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) throws OpenApiRequestException { + {{>operationBody}} + } + {{/hasOptionalParams}} + + /** + *

{{summary}} + *

{{notes}} + {{#responses}} + *

{{code}}{{#message}} - {{message}}{{/message}} + {{/responses}} + {{#requiredParams}} + * @param {{paramName}} + {{#description}} + * {{description}} + {{/description}} + {{^description}} + * The value for the parameter {{paramName}} + {{/description}} + {{/requiredParams}} + {{#returnType}} + * @return {{returnType}} + {{/returnType}} + {{^returnType}} + * @return An OpenApiResponse containing the status code of the HttpResponse. + {{/returnType}} + * @throws OpenApiRequestException if an error occurs while attempting to invoke the API + {{#externalDocs}} + * {{description}} + * @see {{summary}} Documentation + {{/externalDocs}} + {{#isDeprecated}} + * @deprecated + {{/isDeprecated}} + */ + {{#isDeprecated}} + @Deprecated + {{/isDeprecated}} + {{#vendorExtensions.x-return-nullable}}@Nullable{{/vendorExtensions.x-return-nullable}}{{^vendorExtensions.x-return-nullable}}@Nonnull{{/vendorExtensions.x-return-nullable}} + public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}OpenApiResponse {{/returnType}}{{#vendorExtensions.x-sap-cloud-sdk-operation-name}}{{vendorExtensions.x-sap-cloud-sdk-operation-name}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}{{^vendorExtensions.x-sap-cloud-sdk-operation-name}}{{operationId}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}({{#requiredParams}}{{>nullable_var_annotations}} final {{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/requiredParams}}) throws OpenApiRequestException { + {{#hasOptionalParams}} + return {{#vendorExtensions.x-sap-cloud-sdk-operation-name}}{{vendorExtensions.x-sap-cloud-sdk-operation-name}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}{{^vendorExtensions.x-sap-cloud-sdk-operation-name}}{{operationId}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}({{#hasRequiredParams}}{{#requiredParams}}{{paramName}}{{^-last}}, {{/-last}}{{/requiredParams}}, {{/hasRequiredParams}}{{#optionalParams}}null{{^-last}}, {{/-last}}{{/optionalParams}}); + {{/hasOptionalParams}} + {{^hasOptionalParams}} + {{>operationBody}} + {{/hasOptionalParams}} + } {{/operation}} - } +} {{/operations}} \ No newline at end of file diff --git a/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/libraries/apache-httpclient/operationBody.mustache b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/libraries/apache-httpclient/operationBody.mustache index 7f9138e97..b0150a286 100644 --- a/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/libraries/apache-httpclient/operationBody.mustache +++ b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/libraries/apache-httpclient/operationBody.mustache @@ -1,10 +1,10 @@ final Object localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; {{#allParams}}{{#required}} - // verify the required parameter '{{paramName}}' is set - if ({{paramName}} == null) { - throw new OpenApiRequestException("Missing the required parameter '{{paramName}}' when calling {{#vendorExtensions.x-sap-cloud-sdk-operation-name}}{{vendorExtensions.x-sap-cloud-sdk-operation-name}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}{{^vendorExtensions.x-sap-cloud-sdk-operation-name}}{{operationId}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}") - .statusCode(400); - } +// verify the required parameter '{{paramName}}' is set +if ({{paramName}} == null) { +throw new OpenApiRequestException("Missing the required parameter '{{paramName}}' when calling {{#vendorExtensions.x-sap-cloud-sdk-operation-name}}{{vendorExtensions.x-sap-cloud-sdk-operation-name}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}{{^vendorExtensions.x-sap-cloud-sdk-operation-name}}{{operationId}}{{/vendorExtensions.x-sap-cloud-sdk-operation-name}}") +.statusCode(400); +} {{/required}}{{/allParams}} // create path and map variables final String localVarPath = "{{{path}}}"{{#pathParams}} @@ -17,78 +17,77 @@ final List localVarCollectionQueryParams = new ArrayList(); final Map localVarHeaderParams = new HashMap(); final Map localVarFormParams = new HashMap(); - {{#queryParams}} - {{#isDeepObject}} - localVarQueryParameterBaseName = "{{{baseName}}}"; - {{#isArray}} - for (int i=0; i < {{paramName}}.size(); i++) { - localVarQueryStringJoiner.add({{paramName}}.get(i).toUrlQueryString(String.format(Locale.ROOT, "{{baseName}}[%d]", i))); - } - {{/isArray}} - {{^isArray}} - localVarQueryStringJoiner.add({{paramName}}.toUrlQueryString("{{baseName}}")); - {{/isArray}} - {{/isDeepObject}} - {{^isDeepObject}} - {{#isExplode}} - {{#hasVars}} - {{#vars}} - {{#isArray}} - localVarQueryParams.addAll(ApiClient.parameterToPairs("multi", "{{baseName}}", {{paramName}}.{{getter}}())); - {{/isArray}} - {{^isArray}} - localVarQueryParams.addAll(ApiClient.parameterToPair("{{baseName}}", {{paramName}}.{{getter}}())); - {{/isArray}} - {{/vars}} - {{/hasVars}} - {{^hasVars}} - {{#isModel}} - localVarQueryStringJoiner.add({{paramName}}.toUrlQueryString()); - {{/isModel}} - {{^isModel}} - {{#collectionFormat}}localVarCollectionQueryParams.addAll(ApiClient.parameterToPairs("{{{collectionFormat}}}", {{/collectionFormat}}{{^collectionFormat}}localVarQueryParams.addAll(ApiClient.parameterToPair({{/collectionFormat}}"{{baseName}}", {{paramName}})); - {{/isModel}} - {{/hasVars}} - {{/isExplode}} - {{^isExplode}} +{{#queryParams}} + {{#isDeepObject}} + localVarQueryParameterBaseName = "{{{baseName}}}"; + {{#isArray}} + for (int i=0; i < {{paramName}}.size(); i++) { + localVarQueryStringJoiner.add({{paramName}}.get(i).toUrlQueryString(String.format(Locale.ROOT, "{{baseName}}[%d]", i))); + } + {{/isArray}} + {{^isArray}} + localVarQueryStringJoiner.add({{paramName}}.toUrlQueryString("{{baseName}}")); + {{/isArray}} + {{/isDeepObject}} + {{^isDeepObject}} + {{#isExplode}} + {{#hasVars}} + {{#vars}} + {{#isArray}} + localVarQueryParams.addAll(ApiClient.parameterToPairs("multi", "{{baseName}}", {{paramName}}.{{getter}}())); + {{/isArray}} + {{^isArray}} + localVarQueryParams.addAll(ApiClient.parameterToPair("{{baseName}}", {{paramName}}.{{getter}}())); + {{/isArray}} + {{/vars}} + {{/hasVars}} + {{^hasVars}} + {{#isModel}} + localVarQueryStringJoiner.add({{paramName}}.toUrlQueryString()); + {{/isModel}} + {{^isModel}} {{#collectionFormat}}localVarCollectionQueryParams.addAll(ApiClient.parameterToPairs("{{{collectionFormat}}}", {{/collectionFormat}}{{^collectionFormat}}localVarQueryParams.addAll(ApiClient.parameterToPair({{/collectionFormat}}"{{baseName}}", {{paramName}})); - {{/isExplode}} - {{/isDeepObject}} - {{/queryParams}} - {{#headerParams}}if ({{paramName}} != null) - localVarHeaderParams.put("{{baseName}}", ApiClient.parameterToString({{paramName}})); - {{/headerParams}} + {{/isModel}} + {{/hasVars}} + {{/isExplode}} + {{^isExplode}} + {{#collectionFormat}}localVarCollectionQueryParams.addAll(ApiClient.parameterToPairs("{{{collectionFormat}}}", {{/collectionFormat}}{{^collectionFormat}}localVarQueryParams.addAll(ApiClient.parameterToPair({{/collectionFormat}}"{{baseName}}", {{paramName}})); + {{/isExplode}} + {{/isDeepObject}} +{{/queryParams}} +{{#headerParams}}if ({{paramName}} != null) + localVarHeaderParams.put("{{baseName}}", ApiClient.parameterToString({{paramName}})); +{{/headerParams}} +{{#formParams}}if ({{paramName}} != null) + localVarFormParams.put("{{baseName}}", {{paramName}}); +{{/formParams}} - {{#formParams}}if ({{paramName}} != null) - localVarFormParams.put("{{baseName}}", {{paramName}}); - {{/formParams}} +final String[] localVarAccepts = { +{{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} +}; +final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); +final String[] localVarContentTypes = { +{{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} +}; +final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); - final String[] localVarAccepts = { - {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} - }; - final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); +{{#returnType}} +final TypeReference<{{{returnType}}}> localVarReturnType = new TypeReference<{{{returnType}}}>() {}; +{{/returnType}} +{{^returnType}} +final TypeReference localVarReturnType = new TypeReference() {}; +{{/returnType}} - final String[] localVarContentTypes = { - {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} - }; - final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); - - {{#returnType}} - final TypeReference<{{{returnType}}}> localVarReturnType = new TypeReference<{{{returnType}}}>() {}; - {{/returnType}} - {{^returnType}} - final TypeReference localVarReturnType = new TypeReference() {}; - {{/returnType}} - return apiClient.invokeAPI( - localVarPath, - "{{httpMethod}}", - localVarQueryParams, - localVarCollectionQueryParams, - localVarQueryStringJoiner.toString(), - localVarPostBody, - localVarHeaderParams, - localVarFormParams, - localVarAccept, - localVarContentType, - localVarReturnType - ); +return apiClient.invokeAPI( + localVarPath, + "{{httpMethod}}", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType +); diff --git a/datamodel/openapi/openapi-generator/src/test/java/com/sap/cloud/sdk/datamodel/openapi/generator/DataModelGeneratorApacheIntegrationTest.java b/datamodel/openapi/openapi-generator/src/test/java/com/sap/cloud/sdk/datamodel/openapi/generator/DataModelGeneratorApacheIntegrationTest.java new file mode 100644 index 000000000..cbd349e99 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/java/com/sap/cloud/sdk/datamodel/openapi/generator/DataModelGeneratorApacheIntegrationTest.java @@ -0,0 +1,112 @@ +package com.sap.cloud.sdk.datamodel.openapi.generator; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.nio.file.Files; +import java.nio.file.Path; + +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; + +import com.sap.cloud.sdk.datamodel.openapi.generator.model.GenerationConfiguration; +import com.sap.cloud.sdk.datamodel.openapi.generator.model.GenerationResult; + +import io.vavr.control.Try; + +// DataModelGeneratorApacheIntegrationTest.java +class DataModelGeneratorApacheIntegrationTest extends DataModelGeneratorIntegrationTest +{ + + static final String LIBRARY = "apache-httpclient"; + + @Override + @ParameterizedTest + @EnumSource( + value = TestCase.class, + mode = EnumSource.Mode.EXCLUDE, + names = { + "INPUT_SPEC_WITH_UPPERCASE_FILE_EXTENSION", + "ONE_OF_INTERFACES_DISABLED", + "ONE_OF_INTERFACES_ENABLED", + "INPUT_SPEC_WITH_BUILDER", + "GENERATE_APIS" } ) + void integrationTests( final TestCase testCase, @TempDir final Path path ) + throws Throwable + { + final Path inputDirectory = getInputDirectory(testCase); + final Path tempOutputDirectory = path.resolve("outputDirectory"); + final Path comparisonDirectory = getComparisonDirectory(testCase); + + Files.createDirectories(tempOutputDirectory); + + assertThat(inputDirectory).exists().isReadable().isDirectory(); + assertThat(tempOutputDirectory).exists().isReadable().isDirectory(); + assertThat(comparisonDirectory).exists().isReadable().isDirectory(); + + final var generationConfiguration = + GenerationConfiguration + .builder() + // .debugModels(true) enable this for better mustache file debugging + .apiPackage(testCase.apiPackageName) + .generateApis(testCase.generateApis) + .modelPackage(testCase.modelPackageName) + .inputSpec(inputDirectory.resolve(testCase.inputSpecFileName).toAbsolutePath().toString()) + .apiMaturity(testCase.apiMaturity) + .outputDirectory(tempOutputDirectory.toAbsolutePath().toString()) + .withSapCopyrightHeader(true) + .oneOfAnyOfGenerationEnabled(testCase.anyOfOneOfGenerationEnabled) + .additionalProperty("useAbstractionForFiles", "true") + .additionalProperty("library", LIBRARY); + + testCase.additionalProperties.forEach(generationConfiguration::additionalProperty); + + final Try maybeGenerationResult = + new DataModelGenerator().generateDataModel(generationConfiguration.build()); + + assertThat(maybeGenerationResult.get().getGeneratedFiles()).hasSize(testCase.expectedNumberOfGeneratedFiles); + + assertThatDirectoriesHaveSameContent(tempOutputDirectory, comparisonDirectory); + } + + // Add these annotations to regenerate all sources + // @ParameterizedTest + // use this to regenerate all relevant... + // @EnumSource( value=TestCase.class , mode = EnumSource.Mode.EXCLUDE, + // names = { + // "INPUT_SPEC_WITH_UPPERCASE_FILE_EXTENSION", + // "ONE_OF_INTERFACES_DISABLED", + // "ONE_OF_INTERFACES_ENABLED", + // "INPUT_SPEC_WITH_BUILDER", + // "GENERATE_APIS" + // }) + // @EnumSource( value = TestCase.class, names = { "API_CLASS_VENDOR_EXTENSION_YAML" } ) // ...and this one to only generate specific ones + @Override + void generateDataModelForComparison( final TestCase testCase ) + { + final Path inputDirectory = getInputDirectory(testCase); + final Path outputDirectory = getComparisonDirectory(testCase); + + assertThat(inputDirectory).exists().isReadable().isDirectory(); + assertThat(outputDirectory).exists().isReadable().isDirectory(); + + final var generationConfiguration = + GenerationConfiguration + .builder() + .apiPackage(testCase.apiPackageName) + .generateApis(testCase.generateApis) + .modelPackage(testCase.modelPackageName) + .inputSpec(inputDirectory.resolve(testCase.inputSpecFileName).toAbsolutePath().toString()) + .apiMaturity(testCase.apiMaturity) + .outputDirectory(outputDirectory.toAbsolutePath().toString()) + .deleteOutputDirectory(true) + .withSapCopyrightHeader(true) + .oneOfAnyOfGenerationEnabled(testCase.anyOfOneOfGenerationEnabled) + .additionalProperty("useAbstractionForFiles", "true") + .additionalProperty("library", LIBRARY); + testCase.additionalProperties.forEach(generationConfiguration::additionalProperty); + + GenerationConfiguration build = generationConfiguration.build(); + new DataModelGenerator().generateDataModel(build).onFailure(Throwable::printStackTrace); + } +} 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 6d4084e57..3059cfee4 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 @@ -25,7 +25,7 @@ class DataModelGeneratorIntegrationTest { @RequiredArgsConstructor - private enum TestCase + enum TestCase { API_CLASS_FOR_AI_SDK( "api-class-for-ai-sdk", @@ -236,7 +236,7 @@ void generateDataModelForComparison( final TestCase testCase ) new DataModelGenerator().generateDataModel(build).onFailure(Throwable::printStackTrace); } - private static Path getInputDirectory( final TestCase testCase ) + Path getInputDirectory( final TestCase testCase ) { final Path testCaseDirectory = getTestCaseDirectory(testCase); final Path inputDirectory = testCaseDirectory.resolve("input"); @@ -246,20 +246,17 @@ private static Path getInputDirectory( final TestCase testCase ) return inputDirectory; } - private static Path getTestCaseDirectory( final TestCase testCase ) + private Path getTestCaseDirectory( final TestCase testCase ) { final Path testCaseDirectory = - Paths - .get( - "src/test/resources/" + DataModelGeneratorIntegrationTest.class.getSimpleName(), - testCase.testCaseName); + Paths.get("src/test/resources/" + this.getClass().getSimpleName(), testCase.testCaseName); assertThat(testCaseDirectory).exists().isDirectory().isReadable(); return testCaseDirectory; } - private static Path getComparisonDirectory( final TestCase testCase ) + Path getComparisonDirectory( final TestCase testCase ) { final Path testCaseDirectory = getTestCaseDirectory(testCase); final Path comparisonDirectory = testCaseDirectory.resolve("output"); @@ -271,7 +268,7 @@ private static Path getComparisonDirectory( final TestCase testCase ) @SuppressWarnings( "resource" ) @SneakyThrows - private static void assertThatDirectoriesHaveSameContent( final Path a, final Path b ) + static void assertThatDirectoriesHaveSameContent( final Path a, final Path b ) { final Predicate isFile = p -> p.toFile().isFile(); Files.walk(a).filter(isFile).forEach(p -> assertThat(p).hasSameTextualContentAs(b.resolve(a.relativize(p)))); diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/input/sodastore.json b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/input/sodastore.json new file mode 100644 index 000000000..fdacd7c85 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/input/sodastore.json @@ -0,0 +1,249 @@ +{ + "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" + }, + "isAvailable": { + "type": "boolean" + }, + "flavor": { + "type": "string" + }, + "price": { + "type": "number", + "format": "float" + }, + "diet": { + "type": "string", + "enum": ["sugar", "zero", "light"], + "nullable": true + }, + "embedding":{ + "type": "array", + "items": { + "type": "number" + } + } + }, + "required": ["name", "brand", "flavor", "price", "embedding"] + }, + "NewSoda": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "brand": { + "type": "string" + }, + "zero": { + "type": "boolean" + }, + "since": { + "type": "string", + "format": "date" + }, + "flavor": { + "type": "string" + }, + "price": { + "type": "number", + "format": "float" + } + }, + "required": ["name", "brand", "flavor", "price"] + }, + "UpdateSoda": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "zero": { + "type": "boolean" + }, + "since": { + "type": "string", + "format": "date" + }, + "brand": { + "type": "string" + }, + "flavor": { + "type": "string" + }, + "price": { + "type": "number", + "format": "float" + } + } + } + } + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/api/AwesomeSodaApi.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/api/AwesomeSodaApi.java new file mode 100644 index 000000000..d9cb8d6a1 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/api/AwesomeSodaApi.java @@ -0,0 +1,114 @@ +/* +* Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. +*/ + +package com.sap.cloud.sdk.services.builder.api; + +import com.fasterxml.jackson.core.type.TypeReference; + +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +import com.sap.cloud.sdk.services.openapi.apache.OpenApiResponse; +import com.sap.cloud.sdk.services.openapi.apache.ApiClient; +import com.sap.cloud.sdk.services.openapi.apache.BaseApi; +import com.sap.cloud.sdk.services.openapi.apache.Pair; + + +import com.sap.cloud.sdk.services.builder.model.NewSoda; +import com.sap.cloud.sdk.services.builder.model.Soda; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.StringJoiner; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.sap.ai.sdk.core.AiCoreService; + + +/** +* Soda Store API in version 1.0.0. +* +* API for managing sodas in a soda store +*/ +public class AwesomeSodaApi extends BaseApi { + + /** + * Instantiates this API class to invoke operations on the Soda Store API + */ + public AwesomeSodaApi() + { + super(new AiCoreService().getApiClient()); + } + + /** + * Instantiates this API class to invoke operations on the Soda Store API + * + * @param aiCoreService The configured connectivity instance to AI Core + */ + public AwesomeSodaApi( @Nonnull final AiCoreService aiCoreService ) + { + super(aiCoreService.getApiClient()); + } + + + /** + *

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 + */ + @Nonnull + 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") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas"; + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + "application/json" + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "POST", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/api/AwesomeSodasApi.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/api/AwesomeSodasApi.java new file mode 100644 index 000000000..c8b2721cb --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/api/AwesomeSodasApi.java @@ -0,0 +1,105 @@ +/* +* Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. +*/ + +package com.sap.cloud.sdk.services.builder.api; + +import com.fasterxml.jackson.core.type.TypeReference; + +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +import com.sap.cloud.sdk.services.openapi.apache.OpenApiResponse; +import com.sap.cloud.sdk.services.openapi.apache.ApiClient; +import com.sap.cloud.sdk.services.openapi.apache.BaseApi; +import com.sap.cloud.sdk.services.openapi.apache.Pair; + + +import com.sap.cloud.sdk.services.builder.model.Soda; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.StringJoiner; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.sap.ai.sdk.core.AiCoreService; + + +/** +* Soda Store API in version 1.0.0. +* +* API for managing sodas in a soda store +*/ +public class AwesomeSodasApi extends BaseApi { + + /** + * Instantiates this API class to invoke operations on the Soda Store API + */ + public AwesomeSodasApi() + { + super(new AiCoreService().getApiClient()); + } + + /** + * Instantiates this API class to invoke operations on the Soda Store API + * + * @param aiCoreService The configured connectivity instance to AI Core + */ + public AwesomeSodasApi( @Nonnull final AiCoreService aiCoreService ) + { + super(aiCoreService.getApiClient()); + } + + + /** + *

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 + */ + @Nonnull + public List getSodas() throws OpenApiRequestException { + final Object localVarPostBody = null; + + // create path and map variables + final String localVarPath = "/sodas"; + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference> localVarReturnType = new TypeReference>() {}; + + return apiClient.invokeAPI( + localVarPath, + "GET", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/api/DefaultApi.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/api/DefaultApi.java new file mode 100644 index 000000000..d23090170 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/api/DefaultApi.java @@ -0,0 +1,240 @@ +/* +* Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. +*/ + +package com.sap.cloud.sdk.services.builder.api; + +import com.fasterxml.jackson.core.type.TypeReference; + +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +import com.sap.cloud.sdk.services.openapi.apache.OpenApiResponse; +import com.sap.cloud.sdk.services.openapi.apache.ApiClient; +import com.sap.cloud.sdk.services.openapi.apache.BaseApi; +import com.sap.cloud.sdk.services.openapi.apache.Pair; + + +import com.sap.cloud.sdk.services.builder.model.Soda; +import com.sap.cloud.sdk.services.builder.model.UpdateSoda; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.StringJoiner; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.sap.ai.sdk.core.AiCoreService; + + +/** +* Soda Store API in version 1.0.0. +* +* API for managing sodas in a soda store +*/ +public class DefaultApi extends BaseApi { + + /** + * Instantiates this API class to invoke operations on the Soda Store API + */ + public DefaultApi() + { + super(new AiCoreService().getApiClient()); + } + + /** + * Instantiates this API class to invoke operations on the Soda Store API + * + * @param aiCoreService The configured connectivity instance to AI Core + */ + public DefaultApi( @Nonnull final AiCoreService aiCoreService ) + { + super(aiCoreService.getApiClient()); + } + + + /** + *

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") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas/{sodaId}" + .replaceAll("\\{" + "sodaId" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(sodaId))); + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "DELETE", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } + + /** + *

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 + */ + @Nonnull + 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") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas/{sodaId}" + .replaceAll("\\{" + "sodaId" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(sodaId))); + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "GET", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + 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 + */ + @Nonnull + 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") + .statusCode(400); + } + + // verify the required parameter 'updateSoda' is set + if (updateSoda == null) { + throw new OpenApiRequestException("Missing the required parameter 'updateSoda' when calling updateSodaById") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas/{sodaId}" + .replaceAll("\\{" + "sodaId" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(sodaId))); + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + "application/json" + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "PUT", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/model/NewSoda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/model/NewSoda.java new file mode 100644 index 000000000..20ce285d8 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/model/NewSoda.java @@ -0,0 +1,349 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * + * + * 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.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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.time.LocalDate; +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 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("zero") + private Boolean zero; + + @JsonProperty("since") + private LocalDate since; + + @JsonProperty("flavor") + private String flavor; + + @JsonProperty("price") + private Float price; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * 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 zero of this {@link NewSoda} instance and return the same instance. + * + * @param zero The zero of this {@link NewSoda} + * @return The same instance of this {@link NewSoda} class + */ + @Nonnull public NewSoda zero( @Nullable final Boolean zero) { + this.zero = zero; + return this; + } + + /** + * Get zero + * @return zero The zero of this {@link NewSoda} instance. + */ + @Nonnull + public Boolean isZero() { + return zero; + } + + /** + * Set the zero of this {@link NewSoda} instance. + * + * @param zero The zero of this {@link NewSoda} + */ + public void setZero( @Nullable final Boolean zero) { + this.zero = zero; + } + + /** + * Set the since of this {@link NewSoda} instance and return the same instance. + * + * @param since The since of this {@link NewSoda} + * @return The same instance of this {@link NewSoda} class + */ + @Nonnull public NewSoda since( @Nullable final LocalDate since) { + this.since = since; + return this; + } + + /** + * Get since + * @return since The since of this {@link NewSoda} instance. + */ + @Nonnull + public LocalDate getSince() { + return since; + } + + /** + * Set the since of this {@link NewSoda} instance. + * + * @param since The since of this {@link NewSoda} + */ + public void setSince( @Nullable final LocalDate since) { + this.since = since; + } + + /** + * 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. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + 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); + } + + /** + * Get the value of all properties of this {@link NewSoda} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( name != null ) declaredFields.put("name", name); + if( brand != null ) declaredFields.put("brand", brand); + if( zero != null ) declaredFields.put("zero", zero); + if( since != null ) declaredFields.put("since", since); + if( flavor != null ) declaredFields.put("flavor", flavor); + if( price != null ) declaredFields.put("price", price); + return declaredFields; + } + + /** + * 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.zero, newSoda.zero) && + Objects.equals(this.since, newSoda.since) && + Objects.equals(this.flavor, newSoda.flavor) && + Objects.equals(this.price, newSoda.price); + } + + @Override + public int hashCode() { + return Objects.hash(name, brand, zero, since, 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(" zero: ").append(toIndentedString(zero)).append("\n"); + sb.append(" since: ").append(toIndentedString(since)).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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/model/Soda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/model/Soda.java new file mode 100644 index 000000000..b0cab12da --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/model/Soda.java @@ -0,0 +1,481 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * + * + * 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.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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.math.BigDecimal; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +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 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("isAvailable") + private Boolean isAvailable; + + @JsonProperty("flavor") + private String flavor; + + @JsonProperty("price") + private Float price; + + /** + * Gets or Sets diet + */ + public enum DietEnum { + /** + * The SUGAR option of this Soda + */ + SUGAR("sugar"), + + /** + * The ZERO option of this Soda + */ + ZERO("zero"), + + /** + * The LIGHT option of this Soda + */ + LIGHT("light"); + + private String value; + + DietEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * @return The enum value + */ + @JsonValue + @Nonnull public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * @return The enum value as String + */ + @Override + @Nonnull public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * @param value The String value + * @return The enum value of type Soda + */ + @JsonCreator + @Nullable public static DietEnum fromValue(@Nonnull final String value) { + for (DietEnum b : DietEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + return null; + } + } + + @JsonProperty("diet") + private DietEnum diet; + + @JsonProperty("embedding") + private float[] embedding; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * 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( @Nullable 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( @Nullable 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 isAvailable of this {@link Soda} instance and return the same instance. + * + * @param isAvailable The isAvailable of this {@link Soda} + * @return The same instance of this {@link Soda} class + */ + @Nonnull public Soda isAvailable( @Nullable final Boolean isAvailable) { + this.isAvailable = isAvailable; + return this; + } + + /** + * Get isAvailable + * @return isAvailable The isAvailable of this {@link Soda} instance. + */ + @Nonnull + public Boolean isAvailable() { + return isAvailable; + } + + /** + * Set the isAvailable of this {@link Soda} instance. + * + * @param isAvailable The isAvailable of this {@link Soda} + */ + public void setIsAvailable( @Nullable final Boolean isAvailable) { + this.isAvailable = isAvailable; + } + + /** + * Set the flavor of this {@link Soda} instance and return the same instance. + * + * @param flavor The flavor of this {@link Soda} + * @return The same instance of this {@link Soda} class + */ + @Nonnull public Soda flavor( @Nonnull final String flavor) { + this.flavor = flavor; + return this; + } + + /** + * Get flavor + * @return flavor The flavor of this {@link Soda} instance. + */ + @Nonnull + public String getFlavor() { + return flavor; + } + + /** + * Set the flavor of this {@link Soda} instance. + * + * @param flavor The flavor of this {@link Soda} + */ + public void setFlavor( @Nonnull final String flavor) { + this.flavor = flavor; + } + + /** + * 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; + } + + /** + * Set the diet of this {@link Soda} instance and return the same instance. + * + * @param diet The diet of this {@link Soda} + * @return The same instance of this {@link Soda} class + */ + @Nonnull public Soda diet( @Nullable final DietEnum diet) { + this.diet = diet; + return this; + } + + /** + * Get diet + * @return diet The diet of this {@link Soda} instance. + */ + @Nullable + public DietEnum getDiet() { + return diet; + } + + /** + * Set the diet of this {@link Soda} instance. + * + * @param diet The diet of this {@link Soda} + */ + public void setDiet( @Nullable final DietEnum diet) { + this.diet = diet; + } + + /** + * Set the embedding of this {@link Soda} instance and return the same instance. + * + * @param embedding The embedding of this {@link Soda} + * @return The same instance of this {@link Soda} class + */ + @Nonnull public Soda embedding( @Nonnull final float[] embedding) { + this.embedding = embedding; + return this; + } + + /** + * Get embedding + * @return embedding The embedding of this {@link Soda} instance. + */ + @Nonnull + public float[] getEmbedding() { + return embedding; + } + + /** + * Set the embedding of this {@link Soda} instance. + * + * @param embedding The embedding of this {@link Soda} + */ + public void setEmbedding( @Nonnull final float[] embedding) { + this.embedding = embedding; + } + + /** + * 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. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + 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); + } + + /** + * Get the value of all properties of this {@link Soda} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( id != null ) declaredFields.put("id", id); + if( name != null ) declaredFields.put("name", name); + if( brand != null ) declaredFields.put("brand", brand); + if( isAvailable != null ) declaredFields.put("isAvailable", isAvailable); + if( flavor != null ) declaredFields.put("flavor", flavor); + if( price != null ) declaredFields.put("price", price); + if( diet != null ) declaredFields.put("diet", diet); + if( embedding != null ) declaredFields.put("embedding", embedding); + return declaredFields; + } + + /** + * 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.isAvailable, soda.isAvailable) && + Objects.equals(this.flavor, soda.flavor) && + Objects.equals(this.price, soda.price) && + Objects.equals(this.diet, soda.diet) && + Arrays.equals(this.embedding, soda.embedding); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, brand, isAvailable, flavor, price, diet, Arrays.hashCode(embedding), 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(" isAvailable: ").append(toIndentedString(isAvailable)).append("\n"); + sb.append(" flavor: ").append(toIndentedString(flavor)).append("\n"); + sb.append(" price: ").append(toIndentedString(price)).append("\n"); + sb.append(" diet: ").append(toIndentedString(diet)).append("\n"); + sb.append(" embedding: ").append(toIndentedString(embedding)).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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/model/UpdateSoda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/model/UpdateSoda.java new file mode 100644 index 000000000..85f725e6a --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-for-ai-sdk/output/com/sap/cloud/sdk/services/builder/model/UpdateSoda.java @@ -0,0 +1,349 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * + * + * 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.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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.time.LocalDate; +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 javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * UpdateSoda + */ +// CHECKSTYLE:OFF +public class UpdateSoda +// CHECKSTYLE:ON +{ + @JsonProperty("name") + private String name; + + @JsonProperty("zero") + private Boolean zero; + + @JsonProperty("since") + private LocalDate since; + + @JsonProperty("brand") + private String brand; + + @JsonProperty("flavor") + private String flavor; + + @JsonProperty("price") + private Float price; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * 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( @Nullable 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( @Nullable final String name) { + this.name = name; + } + + /** + * Set the zero of this {@link UpdateSoda} instance and return the same instance. + * + * @param zero The zero of this {@link UpdateSoda} + * @return The same instance of this {@link UpdateSoda} class + */ + @Nonnull public UpdateSoda zero( @Nullable final Boolean zero) { + this.zero = zero; + return this; + } + + /** + * Get zero + * @return zero The zero of this {@link UpdateSoda} instance. + */ + @Nonnull + public Boolean isZero() { + return zero; + } + + /** + * Set the zero of this {@link UpdateSoda} instance. + * + * @param zero The zero of this {@link UpdateSoda} + */ + public void setZero( @Nullable final Boolean zero) { + this.zero = zero; + } + + /** + * Set the since of this {@link UpdateSoda} instance and return the same instance. + * + * @param since The since of this {@link UpdateSoda} + * @return The same instance of this {@link UpdateSoda} class + */ + @Nonnull public UpdateSoda since( @Nullable final LocalDate since) { + this.since = since; + return this; + } + + /** + * Get since + * @return since The since of this {@link UpdateSoda} instance. + */ + @Nonnull + public LocalDate getSince() { + return since; + } + + /** + * Set the since of this {@link UpdateSoda} instance. + * + * @param since The since of this {@link UpdateSoda} + */ + public void setSince( @Nullable final LocalDate since) { + this.since = since; + } + + /** + * 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( @Nullable 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( @Nullable 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( @Nullable 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( @Nullable 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( @Nullable 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( @Nullable 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. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + 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); + } + + /** + * Get the value of all properties of this {@link UpdateSoda} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( name != null ) declaredFields.put("name", name); + if( zero != null ) declaredFields.put("zero", zero); + if( since != null ) declaredFields.put("since", since); + if( brand != null ) declaredFields.put("brand", brand); + if( flavor != null ) declaredFields.put("flavor", flavor); + if( price != null ) declaredFields.put("price", price); + return declaredFields; + } + + /** + * 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.zero, updateSoda.zero) && + Objects.equals(this.since, updateSoda.since) && + 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, zero, since, 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(" zero: ").append(toIndentedString(zero)).append("\n"); + sb.append(" since: ").append(toIndentedString(since)).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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/input/sodastore.json b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/input/sodastore.json new file mode 100644 index 000000000..f10d46994 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/input/sodastore.json @@ -0,0 +1,235 @@ +{ + "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" + }, + "flavor": { + "type": "string" + }, + "price": { + "type": "number", + "format": "float" + } + }, + "required": ["name", "brand", "flavor", "price"] + }, + "NewSoda": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "brand": { + "type": "string" + }, + "zero": { + "type": "boolean" + }, + "since": { + "type": "string", + "format": "date" + }, + "flavor": { + "type": "string" + }, + "price": { + "type": "number", + "format": "float" + } + }, + "required": ["name", "brand", "flavor", "price"] + }, + "UpdateSoda": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "zero": { + "type": "boolean" + }, + "since": { + "type": "string", + "format": "date" + }, + "brand": { + "type": "string" + }, + "flavor": { + "type": "string" + }, + "price": { + "type": "number", + "format": "float" + } + } + } + } + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/api/AwesomeSodaApi.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/api/AwesomeSodaApi.java new file mode 100644 index 000000000..963ff8f28 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/api/AwesomeSodaApi.java @@ -0,0 +1,121 @@ +/* +* Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. +*/ + +package com.sap.cloud.sdk.services.apiclassvendorextension.api; + +import com.fasterxml.jackson.core.type.TypeReference; + +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +import com.sap.cloud.sdk.services.openapi.apache.OpenApiResponse; +import com.sap.cloud.sdk.services.openapi.apache.ApiClient; +import com.sap.cloud.sdk.services.openapi.apache.BaseApi; +import com.sap.cloud.sdk.services.openapi.apache.Pair; + + +import com.sap.cloud.sdk.services.apiclassvendorextension.model.NewSoda; +import com.sap.cloud.sdk.services.apiclassvendorextension.model.Soda; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.StringJoiner; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +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 BaseApi { + + /** + * Instantiates this API class to invoke operations on the Soda Store API + */ + public AwesomeSodaApi() {} + + /** + * 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 + */ + 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 + */ + @Nonnull + 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") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas"; + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + "application/json" + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "POST", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/api/AwesomeSodasApi.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/api/AwesomeSodasApi.java new file mode 100644 index 000000000..084e38ade --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/api/AwesomeSodasApi.java @@ -0,0 +1,112 @@ +/* +* Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. +*/ + +package com.sap.cloud.sdk.services.apiclassvendorextension.api; + +import com.fasterxml.jackson.core.type.TypeReference; + +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +import com.sap.cloud.sdk.services.openapi.apache.OpenApiResponse; +import com.sap.cloud.sdk.services.openapi.apache.ApiClient; +import com.sap.cloud.sdk.services.openapi.apache.BaseApi; +import com.sap.cloud.sdk.services.openapi.apache.Pair; + + +import com.sap.cloud.sdk.services.apiclassvendorextension.model.Soda; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.StringJoiner; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +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 BaseApi { + + /** + * Instantiates this API class to invoke operations on the Soda Store API + */ + public AwesomeSodasApi() {} + + /** + * 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 + */ + 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 + */ + @Nonnull + public List getSodas() throws OpenApiRequestException { + final Object localVarPostBody = null; + + // create path and map variables + final String localVarPath = "/sodas"; + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference> localVarReturnType = new TypeReference>() {}; + + return apiClient.invokeAPI( + localVarPath, + "GET", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/api/DefaultApi.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/api/DefaultApi.java new file mode 100644 index 000000000..f60962727 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/api/DefaultApi.java @@ -0,0 +1,247 @@ +/* +* Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. +*/ + +package com.sap.cloud.sdk.services.apiclassvendorextension.api; + +import com.fasterxml.jackson.core.type.TypeReference; + +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +import com.sap.cloud.sdk.services.openapi.apache.OpenApiResponse; +import com.sap.cloud.sdk.services.openapi.apache.ApiClient; +import com.sap.cloud.sdk.services.openapi.apache.BaseApi; +import com.sap.cloud.sdk.services.openapi.apache.Pair; + + +import com.sap.cloud.sdk.services.apiclassvendorextension.model.Soda; +import com.sap.cloud.sdk.services.apiclassvendorextension.model.UpdateSoda; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.StringJoiner; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +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 BaseApi { + + /** + * Instantiates this API class to invoke operations on the Soda Store API + */ + public DefaultApi() {} + + /** + * 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 + */ + 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") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas/{sodaId}" + .replaceAll("\\{" + "sodaId" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(sodaId))); + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "DELETE", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } + + /** + *

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 + */ + @Nonnull + 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") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas/{sodaId}" + .replaceAll("\\{" + "sodaId" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(sodaId))); + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "GET", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + 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 + */ + @Nonnull + 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") + .statusCode(400); + } + + // verify the required parameter 'updateSoda' is set + if (updateSoda == null) { + throw new OpenApiRequestException("Missing the required parameter 'updateSoda' when calling updateSodaById") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas/{sodaId}" + .replaceAll("\\{" + "sodaId" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(sodaId))); + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + "application/json" + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "PUT", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/NewSoda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/NewSoda.java new file mode 100644 index 000000000..6bbd8468d --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/NewSoda.java @@ -0,0 +1,349 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * + * + * 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.apiclassvendorextension.model; + +import java.util.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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.time.LocalDate; +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 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("zero") + private Boolean zero; + + @JsonProperty("since") + private LocalDate since; + + @JsonProperty("flavor") + private String flavor; + + @JsonProperty("price") + private Float price; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * 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 zero of this {@link NewSoda} instance and return the same instance. + * + * @param zero The zero of this {@link NewSoda} + * @return The same instance of this {@link NewSoda} class + */ + @Nonnull public NewSoda zero( @Nullable final Boolean zero) { + this.zero = zero; + return this; + } + + /** + * Get zero + * @return zero The zero of this {@link NewSoda} instance. + */ + @Nonnull + public Boolean isZero() { + return zero; + } + + /** + * Set the zero of this {@link NewSoda} instance. + * + * @param zero The zero of this {@link NewSoda} + */ + public void setZero( @Nullable final Boolean zero) { + this.zero = zero; + } + + /** + * Set the since of this {@link NewSoda} instance and return the same instance. + * + * @param since The since of this {@link NewSoda} + * @return The same instance of this {@link NewSoda} class + */ + @Nonnull public NewSoda since( @Nullable final LocalDate since) { + this.since = since; + return this; + } + + /** + * Get since + * @return since The since of this {@link NewSoda} instance. + */ + @Nonnull + public LocalDate getSince() { + return since; + } + + /** + * Set the since of this {@link NewSoda} instance. + * + * @param since The since of this {@link NewSoda} + */ + public void setSince( @Nullable final LocalDate since) { + this.since = since; + } + + /** + * 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. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + 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); + } + + /** + * Get the value of all properties of this {@link NewSoda} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( name != null ) declaredFields.put("name", name); + if( brand != null ) declaredFields.put("brand", brand); + if( zero != null ) declaredFields.put("zero", zero); + if( since != null ) declaredFields.put("since", since); + if( flavor != null ) declaredFields.put("flavor", flavor); + if( price != null ) declaredFields.put("price", price); + return declaredFields; + } + + /** + * 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.zero, newSoda.zero) && + Objects.equals(this.since, newSoda.since) && + Objects.equals(this.flavor, newSoda.flavor) && + Objects.equals(this.price, newSoda.price); + } + + @Override + public int hashCode() { + return Objects.hash(name, brand, zero, since, 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(" zero: ").append(toIndentedString(zero)).append("\n"); + sb.append(" since: ").append(toIndentedString(since)).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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/Soda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/Soda.java new file mode 100644 index 000000000..b0159f9aa --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/Soda.java @@ -0,0 +1,313 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * + * + * 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.apiclassvendorextension.model; + +import java.util.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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 com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +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("flavor") + private String flavor; + + @JsonProperty("price") + private Float price; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * 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( @Nullable 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( @Nullable 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 flavor of this {@link Soda} instance and return the same instance. + * + * @param flavor The flavor of this {@link Soda} + * @return The same instance of this {@link Soda} class + */ + @Nonnull public Soda flavor( @Nonnull final String flavor) { + this.flavor = flavor; + return this; + } + + /** + * Get flavor + * @return flavor The flavor of this {@link Soda} instance. + */ + @Nonnull + public String getFlavor() { + return flavor; + } + + /** + * Set the flavor of this {@link Soda} instance. + * + * @param flavor The flavor of this {@link Soda} + */ + public void setFlavor( @Nonnull final String flavor) { + this.flavor = flavor; + } + + /** + * 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. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + 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); + } + + /** + * Get the value of all properties of this {@link Soda} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( id != null ) declaredFields.put("id", id); + if( name != null ) declaredFields.put("name", name); + if( brand != null ) declaredFields.put("brand", brand); + if( flavor != null ) declaredFields.put("flavor", flavor); + if( price != null ) declaredFields.put("price", price); + return declaredFields; + } + + /** + * 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.flavor, soda.flavor) && + Objects.equals(this.price, soda.price); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, brand, flavor, 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(" 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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java new file mode 100644 index 000000000..65139c68c --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java @@ -0,0 +1,349 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * + * + * 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.apiclassvendorextension.model; + +import java.util.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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.time.LocalDate; +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 javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * UpdateSoda + */ +// CHECKSTYLE:OFF +public class UpdateSoda +// CHECKSTYLE:ON +{ + @JsonProperty("name") + private String name; + + @JsonProperty("zero") + private Boolean zero; + + @JsonProperty("since") + private LocalDate since; + + @JsonProperty("brand") + private String brand; + + @JsonProperty("flavor") + private String flavor; + + @JsonProperty("price") + private Float price; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * 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( @Nullable 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( @Nullable final String name) { + this.name = name; + } + + /** + * Set the zero of this {@link UpdateSoda} instance and return the same instance. + * + * @param zero The zero of this {@link UpdateSoda} + * @return The same instance of this {@link UpdateSoda} class + */ + @Nonnull public UpdateSoda zero( @Nullable final Boolean zero) { + this.zero = zero; + return this; + } + + /** + * Get zero + * @return zero The zero of this {@link UpdateSoda} instance. + */ + @Nonnull + public Boolean isZero() { + return zero; + } + + /** + * Set the zero of this {@link UpdateSoda} instance. + * + * @param zero The zero of this {@link UpdateSoda} + */ + public void setZero( @Nullable final Boolean zero) { + this.zero = zero; + } + + /** + * Set the since of this {@link UpdateSoda} instance and return the same instance. + * + * @param since The since of this {@link UpdateSoda} + * @return The same instance of this {@link UpdateSoda} class + */ + @Nonnull public UpdateSoda since( @Nullable final LocalDate since) { + this.since = since; + return this; + } + + /** + * Get since + * @return since The since of this {@link UpdateSoda} instance. + */ + @Nonnull + public LocalDate getSince() { + return since; + } + + /** + * Set the since of this {@link UpdateSoda} instance. + * + * @param since The since of this {@link UpdateSoda} + */ + public void setSince( @Nullable final LocalDate since) { + this.since = since; + } + + /** + * 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( @Nullable 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( @Nullable 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( @Nullable 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( @Nullable 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( @Nullable 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( @Nullable 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. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + 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); + } + + /** + * Get the value of all properties of this {@link UpdateSoda} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( name != null ) declaredFields.put("name", name); + if( zero != null ) declaredFields.put("zero", zero); + if( since != null ) declaredFields.put("since", since); + if( brand != null ) declaredFields.put("brand", brand); + if( flavor != null ) declaredFields.put("flavor", flavor); + if( price != null ) declaredFields.put("price", price); + return declaredFields; + } + + /** + * 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.zero, updateSoda.zero) && + Objects.equals(this.since, updateSoda.since) && + 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, zero, since, 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(" zero: ").append(toIndentedString(zero)).append("\n"); + sb.append(" since: ").append(toIndentedString(since)).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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-yaml/input/sodastore.yaml b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-yaml/input/sodastore.yaml new file mode 100644 index 000000000..0acd4ad2d --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-yaml/input/sodastore.yaml @@ -0,0 +1,157 @@ +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 + 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 + 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 + flavor: + type: string + price: + type: number + format: float + required: + - name + - brand + - flavor + - 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/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/api/DefaultApi.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/api/DefaultApi.java new file mode 100644 index 000000000..44651981e --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/api/DefaultApi.java @@ -0,0 +1,352 @@ +/* +* Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. +*/ + +package com.sap.cloud.sdk.services.apiclassvendorextension.api; + +import com.fasterxml.jackson.core.type.TypeReference; + +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +import com.sap.cloud.sdk.services.openapi.apache.OpenApiResponse; +import com.sap.cloud.sdk.services.openapi.apache.ApiClient; +import com.sap.cloud.sdk.services.openapi.apache.BaseApi; +import com.sap.cloud.sdk.services.openapi.apache.Pair; + + +import com.sap.cloud.sdk.services.apiclassvendorextension.model.NewSoda; +import com.sap.cloud.sdk.services.apiclassvendorextension.model.Soda; +import com.sap.cloud.sdk.services.apiclassvendorextension.model.UpdateSoda; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.StringJoiner; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +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 BaseApi { + + /** + * Instantiates this API class to invoke operations on the Soda Store API + */ + public DefaultApi() {} + + /** + * 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 + */ + public DefaultApi(@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 + */ + @Nonnull + 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") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas"; + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + "application/json" + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "POST", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } + + /** + *

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") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas/{sodaId}" + .replaceAll("\\{" + "sodaId" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(sodaId))); + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "DELETE", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } + + /** + *

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 + */ + @Nonnull + 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") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas/{sodaId}" + .replaceAll("\\{" + "sodaId" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(sodaId))); + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "GET", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } + + /** + *

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 + */ + @Nonnull + public List getSodas() throws OpenApiRequestException { + final Object localVarPostBody = null; + + // create path and map variables + final String localVarPath = "/sodas"; + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference> localVarReturnType = new TypeReference>() {}; + + return apiClient.invokeAPI( + localVarPath, + "GET", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + 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 + */ + @Nonnull + 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") + .statusCode(400); + } + + // verify the required parameter 'updateSoda' is set + if (updateSoda == null) { + throw new OpenApiRequestException("Missing the required parameter 'updateSoda' when calling updateSodaById") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas/{sodaId}" + .replaceAll("\\{" + "sodaId" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(sodaId))); + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + "application/json" + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "PUT", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/NewSoda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/NewSoda.java new file mode 100644 index 000000000..bfbecfa18 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/NewSoda.java @@ -0,0 +1,278 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * + * + * 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.apiclassvendorextension.model; + +import java.util.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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 com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +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<>(); + + /** + * 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. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + 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); + } + + /** + * Get the value of all properties of this {@link NewSoda} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( name != null ) declaredFields.put("name", name); + if( brand != null ) declaredFields.put("brand", brand); + if( flavor != null ) declaredFields.put("flavor", flavor); + if( price != null ) declaredFields.put("price", price); + return declaredFields; + } + + /** + * 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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/Soda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/Soda.java new file mode 100644 index 000000000..b0159f9aa --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/Soda.java @@ -0,0 +1,313 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * + * + * 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.apiclassvendorextension.model; + +import java.util.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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 com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +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("flavor") + private String flavor; + + @JsonProperty("price") + private Float price; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * 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( @Nullable 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( @Nullable 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 flavor of this {@link Soda} instance and return the same instance. + * + * @param flavor The flavor of this {@link Soda} + * @return The same instance of this {@link Soda} class + */ + @Nonnull public Soda flavor( @Nonnull final String flavor) { + this.flavor = flavor; + return this; + } + + /** + * Get flavor + * @return flavor The flavor of this {@link Soda} instance. + */ + @Nonnull + public String getFlavor() { + return flavor; + } + + /** + * Set the flavor of this {@link Soda} instance. + * + * @param flavor The flavor of this {@link Soda} + */ + public void setFlavor( @Nonnull final String flavor) { + this.flavor = flavor; + } + + /** + * 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. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + 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); + } + + /** + * Get the value of all properties of this {@link Soda} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( id != null ) declaredFields.put("id", id); + if( name != null ) declaredFields.put("name", name); + if( brand != null ) declaredFields.put("brand", brand); + if( flavor != null ) declaredFields.put("flavor", flavor); + if( price != null ) declaredFields.put("price", price); + return declaredFields; + } + + /** + * 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.flavor, soda.flavor) && + Objects.equals(this.price, soda.price); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, brand, flavor, 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(" 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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java new file mode 100644 index 000000000..84b275fbb --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/api-class-vendor-extension-yaml/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java @@ -0,0 +1,278 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * + * + * 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.apiclassvendorextension.model; + +import java.util.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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 com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +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<>(); + + /** + * 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( @Nullable 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( @Nullable 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( @Nullable 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( @Nullable 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( @Nullable 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( @Nullable 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( @Nullable 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( @Nullable 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. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + 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); + } + + /** + * Get the value of all properties of this {@link UpdateSoda} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( name != null ) declaredFields.put("name", name); + if( brand != null ) declaredFields.put("brand", brand); + if( flavor != null ) declaredFields.put("flavor", flavor); + if( price != null ) declaredFields.put("price", price); + return declaredFields; + } + + /** + * 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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/input/sodastore.yaml b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/input/sodastore.yaml new file mode 100644 index 000000000..ec38cf653 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/input/sodastore.yaml @@ -0,0 +1,81 @@ +openapi: 3.0.0 +info: + title: Soda Store API + version: 1.0.0 + description: API for managing sodas in a soda store + +paths: + /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': + $ref: '#/components/responses/NotFound' + '503': + $ref: '#/components/responses/ServiceUnavailable' + +components: + schemas: + Soda: + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + brand: + type: string + flavor: + type: string + price: + type: number + format: float + required: + - name + - brand + - flavor + - price + responses: + NotFound: + description: The specified resource was not found + content: + application/json: + schema: + type: object + properties: + message: + type: string + example: Resource not found + ServiceUnavailable: + description: The service is currently unavailable + content: + application/json: + schema: + type: object + properties: + message: + type: string + example: Resource not found + application/xml: + schema: + type: object + properties: + message: + type: string + example: Resource not found \ No newline at end of file diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/output/com/sap/cloud/sdk/services/inlineobject/api/DefaultApi.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/output/com/sap/cloud/sdk/services/inlineobject/api/DefaultApi.java new file mode 100644 index 000000000..fe3b311b5 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/output/com/sap/cloud/sdk/services/inlineobject/api/DefaultApi.java @@ -0,0 +1,126 @@ +/* +* Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. +*/ + +package com.sap.cloud.sdk.services.inlineobject.api; + +import com.fasterxml.jackson.core.type.TypeReference; + +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +import com.sap.cloud.sdk.services.openapi.apache.OpenApiResponse; +import com.sap.cloud.sdk.services.openapi.apache.ApiClient; +import com.sap.cloud.sdk.services.openapi.apache.BaseApi; +import com.sap.cloud.sdk.services.openapi.apache.Pair; + + +import com.sap.cloud.sdk.services.inlineobject.model.NotFound; +import com.sap.cloud.sdk.services.inlineobject.model.ServiceUnavailableApplicationJson; +import com.sap.cloud.sdk.services.inlineobject.model.ServiceUnavailableApplicationXml; +import com.sap.cloud.sdk.services.inlineobject.model.Soda; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.StringJoiner; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +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 BaseApi { + + /** + * Instantiates this API class to invoke operations on the Soda Store API + */ + public DefaultApi() {} + + /** + * 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 + */ + public DefaultApi(@Nonnull final ApiClient apiClient) { + super(apiClient); + } + + + /** + *

Get details of a specific soda + *

+ *

200 - The requested soda + *

404 - The specified resource was not found + *

503 - The service is currently unavailable + * @param sodaId + * ID of the soda to retrieve + * @return Soda + * @throws OpenApiRequestException if an error occurs while attempting to invoke the API + */ + @Nonnull + 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") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas/{sodaId}" + .replaceAll("\\{" + "sodaId" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(sodaId))); + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json", "application/xml" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "GET", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/output/com/sap/cloud/sdk/services/inlineobject/model/NotFound.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/output/com/sap/cloud/sdk/services/inlineobject/model/NotFound.java new file mode 100644 index 000000000..d0893c9d6 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/output/com/sap/cloud/sdk/services/inlineobject/model/NotFound.java @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * + * + * 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.inlineobject.model; + +import java.util.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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 com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * NotFound + */ +// CHECKSTYLE:OFF +public class NotFound +// CHECKSTYLE:ON +{ + @JsonProperty("message") + private String message; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the message of this {@link NotFound} instance and return the same instance. + * + * @param message The message of this {@link NotFound} + * @return The same instance of this {@link NotFound} class + */ + @Nonnull public NotFound message( @Nullable final String message) { + this.message = message; + return this; + } + + /** + * Get message + * @return message The message of this {@link NotFound} instance. + */ + @Nonnull + public String getMessage() { + return message; + } + + /** + * Set the message of this {@link NotFound} instance. + * + * @param message The message of this {@link NotFound} + */ + public void setMessage( @Nullable final String message) { + this.message = message; + } + + /** + * Get the names of the unrecognizable properties of the {@link NotFound}. + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link NotFound} instance. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + public Object getCustomField( @Nonnull final String name ) throws NoSuchElementException { + if( !cloudSdkCustomFields.containsKey(name) ) { + throw new NoSuchElementException("NotFound has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link NotFound} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( message != null ) declaredFields.put("message", message); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link NotFound} 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 NotFound notFound = (NotFound) o; + return Objects.equals(this.cloudSdkCustomFields, notFound.cloudSdkCustomFields) && + Objects.equals(this.message, notFound.message); + } + + @Override + public int hashCode() { + return Objects.hash(message, cloudSdkCustomFields); + } + + @Override + @Nonnull public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class NotFound {\n"); + sb.append(" message: ").append(toIndentedString(message)).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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/output/com/sap/cloud/sdk/services/inlineobject/model/ServiceUnavailableApplicationJson.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/output/com/sap/cloud/sdk/services/inlineobject/model/ServiceUnavailableApplicationJson.java new file mode 100644 index 000000000..2945b681e --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/output/com/sap/cloud/sdk/services/inlineobject/model/ServiceUnavailableApplicationJson.java @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * + * + * 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.inlineobject.model; + +import java.util.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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 com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * ServiceUnavailableApplicationJson + */ +// CHECKSTYLE:OFF +public class ServiceUnavailableApplicationJson +// CHECKSTYLE:ON +{ + @JsonProperty("message") + private String message; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the message of this {@link ServiceUnavailableApplicationJson} instance and return the same instance. + * + * @param message The message of this {@link ServiceUnavailableApplicationJson} + * @return The same instance of this {@link ServiceUnavailableApplicationJson} class + */ + @Nonnull public ServiceUnavailableApplicationJson message( @Nullable final String message) { + this.message = message; + return this; + } + + /** + * Get message + * @return message The message of this {@link ServiceUnavailableApplicationJson} instance. + */ + @Nonnull + public String getMessage() { + return message; + } + + /** + * Set the message of this {@link ServiceUnavailableApplicationJson} instance. + * + * @param message The message of this {@link ServiceUnavailableApplicationJson} + */ + public void setMessage( @Nullable final String message) { + this.message = message; + } + + /** + * Get the names of the unrecognizable properties of the {@link ServiceUnavailableApplicationJson}. + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ServiceUnavailableApplicationJson} instance. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + public Object getCustomField( @Nonnull final String name ) throws NoSuchElementException { + if( !cloudSdkCustomFields.containsKey(name) ) { + throw new NoSuchElementException("ServiceUnavailableApplicationJson has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link ServiceUnavailableApplicationJson} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( message != null ) declaredFields.put("message", message); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link ServiceUnavailableApplicationJson} 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 ServiceUnavailableApplicationJson serviceUnavailableApplicationJson = (ServiceUnavailableApplicationJson) o; + return Objects.equals(this.cloudSdkCustomFields, serviceUnavailableApplicationJson.cloudSdkCustomFields) && + Objects.equals(this.message, serviceUnavailableApplicationJson.message); + } + + @Override + public int hashCode() { + return Objects.hash(message, cloudSdkCustomFields); + } + + @Override + @Nonnull public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ServiceUnavailableApplicationJson {\n"); + sb.append(" message: ").append(toIndentedString(message)).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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/output/com/sap/cloud/sdk/services/inlineobject/model/ServiceUnavailableApplicationXml.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/output/com/sap/cloud/sdk/services/inlineobject/model/ServiceUnavailableApplicationXml.java new file mode 100644 index 000000000..7afdf67a4 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/output/com/sap/cloud/sdk/services/inlineobject/model/ServiceUnavailableApplicationXml.java @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * + * + * 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.inlineobject.model; + +import java.util.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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 com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * ServiceUnavailableApplicationXml + */ +// CHECKSTYLE:OFF +public class ServiceUnavailableApplicationXml +// CHECKSTYLE:ON +{ + @JsonProperty("message") + private String message; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the message of this {@link ServiceUnavailableApplicationXml} instance and return the same instance. + * + * @param message The message of this {@link ServiceUnavailableApplicationXml} + * @return The same instance of this {@link ServiceUnavailableApplicationXml} class + */ + @Nonnull public ServiceUnavailableApplicationXml message( @Nullable final String message) { + this.message = message; + return this; + } + + /** + * Get message + * @return message The message of this {@link ServiceUnavailableApplicationXml} instance. + */ + @Nonnull + public String getMessage() { + return message; + } + + /** + * Set the message of this {@link ServiceUnavailableApplicationXml} instance. + * + * @param message The message of this {@link ServiceUnavailableApplicationXml} + */ + public void setMessage( @Nullable final String message) { + this.message = message; + } + + /** + * Get the names of the unrecognizable properties of the {@link ServiceUnavailableApplicationXml}. + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ServiceUnavailableApplicationXml} instance. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + public Object getCustomField( @Nonnull final String name ) throws NoSuchElementException { + if( !cloudSdkCustomFields.containsKey(name) ) { + throw new NoSuchElementException("ServiceUnavailableApplicationXml has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link ServiceUnavailableApplicationXml} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( message != null ) declaredFields.put("message", message); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link ServiceUnavailableApplicationXml} 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 ServiceUnavailableApplicationXml serviceUnavailableApplicationXml = (ServiceUnavailableApplicationXml) o; + return Objects.equals(this.cloudSdkCustomFields, serviceUnavailableApplicationXml.cloudSdkCustomFields) && + Objects.equals(this.message, serviceUnavailableApplicationXml.message); + } + + @Override + public int hashCode() { + return Objects.hash(message, cloudSdkCustomFields); + } + + @Override + @Nonnull public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ServiceUnavailableApplicationXml {\n"); + sb.append(" message: ").append(toIndentedString(message)).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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/output/com/sap/cloud/sdk/services/inlineobject/model/Soda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/output/com/sap/cloud/sdk/services/inlineobject/model/Soda.java new file mode 100644 index 000000000..542eb09b3 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/inlineobject-schemas-enabled/output/com/sap/cloud/sdk/services/inlineobject/model/Soda.java @@ -0,0 +1,313 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * + * + * 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.inlineobject.model; + +import java.util.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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 com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +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("flavor") + private String flavor; + + @JsonProperty("price") + private Float price; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * 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( @Nullable 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( @Nullable 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 flavor of this {@link Soda} instance and return the same instance. + * + * @param flavor The flavor of this {@link Soda} + * @return The same instance of this {@link Soda} class + */ + @Nonnull public Soda flavor( @Nonnull final String flavor) { + this.flavor = flavor; + return this; + } + + /** + * Get flavor + * @return flavor The flavor of this {@link Soda} instance. + */ + @Nonnull + public String getFlavor() { + return flavor; + } + + /** + * Set the flavor of this {@link Soda} instance. + * + * @param flavor The flavor of this {@link Soda} + */ + public void setFlavor( @Nonnull final String flavor) { + this.flavor = flavor; + } + + /** + * 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. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + 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); + } + + /** + * Get the value of all properties of this {@link Soda} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( id != null ) declaredFields.put("id", id); + if( name != null ) declaredFields.put("name", name); + if( brand != null ) declaredFields.put("brand", brand); + if( flavor != null ) declaredFields.put("flavor", flavor); + if( price != null ) declaredFields.put("price", price); + return declaredFields; + } + + /** + * 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.flavor, soda.flavor) && + Objects.equals(this.price, soda.price); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, brand, flavor, 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(" 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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/partial-generation/input/sodastore.json b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/partial-generation/input/sodastore.json new file mode 100644 index 000000000..b629185c6 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/partial-generation/input/sodastore.json @@ -0,0 +1,261 @@ +{ + "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/SodaWithFoo" + } + } + } + }, + "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" + }, + "isAvailable": { + "type": "boolean" + }, + "flavor": { + "type": "string" + }, + "price": { + "type": "number", + "format": "float" + }, + "embedding":{ + "type": "array", + "items": { + "type": "number" + } + } + }, + "required": ["name", "brand", "flavor", "price", "embedding"] + }, + "NewSoda": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "brand": { + "type": "string" + }, + "zero": { + "type": "boolean" + }, + "since": { + "type": "string", + "format": "date" + }, + "flavor": { + "type": "string" + }, + "price": { + "type": "number", + "format": "float" + } + }, + "required": ["name", "brand", "flavor", "price"] + }, + "SodaWithFoo": { + "allOf": [ + { + "$ref": "#/components/schemas/Soda" + }, + { + "type": "object", + "properties": { + "foo": { + "type": "integer", + "format": "int64", + "example": 123 + } + } + } + ] + }, + "UpdateSoda": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "zero": { + "type": "boolean" + }, + "since": { + "type": "string", + "format": "date" + }, + "brand": { + "type": "string" + }, + "flavor": { + "type": "string" + }, + "price": { + "type": "number", + "format": "float" + } + } + } + } + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/partial-generation/output/com/sap/cloud/sdk/services/builder/api/DefaultApi.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/partial-generation/output/com/sap/cloud/sdk/services/builder/api/DefaultApi.java new file mode 100644 index 000000000..88b3baaf7 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/partial-generation/output/com/sap/cloud/sdk/services/builder/api/DefaultApi.java @@ -0,0 +1,248 @@ +/* +* Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. +*/ + +package com.sap.cloud.sdk.services.builder.api; + +import com.fasterxml.jackson.core.type.TypeReference; + +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +import com.sap.cloud.sdk.services.openapi.apache.OpenApiResponse; +import com.sap.cloud.sdk.services.openapi.apache.ApiClient; +import com.sap.cloud.sdk.services.openapi.apache.BaseApi; +import com.sap.cloud.sdk.services.openapi.apache.Pair; + + +import com.sap.cloud.sdk.services.builder.model.Soda; +import com.sap.cloud.sdk.services.builder.model.SodaWithFoo; +import com.sap.cloud.sdk.services.builder.model.UpdateSoda; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.StringJoiner; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +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 BaseApi { + + /** + * Instantiates this API class to invoke operations on the Soda Store API + */ + public DefaultApi() {} + + /** + * 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 + */ + 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") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas/{sodaId}" + .replaceAll("\\{" + "sodaId" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(sodaId))); + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "DELETE", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } + + /** + *

Get details of a specific soda + *

+ *

200 - The requested soda + *

404 - Soda not found + * @param sodaId + * ID of the soda to retrieve + * @return SodaWithFoo + * @throws OpenApiRequestException if an error occurs while attempting to invoke the API + */ + @Nonnull + public SodaWithFoo 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") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas/{sodaId}" + .replaceAll("\\{" + "sodaId" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(sodaId))); + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "GET", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + 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 + */ + @Nonnull + 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") + .statusCode(400); + } + + // verify the required parameter 'updateSoda' is set + if (updateSoda == null) { + throw new OpenApiRequestException("Missing the required parameter 'updateSoda' when calling updateSodaById") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas/{sodaId}" + .replaceAll("\\{" + "sodaId" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(sodaId))); + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + "application/json" + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "PUT", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/partial-generation/output/com/sap/cloud/sdk/services/builder/model/Soda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/partial-generation/output/com/sap/cloud/sdk/services/builder/model/Soda.java new file mode 100644 index 000000000..45a204a0f --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/partial-generation/output/com/sap/cloud/sdk/services/builder/model/Soda.java @@ -0,0 +1,313 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * + * + * 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.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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 com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +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("isAvailable") + private Boolean isAvailable; + + @JsonProperty("price") + private Float price; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * 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( @Nullable 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( @Nullable 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 isAvailable of this {@link Soda} instance and return the same instance. + * + * @param isAvailable The isAvailable of this {@link Soda} + * @return The same instance of this {@link Soda} class + */ + @Nonnull public Soda isAvailable( @Nullable final Boolean isAvailable) { + this.isAvailable = isAvailable; + return this; + } + + /** + * Get isAvailable + * @return isAvailable The isAvailable of this {@link Soda} instance. + */ + @Nonnull + public Boolean isIsAvailable() { + return isAvailable; + } + + /** + * Set the isAvailable of this {@link Soda} instance. + * + * @param isAvailable The isAvailable of this {@link Soda} + */ + public void setIsAvailable( @Nullable final Boolean isAvailable) { + this.isAvailable = isAvailable; + } + + /** + * 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. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + 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); + } + + /** + * Get the value of all properties of this {@link Soda} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( id != null ) declaredFields.put("id", id); + if( name != null ) declaredFields.put("name", name); + if( brand != null ) declaredFields.put("brand", brand); + if( isAvailable != null ) declaredFields.put("isAvailable", isAvailable); + if( price != null ) declaredFields.put("price", price); + return declaredFields; + } + + /** + * 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.isAvailable, soda.isAvailable) && + Objects.equals(this.price, soda.price); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, brand, isAvailable, 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(" isAvailable: ").append(toIndentedString(isAvailable)).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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/partial-generation/output/com/sap/cloud/sdk/services/builder/model/SodaWithFoo.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/partial-generation/output/com/sap/cloud/sdk/services/builder/model/SodaWithFoo.java new file mode 100644 index 000000000..edccab010 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/partial-generation/output/com/sap/cloud/sdk/services/builder/model/SodaWithFoo.java @@ -0,0 +1,313 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * + * + * 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.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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 com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * SodaWithFoo + */ +// CHECKSTYLE:OFF +public class SodaWithFoo +// CHECKSTYLE:ON +{ + @JsonProperty("id") + private Long id; + + @JsonProperty("name") + private String name; + + @JsonProperty("brand") + private String brand; + + @JsonProperty("isAvailable") + private Boolean isAvailable; + + @JsonProperty("price") + private Float price; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the id of this {@link SodaWithFoo} instance and return the same instance. + * + * @param id The id of this {@link SodaWithFoo} + * @return The same instance of this {@link SodaWithFoo} class + */ + @Nonnull public SodaWithFoo id( @Nullable final Long id) { + this.id = id; + return this; + } + + /** + * Get id + * @return id The id of this {@link SodaWithFoo} instance. + */ + @Nonnull + public Long getId() { + return id; + } + + /** + * Set the id of this {@link SodaWithFoo} instance. + * + * @param id The id of this {@link SodaWithFoo} + */ + public void setId( @Nullable final Long id) { + this.id = id; + } + + /** + * Set the name of this {@link SodaWithFoo} instance and return the same instance. + * + * @param name The name of this {@link SodaWithFoo} + * @return The same instance of this {@link SodaWithFoo} class + */ + @Nonnull public SodaWithFoo name( @Nonnull final String name) { + this.name = name; + return this; + } + + /** + * Get name + * @return name The name of this {@link SodaWithFoo} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link SodaWithFoo} instance. + * + * @param name The name of this {@link SodaWithFoo} + */ + public void setName( @Nonnull final String name) { + this.name = name; + } + + /** + * Set the brand of this {@link SodaWithFoo} instance and return the same instance. + * + * @param brand The brand of this {@link SodaWithFoo} + * @return The same instance of this {@link SodaWithFoo} class + */ + @Nonnull public SodaWithFoo brand( @Nonnull final String brand) { + this.brand = brand; + return this; + } + + /** + * Get brand + * @return brand The brand of this {@link SodaWithFoo} instance. + */ + @Nonnull + public String getBrand() { + return brand; + } + + /** + * Set the brand of this {@link SodaWithFoo} instance. + * + * @param brand The brand of this {@link SodaWithFoo} + */ + public void setBrand( @Nonnull final String brand) { + this.brand = brand; + } + + /** + * Set the isAvailable of this {@link SodaWithFoo} instance and return the same instance. + * + * @param isAvailable The isAvailable of this {@link SodaWithFoo} + * @return The same instance of this {@link SodaWithFoo} class + */ + @Nonnull public SodaWithFoo isAvailable( @Nullable final Boolean isAvailable) { + this.isAvailable = isAvailable; + return this; + } + + /** + * Get isAvailable + * @return isAvailable The isAvailable of this {@link SodaWithFoo} instance. + */ + @Nonnull + public Boolean isIsAvailable() { + return isAvailable; + } + + /** + * Set the isAvailable of this {@link SodaWithFoo} instance. + * + * @param isAvailable The isAvailable of this {@link SodaWithFoo} + */ + public void setIsAvailable( @Nullable final Boolean isAvailable) { + this.isAvailable = isAvailable; + } + + /** + * Set the price of this {@link SodaWithFoo} instance and return the same instance. + * + * @param price The price of this {@link SodaWithFoo} + * @return The same instance of this {@link SodaWithFoo} class + */ + @Nonnull public SodaWithFoo price( @Nonnull final Float price) { + this.price = price; + return this; + } + + /** + * Get price + * @return price The price of this {@link SodaWithFoo} instance. + */ + @Nonnull + public Float getPrice() { + return price; + } + + /** + * Set the price of this {@link SodaWithFoo} instance. + * + * @param price The price of this {@link SodaWithFoo} + */ + public void setPrice( @Nonnull final Float price) { + this.price = price; + } + + /** + * Get the names of the unrecognizable properties of the {@link SodaWithFoo}. + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link SodaWithFoo} instance. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + public Object getCustomField( @Nonnull final String name ) throws NoSuchElementException { + if( !cloudSdkCustomFields.containsKey(name) ) { + throw new NoSuchElementException("SodaWithFoo has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link SodaWithFoo} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( id != null ) declaredFields.put("id", id); + if( name != null ) declaredFields.put("name", name); + if( brand != null ) declaredFields.put("brand", brand); + if( isAvailable != null ) declaredFields.put("isAvailable", isAvailable); + if( price != null ) declaredFields.put("price", price); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link SodaWithFoo} 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 SodaWithFoo sodaWithFoo = (SodaWithFoo) o; + return Objects.equals(this.cloudSdkCustomFields, sodaWithFoo.cloudSdkCustomFields) && + Objects.equals(this.id, sodaWithFoo.id) && + Objects.equals(this.name, sodaWithFoo.name) && + Objects.equals(this.brand, sodaWithFoo.brand) && + Objects.equals(this.isAvailable, sodaWithFoo.isAvailable) && + Objects.equals(this.price, sodaWithFoo.price); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, brand, isAvailable, price, cloudSdkCustomFields); + } + + @Override + @Nonnull public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class SodaWithFoo {\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(" isAvailable: ").append(toIndentedString(isAvailable)).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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/partial-generation/output/com/sap/cloud/sdk/services/builder/model/UpdateSoda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/partial-generation/output/com/sap/cloud/sdk/services/builder/model/UpdateSoda.java new file mode 100644 index 000000000..40d04555d --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/partial-generation/output/com/sap/cloud/sdk/services/builder/model/UpdateSoda.java @@ -0,0 +1,314 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * Soda Store API + * API for managing sodas in a soda store + * + * + * + * 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.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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.time.LocalDate; +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 javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * UpdateSoda + */ +// CHECKSTYLE:OFF +public class UpdateSoda +// CHECKSTYLE:ON +{ + @JsonProperty("name") + private String name; + + @JsonProperty("zero") + private Boolean zero; + + @JsonProperty("since") + private LocalDate since; + + @JsonProperty("brand") + private String brand; + + @JsonProperty("price") + private Float price; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * 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( @Nullable 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( @Nullable final String name) { + this.name = name; + } + + /** + * Set the zero of this {@link UpdateSoda} instance and return the same instance. + * + * @param zero The zero of this {@link UpdateSoda} + * @return The same instance of this {@link UpdateSoda} class + */ + @Nonnull public UpdateSoda zero( @Nullable final Boolean zero) { + this.zero = zero; + return this; + } + + /** + * Get zero + * @return zero The zero of this {@link UpdateSoda} instance. + */ + @Nonnull + public Boolean isZero() { + return zero; + } + + /** + * Set the zero of this {@link UpdateSoda} instance. + * + * @param zero The zero of this {@link UpdateSoda} + */ + public void setZero( @Nullable final Boolean zero) { + this.zero = zero; + } + + /** + * Set the since of this {@link UpdateSoda} instance and return the same instance. + * + * @param since The since of this {@link UpdateSoda} + * @return The same instance of this {@link UpdateSoda} class + */ + @Nonnull public UpdateSoda since( @Nullable final LocalDate since) { + this.since = since; + return this; + } + + /** + * Get since + * @return since The since of this {@link UpdateSoda} instance. + */ + @Nonnull + public LocalDate getSince() { + return since; + } + + /** + * Set the since of this {@link UpdateSoda} instance. + * + * @param since The since of this {@link UpdateSoda} + */ + public void setSince( @Nullable final LocalDate since) { + this.since = since; + } + + /** + * 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( @Nullable 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( @Nullable final String brand) { + this.brand = brand; + } + + /** + * 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( @Nullable 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( @Nullable 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. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + 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); + } + + /** + * Get the value of all properties of this {@link UpdateSoda} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( name != null ) declaredFields.put("name", name); + if( zero != null ) declaredFields.put("zero", zero); + if( since != null ) declaredFields.put("since", since); + if( brand != null ) declaredFields.put("brand", brand); + if( price != null ) declaredFields.put("price", price); + return declaredFields; + } + + /** + * 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.zero, updateSoda.zero) && + Objects.equals(this.since, updateSoda.since) && + Objects.equals(this.brand, updateSoda.brand) && + Objects.equals(this.price, updateSoda.price); + } + + @Override + public int hashCode() { + return Objects.hash(name, zero, since, brand, 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(" zero: ").append(toIndentedString(zero)).append("\n"); + sb.append(" since: ").append(toIndentedString(since)).append("\n"); + sb.append(" brand: ").append(toIndentedString(brand)).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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/input/sodastore.json b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/input/sodastore.json new file mode 100644 index 000000000..e9ca71a1d --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/input/sodastore.json @@ -0,0 +1,292 @@ +{ + "openapi": "3.0.3", + "info": { + "title": "SodaStore API", + "version": "1.0.0", + "description": "API for managing soda products and orders in SodaStore." + }, + "tags": [ + { + "name": "Sodas", + "description": "Everything about our Sodas" + }, + { + "name": "user", + "description": "Operations about user" + }, + { + "name": "Orders", + "description": "Access to Sodastore orders" + } + ], + "components": { + "securitySchemes": { + "apiKeyAuth": { + "type": "apiKey", + "in": "header", + "name": "X-API-Key" + }, + "bearerAuth": { + "type": "http", + "scheme": "bearer" + } + }, + "schemas": { + "Soda": { + "type": "object", + "required": [ + "name", + "brand", + "quantity", + "price" + ], + "properties": { + "name": { + "type": "string", + "example": "Cola" + }, + "brand": { + "type": "string", + "example": "Coca-Cola" + }, + "quantity": { + "type": "integer", + "format": "int32", + "example": 100 + }, + "packaging": { + "type": "string", + "enum": ["glass", "carton", "can"], + "nullable": false + }, + "price": { + "type": "number", + "format": "float", + "example": 1.5 + } + } + }, + "SodaWithId": { + "allOf": [ + { + "$ref": "#/components/schemas/Soda" + }, + { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64", + "example": 123 + } + } + } + ] + }, + "Order": { + "type": "object", + "required": [ + "productId", + "quantity" + ], + "properties": { + "productId": { + "type": "integer", + "format": "int64", + "example": 1 + }, + "quantity": { + "type": "integer", + "format": "int32", + "example": 2 + }, + "totalPrice": { + "type": "number", + "format": "float", + "example": 3.0 + }, + "typelessProperty": { + "description": "Some typeless property, interpreted by the generator as nullable by default (because typeless)" + }, + "nullableProperty": { + "type": "string", + "description": "Some typed property that is deliberately made nullable", + "nullable": true + } + } + }, + "OrderWithTimestamp": { + "allOf": [ + { + "$ref": "#/components/schemas/Order" + }, + { + "type": "object", + "properties": { + "timestamp": { + "type": "string", + "format": "date-time" + } + } + } + ] + } + } + }, + "paths": { + "/sodas": { + "get": { + "operationId": "foo.bar.get", + "summary": "Get all soda products", + "tags": [ + "Sodas" + ], + "security": [ + { + "apiKeyAuth": [ ] + } + ], + "responses": { + "200": { + "description": "A list of soda products", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/SodaWithId" + } + } + } + } + } + } + }, + "put": { + "summary": "Update a specific soda product by ID", + "tags": [ + "Sodas" + ], + "security": [ + { + "apiKeyAuth": [ ] + } + ], + "requestBody": { + "description": "The updated soda product", + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SodaWithId" + } + } + } + }, + "responses": { + "200": { + "description": "The updated soda product", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Soda" + } + } + } + }, + "404": { + "description": "Soda product not found" + }, + "204": { + "description": "Nothing has changed" + } + } + } + }, + "/sodas/{id}": { + "get": { + "summary": "Get a specific soda product by ID", + "tags": [ + "Sodas" + ], + "security": [ + { + "apiKeyAuth": [ ] + } + ], + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of the soda product to retrieve", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + } + ], + "responses": { + "200": { + "description": "The soda product", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SodaWithId" + } + } + } + }, + "404": { + "description": "Soda product not found" + } + } + } + }, + "/orders": { + "post": { + "operationId": "foo2.bar2.get", + "summary": "Create a new order", + "tags": [ + "Orders" + ], + "security": [ + { + "apiKeyAuth": [ ] + } + ], + "requestBody": { + "description": "The order details", + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Order" + } + } + } + }, + "responses": { + "201": { + "description": "The created order", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Order" + } + } + } + } + } + } + } + }, + "security": [ + { + "apiKeyAuth": [ ] + }, + { + "bearerAuth": [ ] + } + ] +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/api/OrdersApi.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/api/OrdersApi.java new file mode 100644 index 000000000..fd890ccd3 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/api/OrdersApi.java @@ -0,0 +1,120 @@ +/* +* Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. +*/ + +package com.sap.cloud.sdk.services.builder.api; + +import com.fasterxml.jackson.core.type.TypeReference; + +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +import com.sap.cloud.sdk.services.openapi.apache.OpenApiResponse; +import com.sap.cloud.sdk.services.openapi.apache.ApiClient; +import com.sap.cloud.sdk.services.openapi.apache.BaseApi; +import com.sap.cloud.sdk.services.openapi.apache.Pair; + + +import com.sap.cloud.sdk.services.builder.model.Order; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.StringJoiner; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; + + +/** +* SodaStore API in version 1.0.0. +* +* API for managing soda products and orders in SodaStore. +*/ +public class OrdersApi extends BaseApi { + + /** + * Instantiates this API class to invoke operations on the SodaStore API + */ + public OrdersApi() {} + + /** + * Instantiates this API class to invoke operations on the SodaStore API. + * + * @param httpDestination The destination that API should be used with + */ + public OrdersApi( @Nonnull final Destination httpDestination ) + { + super(httpDestination); + } + + /** + * Instantiates this API class to invoke operations on the SodaStore API based on a given {@link ApiClient}. + * + * @param apiClient + * ApiClient to invoke the API on + */ + public OrdersApi(@Nonnull final ApiClient apiClient) { + super(apiClient); + } + + + /** + *

Create a new order + *

+ *

201 - The created order + * @param order + * The order details + * @return Order + * @throws OpenApiRequestException if an error occurs while attempting to invoke the API + */ + @Nonnull + public Order get(@Nonnull final Order order) throws OpenApiRequestException { + final Object localVarPostBody = order; + + // verify the required parameter 'order' is set + if (order == null) { + throw new OpenApiRequestException("Missing the required parameter 'order' when calling get") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/orders"; + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + "application/json" + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "POST", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/api/SodasApi.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/api/SodasApi.java new file mode 100644 index 000000000..b4713b3fb --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/api/SodasApi.java @@ -0,0 +1,229 @@ +/* +* Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. +*/ + +package com.sap.cloud.sdk.services.builder.api; + +import com.fasterxml.jackson.core.type.TypeReference; + +import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException; +import com.sap.cloud.sdk.services.openapi.apache.OpenApiResponse; +import com.sap.cloud.sdk.services.openapi.apache.ApiClient; +import com.sap.cloud.sdk.services.openapi.apache.BaseApi; +import com.sap.cloud.sdk.services.openapi.apache.Pair; + + +import com.sap.cloud.sdk.services.builder.model.Soda; +import com.sap.cloud.sdk.services.builder.model.SodaWithId; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.StringJoiner; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.sap.cloud.sdk.cloudplatform.connectivity.Destination; + + +/** +* SodaStore API in version 1.0.0. +* +* API for managing soda products and orders in SodaStore. +*/ +public class SodasApi extends BaseApi { + + /** + * Instantiates this API class to invoke operations on the SodaStore API + */ + public SodasApi() {} + + /** + * Instantiates this API class to invoke operations on the SodaStore API. + * + * @param httpDestination The destination that API should be used with + */ + public SodasApi( @Nonnull final Destination httpDestination ) + { + super(httpDestination); + } + + /** + * Instantiates this API class to invoke operations on the SodaStore API based on a given {@link ApiClient}. + * + * @param apiClient + * ApiClient to invoke the API on + */ + public SodasApi(@Nonnull final ApiClient apiClient) { + super(apiClient); + } + + + /** + *

Get all soda products + *

+ *

200 - A list of soda products + * @return List<SodaWithId> + * @throws OpenApiRequestException if an error occurs while attempting to invoke the API + */ + @Nonnull + public List get() throws OpenApiRequestException { + final Object localVarPostBody = null; + + // create path and map variables + final String localVarPath = "/sodas"; + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference> localVarReturnType = new TypeReference>() {}; + + return apiClient.invokeAPI( + localVarPath, + "GET", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } + + /** + *

Get a specific soda product by ID + *

+ *

200 - The soda product + *

404 - Soda product not found + * @param id + * ID of the soda product to retrieve + * @return SodaWithId + * @throws OpenApiRequestException if an error occurs while attempting to invoke the API + */ + @Nonnull + public SodaWithId sodasIdGet(@Nonnull final Long id) throws OpenApiRequestException { + final Object localVarPostBody = null; + + // verify the required parameter 'id' is set + if (id == null) { + throw new OpenApiRequestException("Missing the required parameter 'id' when calling sodasIdGet") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas/{id}" + .replaceAll("\\{" + "id" + "\\}", ApiClient.escapeString(ApiClient.parameterToString(id))); + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "GET", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } + + /** + *

Update a specific soda product by ID + *

+ *

200 - The updated soda product + *

404 - Soda product not found + *

204 - Nothing has changed + * @param sodaWithId + * The updated soda product + * @return Soda + * @throws OpenApiRequestException if an error occurs while attempting to invoke the API + */ + @Nullable + public Soda sodasPut(@Nonnull final SodaWithId sodaWithId) throws OpenApiRequestException { + final Object localVarPostBody = sodaWithId; + + // verify the required parameter 'sodaWithId' is set + if (sodaWithId == null) { + throw new OpenApiRequestException("Missing the required parameter 'sodaWithId' when calling sodasPut") + .statusCode(400); + } + + // create path and map variables + final String localVarPath = "/sodas"; + + final StringJoiner localVarQueryStringJoiner = new StringJoiner("&"); + String localVarQueryParameterBaseName; + final List localVarQueryParams = new ArrayList(); + final List localVarCollectionQueryParams = new ArrayList(); + final Map localVarHeaderParams = new HashMap(); + final Map localVarFormParams = new HashMap(); + + + final String[] localVarAccepts = { + "application/json" + }; + final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts); + final String[] localVarContentTypes = { + "application/json" + }; + final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes); + + final TypeReference localVarReturnType = new TypeReference() {}; + + return apiClient.invokeAPI( + localVarPath, + "PUT", + localVarQueryParams, + localVarCollectionQueryParams, + localVarQueryStringJoiner.toString(), + localVarPostBody, + localVarHeaderParams, + localVarFormParams, + localVarAccept, + localVarContentType, + localVarReturnType + ); + } +} diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/model/Order.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/model/Order.java new file mode 100644 index 000000000..30c807a7b --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/model/Order.java @@ -0,0 +1,313 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * SodaStore API + * API for managing soda products and orders in SodaStore. + * + * + * + * 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.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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 com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Order + */ +// CHECKSTYLE:OFF +public class Order +// CHECKSTYLE:ON +{ + @JsonProperty("productId") + private Long productId; + + @JsonProperty("quantity") + private Integer quantity; + + @JsonProperty("totalPrice") + private Float totalPrice; + + @JsonProperty("typelessProperty") + private Object typelessProperty = null; + + @JsonProperty("nullableProperty") + private String nullableProperty; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the productId of this {@link Order} instance and return the same instance. + * + * @param productId The productId of this {@link Order} + * @return The same instance of this {@link Order} class + */ + @Nonnull public Order productId( @Nonnull final Long productId) { + this.productId = productId; + return this; + } + + /** + * Get productId + * @return productId The productId of this {@link Order} instance. + */ + @Nonnull + public Long getProductId() { + return productId; + } + + /** + * Set the productId of this {@link Order} instance. + * + * @param productId The productId of this {@link Order} + */ + public void setProductId( @Nonnull final Long productId) { + this.productId = productId; + } + + /** + * Set the quantity of this {@link Order} instance and return the same instance. + * + * @param quantity The quantity of this {@link Order} + * @return The same instance of this {@link Order} class + */ + @Nonnull public Order quantity( @Nonnull final Integer quantity) { + this.quantity = quantity; + return this; + } + + /** + * Get quantity + * @return quantity The quantity of this {@link Order} instance. + */ + @Nonnull + public Integer getQuantity() { + return quantity; + } + + /** + * Set the quantity of this {@link Order} instance. + * + * @param quantity The quantity of this {@link Order} + */ + public void setQuantity( @Nonnull final Integer quantity) { + this.quantity = quantity; + } + + /** + * Set the totalPrice of this {@link Order} instance and return the same instance. + * + * @param totalPrice The totalPrice of this {@link Order} + * @return The same instance of this {@link Order} class + */ + @Nonnull public Order totalPrice( @Nullable final Float totalPrice) { + this.totalPrice = totalPrice; + return this; + } + + /** + * Get totalPrice + * @return totalPrice The totalPrice of this {@link Order} instance. + */ + @Nonnull + public Float getTotalPrice() { + return totalPrice; + } + + /** + * Set the totalPrice of this {@link Order} instance. + * + * @param totalPrice The totalPrice of this {@link Order} + */ + public void setTotalPrice( @Nullable final Float totalPrice) { + this.totalPrice = totalPrice; + } + + /** + * Set the typelessProperty of this {@link Order} instance and return the same instance. + * + * @param typelessProperty Some typeless property, interpreted by the generator as nullable by default (because typeless) + * @return The same instance of this {@link Order} class + */ + @Nonnull public Order typelessProperty( @Nullable final Object typelessProperty) { + this.typelessProperty = typelessProperty; + return this; + } + + /** + * Some typeless property, interpreted by the generator as nullable by default (because typeless) + * @return typelessProperty The typelessProperty of this {@link Order} instance. + */ + @Nullable + public Object getTypelessProperty() { + return typelessProperty; + } + + /** + * Set the typelessProperty of this {@link Order} instance. + * + * @param typelessProperty Some typeless property, interpreted by the generator as nullable by default (because typeless) + */ + public void setTypelessProperty( @Nullable final Object typelessProperty) { + this.typelessProperty = typelessProperty; + } + + /** + * Set the nullableProperty of this {@link Order} instance and return the same instance. + * + * @param nullableProperty Some typed property that is deliberately made nullable + * @return The same instance of this {@link Order} class + */ + @Nonnull public Order nullableProperty( @Nullable final String nullableProperty) { + this.nullableProperty = nullableProperty; + return this; + } + + /** + * Some typed property that is deliberately made nullable + * @return nullableProperty The nullableProperty of this {@link Order} instance. + */ + @Nullable + public String getNullableProperty() { + return nullableProperty; + } + + /** + * Set the nullableProperty of this {@link Order} instance. + * + * @param nullableProperty Some typed property that is deliberately made nullable + */ + public void setNullableProperty( @Nullable final String nullableProperty) { + this.nullableProperty = nullableProperty; + } + + /** + * Get the names of the unrecognizable properties of the {@link Order}. + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link Order} instance. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + public Object getCustomField( @Nonnull final String name ) throws NoSuchElementException { + if( !cloudSdkCustomFields.containsKey(name) ) { + throw new NoSuchElementException("Order has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link Order} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( productId != null ) declaredFields.put("productId", productId); + if( quantity != null ) declaredFields.put("quantity", quantity); + if( totalPrice != null ) declaredFields.put("totalPrice", totalPrice); + if( typelessProperty != null ) declaredFields.put("typelessProperty", typelessProperty); + if( nullableProperty != null ) declaredFields.put("nullableProperty", nullableProperty); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link Order} 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 Order order = (Order) o; + return Objects.equals(this.cloudSdkCustomFields, order.cloudSdkCustomFields) && + Objects.equals(this.productId, order.productId) && + Objects.equals(this.quantity, order.quantity) && + Objects.equals(this.totalPrice, order.totalPrice) && + Objects.equals(this.typelessProperty, order.typelessProperty) && + Objects.equals(this.nullableProperty, order.nullableProperty); + } + + @Override + public int hashCode() { + return Objects.hash(productId, quantity, totalPrice, typelessProperty, nullableProperty, cloudSdkCustomFields); + } + + @Override + @Nonnull public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class Order {\n"); + sb.append(" productId: ").append(toIndentedString(productId)).append("\n"); + sb.append(" quantity: ").append(toIndentedString(quantity)).append("\n"); + sb.append(" totalPrice: ").append(toIndentedString(totalPrice)).append("\n"); + sb.append(" typelessProperty: ").append(toIndentedString(typelessProperty)).append("\n"); + sb.append(" nullableProperty: ").append(toIndentedString(nullableProperty)).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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/model/OrderWithTimestamp.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/model/OrderWithTimestamp.java new file mode 100644 index 000000000..b81a924cb --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/model/OrderWithTimestamp.java @@ -0,0 +1,349 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * SodaStore API + * API for managing soda products and orders in SodaStore. + * + * + * + * 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.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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.time.OffsetDateTime; +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 javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * OrderWithTimestamp + */ +// CHECKSTYLE:OFF +public class OrderWithTimestamp +// CHECKSTYLE:ON +{ + @JsonProperty("productId") + private Long productId; + + @JsonProperty("quantity") + private Integer quantity; + + @JsonProperty("totalPrice") + private Float totalPrice; + + @JsonProperty("typelessProperty") + private Object typelessProperty; + + @JsonProperty("nullableProperty") + private String nullableProperty; + + @JsonProperty("timestamp") + private OffsetDateTime timestamp; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the productId of this {@link OrderWithTimestamp} instance and return the same instance. + * + * @param productId The productId of this {@link OrderWithTimestamp} + * @return The same instance of this {@link OrderWithTimestamp} class + */ + @Nonnull public OrderWithTimestamp productId( @Nonnull final Long productId) { + this.productId = productId; + return this; + } + + /** + * Get productId + * @return productId The productId of this {@link OrderWithTimestamp} instance. + */ + @Nonnull + public Long getProductId() { + return productId; + } + + /** + * Set the productId of this {@link OrderWithTimestamp} instance. + * + * @param productId The productId of this {@link OrderWithTimestamp} + */ + public void setProductId( @Nonnull final Long productId) { + this.productId = productId; + } + + /** + * Set the quantity of this {@link OrderWithTimestamp} instance and return the same instance. + * + * @param quantity The quantity of this {@link OrderWithTimestamp} + * @return The same instance of this {@link OrderWithTimestamp} class + */ + @Nonnull public OrderWithTimestamp quantity( @Nonnull final Integer quantity) { + this.quantity = quantity; + return this; + } + + /** + * Get quantity + * @return quantity The quantity of this {@link OrderWithTimestamp} instance. + */ + @Nonnull + public Integer getQuantity() { + return quantity; + } + + /** + * Set the quantity of this {@link OrderWithTimestamp} instance. + * + * @param quantity The quantity of this {@link OrderWithTimestamp} + */ + public void setQuantity( @Nonnull final Integer quantity) { + this.quantity = quantity; + } + + /** + * Set the totalPrice of this {@link OrderWithTimestamp} instance and return the same instance. + * + * @param totalPrice The totalPrice of this {@link OrderWithTimestamp} + * @return The same instance of this {@link OrderWithTimestamp} class + */ + @Nonnull public OrderWithTimestamp totalPrice( @Nullable final Float totalPrice) { + this.totalPrice = totalPrice; + return this; + } + + /** + * Get totalPrice + * @return totalPrice The totalPrice of this {@link OrderWithTimestamp} instance. + */ + @Nonnull + public Float getTotalPrice() { + return totalPrice; + } + + /** + * Set the totalPrice of this {@link OrderWithTimestamp} instance. + * + * @param totalPrice The totalPrice of this {@link OrderWithTimestamp} + */ + public void setTotalPrice( @Nullable final Float totalPrice) { + this.totalPrice = totalPrice; + } + + /** + * Set the typelessProperty of this {@link OrderWithTimestamp} instance and return the same instance. + * + * @param typelessProperty Some typeless property, interpreted by the generator as nullable by default (because typeless) + * @return The same instance of this {@link OrderWithTimestamp} class + */ + @Nonnull public OrderWithTimestamp typelessProperty( @Nullable final Object typelessProperty) { + this.typelessProperty = typelessProperty; + return this; + } + + /** + * Some typeless property, interpreted by the generator as nullable by default (because typeless) + * @return typelessProperty The typelessProperty of this {@link OrderWithTimestamp} instance. + */ + @Nullable + public Object getTypelessProperty() { + return typelessProperty; + } + + /** + * Set the typelessProperty of this {@link OrderWithTimestamp} instance. + * + * @param typelessProperty Some typeless property, interpreted by the generator as nullable by default (because typeless) + */ + public void setTypelessProperty( @Nullable final Object typelessProperty) { + this.typelessProperty = typelessProperty; + } + + /** + * Set the nullableProperty of this {@link OrderWithTimestamp} instance and return the same instance. + * + * @param nullableProperty Some typed property that is deliberately made nullable + * @return The same instance of this {@link OrderWithTimestamp} class + */ + @Nonnull public OrderWithTimestamp nullableProperty( @Nullable final String nullableProperty) { + this.nullableProperty = nullableProperty; + return this; + } + + /** + * Some typed property that is deliberately made nullable + * @return nullableProperty The nullableProperty of this {@link OrderWithTimestamp} instance. + */ + @Nullable + public String getNullableProperty() { + return nullableProperty; + } + + /** + * Set the nullableProperty of this {@link OrderWithTimestamp} instance. + * + * @param nullableProperty Some typed property that is deliberately made nullable + */ + public void setNullableProperty( @Nullable final String nullableProperty) { + this.nullableProperty = nullableProperty; + } + + /** + * Set the timestamp of this {@link OrderWithTimestamp} instance and return the same instance. + * + * @param timestamp The timestamp of this {@link OrderWithTimestamp} + * @return The same instance of this {@link OrderWithTimestamp} class + */ + @Nonnull public OrderWithTimestamp timestamp( @Nullable final OffsetDateTime timestamp) { + this.timestamp = timestamp; + return this; + } + + /** + * Get timestamp + * @return timestamp The timestamp of this {@link OrderWithTimestamp} instance. + */ + @Nonnull + public OffsetDateTime getTimestamp() { + return timestamp; + } + + /** + * Set the timestamp of this {@link OrderWithTimestamp} instance. + * + * @param timestamp The timestamp of this {@link OrderWithTimestamp} + */ + public void setTimestamp( @Nullable final OffsetDateTime timestamp) { + this.timestamp = timestamp; + } + + /** + * Get the names of the unrecognizable properties of the {@link OrderWithTimestamp}. + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link OrderWithTimestamp} instance. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + public Object getCustomField( @Nonnull final String name ) throws NoSuchElementException { + if( !cloudSdkCustomFields.containsKey(name) ) { + throw new NoSuchElementException("OrderWithTimestamp has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link OrderWithTimestamp} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( productId != null ) declaredFields.put("productId", productId); + if( quantity != null ) declaredFields.put("quantity", quantity); + if( totalPrice != null ) declaredFields.put("totalPrice", totalPrice); + if( typelessProperty != null ) declaredFields.put("typelessProperty", typelessProperty); + if( nullableProperty != null ) declaredFields.put("nullableProperty", nullableProperty); + if( timestamp != null ) declaredFields.put("timestamp", timestamp); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link OrderWithTimestamp} 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 OrderWithTimestamp orderWithTimestamp = (OrderWithTimestamp) o; + return Objects.equals(this.cloudSdkCustomFields, orderWithTimestamp.cloudSdkCustomFields) && + Objects.equals(this.productId, orderWithTimestamp.productId) && + Objects.equals(this.quantity, orderWithTimestamp.quantity) && + Objects.equals(this.totalPrice, orderWithTimestamp.totalPrice) && + Objects.equals(this.typelessProperty, orderWithTimestamp.typelessProperty) && + Objects.equals(this.nullableProperty, orderWithTimestamp.nullableProperty) && + Objects.equals(this.timestamp, orderWithTimestamp.timestamp); + } + + @Override + public int hashCode() { + return Objects.hash(productId, quantity, totalPrice, typelessProperty, nullableProperty, timestamp, cloudSdkCustomFields); + } + + @Override + @Nonnull public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class OrderWithTimestamp {\n"); + sb.append(" productId: ").append(toIndentedString(productId)).append("\n"); + sb.append(" quantity: ").append(toIndentedString(quantity)).append("\n"); + sb.append(" totalPrice: ").append(toIndentedString(totalPrice)).append("\n"); + sb.append(" typelessProperty: ").append(toIndentedString(typelessProperty)).append("\n"); + sb.append(" nullableProperty: ").append(toIndentedString(nullableProperty)).append("\n"); + sb.append(" timestamp: ").append(toIndentedString(timestamp)).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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/model/Soda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/model/Soda.java new file mode 100644 index 000000000..862a33733 --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/model/Soda.java @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * SodaStore API + * API for managing soda products and orders in SodaStore. + * + * + * + * 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.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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 com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Soda + */ +// CHECKSTYLE:OFF +public class Soda +// CHECKSTYLE:ON +{ + @JsonProperty("name") + private String name; + + @JsonProperty("brand") + private String brand; + + @JsonProperty("quantity") + private Integer quantity; + + /** + * Gets or Sets packaging + */ + public enum PackagingEnum { + /** + * The GLASS option of this Soda + */ + GLASS("glass"), + + /** + * The CARTON option of this Soda + */ + CARTON("carton"), + + /** + * The CAN option of this Soda + */ + CAN("can"); + + private String value; + + PackagingEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * @return The enum value + */ + @JsonValue + @Nonnull public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * @return The enum value as String + */ + @Override + @Nonnull public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * @param value The String value + * @return The enum value of type Soda + */ + @JsonCreator + @Nonnull public static PackagingEnum fromValue(@Nonnull final String value) { + for (PackagingEnum b : PackagingEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("packaging") + private PackagingEnum packaging; + + @JsonProperty("price") + private Float price; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * 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 quantity of this {@link Soda} instance and return the same instance. + * + * @param quantity The quantity of this {@link Soda} + * @return The same instance of this {@link Soda} class + */ + @Nonnull public Soda quantity( @Nonnull final Integer quantity) { + this.quantity = quantity; + return this; + } + + /** + * Get quantity + * @return quantity The quantity of this {@link Soda} instance. + */ + @Nonnull + public Integer getQuantity() { + return quantity; + } + + /** + * Set the quantity of this {@link Soda} instance. + * + * @param quantity The quantity of this {@link Soda} + */ + public void setQuantity( @Nonnull final Integer quantity) { + this.quantity = quantity; + } + + /** + * Set the packaging of this {@link Soda} instance and return the same instance. + * + * @param packaging The packaging of this {@link Soda} + * @return The same instance of this {@link Soda} class + */ + @Nonnull public Soda packaging( @Nullable final PackagingEnum packaging) { + this.packaging = packaging; + return this; + } + + /** + * Get packaging + * @return packaging The packaging of this {@link Soda} instance. + */ + @Nonnull + public PackagingEnum getPackaging() { + return packaging; + } + + /** + * Set the packaging of this {@link Soda} instance. + * + * @param packaging The packaging of this {@link Soda} + */ + public void setPackaging( @Nullable final PackagingEnum packaging) { + this.packaging = packaging; + } + + /** + * 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. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + 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); + } + + /** + * Get the value of all properties of this {@link Soda} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( name != null ) declaredFields.put("name", name); + if( brand != null ) declaredFields.put("brand", brand); + if( quantity != null ) declaredFields.put("quantity", quantity); + if( packaging != null ) declaredFields.put("packaging", packaging); + if( price != null ) declaredFields.put("price", price); + return declaredFields; + } + + /** + * 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.name, soda.name) && + Objects.equals(this.brand, soda.brand) && + Objects.equals(this.quantity, soda.quantity) && + Objects.equals(this.packaging, soda.packaging) && + Objects.equals(this.price, soda.price); + } + + @Override + public int hashCode() { + return Objects.hash(name, brand, quantity, packaging, price, cloudSdkCustomFields); + } + + @Override + @Nonnull public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class Soda {\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" brand: ").append(toIndentedString(brand)).append("\n"); + sb.append(" quantity: ").append(toIndentedString(quantity)).append("\n"); + sb.append(" packaging: ").append(toIndentedString(packaging)).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 "); + } + +} + diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/model/SodaWithId.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/model/SodaWithId.java new file mode 100644 index 000000000..70553d4ca --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorApacheIntegrationTest/remove-operation-id-prefix/output/com/sap/cloud/sdk/services/builder/model/SodaWithId.java @@ -0,0 +1,407 @@ +/* + * Copyright (c) 2026 SAP SE or an SAP affiliate company. All rights reserved. + */ + +/* + * SodaStore API + * API for managing soda products and orders in SodaStore. + * + * + * + * 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.Objects; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +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 com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * SodaWithId + */ +// CHECKSTYLE:OFF +public class SodaWithId +// CHECKSTYLE:ON +{ + @JsonProperty("name") + private String name; + + @JsonProperty("brand") + private String brand; + + @JsonProperty("quantity") + private Integer quantity; + + /** + * Gets or Sets packaging + */ + public enum PackagingEnum { + /** + * The GLASS option of this SodaWithId + */ + GLASS("glass"), + + /** + * The CARTON option of this SodaWithId + */ + CARTON("carton"), + + /** + * The CAN option of this SodaWithId + */ + CAN("can"); + + private String value; + + PackagingEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * @return The enum value + */ + @JsonValue + @Nonnull public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * @return The enum value as String + */ + @Override + @Nonnull public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * @param value The String value + * @return The enum value of type SodaWithId + */ + @JsonCreator + @Nonnull public static PackagingEnum fromValue(@Nonnull final String value) { + for (PackagingEnum b : PackagingEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + @JsonProperty("packaging") + private PackagingEnum packaging; + + @JsonProperty("price") + private Float price; + + @JsonProperty("id") + private Long id; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the name of this {@link SodaWithId} instance and return the same instance. + * + * @param name The name of this {@link SodaWithId} + * @return The same instance of this {@link SodaWithId} class + */ + @Nonnull public SodaWithId name( @Nonnull final String name) { + this.name = name; + return this; + } + + /** + * Get name + * @return name The name of this {@link SodaWithId} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link SodaWithId} instance. + * + * @param name The name of this {@link SodaWithId} + */ + public void setName( @Nonnull final String name) { + this.name = name; + } + + /** + * Set the brand of this {@link SodaWithId} instance and return the same instance. + * + * @param brand The brand of this {@link SodaWithId} + * @return The same instance of this {@link SodaWithId} class + */ + @Nonnull public SodaWithId brand( @Nonnull final String brand) { + this.brand = brand; + return this; + } + + /** + * Get brand + * @return brand The brand of this {@link SodaWithId} instance. + */ + @Nonnull + public String getBrand() { + return brand; + } + + /** + * Set the brand of this {@link SodaWithId} instance. + * + * @param brand The brand of this {@link SodaWithId} + */ + public void setBrand( @Nonnull final String brand) { + this.brand = brand; + } + + /** + * Set the quantity of this {@link SodaWithId} instance and return the same instance. + * + * @param quantity The quantity of this {@link SodaWithId} + * @return The same instance of this {@link SodaWithId} class + */ + @Nonnull public SodaWithId quantity( @Nonnull final Integer quantity) { + this.quantity = quantity; + return this; + } + + /** + * Get quantity + * @return quantity The quantity of this {@link SodaWithId} instance. + */ + @Nonnull + public Integer getQuantity() { + return quantity; + } + + /** + * Set the quantity of this {@link SodaWithId} instance. + * + * @param quantity The quantity of this {@link SodaWithId} + */ + public void setQuantity( @Nonnull final Integer quantity) { + this.quantity = quantity; + } + + /** + * Set the packaging of this {@link SodaWithId} instance and return the same instance. + * + * @param packaging The packaging of this {@link SodaWithId} + * @return The same instance of this {@link SodaWithId} class + */ + @Nonnull public SodaWithId packaging( @Nullable final PackagingEnum packaging) { + this.packaging = packaging; + return this; + } + + /** + * Get packaging + * @return packaging The packaging of this {@link SodaWithId} instance. + */ + @Nonnull + public PackagingEnum getPackaging() { + return packaging; + } + + /** + * Set the packaging of this {@link SodaWithId} instance. + * + * @param packaging The packaging of this {@link SodaWithId} + */ + public void setPackaging( @Nullable final PackagingEnum packaging) { + this.packaging = packaging; + } + + /** + * Set the price of this {@link SodaWithId} instance and return the same instance. + * + * @param price The price of this {@link SodaWithId} + * @return The same instance of this {@link SodaWithId} class + */ + @Nonnull public SodaWithId price( @Nonnull final Float price) { + this.price = price; + return this; + } + + /** + * Get price + * @return price The price of this {@link SodaWithId} instance. + */ + @Nonnull + public Float getPrice() { + return price; + } + + /** + * Set the price of this {@link SodaWithId} instance. + * + * @param price The price of this {@link SodaWithId} + */ + public void setPrice( @Nonnull final Float price) { + this.price = price; + } + + /** + * Set the id of this {@link SodaWithId} instance and return the same instance. + * + * @param id The id of this {@link SodaWithId} + * @return The same instance of this {@link SodaWithId} class + */ + @Nonnull public SodaWithId id( @Nullable final Long id) { + this.id = id; + return this; + } + + /** + * Get id + * @return id The id of this {@link SodaWithId} instance. + */ + @Nonnull + public Long getId() { + return id; + } + + /** + * Set the id of this {@link SodaWithId} instance. + * + * @param id The id of this {@link SodaWithId} + */ + public void setId( @Nullable final Long id) { + this.id = id; + } + + /** + * Get the names of the unrecognizable properties of the {@link SodaWithId}. + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link SodaWithId} instance. + * @deprecated Use {@link #toMap()} instead. + * @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 + @Deprecated + public Object getCustomField( @Nonnull final String name ) throws NoSuchElementException { + if( !cloudSdkCustomFields.containsKey(name) ) { + throw new NoSuchElementException("SodaWithId has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link SodaWithId} instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( name != null ) declaredFields.put("name", name); + if( brand != null ) declaredFields.put("brand", brand); + if( quantity != null ) declaredFields.put("quantity", quantity); + if( packaging != null ) declaredFields.put("packaging", packaging); + if( price != null ) declaredFields.put("price", price); + if( id != null ) declaredFields.put("id", id); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link SodaWithId} 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 SodaWithId sodaWithId = (SodaWithId) o; + return Objects.equals(this.cloudSdkCustomFields, sodaWithId.cloudSdkCustomFields) && + Objects.equals(this.name, sodaWithId.name) && + Objects.equals(this.brand, sodaWithId.brand) && + Objects.equals(this.quantity, sodaWithId.quantity) && + Objects.equals(this.packaging, sodaWithId.packaging) && + Objects.equals(this.price, sodaWithId.price) && + Objects.equals(this.id, sodaWithId.id); + } + + @Override + public int hashCode() { + return Objects.hash(name, brand, quantity, packaging, price, id, cloudSdkCustomFields); + } + + @Override + @Nonnull public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class SodaWithId {\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" brand: ").append(toIndentedString(brand)).append("\n"); + sb.append(" quantity: ").append(toIndentedString(quantity)).append("\n"); + sb.append(" packaging: ").append(toIndentedString(packaging)).append("\n"); + sb.append(" price: ").append(toIndentedString(price)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).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 "); + } + +} +