How can I control tag name on API in OpenAPI Spring generator?

You can control the tag name in the OpenAPI Spring generator by using the @ApiTag annotation in your controller class. This annotation allows you to specify a custom tag name for each endpoint in your API.


Here's an example:


less

Copy code

@RestController

@RequestMapping("/api/v1")

@Api(tags = "My API")

public class MyController {


    @GetMapping

    @ApiOperation(value = "Get endpoint", tags = "My API")

    @ApiResponse(response = MyModel.class, code = 200, message = "Successful")

    @ApiTag(name = "My Endpoint")

    public MyModel getEndpoint() {

        return new MyModel();

    }

}

In this example, the @Api annotation is applied to the controller class and sets the tag name for all endpoints within the class to "My API". The @ApiTag annotation is then applied to the getEndpoint method to set the tag name for just that endpoint to "My Endpoint".

Post a Comment

Previous Post Next Post