Forum Discussion

Evgeny2's avatar
6 years ago

Swagger show file content via @ExampleProperty annotation

I am using swagger 3.0.0-Snapshot to create documentation for my Spring Boot application. My maven dependencies are


My swagger config class is as simple as possible:

public class SwaggerConfig {
    public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)

And my controller method has the following annotation:

@ApiOperation(value = "Hello world", httpMethod = "POST")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "OK",
                    examples = @Example(value = @ExampleProperty(mediaType = "application/json",
                            value = exampleValue)))

It is working and shows in Swagger UI "Example Value" field value that has constant string exampleValue that is private static String.

The question is how to pass the content of json file that is in resources folder to @ExampleProperty value?

I tried to read file content in static block and pass it to initialize final String with it, but then the compiler says that "Attribute value has to be constant".

The content of json file must be shown in example field in Swagger UI.

No RepliesBe the first to reply