Specify the fetch value for the query parameter in Swagger

I have a method signature for a rest method in a Spring-Boot RestController that looks like this:

@RequestMapping(
        value = "/path",
        method = RequestMethod.POST,
        consumes = MediaType.APPLICATION_JSON_VALUE,
        produces = MediaType.APPLICATION_JSON_VALUE
)
@ApiImplicitParams({
        @ApiImplicitParam(
                name = "message", 
                value = "Message that is sent to the method", 
                required = true, 
                dataType = "string", 
                paramType = "body"
        )
})
public @ResponseBody String receiveMessage(@RequestBody String message) {
    // ...

    return "{\"success\": true}";
}

I would like to provide a “sample” value for a parameter messagethat is a JSON string (for example, {"key": "value"}). Does anyone know how I can do this using Swagger annotations? I did my best

@ApiImplicitParams({
        @ApiImplicitParam(
                // ...
                example = "...JSON value..."
        )
})

but it didn’t work. What I would like to have is an “approximate value” in the documentation, which the reader can click to fill in the parameter value field in the documentation with a given standard value. Is it possible?

Here is a screenshot of how this might look:

enter image description here

"" : String - - -.

+8
3

, atomic parametera (String, Number,...).

, , example :

properties:
  firstName:
    description: first name
    type: string
    example: John

(value ApiImplicitParam).

    @ApiImplicitParam(
            name = "message", 
            value = "Message that is sent to the method. Example: value", 
            required = true, 
            dataType = "string", 
            paramType = "body"
    )
+6

Spring Boot, REST, json, @RequestBody. , Swagger

SpringFox SpringFox

@Bean
public Docket apiDocket() {
     return new Docket(DocumentationType.SWAGGER_2)
             // ...
             .additionalModels(new TypeResolver().resolve(YourRequestModel.class));
}

API @ApiImplicitParams

@PostMapping("/your-api")
@ApiOperation(value = "brief description", notes = "Greater details come here")
@ApiImplicitParams({
   @ApiImplicitParam(paramType = "header", name = "x-locale", example = "en"),
   @ApiImplicitParam(paramType = "body", dataType = "YourRequestModel")
})
public YourResponsetModel processRequest() {
   // ...
   return null;
}

Swagger x-locale body YourRequestModel.

0

You can try this:

public MyObject myController(@ApiParam(example = "examplestring") @RequestParam("name") String name,
            @ApiParam(example = "1")@RequestParam("eventNo") int eventNo, @ApiParam(example = "2")@RequestParam("halRequestNo") int halRequestNo){
0
source

Source: https://habr.com/ru/post/1653453/