Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add description to API controller in Swagger 1.5.20?

Tags:

java

swagger

I'm trying to provide formatted description to a controller in Swagger. However I can't find any annotation that enables it. Currently it looks like this:

@Api(tags = {"Change timezone"})

enter image description here

However I would like to provide meaningful description. The description parameter withing @Api is deprecated.

like image 308
Yoda Avatar asked Nov 05 '25 08:11

Yoda


1 Answers

It seems that, there is a hole with this deprecation. This feature has been deprecated but no other Annotation has replaced that functionality.

For now it seems that you can only add description programmatically

@Bean 
public Docket commonDocketConfig() { 

 return new Docket(DocumentationType.SWAGGER_2) .select() 
       .apis(RequestHandlerSelectors.basePackage("com.company")) 
       .paths(PathSelectors.any()) 
       .build() .apiInfo(apiEndPointsInfo()) 
       .tags(new Tag("Change timezone", "your description")); 
 }

Issue can be tracked here

@Api description deprecated without any alternative

You can try also with

@Api(tags = {"Change timezone"})
@SwaggerDefinition(tags = {
        @Tag(name = "Change timezone", description = "your Description")
})
public class YourController {
}

This annotation however already has an open bug for not behaving correctly @SwaggerDefinition bug

like image 90
Panagiotis Bougioukos Avatar answered Nov 06 '25 21:11

Panagiotis Bougioukos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!