[Rest Catalog Open API] Usage of "oneof" in the definition
- Dominant language
- Java
- Stars
- 9.2k
- Forks
- 3.5k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 132
Description
### Query engine
Not related to query engine.
### Question
## **Summary**
I attempted to use open api generator (jaxrs-spec) to generate java api&service code using the provided Iceberg Rest Catalog OpenAPI spec provided [here](https://github.com/apache/iceberg/blob/master/open-api/rest-catalog-open-api.yaml). I spotted some potential misusage of "**oneof**" key word in the API yaml definition that produced undesired result in the generated java code, therefore I want to raise a question to see if there's anything I did incorrectly.
## **Details**
### Background:
1. Tools I'm using:
OpenAPI generator cli version: 6.3.0
2. cmd that I ran:
```
openapi-generator generate -i rest-catalog-open-api.yaml -g jaxrs-spec -o output
```
3. Section concerned in the API definition:
[#/components/schemas/Type](https://github.com/apache/iceberg/blob/master/open-api/rest-catalog-open-api.yaml#L1068)
4. Java Model generated by OpenAPI generator:
https://github.com/haizhou-zhao/test-iceberg-rest-jaxrs/blob/master/src/gen/java/org/openapitools/model/Type.java
### What went wrong:
Java code generated successfully. Yet the generated code is very different from the original Type API in Iceberg: [ref](https://github.com/apache/iceberg/blob/master/api/src/main/java/org/apache/iceberg/types/Type.java).
My guess is that the original intention is to generate code using inheritance (polymorphism) like `MapType extends Type` , but OpenAPI generated code is closer to a Uber class (composition) like
```
class Type {
MapType mapType;
StructType structType;
ListType listType;
...
}
```
### Question:
Am I correct assuming that that the original intention was to define a polymorphic (instead of composite) relationship between `Type` and `{MapType, StructType, ListType}`?
Am I misusing OpenAPI generator (e.g. incorrect options, etc.) which is causing me to generate undesired java code?
### Further thoughts
If we want polymorphism instead of composition, then instead of this definition (the current version)
```
Type:
oneOf:
- $ref: '#/components/schemas/PrimitiveType'
- $ref: '#/components/schemas/StructType'
- $ref: '#/components/schemas/ListType'
- $ref: '#/components/schemas/MapType'
```
the following definition might be better
```
Type:
discriminator:
propertyName: typeId
type: object
properties:
typeId:
type: string
example:
- "string"
- "boolean"
- "integer"
- ...
NestedType:
allOf:
- $ref: '#/components/schemas/Type'
MapType:
allOf:
- $ref: '#/components/schemas/NestedType'
- type: object
properties:
keyField:
type: $ref: '#/components/schemas/NestedField'
valueField:
type: $ref: '#/components/schemas/NestedField'
...
```
Contributor guide
Assessment
This issue has not been assessed yet.