spring-bootyamlswagger

How to import text from yml file into Swagger Annotations


I'm using @RequestBody anotation from swagger to add description.

The below anotation doesnot print text from yml:

@io.swagger.v3.oas.annotations.parameters.RequestBody(description = **"${project-text}"**)

Whereas the below anotation show text properly:

@io.swagger.v3.oas.annotations.parameters.RequestBody(description = **"Sample text to print from yml file"**)

I have the proper value in yml file. But I donot see Swagger RequestBody anotation is taking the value from yml file.

Any suggestion on how to use text from yml to be used in Swagger RequestBody's description ? Thanks in advance


Solution

  • This won't work, you'll get "Attribute value must be constant" error.

    Reason: Annotations in Java are processed at compile-time, and their attribute values must be resolvable without executing runtime logic.