I'm using SpringBoot + Swagger (OpenApi3) + Java for my application. I use the Swagger documentation to import the API into API Gateway.
I have a couple of Java models that both have the following field: List<MyOwnObject> objectList.
When transformed by swagger, I get my models transformed with the same definition for the field:
model1:
type: object
properties:
... // other properties here
objectList:
type: array
items:
$ref: #/components/schemas/MyOwnObject
model2:
type: object
properties:
... // other properties here
objectList:
type: array
items:
$ref: #/components/schemas/MyOwnObject
Now, because of a "feature" in API Gateway, I need to extract these arrays definitions into a single one, referenced in the two models, but I'm not able to find a way to remodel my POJOs to accomplish it.
I require an output similar to this:
model1:
type: object
properties:
... // other properties here
objectList:
$ref: #/components/schemas/commonArray
model2:
type: object
properties:
... // other properties here
objectList:
$ref: #/components/schemas/commonArray
commonArray:
type: array
items:
$ref: #/components/schemas/MyOwnObject
What have I tried
- I created a new POJO, containing the list variable. This works, but given that we are adding an extra variable, this affects a current-in-production API schema, which we prefer not to modify.
- I created a new POJO extending from
ArrayList<MyOwnObject>. During generation, Swagger replaces the new object for the samearrayschema, leaving the output equal to the original. - I've played with the
@Schemaand@ArraySchemaSwagger annotations without luck.
Do you guys have any idea on how to solve this issue? Is it even possible to accomplish?
Thanks!