Reputation: 75
I made a REST endpoint and an open-api documentation for it using SpringDoc+Swagger. Request body of endpoint has a field - set of objects. As I see in generated documentation, it's the same thing as array, except the uniqueItems
field:
"fooSet": {
"uniqueItems": true,
"type": "array",
"items": {
"$ref": "#/components/schemas/Foo"
}
}
Frontend dev uses openapitools/openapi-generator-cli to interact with my endpoint using open-api docs. This lib enforces him to use JS Set in this case. But it cannot serialize Set properly! The openapi-generator-cli generated this code for serialization:
JSON.stringify returns empty array for any Set: JSON stringify a Set
uniqueItems
for all Sets without having to replace all of them to Lists, or add annotation on each Set in each DTO?Upvotes: 0
Views: 2042
Reputation: 75
As Helen commented, the problem could be solved by mapping Set to Array via type mappings in gradle task: github.com/OpenAPITools/openapi-generator/issues/11746
The other solution I found is to remove uniqueItems
flag manually in OpenApiCustomiser
:
override fun customise(openApi: OpenAPI) {
openApi.components.schemas.forEach { customSchema ->
customSchema.value.properties.values
.forEach {
if (it.uniqueItems == true) {
it.uniqueItems = null
}
}
}
}
Upvotes: 0