How do I document a Rest parameter providing another type (MyClass vs. String)?

Tags: ,



In Springfox I once used the following syntax to render a String parameter with a full model (original Github issue):

@PatchMapping(path="/{objId}")
@ApiImplicitParams(@ApiImplicitParam(name="update", dataType="MyClass")) 
    public ApiResponse<MyClass> updateMyClassInst(@PathVariable String objId, @RequestBody String update) {

The reason for this formulation is that if I put MyClass as type for the request body I had no way to distinguish when a property has not been updated or when has been set to null, because both would be deserialized to a null field value.

How do I do that with Springdoc?

Answer

This the equivalent code, using OpenAPI 3.

@PatchMapping(path="/{objId}")
@RequestBody( content = @Content(schema = @Schema(implementation = MyClass.class)))
public ApiResponse<MyClass> updateMyClassInst(@PathVariable String objId, @RequestBody String update) {
    return null;
}

You can have a look at hte migration guide:

And the swagger documentation:



Source: stackoverflow