Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [OpenAPI] PoC: Internal Flag #697

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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}});
Expand Down Expand Up @@ -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}});
Expand Down Expand Up @@ -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}}
Expand All @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Object> 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<String> 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 ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,6 +61,9 @@ public class UpdateSoda
@JsonProperty("price")
private Float price;

@JsonProperty("internal")
private Internal internal;

@JsonAnySetter
@JsonAnyGetter
private final Map<String, Object> cloudSdkCustomFields = new LinkedHashMap<>();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down
Loading