Skip to content

Instantly share code, notes, and snippets.

@sombochea
Created December 18, 2020 11:16
Show Gist options
  • Save sombochea/0324964054c8269ce5f21e7f8ff4c01a to your computer and use it in GitHub Desktop.
Save sombochea/0324964054c8269ce5f21e7f8ff4c01a to your computer and use it in GitHub Desktop.
SpringFox Swagger @AliasFor not working on @ApiOperation in Spring Boot
package com.example.mytest;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.AliasFor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Configuration
@EnableSwagger2
class SwaggerConfig {
@Bean
Docket docket(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
@ApiOperation("Default Api Operation : not working")
@Retention(RetentionPolicy.RUNTIME)
@RequestMapping(value = "/request-path-default-NOT_WORKING" ,method = RequestMethod.GET )
@Inherited
@interface OverrideApiOperation {
@AliasFor(annotation = ApiOperation.class, attribute = "value")
String value() default "Default In Override : working in override";
@AliasFor(annotation = RequestMapping.class, attribute = "value")
String path11() default "/request-path-override-default : working-default";
}
@RestController
@RequestMapping("/index")
class IndexController {
@OverrideApiOperation(value = "When See this mean WORKING",path11 = "/request-path-working")
String index(){
return "Welcome ";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment