How can I manually describe an example input for a java @RequestBody Map<String, String>?

The issues mentioned in @g00glen00b's answer seems to be fixed. Here is a code snippet of how it can be done.

In your controller class:

// omitted other annotations
@ApiImplicitParams(
        @ApiImplicitParam(
                name = "body",
                dataType = "ApplicationProperties",
                examples = @Example(
                        @ExampleProperty(
                                mediaType = "application/json",
                                value = "{\"applicationName\":\"application-name\"}"
                        )
                )
        )
)
public Application updateApplicationName(
        @RequestBody Map<String, String> body
) {
    // ...
}

// Helper class for Swagger documentation - see http://springfox.github.io/springfox/docs/snapshot/#q27
public static class ApplicationProperties {

    private String applicationName;

    public String getApplicationName() {
        return applicationName;
    }

    public void setApplicationName(String applicationName) {
        this.applicationName = applicationName;
    }

}

Additionally, you need to add the following line to your Swagger config:

// omitted other imports...
import com.fasterxml.classmate.TypeResolver;

@Bean
public Docket api(TypeResolver resolver) {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.any())
            .build()
            .apiInfo(apiInfo())
            // the following line is important!
            .additionalModels(resolver.resolve(DashboardController.ApplicationProperties.class));
}

Further documentation can be found here: http://springfox.github.io/springfox/docs/snapshot/#q27


Swagger only provides the API, these annotations still have to be integrated into the Springfox framework to work. At the time this question was posted, neither @ExampleProperty nor @Example were supported by Springfox. This can be seen in #853 and #1536.

Since version 2.9.0, this has been implemented. For an example, you can check this answer.