From af953c9993bb854c72f867e9ca07090a14c3acd4 Mon Sep 17 00:00:00 2001 From: Roshin Rajan Panackal Date: Tue, 3 Jun 2025 14:25:35 +0200 Subject: [PATCH 01/10] Generate compilable code for multi level array --- .../openapi/sample/model/FantaFlavor.java | 18 +++++++++++ .../src/main/resources/sodastore.yaml | 5 +++ .../generator/CustomJavaClientCodegen.java | 32 ++++++++++++++++--- .../oneof_interface.mustache | 21 ++++++++++-- 4 files changed, 70 insertions(+), 6 deletions(-) diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/FantaFlavor.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/FantaFlavor.java index b684357a2..e543fc0a9 100644 --- a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/FantaFlavor.java +++ b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/FantaFlavor.java @@ -103,4 +103,22 @@ static InnerFlavorTypes create( @Nonnull final List val ) return new InnerFlavorTypes(val); } + /** + * Helper class to create {@code List> } that implements {@link FantaFlavor }. + */ + record InnerFlavorTypes2D(@com.fasterxml.jackson.annotation.JsonValue @Nonnull List> values) implements FantaFlavor {} + + /** + * Creator to enable deserialization of {@code List> }. + * + * @param val + * the value to use + * @return a new instance of {@link InnerFlavorTypes2D}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + @Nonnull + static InnerFlavorTypes2D create2DList( @Nonnull final List> val ) + { + return new InnerFlavorTypes2D(val); + } } diff --git a/datamodel/openapi/openapi-api-sample/src/main/resources/sodastore.yaml b/datamodel/openapi/openapi-api-sample/src/main/resources/sodastore.yaml index ca8212296..e786d5dfe 100644 --- a/datamodel/openapi/openapi-api-sample/src/main/resources/sodastore.yaml +++ b/datamodel/openapi/openapi-api-sample/src/main/resources/sodastore.yaml @@ -169,6 +169,11 @@ components: items: $ref: '#/components/schemas/FlavorType' - $ref: '#/components/schemas/FlavorType' + - type: array + items: + type: array + items: + $ref: '#/components/schemas/FlavorType' FlavorType: type: object properties: diff --git a/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java b/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java index 720e6b47e..8ca3fc7e8 100644 --- a/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java +++ b/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java @@ -272,12 +272,28 @@ private void useCreatorsForInterfaceSubtypes( @Nonnull final CodegenModel m ) for( final Set candidates : List.of(m.anyOf, m.oneOf) ) { int nonPrimitives = 0; final var candidatesSingle = new HashSet(); - final var candidatesMultiple = new HashSet(); + final var candidatesMultiple1D = new HashSet(); + final var candidatesMultipleND = new HashSet>(); for( final String candidate : candidates ) { if( candidate.startsWith("List<") ) { - final var c1 = candidate.substring(5, candidate.length() - 1); - candidatesMultiple.add(c1); + + int depth = 0; + String sub = candidate; + + while( sub.startsWith("List<") ) { + sub = sub.substring(5, sub.length() - 1); + depth++; + } + + final String innerType = sub; + + if( depth == 1 ) { + candidatesMultiple1D.add(innerType); + } else { + candidatesMultipleND + .add(Map.of("innerType", innerType, "depth", String.valueOf(depth), "fullType", candidate)); + } useCreators = true; } else { candidatesSingle.add(candidate); @@ -294,7 +310,15 @@ private void useCreatorsForInterfaceSubtypes( @Nonnull final CodegenModel m ) log.warn(msg, m.name); } candidates.clear(); - final var monads = Map.of("single", candidatesSingle, "multiple", candidatesMultiple); + final var monads = + Map + .of( + "single", + candidatesSingle, + "multiple1D", + candidatesMultiple1D, + "multipleND", + candidatesMultipleND); m.vendorExtensions.put("x-monads", monads); m.vendorExtensions.put("x-is-one-of-interface", true); // enforce template usage } 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 b88e6d5a1..e91cae0ae 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 @@ -28,7 +28,7 @@ public interface {{classname}} {{#vendorExtensions.x-implements}}{{#-first}}exte static Inner{{.}} create( @Nonnull final {{.}} val) { return new Inner{{.}}(val); } {{/model.vendorExtensions.x-monads.single}} -{{#model.vendorExtensions.x-monads.multiple}} +{{#model.vendorExtensions.x-monads.multiple1D}} /** * Helper class to create a list of {{.}} that implements {@link {{classname}}}. */ @@ -44,5 +44,22 @@ public interface {{classname}} {{#vendorExtensions.x-implements}}{{#-first}}exte @Nonnull static Inner{{.}}s create( @Nonnull final List<{{.}}> val) { return new Inner{{.}}s(val); } -{{/model.vendorExtensions.x-monads.multiple}} +{{/model.vendorExtensions.x-monads.multiple1D}} +{{#model.vendorExtensions.x-monads.multipleND}} + /** + * Helper class to create {@code {{{fullType}}} } that implements {@link {{classname}}}. + */ + record Inner{{innerType}}s{{depth}}D(@com.fasterxml.jackson.annotation.JsonValue @Nonnull {{{fullType}}} values) implements {{classname}} {} + + /** + * Creator to enable deserialization of {@code {{{fullType}}} }. + * + * @param val the value to use + * @return a new instance of {@link Inner{{innerType}}s{{depth}}D}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + @Nonnull + static Inner{{innerType}}s{{depth}}D create{{depth}}DList( @Nonnull final {{{fullType}}} val) { return new Inner{{innerType}}s{{depth}}D(val); } + +{{/model.vendorExtensions.x-monads.multipleND}} } From ebac9ae06f9854a321555374b5d37661e6f4f869 Mon Sep 17 00:00:00 2001 From: Roshin Rajan Panackal Date: Fri, 6 Jun 2025 15:00:14 +0200 Subject: [PATCH 02/10] New Spec definition without any generator fixes --- .../sample/model/EmbeddingsInputTextById.java | 31 +++ .../model/EmbeddingsInputTextById1D.java | 253 ++++++++++++++++++ .../model/EmbeddingsInputTextById2D.java | 253 ++++++++++++++++++ .../openapi/sample/model/FantaFlavor.java | 18 -- .../sample/model/OneOfWithMultipleArrays.java | 87 ++++++ .../src/main/resources/sodastore.yaml | 46 +++- ...OneOfMultipleArrayDeserializationTest.java | 82 ++++++ pom.xml | 2 +- 8 files changed, 748 insertions(+), 24 deletions(-) create mode 100644 datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById.java create mode 100644 datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById1D.java create mode 100644 datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById2D.java create mode 100644 datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OneOfWithMultipleArrays.java create mode 100644 datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfMultipleArrayDeserializationTest.java diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById.java new file mode 100644 index 000000000..697747c5e --- /dev/null +++ b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 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.datamodel.openapi.sample.model; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +/** + * EmbeddingsInputTextById + */ +@JsonTypeInfo( use = JsonTypeInfo.Id.DEDUCTION ) +@JsonSubTypes( { + @JsonSubTypes.Type( value = EmbeddingsInputTextById1D.class ), + @JsonSubTypes.Type( value = EmbeddingsInputTextById2D.class ), } ) + +public interface EmbeddingsInputTextById +{ +} diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById1D.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById1D.java new file mode 100644 index 000000000..176a590aa --- /dev/null +++ b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById1D.java @@ -0,0 +1,253 @@ +/* + * Copyright (c) 2025 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.datamodel.openapi.sample.model; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * EmbeddingsInputTextById1D + */ +// CHECKSTYLE:OFF +public class EmbeddingsInputTextById1D implements EmbeddingsInputTextById +// CHECKSTYLE:ON +{ + @JsonProperty( "vector" ) + private List vector = new ArrayList<>(); + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Default constructor for EmbeddingsInputTextById1D. + */ + protected EmbeddingsInputTextById1D() + { + } + + /** + * Set the vector of this {@link EmbeddingsInputTextById1D} instance and return the same instance. + * + * @param vector + * The vector of this {@link EmbeddingsInputTextById1D} + * @return The same instance of this {@link EmbeddingsInputTextById1D} class + */ + @Nonnull + public EmbeddingsInputTextById1D vector( @Nonnull final List vector ) + { + this.vector = vector; + return this; + } + + /** + * Add one vector instance to this {@link EmbeddingsInputTextById1D}. + * + * @param vectorItem + * The vector that should be added + * @return The same instance of type {@link EmbeddingsInputTextById1D} + */ + @Nonnull + public EmbeddingsInputTextById1D addVectorItem( @Nonnull final Integer vectorItem ) + { + if( this.vector == null ) { + this.vector = new ArrayList<>(); + } + this.vector.add(vectorItem); + return this; + } + + /** + * Get vector + * + * @return vector The vector of this {@link EmbeddingsInputTextById1D} instance. + */ + @Nonnull + public List getVector() + { + return vector; + } + + /** + * Set the vector of this {@link EmbeddingsInputTextById1D} instance. + * + * @param vector + * The vector of this {@link EmbeddingsInputTextById1D} + */ + public void setVector( @Nonnull final List vector ) + { + this.vector = vector; + } + + /** + * Get the names of the unrecognizable properties of the {@link EmbeddingsInputTextById1D}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() + { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link EmbeddingsInputTextById1D} 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("EmbeddingsInputTextById1D has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link EmbeddingsInputTextById1D} instance including unrecognized + * properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( vector != null ) + declaredFields.put("vector", vector); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link EmbeddingsInputTextById1D} 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 EmbeddingsInputTextById1D embeddingsInputTextById1D = (EmbeddingsInputTextById1D) o; + return Objects.equals(this.cloudSdkCustomFields, embeddingsInputTextById1D.cloudSdkCustomFields) + && Objects.equals(this.vector, embeddingsInputTextById1D.vector); + } + + @Override + public int hashCode() + { + return Objects.hash(vector, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append("class EmbeddingsInputTextById1D {\n"); + sb.append(" vector: ").append(toIndentedString(vector)).append("\n"); + cloudSdkCustomFields + .forEach(( k, v ) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString( final java.lang.Object o ) + { + if( o == null ) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + /** + * Create a type-safe, fluent-api builder object to construct a new {@link EmbeddingsInputTextById1D} instance with + * all required arguments. + */ + public static Builder create() + { + return ( vector ) -> new EmbeddingsInputTextById1D().vector(vector); + } + + /** + * Builder helper class. + */ + public interface Builder + { + /** + * Set the vector of this {@link EmbeddingsInputTextById1D} instance. + * + * @param vector + * The vector of this {@link EmbeddingsInputTextById1D} + * @return The EmbeddingsInputTextById1D instance. + */ + EmbeddingsInputTextById1D vector( @Nonnull final List vector ); + + /** + * Set the vector of this {@link EmbeddingsInputTextById1D} instance. + * + * @param vector + * The vector of this {@link EmbeddingsInputTextById1D} + * @return The EmbeddingsInputTextById1D instance. + */ + default EmbeddingsInputTextById1D vector( @Nonnull final Integer... vector ) + { + return vector(Arrays.asList(vector)); + } + } + +} diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById2D.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById2D.java new file mode 100644 index 000000000..bc3c91f19 --- /dev/null +++ b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById2D.java @@ -0,0 +1,253 @@ +/* + * Copyright (c) 2025 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.datamodel.openapi.sample.model; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * EmbeddingsInputTextById2D + */ +// CHECKSTYLE:OFF +public class EmbeddingsInputTextById2D implements EmbeddingsInputTextById +// CHECKSTYLE:ON +{ + @JsonProperty( "matrix" ) + private List> matrix = new ArrayList<>(); + + @JsonAnySetter + @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** + * Default constructor for EmbeddingsInputTextById2D. + */ + protected EmbeddingsInputTextById2D() + { + } + + /** + * Set the matrix of this {@link EmbeddingsInputTextById2D} instance and return the same instance. + * + * @param matrix + * The matrix of this {@link EmbeddingsInputTextById2D} + * @return The same instance of this {@link EmbeddingsInputTextById2D} class + */ + @Nonnull + public EmbeddingsInputTextById2D matrix( @Nonnull final List> matrix ) + { + this.matrix = matrix; + return this; + } + + /** + * Add one matrix instance to this {@link EmbeddingsInputTextById2D}. + * + * @param matrixItem + * The matrix that should be added + * @return The same instance of type {@link EmbeddingsInputTextById2D} + */ + @Nonnull + public EmbeddingsInputTextById2D addMatrixItem( @Nonnull final List matrixItem ) + { + if( this.matrix == null ) { + this.matrix = new ArrayList<>(); + } + this.matrix.add(matrixItem); + return this; + } + + /** + * Get matrix + * + * @return matrix The matrix of this {@link EmbeddingsInputTextById2D} instance. + */ + @Nonnull + public List> getMatrix() + { + return matrix; + } + + /** + * Set the matrix of this {@link EmbeddingsInputTextById2D} instance. + * + * @param matrix + * The matrix of this {@link EmbeddingsInputTextById2D} + */ + public void setMatrix( @Nonnull final List> matrix ) + { + this.matrix = matrix; + } + + /** + * Get the names of the unrecognizable properties of the {@link EmbeddingsInputTextById2D}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() + { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link EmbeddingsInputTextById2D} 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("EmbeddingsInputTextById2D has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link EmbeddingsInputTextById2D} instance including unrecognized + * properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() + { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if( matrix != null ) + declaredFields.put("matrix", matrix); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link EmbeddingsInputTextById2D} 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 EmbeddingsInputTextById2D embeddingsInputTextById2D = (EmbeddingsInputTextById2D) o; + return Objects.equals(this.cloudSdkCustomFields, embeddingsInputTextById2D.cloudSdkCustomFields) + && Objects.equals(this.matrix, embeddingsInputTextById2D.matrix); + } + + @Override + public int hashCode() + { + return Objects.hash(matrix, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append("class EmbeddingsInputTextById2D {\n"); + sb.append(" matrix: ").append(toIndentedString(matrix)).append("\n"); + cloudSdkCustomFields + .forEach(( k, v ) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString( final java.lang.Object o ) + { + if( o == null ) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + /** + * Create a type-safe, fluent-api builder object to construct a new {@link EmbeddingsInputTextById2D} instance with + * all required arguments. + */ + public static Builder create() + { + return ( matrix ) -> new EmbeddingsInputTextById2D().matrix(matrix); + } + + /** + * Builder helper class. + */ + public interface Builder + { + /** + * Set the matrix of this {@link EmbeddingsInputTextById2D} instance. + * + * @param matrix + * The matrix of this {@link EmbeddingsInputTextById2D} + * @return The EmbeddingsInputTextById2D instance. + */ + EmbeddingsInputTextById2D matrix( @Nonnull final List> matrix ); + + /** + * Set the matrix of this {@link EmbeddingsInputTextById2D} instance. + * + * @param matrix + * The matrix of this {@link EmbeddingsInputTextById2D} + * @return The EmbeddingsInputTextById2D instance. + */ + default EmbeddingsInputTextById2D matrix( @Nonnull final List... matrix ) + { + return matrix(Arrays.asList(matrix)); + } + } + +} diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/FantaFlavor.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/FantaFlavor.java index e543fc0a9..b684357a2 100644 --- a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/FantaFlavor.java +++ b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/FantaFlavor.java @@ -103,22 +103,4 @@ static InnerFlavorTypes create( @Nonnull final List val ) return new InnerFlavorTypes(val); } - /** - * Helper class to create {@code List> } that implements {@link FantaFlavor }. - */ - record InnerFlavorTypes2D(@com.fasterxml.jackson.annotation.JsonValue @Nonnull List> values) implements FantaFlavor {} - - /** - * Creator to enable deserialization of {@code List> }. - * - * @param val - * the value to use - * @return a new instance of {@link InnerFlavorTypes2D}. - */ - @com.fasterxml.jackson.annotation.JsonCreator - @Nonnull - static InnerFlavorTypes2D create2DList( @Nonnull final List> val ) - { - return new InnerFlavorTypes2D(val); - } } diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OneOfWithMultipleArrays.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OneOfWithMultipleArrays.java new file mode 100644 index 000000000..df336e96d --- /dev/null +++ b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OneOfWithMultipleArrays.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2025 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.datamodel.openapi.sample.model; + +import java.util.List; + +import javax.annotation.Nonnull; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * OneOfWithMultipleArrays + */ +public interface OneOfWithMultipleArrays +{ + /** + * Helper class to create a EmbeddingsInputTextById that implements {@link OneOfWithMultipleArrays}. + */ + record InnerEmbeddingsInputTextById(@com.fasterxml.jackson.annotation.JsonValue @Nonnull EmbeddingsInputTextById value) implements OneOfWithMultipleArrays {} + + /** + * Creator to enable deserialization of a EmbeddingsInputTextById. + * + * @param val + * the value to use + * @return a new instance of {@link InnerEmbeddingsInputTextById}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + @Nonnull + static InnerEmbeddingsInputTextById create( @Nonnull final EmbeddingsInputTextById val ) + { + return new InnerEmbeddingsInputTextById(val); + } + + /** + * Helper class to create a String that implements {@link OneOfWithMultipleArrays}. + */ + record InnerString(@com.fasterxml.jackson.annotation.JsonValue @Nonnull String value) implements OneOfWithMultipleArrays {} + + /** + * Creator to enable deserialization of a String. + * + * @param val + * the value to use + * @return a new instance of {@link InnerString}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + @Nonnull + static InnerString create( @Nonnull final String val ) + { + return new InnerString(val); + } + + /** + * Helper class to create a list of String that implements {@link OneOfWithMultipleArrays}. + */ + record InnerStrings(@com.fasterxml.jackson.annotation.JsonValue @Nonnull List values) implements OneOfWithMultipleArrays {} + + /** + * Creator to enable deserialization of a list of String. + * + * @param val + * the value to use + * @return a new instance of {@link InnerStrings}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + @Nonnull + static InnerStrings create( @Nonnull final List val ) + { + return new InnerStrings(val); + } + +} diff --git a/datamodel/openapi/openapi-api-sample/src/main/resources/sodastore.yaml b/datamodel/openapi/openapi-api-sample/src/main/resources/sodastore.yaml index e786d5dfe..1256e4d8a 100644 --- a/datamodel/openapi/openapi-api-sample/src/main/resources/sodastore.yaml +++ b/datamodel/openapi/openapi-api-sample/src/main/resources/sodastore.yaml @@ -117,6 +117,47 @@ components: mapping: disc_foo: '#/components/schemas/Foo' disc_bar: '#/components/schemas/Bar' + OneOfWithMultipleArrays: + oneOf: + - type: string + description: The string that will be turned into an embedding. + example: Hello World! + - type: array + description: The array of strings that will be turned into an embedding. + minItems: 1 + items: + type: string + minLength: 1 + example: "['Hello', 'World', '!']" + - $ref: '#/components/schemas/EmbeddingsInputTextById' + EmbeddingsInputTextById: + oneOf: + - $ref: '#/components/schemas/EmbeddingsInputTextById1D' + - $ref: '#/components/schemas/EmbeddingsInputTextById2D' + EmbeddingsInputTextById1D: + type: object + required: + - vector + properties: + vector: + type: array + minItems: 1 + items: + type: integer + minLength: 1 + EmbeddingsInputTextById2D: + type: object + required: + - matrix + properties: + matrix: + type: array + minItems: 1 + items: + type: array + minItems: 1 + items: + type: integer Foo: type: object properties: @@ -169,11 +210,6 @@ components: items: $ref: '#/components/schemas/FlavorType' - $ref: '#/components/schemas/FlavorType' - - type: array - items: - type: array - items: - $ref: '#/components/schemas/FlavorType' FlavorType: type: object properties: diff --git a/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfMultipleArrayDeserializationTest.java b/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfMultipleArrayDeserializationTest.java new file mode 100644 index 000000000..16a1eb3c4 --- /dev/null +++ b/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfMultipleArrayDeserializationTest.java @@ -0,0 +1,82 @@ +package com.sap.cloud.sdk.datamodel.openapi.sample.api; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.sap.cloud.sdk.datamodel.openapi.sample.model.EmbeddingsInputTextById1D; +import com.sap.cloud.sdk.datamodel.openapi.sample.model.EmbeddingsInputTextById2D; +import com.sap.cloud.sdk.datamodel.openapi.sample.model.OneOfWithMultipleArrays; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class OneOfMultipleArrayDeserializationTest { + private ObjectMapper objectMapper = new ObjectMapper(); + private static final String JSON_ARRAY_INTEGERS = """ + { + "vector": [1, 2, 3, 4] + } + """; + private static final String JSON_ARRAY_OF_INTEGERS_2D = """ + { + "matrix": [[1, 2], [3, 4]] + } + """; + private static final String JSON_STRING = "\"test\""; + private static final String JSON_ARRAY_OF_STRINGS = """ + ["test1", "test2"] + """; + + @Test + public void testDeserializeArrayOfIntegers() + throws Exception { + + final OneOfWithMultipleArrays result = objectMapper.readValue( + JSON_ARRAY_INTEGERS, OneOfWithMultipleArrays.class); + + assertThat(result).isNotNull(); + assertThat(result).isInstanceOf(OneOfWithMultipleArrays.InnerEmbeddingsInputTextById.class); + final var inner = (OneOfWithMultipleArrays.InnerEmbeddingsInputTextById) result; + assertThat(inner.value()).isInstanceOf(EmbeddingsInputTextById1D.class); + } + + @Test + public void testDeserializeArrayOfIntegers2D() + throws Exception { + + final OneOfWithMultipleArrays result = objectMapper.readValue( + JSON_ARRAY_OF_INTEGERS_2D, OneOfWithMultipleArrays.class); + assertThat(result).isNotNull(); + assertThat(result).isInstanceOf(OneOfWithMultipleArrays.InnerEmbeddingsInputTextById.class); + final var inner = (OneOfWithMultipleArrays.InnerEmbeddingsInputTextById) result; + assertThat(inner.value()).isInstanceOf(EmbeddingsInputTextById2D.class); + } + + @Test + public void testDeserializeString() + throws Exception { + + final OneOfWithMultipleArrays result = objectMapper.readValue( + JSON_STRING, OneOfWithMultipleArrays.class); + + assertThat(result).isNotNull(); + assertThat(result).isInstanceOf(OneOfWithMultipleArrays.InnerString.class); + final var inner = (OneOfWithMultipleArrays.InnerString) result; + assertThat(inner.value()).isInstanceOf(String.class); + } + + @Test + public void testDeserializeArrayOfStrings() + throws Exception { + + final OneOfWithMultipleArrays result = objectMapper.readValue( + JSON_ARRAY_OF_STRINGS, OneOfWithMultipleArrays.class); + + assertThat(result).isNotNull(); + assertThat(result).isInstanceOf(OneOfWithMultipleArrays.InnerStrings.class); + final var inner = (OneOfWithMultipleArrays.InnerStrings) result; + assertThat(inner.values()).isInstanceOf(java.util.List.class); + assertThat(inner.values()).hasSize(2); + assertThat(inner.values().get(0)).isEqualTo("test1"); + assertThat(inner.values().get(1)).isEqualTo("test2"); + } + +} diff --git a/pom.xml b/pom.xml index f93e4894e..517b37b9e 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,7 @@ 5.20.0-SNAPSHOT 3.5 17 - true + false ${project.basedir} From 1845b847e8444cd6b082e1de43646829e3dcec1c Mon Sep 17 00:00:00 2001 From: Roshin Rajan Panackal Date: Wed, 11 Jun 2025 15:01:52 +0200 Subject: [PATCH 03/10] Change test class name --- ...pleArrays.java => EmbeddingInputText.java} | 16 ++-- .../src/main/resources/sodastore.yaml | 2 +- ...OneOfMultipleArrayDeserializationTest.java | 75 ++++++++++--------- 3 files changed, 47 insertions(+), 46 deletions(-) rename datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/{OneOfWithMultipleArrays.java => EmbeddingInputText.java} (84%) diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OneOfWithMultipleArrays.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingInputText.java similarity index 84% rename from datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OneOfWithMultipleArrays.java rename to datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingInputText.java index df336e96d..de8d0e713 100644 --- a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OneOfWithMultipleArrays.java +++ b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingInputText.java @@ -23,14 +23,14 @@ import com.fasterxml.jackson.annotation.JsonValue; /** - * OneOfWithMultipleArrays + * EmbeddingInputText */ -public interface OneOfWithMultipleArrays +public interface EmbeddingInputText { /** - * Helper class to create a EmbeddingsInputTextById that implements {@link OneOfWithMultipleArrays}. + * Helper class to create a EmbeddingsInputTextById that implements {@link EmbeddingInputText}. */ - record InnerEmbeddingsInputTextById(@com.fasterxml.jackson.annotation.JsonValue @Nonnull EmbeddingsInputTextById value) implements OneOfWithMultipleArrays {} + record InnerEmbeddingsInputTextById(@com.fasterxml.jackson.annotation.JsonValue @Nonnull EmbeddingsInputTextById value) implements EmbeddingInputText {} /** * Creator to enable deserialization of a EmbeddingsInputTextById. @@ -47,9 +47,9 @@ static InnerEmbeddingsInputTextById create( @Nonnull final EmbeddingsInputTextBy } /** - * Helper class to create a String that implements {@link OneOfWithMultipleArrays}. + * Helper class to create a String that implements {@link EmbeddingInputText}. */ - record InnerString(@com.fasterxml.jackson.annotation.JsonValue @Nonnull String value) implements OneOfWithMultipleArrays {} + record InnerString(@com.fasterxml.jackson.annotation.JsonValue @Nonnull String value) implements EmbeddingInputText {} /** * Creator to enable deserialization of a String. @@ -66,9 +66,9 @@ static InnerString create( @Nonnull final String val ) } /** - * Helper class to create a list of String that implements {@link OneOfWithMultipleArrays}. + * Helper class to create a list of String that implements {@link EmbeddingInputText}. */ - record InnerStrings(@com.fasterxml.jackson.annotation.JsonValue @Nonnull List values) implements OneOfWithMultipleArrays {} + record InnerStrings(@com.fasterxml.jackson.annotation.JsonValue @Nonnull List values) implements EmbeddingInputText {} /** * Creator to enable deserialization of a list of String. diff --git a/datamodel/openapi/openapi-api-sample/src/main/resources/sodastore.yaml b/datamodel/openapi/openapi-api-sample/src/main/resources/sodastore.yaml index 1256e4d8a..1b348884c 100644 --- a/datamodel/openapi/openapi-api-sample/src/main/resources/sodastore.yaml +++ b/datamodel/openapi/openapi-api-sample/src/main/resources/sodastore.yaml @@ -117,7 +117,7 @@ components: mapping: disc_foo: '#/components/schemas/Foo' disc_bar: '#/components/schemas/Bar' - OneOfWithMultipleArrays: + EmbeddingInputText: oneOf: - type: string description: The string that will be turned into an embedding. diff --git a/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfMultipleArrayDeserializationTest.java b/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfMultipleArrayDeserializationTest.java index 16a1eb3c4..bedd69b6e 100644 --- a/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfMultipleArrayDeserializationTest.java +++ b/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfMultipleArrayDeserializationTest.java @@ -1,14 +1,16 @@ package com.sap.cloud.sdk.datamodel.openapi.sample.api; +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.databind.ObjectMapper; +import com.sap.cloud.sdk.datamodel.openapi.sample.model.EmbeddingInputText; import com.sap.cloud.sdk.datamodel.openapi.sample.model.EmbeddingsInputTextById1D; import com.sap.cloud.sdk.datamodel.openapi.sample.model.EmbeddingsInputTextById2D; -import com.sap.cloud.sdk.datamodel.openapi.sample.model.OneOfWithMultipleArrays; -import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; - -class OneOfMultipleArrayDeserializationTest { +class OneOfMultipleArrayDeserializationTest +{ private ObjectMapper objectMapper = new ObjectMapper(); private static final String JSON_ARRAY_INTEGERS = """ { @@ -24,59 +26,58 @@ class OneOfMultipleArrayDeserializationTest { private static final String JSON_ARRAY_OF_STRINGS = """ ["test1", "test2"] """; - + @Test public void testDeserializeArrayOfIntegers() - throws Exception { - - final OneOfWithMultipleArrays result = objectMapper.readValue( - JSON_ARRAY_INTEGERS, OneOfWithMultipleArrays.class); - + throws Exception + { + + final EmbeddingInputText result = objectMapper.readValue(JSON_ARRAY_INTEGERS, EmbeddingInputText.class); + assertThat(result).isNotNull(); - assertThat(result).isInstanceOf(OneOfWithMultipleArrays.InnerEmbeddingsInputTextById.class); - final var inner = (OneOfWithMultipleArrays.InnerEmbeddingsInputTextById) result; + assertThat(result).isInstanceOf(EmbeddingInputText.InnerEmbeddingsInputTextById.class); + final var inner = (EmbeddingInputText.InnerEmbeddingsInputTextById) result; assertThat(inner.value()).isInstanceOf(EmbeddingsInputTextById1D.class); } - + @Test public void testDeserializeArrayOfIntegers2D() - throws Exception { - - final OneOfWithMultipleArrays result = objectMapper.readValue( - JSON_ARRAY_OF_INTEGERS_2D, OneOfWithMultipleArrays.class); + throws Exception + { + + final EmbeddingInputText result = objectMapper.readValue(JSON_ARRAY_OF_INTEGERS_2D, EmbeddingInputText.class); assertThat(result).isNotNull(); - assertThat(result).isInstanceOf(OneOfWithMultipleArrays.InnerEmbeddingsInputTextById.class); - final var inner = (OneOfWithMultipleArrays.InnerEmbeddingsInputTextById) result; + assertThat(result).isInstanceOf(EmbeddingInputText.InnerEmbeddingsInputTextById.class); + final var inner = (EmbeddingInputText.InnerEmbeddingsInputTextById) result; assertThat(inner.value()).isInstanceOf(EmbeddingsInputTextById2D.class); } - + @Test public void testDeserializeString() - throws Exception { - - final OneOfWithMultipleArrays result = objectMapper.readValue( - JSON_STRING, OneOfWithMultipleArrays.class); - + throws Exception + { + + final EmbeddingInputText result = objectMapper.readValue(JSON_STRING, EmbeddingInputText.class); + assertThat(result).isNotNull(); - assertThat(result).isInstanceOf(OneOfWithMultipleArrays.InnerString.class); - final var inner = (OneOfWithMultipleArrays.InnerString) result; + assertThat(result).isInstanceOf(EmbeddingInputText.InnerString.class); + final var inner = (EmbeddingInputText.InnerString) result; assertThat(inner.value()).isInstanceOf(String.class); } - + @Test public void testDeserializeArrayOfStrings() - throws Exception { - - final OneOfWithMultipleArrays result = objectMapper.readValue( - JSON_ARRAY_OF_STRINGS, OneOfWithMultipleArrays.class); - + throws Exception + { + + final EmbeddingInputText result = objectMapper.readValue(JSON_ARRAY_OF_STRINGS, EmbeddingInputText.class); + assertThat(result).isNotNull(); - assertThat(result).isInstanceOf(OneOfWithMultipleArrays.InnerStrings.class); - final var inner = (OneOfWithMultipleArrays.InnerStrings) result; + assertThat(result).isInstanceOf(EmbeddingInputText.InnerStrings.class); + final var inner = (EmbeddingInputText.InnerStrings) result; assertThat(inner.values()).isInstanceOf(java.util.List.class); assertThat(inner.values()).hasSize(2); assertThat(inner.values().get(0)).isEqualTo("test1"); assertThat(inner.values().get(1)).isEqualTo("test2"); } - } From 41a9e61b125ddea8dc27eee28d2753a75ea64342 Mon Sep 17 00:00:00 2001 From: Roshin Rajan Panackal Date: Mon, 18 Aug 2025 17:00:20 +0200 Subject: [PATCH 04/10] Test for matrix --- .../sample/model/EmbeddingInputText.java | 87 ------ .../sample/model/EmbeddingsInputTextById.java | 31 --- .../model/EmbeddingsInputTextById1D.java | 253 ------------------ .../model/EmbeddingsInputTextById2D.java | 253 ------------------ .../openapi/sample/model/OneOfWithMatrix.java | 65 +++++ .../sample/model/OneOfWithMatrixAndArray.java | 65 +++++ .../src/main/resources/sodastore.yaml | 39 +-- .../sample/api/OneOfDeserializationTest.java | 26 ++ ...OneOfMultipleArrayDeserializationTest.java | 83 ------ .../generator/CustomJavaClientCodegen.java | 4 +- pom.xml | 2 +- 11 files changed, 166 insertions(+), 742 deletions(-) delete mode 100644 datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingInputText.java delete mode 100644 datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById.java delete mode 100644 datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById1D.java delete mode 100644 datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById2D.java create mode 100644 datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OneOfWithMatrix.java create mode 100644 datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OneOfWithMatrixAndArray.java delete mode 100644 datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfMultipleArrayDeserializationTest.java diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingInputText.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingInputText.java deleted file mode 100644 index de8d0e713..000000000 --- a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingInputText.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2025 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.datamodel.openapi.sample.model; - -import java.util.List; - -import javax.annotation.Nonnull; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -/** - * EmbeddingInputText - */ -public interface EmbeddingInputText -{ - /** - * Helper class to create a EmbeddingsInputTextById that implements {@link EmbeddingInputText}. - */ - record InnerEmbeddingsInputTextById(@com.fasterxml.jackson.annotation.JsonValue @Nonnull EmbeddingsInputTextById value) implements EmbeddingInputText {} - - /** - * Creator to enable deserialization of a EmbeddingsInputTextById. - * - * @param val - * the value to use - * @return a new instance of {@link InnerEmbeddingsInputTextById}. - */ - @com.fasterxml.jackson.annotation.JsonCreator - @Nonnull - static InnerEmbeddingsInputTextById create( @Nonnull final EmbeddingsInputTextById val ) - { - return new InnerEmbeddingsInputTextById(val); - } - - /** - * Helper class to create a String that implements {@link EmbeddingInputText}. - */ - record InnerString(@com.fasterxml.jackson.annotation.JsonValue @Nonnull String value) implements EmbeddingInputText {} - - /** - * Creator to enable deserialization of a String. - * - * @param val - * the value to use - * @return a new instance of {@link InnerString}. - */ - @com.fasterxml.jackson.annotation.JsonCreator - @Nonnull - static InnerString create( @Nonnull final String val ) - { - return new InnerString(val); - } - - /** - * Helper class to create a list of String that implements {@link EmbeddingInputText}. - */ - record InnerStrings(@com.fasterxml.jackson.annotation.JsonValue @Nonnull List values) implements EmbeddingInputText {} - - /** - * Creator to enable deserialization of a list of String. - * - * @param val - * the value to use - * @return a new instance of {@link InnerStrings}. - */ - @com.fasterxml.jackson.annotation.JsonCreator - @Nonnull - static InnerStrings create( @Nonnull final List val ) - { - return new InnerStrings(val); - } - -} diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById.java deleted file mode 100644 index 697747c5e..000000000 --- a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2025 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.datamodel.openapi.sample.model; - -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeInfo; - -/** - * EmbeddingsInputTextById - */ -@JsonTypeInfo( use = JsonTypeInfo.Id.DEDUCTION ) -@JsonSubTypes( { - @JsonSubTypes.Type( value = EmbeddingsInputTextById1D.class ), - @JsonSubTypes.Type( value = EmbeddingsInputTextById2D.class ), } ) - -public interface EmbeddingsInputTextById -{ -} diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById1D.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById1D.java deleted file mode 100644 index 176a590aa..000000000 --- a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById1D.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (c) 2025 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.datamodel.openapi.sample.model; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Objects; -import java.util.Set; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * EmbeddingsInputTextById1D - */ -// CHECKSTYLE:OFF -public class EmbeddingsInputTextById1D implements EmbeddingsInputTextById -// CHECKSTYLE:ON -{ - @JsonProperty( "vector" ) - private List vector = new ArrayList<>(); - - @JsonAnySetter - @JsonAnyGetter - private final Map cloudSdkCustomFields = new LinkedHashMap<>(); - - /** - * Default constructor for EmbeddingsInputTextById1D. - */ - protected EmbeddingsInputTextById1D() - { - } - - /** - * Set the vector of this {@link EmbeddingsInputTextById1D} instance and return the same instance. - * - * @param vector - * The vector of this {@link EmbeddingsInputTextById1D} - * @return The same instance of this {@link EmbeddingsInputTextById1D} class - */ - @Nonnull - public EmbeddingsInputTextById1D vector( @Nonnull final List vector ) - { - this.vector = vector; - return this; - } - - /** - * Add one vector instance to this {@link EmbeddingsInputTextById1D}. - * - * @param vectorItem - * The vector that should be added - * @return The same instance of type {@link EmbeddingsInputTextById1D} - */ - @Nonnull - public EmbeddingsInputTextById1D addVectorItem( @Nonnull final Integer vectorItem ) - { - if( this.vector == null ) { - this.vector = new ArrayList<>(); - } - this.vector.add(vectorItem); - return this; - } - - /** - * Get vector - * - * @return vector The vector of this {@link EmbeddingsInputTextById1D} instance. - */ - @Nonnull - public List getVector() - { - return vector; - } - - /** - * Set the vector of this {@link EmbeddingsInputTextById1D} instance. - * - * @param vector - * The vector of this {@link EmbeddingsInputTextById1D} - */ - public void setVector( @Nonnull final List vector ) - { - this.vector = vector; - } - - /** - * Get the names of the unrecognizable properties of the {@link EmbeddingsInputTextById1D}. - * - * @return The set of properties names - */ - @JsonIgnore - @Nonnull - public Set getCustomFieldNames() - { - return cloudSdkCustomFields.keySet(); - } - - /** - * Get the value of an unrecognizable property of this {@link EmbeddingsInputTextById1D} 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("EmbeddingsInputTextById1D has no field with name '" + name + "'."); - } - return cloudSdkCustomFields.get(name); - } - - /** - * Get the value of all properties of this {@link EmbeddingsInputTextById1D} instance including unrecognized - * properties. - * - * @return The map of all properties - */ - @JsonIgnore - @Nonnull - public Map toMap() - { - final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); - if( vector != null ) - declaredFields.put("vector", vector); - return declaredFields; - } - - /** - * Set an unrecognizable property of this {@link EmbeddingsInputTextById1D} 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 EmbeddingsInputTextById1D embeddingsInputTextById1D = (EmbeddingsInputTextById1D) o; - return Objects.equals(this.cloudSdkCustomFields, embeddingsInputTextById1D.cloudSdkCustomFields) - && Objects.equals(this.vector, embeddingsInputTextById1D.vector); - } - - @Override - public int hashCode() - { - return Objects.hash(vector, cloudSdkCustomFields); - } - - @Override - @Nonnull - public String toString() - { - final StringBuilder sb = new StringBuilder(); - sb.append("class EmbeddingsInputTextById1D {\n"); - sb.append(" vector: ").append(toIndentedString(vector)).append("\n"); - cloudSdkCustomFields - .forEach(( k, v ) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces (except the first line). - */ - private String toIndentedString( final java.lang.Object o ) - { - if( o == null ) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } - - /** - * Create a type-safe, fluent-api builder object to construct a new {@link EmbeddingsInputTextById1D} instance with - * all required arguments. - */ - public static Builder create() - { - return ( vector ) -> new EmbeddingsInputTextById1D().vector(vector); - } - - /** - * Builder helper class. - */ - public interface Builder - { - /** - * Set the vector of this {@link EmbeddingsInputTextById1D} instance. - * - * @param vector - * The vector of this {@link EmbeddingsInputTextById1D} - * @return The EmbeddingsInputTextById1D instance. - */ - EmbeddingsInputTextById1D vector( @Nonnull final List vector ); - - /** - * Set the vector of this {@link EmbeddingsInputTextById1D} instance. - * - * @param vector - * The vector of this {@link EmbeddingsInputTextById1D} - * @return The EmbeddingsInputTextById1D instance. - */ - default EmbeddingsInputTextById1D vector( @Nonnull final Integer... vector ) - { - return vector(Arrays.asList(vector)); - } - } - -} diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById2D.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById2D.java deleted file mode 100644 index bc3c91f19..000000000 --- a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/EmbeddingsInputTextById2D.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (c) 2025 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.datamodel.openapi.sample.model; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Objects; -import java.util.Set; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * EmbeddingsInputTextById2D - */ -// CHECKSTYLE:OFF -public class EmbeddingsInputTextById2D implements EmbeddingsInputTextById -// CHECKSTYLE:ON -{ - @JsonProperty( "matrix" ) - private List> matrix = new ArrayList<>(); - - @JsonAnySetter - @JsonAnyGetter - private final Map cloudSdkCustomFields = new LinkedHashMap<>(); - - /** - * Default constructor for EmbeddingsInputTextById2D. - */ - protected EmbeddingsInputTextById2D() - { - } - - /** - * Set the matrix of this {@link EmbeddingsInputTextById2D} instance and return the same instance. - * - * @param matrix - * The matrix of this {@link EmbeddingsInputTextById2D} - * @return The same instance of this {@link EmbeddingsInputTextById2D} class - */ - @Nonnull - public EmbeddingsInputTextById2D matrix( @Nonnull final List> matrix ) - { - this.matrix = matrix; - return this; - } - - /** - * Add one matrix instance to this {@link EmbeddingsInputTextById2D}. - * - * @param matrixItem - * The matrix that should be added - * @return The same instance of type {@link EmbeddingsInputTextById2D} - */ - @Nonnull - public EmbeddingsInputTextById2D addMatrixItem( @Nonnull final List matrixItem ) - { - if( this.matrix == null ) { - this.matrix = new ArrayList<>(); - } - this.matrix.add(matrixItem); - return this; - } - - /** - * Get matrix - * - * @return matrix The matrix of this {@link EmbeddingsInputTextById2D} instance. - */ - @Nonnull - public List> getMatrix() - { - return matrix; - } - - /** - * Set the matrix of this {@link EmbeddingsInputTextById2D} instance. - * - * @param matrix - * The matrix of this {@link EmbeddingsInputTextById2D} - */ - public void setMatrix( @Nonnull final List> matrix ) - { - this.matrix = matrix; - } - - /** - * Get the names of the unrecognizable properties of the {@link EmbeddingsInputTextById2D}. - * - * @return The set of properties names - */ - @JsonIgnore - @Nonnull - public Set getCustomFieldNames() - { - return cloudSdkCustomFields.keySet(); - } - - /** - * Get the value of an unrecognizable property of this {@link EmbeddingsInputTextById2D} 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("EmbeddingsInputTextById2D has no field with name '" + name + "'."); - } - return cloudSdkCustomFields.get(name); - } - - /** - * Get the value of all properties of this {@link EmbeddingsInputTextById2D} instance including unrecognized - * properties. - * - * @return The map of all properties - */ - @JsonIgnore - @Nonnull - public Map toMap() - { - final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); - if( matrix != null ) - declaredFields.put("matrix", matrix); - return declaredFields; - } - - /** - * Set an unrecognizable property of this {@link EmbeddingsInputTextById2D} 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 EmbeddingsInputTextById2D embeddingsInputTextById2D = (EmbeddingsInputTextById2D) o; - return Objects.equals(this.cloudSdkCustomFields, embeddingsInputTextById2D.cloudSdkCustomFields) - && Objects.equals(this.matrix, embeddingsInputTextById2D.matrix); - } - - @Override - public int hashCode() - { - return Objects.hash(matrix, cloudSdkCustomFields); - } - - @Override - @Nonnull - public String toString() - { - final StringBuilder sb = new StringBuilder(); - sb.append("class EmbeddingsInputTextById2D {\n"); - sb.append(" matrix: ").append(toIndentedString(matrix)).append("\n"); - cloudSdkCustomFields - .forEach(( k, v ) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces (except the first line). - */ - private String toIndentedString( final java.lang.Object o ) - { - if( o == null ) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } - - /** - * Create a type-safe, fluent-api builder object to construct a new {@link EmbeddingsInputTextById2D} instance with - * all required arguments. - */ - public static Builder create() - { - return ( matrix ) -> new EmbeddingsInputTextById2D().matrix(matrix); - } - - /** - * Builder helper class. - */ - public interface Builder - { - /** - * Set the matrix of this {@link EmbeddingsInputTextById2D} instance. - * - * @param matrix - * The matrix of this {@link EmbeddingsInputTextById2D} - * @return The EmbeddingsInputTextById2D instance. - */ - EmbeddingsInputTextById2D matrix( @Nonnull final List> matrix ); - - /** - * Set the matrix of this {@link EmbeddingsInputTextById2D} instance. - * - * @param matrix - * The matrix of this {@link EmbeddingsInputTextById2D} - * @return The EmbeddingsInputTextById2D instance. - */ - default EmbeddingsInputTextById2D matrix( @Nonnull final List... matrix ) - { - return matrix(Arrays.asList(matrix)); - } - } - -} diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OneOfWithMatrix.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OneOfWithMatrix.java new file mode 100644 index 000000000..45ddb0c62 --- /dev/null +++ b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OneOfWithMatrix.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2025 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.datamodel.openapi.sample.model; + +import java.util.List; + +import javax.annotation.Nonnull; + +/** + * OneOfWithMatrix + */ +public interface OneOfWithMatrix +{ + /** + * Helper class to create a Integer that implements {@link OneOfWithMatrix}. + */ + record InnerInteger(@com.fasterxml.jackson.annotation.JsonValue @Nonnull Integer value) implements OneOfWithMatrix {} + + /** + * Creator to enable deserialization of a Integer. + * + * @param val + * the value to use + * @return a new instance of {@link InnerInteger}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + @Nonnull + static InnerInteger create( @Nonnull final Integer val ) + { + return new InnerInteger(val); + } + + /** + * Helper class to create {@code List> } that implements {@link OneOfWithMatrix}. + */ + record InnerIntegers2D(@com.fasterxml.jackson.annotation.JsonValue @Nonnull List> values) implements OneOfWithMatrix {} + + /** + * Creator to enable deserialization of {@code List> }. + * + * @param val + * the value to use + * @return a new instance of {@link InnerIntegers2D}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + @Nonnull + static InnerIntegers2D create2DList( @Nonnull final List> val ) + { + return new InnerIntegers2D(val); + } + +} diff --git a/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OneOfWithMatrixAndArray.java b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OneOfWithMatrixAndArray.java new file mode 100644 index 000000000..aabbd87f9 --- /dev/null +++ b/datamodel/openapi/openapi-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/openapi/sample/model/OneOfWithMatrixAndArray.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2025 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.datamodel.openapi.sample.model; + +import java.util.List; + +import javax.annotation.Nonnull; + +/** + * OneOfWithMatrixAndArray + */ +public interface OneOfWithMatrixAndArray +{ + /** + * Helper class to create a list of Integer that implements {@link OneOfWithMatrixAndArray}. + */ + record InnerIntegers(@com.fasterxml.jackson.annotation.JsonValue @Nonnull List values) implements OneOfWithMatrixAndArray {} + + /** + * Creator to enable deserialization of a list of Integer. + * + * @param val + * the value to use + * @return a new instance of {@link InnerIntegers}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + @Nonnull + static InnerIntegers create( @Nonnull final List val ) + { + return new InnerIntegers(val); + } + + /** + * Helper class to create {@code List> } that implements {@link OneOfWithMatrixAndArray}. + */ + record InnerIntegers2D(@com.fasterxml.jackson.annotation.JsonValue @Nonnull List> values) implements OneOfWithMatrixAndArray {} + + /** + * Creator to enable deserialization of {@code List> }. + * + * @param val + * the value to use + * @return a new instance of {@link InnerIntegers2D}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + @Nonnull + static InnerIntegers2D create2DList( @Nonnull final List> val ) + { + return new InnerIntegers2D(val); + } + +} diff --git a/datamodel/openapi/openapi-api-sample/src/main/resources/sodastore.yaml b/datamodel/openapi/openapi-api-sample/src/main/resources/sodastore.yaml index 1b348884c..71f7d6a68 100644 --- a/datamodel/openapi/openapi-api-sample/src/main/resources/sodastore.yaml +++ b/datamodel/openapi/openapi-api-sample/src/main/resources/sodastore.yaml @@ -117,45 +117,22 @@ components: mapping: disc_foo: '#/components/schemas/Foo' disc_bar: '#/components/schemas/Bar' - EmbeddingInputText: + OneOfWithMatrix: oneOf: - - type: string - description: The string that will be turned into an embedding. - example: Hello World! + - type: integer - type: array - description: The array of strings that will be turned into an embedding. - minItems: 1 items: - type: string - minLength: 1 - example: "['Hello', 'World', '!']" - - $ref: '#/components/schemas/EmbeddingsInputTextById' - EmbeddingsInputTextById: + type: array + items: + type: integer + OneOfWithMatrixAndArray: oneOf: - - $ref: '#/components/schemas/EmbeddingsInputTextById1D' - - $ref: '#/components/schemas/EmbeddingsInputTextById2D' - EmbeddingsInputTextById1D: - type: object - required: - - vector - properties: - vector: - type: array - minItems: 1 + - type: array items: type: integer - minLength: 1 - EmbeddingsInputTextById2D: - type: object - required: - - matrix - properties: - matrix: - type: array - minItems: 1 + - type: array items: type: array - minItems: 1 items: type: integer Foo: diff --git a/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfDeserializationTest.java b/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfDeserializationTest.java index abd8f1c24..14bc43de5 100644 --- a/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfDeserializationTest.java +++ b/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfDeserializationTest.java @@ -3,6 +3,7 @@ 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; @@ -17,6 +18,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.exc.InvalidDefinitionException; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.sap.cloud.sdk.datamodel.openapi.sample.model.AllOf; import com.sap.cloud.sdk.datamodel.openapi.sample.model.AnyOf; @@ -30,6 +32,8 @@ import com.sap.cloud.sdk.datamodel.openapi.sample.model.OneOfWithDiscriminator; import com.sap.cloud.sdk.datamodel.openapi.sample.model.OneOfWithDiscriminatorAndMapping; import com.sap.cloud.sdk.datamodel.openapi.sample.model.OneOfWithEnumDiscriminator; +import com.sap.cloud.sdk.datamodel.openapi.sample.model.OneOfWithMatrix; +import com.sap.cloud.sdk.datamodel.openapi.sample.model.OneOfWithMatrixAndArray; class OneOfDeserializationTest { @@ -169,6 +173,28 @@ void oneOfWithNestedArrayOfObjects( Class strategy ) } + @Test + void oneOfWIthMatrixOfObjects() + throws JsonProcessingException + { + var json = """ + [ + [1, 2, 3 ], + [4, 5, 6 ] + ] + """; + var matrix = objectMapper.readValue(json, OneOfWithMatrix.class); + assertThat(matrix) + .describedAs("Object should be deserialized as InnerIntegers2D") + .isInstanceOf(OneOfWithMatrix.InnerIntegers2D.class); + var integers2D = (OneOfWithMatrix.InnerIntegers2D) matrix; + assertThat(integers2D.values()).isEqualTo(List.of(List.of(1, 2, 3), List.of(4, 5, 6))); + + assertThatThrownBy(() -> objectMapper.readValue(json, OneOfWithMatrixAndArray.class)) + .hasMessageContaining("Conflicting array-delegate creators") + .isInstanceOf(InvalidDefinitionException.class); + } + @Test void anyOf() throws JsonProcessingException diff --git a/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfMultipleArrayDeserializationTest.java b/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfMultipleArrayDeserializationTest.java deleted file mode 100644 index bedd69b6e..000000000 --- a/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfMultipleArrayDeserializationTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.sap.cloud.sdk.datamodel.openapi.sample.api; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.jupiter.api.Test; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.sap.cloud.sdk.datamodel.openapi.sample.model.EmbeddingInputText; -import com.sap.cloud.sdk.datamodel.openapi.sample.model.EmbeddingsInputTextById1D; -import com.sap.cloud.sdk.datamodel.openapi.sample.model.EmbeddingsInputTextById2D; - -class OneOfMultipleArrayDeserializationTest -{ - private ObjectMapper objectMapper = new ObjectMapper(); - private static final String JSON_ARRAY_INTEGERS = """ - { - "vector": [1, 2, 3, 4] - } - """; - private static final String JSON_ARRAY_OF_INTEGERS_2D = """ - { - "matrix": [[1, 2], [3, 4]] - } - """; - private static final String JSON_STRING = "\"test\""; - private static final String JSON_ARRAY_OF_STRINGS = """ - ["test1", "test2"] - """; - - @Test - public void testDeserializeArrayOfIntegers() - throws Exception - { - - final EmbeddingInputText result = objectMapper.readValue(JSON_ARRAY_INTEGERS, EmbeddingInputText.class); - - assertThat(result).isNotNull(); - assertThat(result).isInstanceOf(EmbeddingInputText.InnerEmbeddingsInputTextById.class); - final var inner = (EmbeddingInputText.InnerEmbeddingsInputTextById) result; - assertThat(inner.value()).isInstanceOf(EmbeddingsInputTextById1D.class); - } - - @Test - public void testDeserializeArrayOfIntegers2D() - throws Exception - { - - final EmbeddingInputText result = objectMapper.readValue(JSON_ARRAY_OF_INTEGERS_2D, EmbeddingInputText.class); - assertThat(result).isNotNull(); - assertThat(result).isInstanceOf(EmbeddingInputText.InnerEmbeddingsInputTextById.class); - final var inner = (EmbeddingInputText.InnerEmbeddingsInputTextById) result; - assertThat(inner.value()).isInstanceOf(EmbeddingsInputTextById2D.class); - } - - @Test - public void testDeserializeString() - throws Exception - { - - final EmbeddingInputText result = objectMapper.readValue(JSON_STRING, EmbeddingInputText.class); - - assertThat(result).isNotNull(); - assertThat(result).isInstanceOf(EmbeddingInputText.InnerString.class); - final var inner = (EmbeddingInputText.InnerString) result; - assertThat(inner.value()).isInstanceOf(String.class); - } - - @Test - public void testDeserializeArrayOfStrings() - throws Exception - { - - final EmbeddingInputText result = objectMapper.readValue(JSON_ARRAY_OF_STRINGS, EmbeddingInputText.class); - - assertThat(result).isNotNull(); - assertThat(result).isInstanceOf(EmbeddingInputText.InnerStrings.class); - final var inner = (EmbeddingInputText.InnerStrings) result; - assertThat(inner.values()).isInstanceOf(java.util.List.class); - assertThat(inner.values()).hasSize(2); - assertThat(inner.values().get(0)).isEqualTo("test1"); - assertThat(inner.values().get(1)).isEqualTo("test2"); - } -} diff --git a/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java b/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java index 8ca3fc7e8..084568a60 100644 --- a/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java +++ b/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java @@ -277,23 +277,21 @@ private void useCreatorsForInterfaceSubtypes( @Nonnull final CodegenModel m ) for( final String candidate : candidates ) { if( candidate.startsWith("List<") ) { - int depth = 0; String sub = candidate; - while( sub.startsWith("List<") ) { sub = sub.substring(5, sub.length() - 1); depth++; } final String innerType = sub; - if( depth == 1 ) { candidatesMultiple1D.add(innerType); } else { candidatesMultipleND .add(Map.of("innerType", innerType, "depth", String.valueOf(depth), "fullType", candidate)); } + useCreators = true; } else { candidatesSingle.add(candidate); diff --git a/pom.xml b/pom.xml index 86f6b387a..01a2c9d9f 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,7 @@ 5.22.0-SNAPSHOT 3.5 17 - false + true ${project.basedir} UTF-8 From 604ae5c11239a249b1acb2dfd7be4cd9c0403192 Mon Sep 17 00:00:00 2001 From: Roshin Rajan Panackal Date: Tue, 19 Aug 2025 10:13:37 +0200 Subject: [PATCH 05/10] Log a warning for multiple array type fields --- .../openapi/generator/CustomJavaClientCodegen.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java b/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java index 084568a60..7920370a5 100644 --- a/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java +++ b/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java @@ -307,6 +307,14 @@ private void useCreatorsForInterfaceSubtypes( @Nonnull final CodegenModel m ) "Generating interface with mixed multiple non-primitive and primitive sub-types: {}. Deserialization may not work."; log.warn(msg, m.name); } + var numArrayTypes = candidatesSingle.size() + candidatesMultipleND.size(); + if( numArrayTypes > 1 ) { + final var msg = + "Field can be oneOf %d array types. Deserialization may not work as expected." + .formatted(numArrayTypes); + log.warn(msg, m.name); + } + candidates.clear(); final var monads = Map From 3e31494bff01e47c3b72e652fd211f1e6dc8dc57 Mon Sep 17 00:00:00 2001 From: Roshin Rajan Panackal Date: Tue, 19 Aug 2025 10:17:10 +0200 Subject: [PATCH 06/10] pmd --- .../datamodel/openapi/generator/CustomJavaClientCodegen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java b/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java index 7920370a5..bb1aac72a 100644 --- a/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java +++ b/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java @@ -307,7 +307,7 @@ private void useCreatorsForInterfaceSubtypes( @Nonnull final CodegenModel m ) "Generating interface with mixed multiple non-primitive and primitive sub-types: {}. Deserialization may not work."; log.warn(msg, m.name); } - var numArrayTypes = candidatesSingle.size() + candidatesMultipleND.size(); + final var numArrayTypes = candidatesSingle.size() + candidatesMultipleND.size(); if( numArrayTypes > 1 ) { final var msg = "Field can be oneOf %d array types. Deserialization may not work as expected." From 1d90a824a393fe1b24abb3870f1ac8ff3d405b4e Mon Sep 17 00:00:00 2001 From: Roshin Rajan Panackal Date: Tue, 19 Aug 2025 12:12:23 +0200 Subject: [PATCH 07/10] variable naming --- .../generator/CustomJavaClientCodegen.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java b/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java index bb1aac72a..fa3210e73 100644 --- a/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java +++ b/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java @@ -269,32 +269,33 @@ private void useCreatorsForInterfaceSubtypes( @Nonnull final CodegenModel m ) return; } boolean useCreators = false; + final var LIST_TYPE_PREFIX = "List<"; for( final Set candidates : List.of(m.anyOf, m.oneOf) ) { int nonPrimitives = 0; - final var candidatesSingle = new HashSet(); - final var candidatesMultiple1D = new HashSet(); - final var candidatesMultipleND = new HashSet>(); + final var singleTypes = new HashSet(); + final var arrayTypes1D = new HashSet(); + final var arrayTypesND = new HashSet>(); for( final String candidate : candidates ) { - if( candidate.startsWith("List<") ) { + if( candidate.startsWith(LIST_TYPE_PREFIX) ) { int depth = 0; String sub = candidate; - while( sub.startsWith("List<") ) { + while( sub.startsWith(LIST_TYPE_PREFIX) ) { sub = sub.substring(5, sub.length() - 1); depth++; } final String innerType = sub; if( depth == 1 ) { - candidatesMultiple1D.add(innerType); + arrayTypes1D.add(innerType); } else { - candidatesMultipleND + arrayTypesND .add(Map.of("innerType", innerType, "depth", String.valueOf(depth), "fullType", candidate)); } useCreators = true; } else { - candidatesSingle.add(candidate); + singleTypes.add(candidate); useCreators |= PRIMITIVES.contains(candidate); if( !PRIMITIVES.contains(candidate) ) { nonPrimitives++; @@ -307,7 +308,7 @@ private void useCreatorsForInterfaceSubtypes( @Nonnull final CodegenModel m ) "Generating interface with mixed multiple non-primitive and primitive sub-types: {}. Deserialization may not work."; log.warn(msg, m.name); } - final var numArrayTypes = candidatesSingle.size() + candidatesMultipleND.size(); + final var numArrayTypes = singleTypes.size() + arrayTypesND.size(); if( numArrayTypes > 1 ) { final var msg = "Field can be oneOf %d array types. Deserialization may not work as expected." @@ -320,11 +321,11 @@ private void useCreatorsForInterfaceSubtypes( @Nonnull final CodegenModel m ) Map .of( "single", - candidatesSingle, + singleTypes, "multiple1D", - candidatesMultiple1D, + arrayTypes1D, "multipleND", - candidatesMultipleND); + arrayTypesND); m.vendorExtensions.put("x-monads", monads); m.vendorExtensions.put("x-is-one-of-interface", true); // enforce template usage } From 864f64b90ad477c98166057c172743f547311e8a Mon Sep 17 00:00:00 2001 From: Roshin Rajan Panackal Date: Tue, 19 Aug 2025 12:38:55 +0200 Subject: [PATCH 08/10] formatting --- .../openapi/generator/CustomJavaClientCodegen.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java b/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java index fa3210e73..8b928a146 100644 --- a/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java +++ b/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java @@ -318,14 +318,7 @@ private void useCreatorsForInterfaceSubtypes( @Nonnull final CodegenModel m ) candidates.clear(); final var monads = - Map - .of( - "single", - singleTypes, - "multiple1D", - arrayTypes1D, - "multipleND", - arrayTypesND); + Map.of("single", singleTypes, "multiple1D", arrayTypes1D, "multipleND", arrayTypesND); m.vendorExtensions.put("x-monads", monads); m.vendorExtensions.put("x-is-one-of-interface", true); // enforce template usage } From 8d60fd869efa0509770283d367bdf9830196a465 Mon Sep 17 00:00:00 2001 From: Roshin Rajan Panackal Date: Tue, 19 Aug 2025 12:45:14 +0200 Subject: [PATCH 09/10] minor refactoring --- .../datamodel/openapi/generator/CustomJavaClientCodegen.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java b/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java index 8b928a146..4637d4e8a 100644 --- a/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java +++ b/datamodel/openapi/openapi-generator/src/main/java/com/sap/cloud/sdk/datamodel/openapi/generator/CustomJavaClientCodegen.java @@ -269,7 +269,6 @@ private void useCreatorsForInterfaceSubtypes( @Nonnull final CodegenModel m ) return; } boolean useCreators = false; - final var LIST_TYPE_PREFIX = "List<"; for( final Set candidates : List.of(m.anyOf, m.oneOf) ) { int nonPrimitives = 0; final var singleTypes = new HashSet(); @@ -277,10 +276,10 @@ private void useCreatorsForInterfaceSubtypes( @Nonnull final CodegenModel m ) final var arrayTypesND = new HashSet>(); for( final String candidate : candidates ) { - if( candidate.startsWith(LIST_TYPE_PREFIX) ) { + if( candidate.startsWith("List<") ) { int depth = 0; String sub = candidate; - while( sub.startsWith(LIST_TYPE_PREFIX) ) { + while( sub.startsWith("List<") ) { sub = sub.substring(5, sub.length() - 1); depth++; } From 358aee759ec0d42348176b60342e72b51b2b1421 Mon Sep 17 00:00:00 2001 From: Roshin Rajan Panackal <36329474+rpanackal@users.noreply.github.com> Date: Tue, 19 Aug 2025 17:36:47 +0200 Subject: [PATCH 10/10] Update datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfDeserializationTest.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alexander Dümont <22489773+newtork@users.noreply.github.com> --- .../openapi/sample/api/OneOfDeserializationTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfDeserializationTest.java b/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfDeserializationTest.java index 14bc43de5..368614a95 100644 --- a/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfDeserializationTest.java +++ b/datamodel/openapi/openapi-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/openapi/sample/api/OneOfDeserializationTest.java @@ -186,9 +186,9 @@ void oneOfWIthMatrixOfObjects() var matrix = objectMapper.readValue(json, OneOfWithMatrix.class); assertThat(matrix) .describedAs("Object should be deserialized as InnerIntegers2D") - .isInstanceOf(OneOfWithMatrix.InnerIntegers2D.class); - var integers2D = (OneOfWithMatrix.InnerIntegers2D) matrix; - assertThat(integers2D.values()).isEqualTo(List.of(List.of(1, 2, 3), List.of(4, 5, 6))); + .isInstanceOfSatisfying( + OneOfWithMatrix.InnerIntegers2D.class, + integers2D -> assertThat(integers2D.values()).isEqualTo(List.of(List.of(1, 2, 3), List.of(4, 5, 6)))); assertThatThrownBy(() -> objectMapper.readValue(json, OneOfWithMatrixAndArray.class)) .hasMessageContaining("Conflicting array-delegate creators")