Set description from property file for swagger @schema in spring boot

Viewed 1276

I'm working on spring boot(v2.5.6) with dependency openapi-ui(v1.5.2) for swagger UI. I want to set description and other attribute such as required in @schema. The problem is I need to read this value from a property(resource-bundle). Also I want to read other attribute such as min/max/.. from some properties.

I'v tried below code but not worked:

@Schema( description ="{postalCode.description}" ,required ="{postalCode.required}")
String postalCode;

whereas postalCode.description is a property key in a resource bundle.

Is There any way to use some dictionary like properties for swagger?

1 Answers

You can add file with swagger properties and then add configuration for it in Application.java: @PropertySource(value = "classpath:swagger-messages.properties", encoding = "UTF-8").

Then you have to use description ="${postalCode.description}" (add $) and set springdoc.api-docs.resolve-schema-properties to true.

source: https://springdoc.org/faq.html

Related