diff --git a/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/modelEnum.mustache b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/modelEnum.mustache index af40d5209..40ffd1d78 100644 --- a/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/modelEnum.mustache +++ b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/modelEnum.mustache @@ -23,7 +23,7 @@ import java.net.URI; @JsonbTypeSerializer({{datatypeWithEnum}}.Serializer.class) @JsonbTypeDeserializer({{datatypeWithEnum}}.Deserializer.class) {{/jsonb}} -{{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} { +{{>additionalEnumTypeAnnotations}}{{^vendorExtensions.x-sap-cloud-sdk-internal}}public{{/vendorExtensions.x-sap-cloud-sdk-internal}} enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} { {{#allowableValues}}{{#enumVars}} {{#enumDescription}} /** diff --git a/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/oneof_interface.mustache b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/oneof_interface.mustache index f84cb4603..128e0bd94 100644 --- a/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/oneof_interface.mustache +++ b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/oneof_interface.mustache @@ -5,8 +5,8 @@ @Deprecated{{/isDeprecated}}{{^isReleased}} @Beta{{/isReleased}} {{>additionalOneOfTypeAnnotations}}{{>typeInfoAnnotation}}{{>xmlAnnotation}} -public interface {{classname}} {{#vendorExtensions.x-implements}}{{#-first}}extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} { -{{#discriminator}} +{{^vendorExtensions.x-sap-cloud-sdk-internal}}public{{/vendorExtensions.x-sap-cloud-sdk-internal}} interface {{classname}} {{#vendorExtensions.x-implements}}{{#-first}}extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} { + {{#discriminator}} Object {{propertyGetter}}(); -{{/discriminator}} + {{/discriminator}} } diff --git a/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/pojo.mustache b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/pojo.mustache index 3f43f0bad..c234f1d3e 100644 --- a/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/pojo.mustache +++ b/datamodel/openapi/openapi-generator/src/main/resources/openapi-generator/mustache-templates/pojo.mustache @@ -19,7 +19,7 @@ {{/jackson}} {{>additionalModelTypeAnnotations}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}{{^isReleased}} @Beta{{/isReleased}}// CHECKSTYLE:OFF -public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtensions.x-implements}}{{#-first}}implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{#-last}} {{/-last}}{{/vendorExtensions.x-implements}} +{{^vendorExtensions.x-sap-cloud-sdk-internal}}public{{/vendorExtensions.x-sap-cloud-sdk-internal}} class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtensions.x-implements}}{{#-first}}implements {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{#-last}} {{/-last}}{{/vendorExtensions.x-implements}} // CHECKSTYLE:ON { {{#serializableModel}} @@ -116,7 +116,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{/maximum}} * @return The same instance of this {@link {{classname}}} class */ - @Nonnull public {{classname}} {{name}}( {{#isNullable}}@Nullable{{/isNullable}}{{^isNullable}}{{#required}}@Nonnull{{/required}}{{^required}}@Nullable{{/required}}{{/isNullable}} final {{{datatypeWithEnum}}} {{name}}) { + @Nonnull {{^vendorExtensions.x-sap-cloud-sdk-internal}}public{{/vendorExtensions.x-sap-cloud-sdk-internal}} {{classname}} {{name}}( {{#isNullable}}@Nullable{{/isNullable}}{{^isNullable}}{{#required}}@Nonnull{{/required}}{{^required}}@Nullable{{/required}}{{/isNullable}} final {{{datatypeWithEnum}}} {{name}}) { this.{{name}} = {{name}}{{#isByteArray}}.clone(){{/isByteArray}}; return this; } @@ -126,7 +126,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens * @param {{name}}Item The {{nameInCamelCase}} that should be added * @return The same instance of type {@link {{classname}}} */ - @Nonnull public {{classname}} add{{nameInPascalCase}}Item( @Nonnull final {{{items.datatypeWithEnum}}} {{name}}Item) { + @Nonnull {{^vendorExtensions.x-sap-cloud-sdk-internal}}public{{/vendorExtensions.x-sap-cloud-sdk-internal}} {{classname}} add{{nameInPascalCase}}Item( @Nonnull final {{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent()) { this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}); @@ -155,7 +155,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens * @param {{name}}Item The {{nameInCamelCase}} that should be added under the given key * @return The same instance of type {@link {{classname}}} */ - @Nonnull public {{classname}} put{{nameInCamelCase}}Item( @Nonnull final String key, {{#items.isNullable}}@Nullable{{/items.isNullable}}{{^items.isNullable}}@Nonnull{{/items.isNullable}} final {{{items.datatypeWithEnum}}} {{name}}Item) { + @Nonnull {{^vendorExtensions.x-sap-cloud-sdk-internal}}public{{/vendorExtensions.x-sap-cloud-sdk-internal}} {{classname}} put{{nameInCamelCase}}Item( @Nonnull final String key, {{#items.isNullable}}@Nullable{{/items.isNullable}}{{^items.isNullable}}@Nonnull{{/items.isNullable}} final {{{items.datatypeWithEnum}}} {{name}}Item) { {{#vendorExtensions.x-is-jackson-optional-nullable}} if (this.{{name}} == null || !this.{{name}}.isPresent()) { this.{{name}} = JsonNullable.<{{{datatypeWithEnum}}}>of({{{defaultValue}}}{{^defaultValue}}new HashMap<>(){{/defaultValue}}); @@ -222,7 +222,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{#vendorExtensions.x-extra-annotation}} {{{vendorExtensions.x-extra-annotation}}} {{/vendorExtensions.x-extra-annotation}} - public {{{datatypeWithEnum}}} {{getter}}() { + {{^vendorExtensions.x-sap-cloud-sdk-internal}}public{{/vendorExtensions.x-sap-cloud-sdk-internal}} {{{datatypeWithEnum}}} {{getter}}() { return {{name}}{{#isByteArray}}.clone(){{/isByteArray}}; } {{^isReadOnly}} @@ -238,7 +238,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens * Maximum: {{maximum}} {{/maximum}} */ - public void {{setter}}( {{#isNullable}}@Nullable{{/isNullable}}{{^isNullable}}{{#required}}@Nonnull{{/required}}{{^required}}@Nullable{{/required}}{{/isNullable}} final {{{datatypeWithEnum}}} {{name}}) { + {{^vendorExtensions.x-sap-cloud-sdk-internal}}public{{/vendorExtensions.x-sap-cloud-sdk-internal}} void {{setter}}( {{#isNullable}}@Nullable{{/isNullable}}{{^isNullable}}{{#required}}@Nonnull{{/required}}{{^required}}@Nullable{{/required}}{{/isNullable}} final {{{datatypeWithEnum}}} {{name}}) { this.{{name}} = {{name}}; } {{/isReadOnly}} 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 0d2df3a24..ec0b0e41b 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 @@ -180,9 +180,9 @@ void integrationTests( final TestCase testCase, @TempDir final Path path ) } // Add these annotations to regenerate all sources - // @ParameterizedTest + @ParameterizedTest // @EnumSource( TestCase.class ) // use this to regenerate all... - // @EnumSource( value = TestCase.class, names = { "API_CLASS_VENDOR_EXTENSION_YAML" } ) // ...and this one to only generate specific ones + @EnumSource( value = TestCase.class, names = { "API_CLASS_VENDOR_EXTENSION_JSON" } ) // ...and this one to only generate specific ones void generateDataModelForComparison( final TestCase testCase ) { final Path inputDirectory = getInputDirectory(testCase); diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/input/sodastore.json b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/input/sodastore.json index f10d46994..55ce5d0ba 100644 --- a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/input/sodastore.json +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/input/sodastore.json @@ -227,6 +227,19 @@ "price": { "type": "number", "format": "float" + }, + "internal": { + "$ref": "#/components/schemas/Internal", + "x-sap-cloud-sdk-internal": true + } + } + }, + "Internal": { + "type": "object", + "x-sap-cloud-sdk-internal": true, + "properties": { + "secret": { + "type": "string" } } } diff --git a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/Internal.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/Internal.java new file mode 100644 index 000000000..ab237292d --- /dev/null +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/Internal.java @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2025 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; + +/** + * Internal + */ +// CHECKSTYLE:OFF + class Internal +// CHECKSTYLE:ON +{ + @JsonProperty("secret") + private String secret; + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Set the secret of this {@link Internal} instance and return the same instance. + * + * @param secret The secret of this {@link Internal} + * @return The same instance of this {@link Internal} class + */ + @Nonnull public Internal secret( @Nullable final String secret) { + this.secret = secret; + return this; + } + + /** + * Get secret + * @return secret The secret of this {@link Internal} instance. + */ + @Nonnull + public String getSecret() { + return secret; + } + + /** + * Set the secret of this {@link Internal} instance. + * + * @param secret The secret of this {@link Internal} + */ + public void setSecret( @Nullable final String secret) { + this.secret = secret; + } + + /** + * Get the names of the unrecognizable properties of the {@link Internal}. + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link Internal} instance. + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + public Object getCustomField( @Nonnull final String name ) throws NoSuchElementException { + if( !cloudSdkCustomFields.containsKey(name) ) { + throw new NoSuchElementException("Internal has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Set an unrecognizable property of this {@link Internal} 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 Internal internal = (Internal) o; + return Objects.equals(this.cloudSdkCustomFields, internal.cloudSdkCustomFields) && + Objects.equals(this.secret, internal.secret); + } + + @Override + public int hashCode() { + return Objects.hash(secret, cloudSdkCustomFields); + } + + @Override + @Nonnull public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class Internal {\n"); + sb.append(" secret: ").append(toIndentedString(secret)).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/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java index 742b94d7e..970cb1ca9 100644 --- a/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java +++ b/datamodel/openapi/openapi-generator/src/test/resources/DataModelGeneratorIntegrationTest/api-class-vendor-extension-json/output/com/sap/cloud/sdk/services/apiclassvendorextension/model/UpdateSoda.java @@ -26,6 +26,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonTypeName; import com.fasterxml.jackson.annotation.JsonValue; +import com.sap.cloud.sdk.services.apiclassvendorextension.model.Internal; import java.time.LocalDate; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonAnyGetter; @@ -60,6 +61,9 @@ public class UpdateSoda @JsonProperty("price") private Float price; + @JsonProperty("internal") + private Internal internal; + @JsonAnySetter @JsonAnyGetter private final Map cloudSdkCustomFields = new LinkedHashMap<>(); @@ -238,6 +242,35 @@ public void setPrice( @Nullable final Float price) { this.price = price; } + /** + * Set the internal of this {@link UpdateSoda} instance and return the same instance. + * + * @param internal The internal of this {@link UpdateSoda} + * @return The same instance of this {@link UpdateSoda} class + */ + @Nonnull UpdateSoda internal( @Nullable final Internal internal) { + this.internal = internal; + return this; + } + + /** + * Get internal + * @return internal The internal of this {@link UpdateSoda} instance. + */ + @Nonnull + Internal getInternal() { + return internal; + } + + /** + * Set the internal of this {@link UpdateSoda} instance. + * + * @param internal The internal of this {@link UpdateSoda} + */ + void setInternal( @Nullable final Internal internal) { + this.internal = internal; + } + /** * Get the names of the unrecognizable properties of the {@link UpdateSoda}. * @return The set of properties names @@ -290,12 +323,13 @@ public boolean equals(@Nullable final java.lang.Object o) { Objects.equals(this.since, updateSoda.since) && Objects.equals(this.brand, updateSoda.brand) && Objects.equals(this.flavor, updateSoda.flavor) && - Objects.equals(this.price, updateSoda.price); + Objects.equals(this.price, updateSoda.price) && + Objects.equals(this.internal, updateSoda.internal); } @Override public int hashCode() { - return Objects.hash(name, zero, since, brand, flavor, price, cloudSdkCustomFields); + return Objects.hash(name, zero, since, brand, flavor, price, internal, cloudSdkCustomFields); } @Override @@ -308,6 +342,7 @@ public int hashCode() { sb.append(" brand: ").append(toIndentedString(brand)).append("\n"); sb.append(" flavor: ").append(toIndentedString(flavor)).append("\n"); sb.append(" price: ").append(toIndentedString(price)).append("\n"); + sb.append(" internal: ").append(toIndentedString(internal)).append("\n"); cloudSdkCustomFields.forEach((k,v) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); sb.append("}"); return sb.toString();