I'm using Swagger 2 for API UI. So, my gradle.build
has:
compile "io.springfox:springfox-swagger2:${swaggerVersion}"
compile "io.springfox:springfox-swagger-ui:${swaggerVersion}"
I've configured Swagger as below:
@Configuration
@Profile("!production")
@EnableSwagger2
@ComponentScan(basePackageClasses = com.company.controllers.ContentController.class)
public class SwaggerConfiguration {
@Autowired
private BuildInfo buildInfo;
@Bean
public Docket awesomeApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(this.awesomeApiInfo())
.select()
.apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.boot")))
.build();
}
private ApiInfo awesomeApiInfo() {
return new ApiInfoBuilder()
.title("Awesome API - build #" + this.buildInfo.getVersion())
.description("Enter the IDs in order to look for the content")
.version("0.1")
.build();
}
}
I'm getting the api endpoint that I have defined, but also getting the Spring MVC endpoints as below:
Now, I need to get rid of these mvc endpoints.
Any help is highly appreciated!!
To hide the "Models" section, add defaultModelsExpandDepth: -1 to the Swagger UI configuration code in your index.
By adding this attribute on a controller or action and specifying IgnoreApi = true , it gets hidden from auto-generated documentation.
You can use the @Hidden annotation from swagger-annotations, on the top of the controller you want to hide. Save this answer. Show activity on this post. You can remove @EnableSwagger2 from your swagger config file or openapi config file then these openapi-resource controller will authomatically be removed.
Ohhh... actually it was my silly mistake. I changed RequestHandlerSelectors to select only endpoints from my own controller package as follow:
@Bean
public Docket awesomeApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(this.awesomeApiInfo())
.select()
.paths(PathSelectors.any())
.apis(RequestHandlerSelectors.basePackage("com.company.awesome.controllers"))
.build();
}
And this shows only the endpoints mapped within the classes in controller
package.
The best approach you can follow is to restrict visibility and access to ServiceStack. So you can hide it from being visible externally with:
[Restrict(VisibleInternalOnly = true)]
public class InternalAdmin { }
you can read more about it here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With