How to handle Map<String,Object> in the response
See original GitHub issueI have an endpoint which returns Map<Locale,Product>. I am not sure how annotate it correctly. My Swagger UI shows empty in the response.
enum class Locale(en_US, en_CA, fr_CA) data class Product(name:String, description:String)
Also, where ever I have Map object, it always shows as following in the swagger
“additionalProp1”: “string”, “additionalProp2”: “string”, “additionalProp3”: “string”
With swagger 2 i was able to manually fix the spec by doing something like following
description: type: object properties: en_US: type: string example: 'Open' fr_CA: type: string example: 'OUVERT' en_CA: type: string example: 'Open'
or using this
details: description: This map represents locale specific map for various product names type: object properties: en_US: $ref: '#/components/schemas/ProductNameDetails' fr_CA: $ref: '#/components/schemas/ProductNameDetails' en_CA: $ref: '#/components/schemas/ProductNameDetails'
I also found this stackoverflow but not sure how to do this with springdoc https://stackoverflow.com/questions/46552863/how-to-write-openapi-3-swagger-specification-for-property-name-in-map-object
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Great, that is exactly what I was looking for,
io.swagger.v3.core.converter.ResolvedSchema
class! Thank you @bnasslahsen!@nehalshah50,
Your question is not directly related to springdoc-openapi, but to the usage of OpenAPI 3. Anyway, here is a sample working code that you can customize: