-
Notifications
You must be signed in to change notification settings - Fork 19
feat: [OpenAPI] oneOf
with a Tensor (n-Dimensional array)
#898
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
base: main
Are you sure you want to change the base?
Changes from all commits
af953c9
ebac9ae
1845b84
c6d9ce9
41a9e61
604ae5c
3e31494
1d90a82
864f64b
8d60fd8
b0be634
358aee7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<List<Integer>> } that implements {@link OneOfWithMatrix}. | ||
*/ | ||
record InnerIntegers2D(@com.fasterxml.jackson.annotation.JsonValue @Nonnull List<List<Integer>> values) implements OneOfWithMatrix {} | ||
|
||
/** | ||
* Creator to enable deserialization of {@code List<List<Integer>> }. | ||
* | ||
* @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<List<Integer>> val ) | ||
{ | ||
return new InnerIntegers2D(val); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Integer> 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<Integer> val ) | ||
{ | ||
return new InnerIntegers(val); | ||
} | ||
|
||
/** | ||
* Helper class to create {@code List<List<Integer>> } that implements {@link OneOfWithMatrixAndArray}. | ||
*/ | ||
record InnerIntegers2D(@com.fasterxml.jackson.annotation.JsonValue @Nonnull List<List<Integer>> values) implements OneOfWithMatrixAndArray {} | ||
|
||
/** | ||
* Creator to enable deserialization of {@code List<List<Integer>> }. | ||
* | ||
* @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<List<Integer>> val ) | ||
{ | ||
return new InnerIntegers2D(val); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,24 @@ components: | |
mapping: | ||
disc_foo: '#/components/schemas/Foo' | ||
disc_bar: '#/components/schemas/Bar' | ||
OneOfWithMatrix: | ||
oneOf: | ||
- type: integer | ||
- type: array | ||
items: | ||
type: array | ||
items: | ||
type: integer | ||
OneOfWithMatrixAndArray: | ||
oneOf: | ||
- type: array | ||
items: | ||
type: integer | ||
- type: array | ||
items: | ||
type: array | ||
items: | ||
type: integer | ||
Comment on lines
+120
to
+137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Comment) I think it's a bad idea to abuse the sample module das unit test ground. We should move it to generator module instead. |
||
Foo: | ||
type: object | ||
properties: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,16 +271,30 @@ private void useCreatorsForInterfaceSubtypes( @Nonnull final CodegenModel m ) | |
boolean useCreators = false; | ||
for( final Set<String> candidates : List.of(m.anyOf, m.oneOf) ) { | ||
int nonPrimitives = 0; | ||
final var candidatesSingle = new HashSet<String>(); | ||
final var candidatesMultiple = new HashSet<String>(); | ||
final var singleTypes = new HashSet<String>(); | ||
final var arrayTypes1D = new HashSet<String>(); | ||
final var arrayTypesND = new HashSet<Map<String, String>>(); | ||
Comment on lines
+274
to
+276
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Minor)
|
||
|
||
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 ) { | ||
arrayTypes1D.add(innerType); | ||
} else { | ||
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++; | ||
|
@@ -293,8 +307,17 @@ 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 = singleTypes.size() + arrayTypesND.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.of("single", candidatesSingle, "multiple", candidatesMultiple); | ||
final var monads = | ||
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 | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Major/Discussion)
I think that's a bad name. Unfortunately I do not have a good alternative at the moment.
I don't think we can use the terms dimension or matrix in our generator, because they indicate well defined
m * n
vectors, which does not really match the semantics of arrays of arbitrary size having elements of arrays of arbitrary size.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid conflicting methods due to type erasure, we need to somehow name the methods distinctly by dimensionality.
Its not clear to me why it is a bad name. And, I don't see how we may name the creators without including the num of dimensions. But, here are few suggestions
from2D
,from3D
etcfromDepth2
,fromDepth3
etcfromRank2
,fromRank3
etccreate2D
,create3D
etccreateMatrix
,createTensor
and cap maximum dimensions supported to 3No strong opinion on this. So, I will accept any naming you prefer.