-
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?
Conversation
final var monads = | ||
Map | ||
.of( | ||
"single", | ||
candidatesSingle, | ||
"multiple1D", | ||
candidatesMultiple1D, | ||
"multipleND", | ||
candidatesMultipleND); |
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.
Question/Discussion
In the current state, we will be generating multiple creator methods like
create(Integer)
create(List<Integer>)
create2DList(List<List<Integer>>)
for the spec below:
OneOfExample
oneOf
- type: integer
- type: array
items:
type: integer
- type: array
items:
type: array
items:
type: integer
Though the above code compiles, deserialisation will fail at runtime.
I am not sure if we ideally,
- Throw exception at code generation time for early detection because Jackson default deserializer will throw 100%
- Useful to fail our spec update workflow. Otherwise, such issues may be missed and hard to work around afterwards.
- Dont throw an exception but log a warning (current state)
- Useful because the user may write their own custom deserializer/decoder on top
oneOf
with a matrix (2D array)
oneOf
with a matrix (2D array)oneOf
with a Tensor (n-Dimensional array)
final var singleTypes = new HashSet<String>(); | ||
final var arrayTypes1D = new HashSet<String>(); | ||
final var arrayTypesND = new HashSet<Map<String, String>>(); |
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.
(Minor)
- Can you combine
arrayTypes1D
andarrayTypesND
? I don't see a reason why we need to maintain both sets(?) - Have you considered a record type instead of generic
Map<String, String>
? Looks a little lazy for storing 3 static values.
*/ | ||
@com.fasterxml.jackson.annotation.JsonCreator | ||
@Nonnull | ||
static InnerIntegers2D create2DList( @Nonnull final List<List<Integer>> val ) |
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)
create2DList
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.
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 |
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.
(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.
However since probably I'm offender too, I cannot force it here.
Maybe as part of a separate house-keeping PR.
.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))); |
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.
(Comment)
You could also use the .isInstanceOfSatisfying
API from AssertJ
.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)))); |
Context
#291
The PR focus on generating compilable code when multi dimentional arrays exist.
This PR does NOT fix the problem where there are multiple arrays under
oneOf
, but simply successfully generate a creator (annotated@JsonCreator
) for a multi-dimentional array.What does the PR solve?
Scenario 1: The
oneOf
contains only one array. But it is n-dim array, with n > 1.Scenario 2: The
oneOf
contains two array. Here dimensionality doesn't matterFeature scope:
oneOf
. Effectively, when there is a single n-dim (n >=1) array, deserialization is successful.Definition of Done
Error handling created / updated & covered by the tests aboveDocumentation updatedRelease notes updated