springfox.documentation.spring.web.paths.RelativePathProvider Java Examples

The following examples show how to use springfox.documentation.spring.web.paths.RelativePathProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SwaggerConfig.java    From swagger-more with Apache License 2.0 6 votes vote down vote up
@Bean
@Autowired
public Docket complete(ServletContext servletContext) {
    List<ResponseMessage> responseMessageList = newArrayList();
    return new Docket(SWAGGER_2)
            .pathProvider(new RelativePathProvider(servletContext) {
                @Override
                public String getApplicationBasePath() {
                    return "/dubbo";
                }
            })
            .apiInfo(apiInfo())
            .select()
            .apis(ExtendRequestHandlerSelectors.dubboApi())
            .paths(PathSelectors.any())
            .build()
            .groupName("dubbo")
            .produces(Sets.newHashSet("application/json", "text/plain"))
            .consumes(Collections.singleton("application/json"))
            .useDefaultResponseMessages(false)
            .globalResponseMessage(RequestMethod.GET, responseMessageList)
            .globalResponseMessage(RequestMethod.POST, responseMessageList);
}
 
Example #2
Source File: DocAutoConfiguration.java    From dew with Apache License 2.0 5 votes vote down vote up
/**
 * Rest api docket.
 *
 * @param servletContext the servlet context
 * @return the docket
 */
@Bean
public Docket restApi(ServletContext servletContext) {
    return new Docket(DocumentationType.SWAGGER_2)
            .tags(new Tag(FLAG_APPLICATION_NAME, Dew.Info.name))
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage(dewConfig.getBasic().getDoc().getBasePackage()))
            .paths(PathSelectors.any())
            .build()
            /*.securitySchemes(new ArrayList<ApiKey>() {{
                add(new ApiKey("access_token", "accessToken", "develop"));
            }})
            .globalOperationParameters(new ArrayList<Parameter>() {{
                add(new ParameterBuilder()
                        .name(Dew.dewConfig.getSecurity().getTokenFlag())
                        .description("token 用于鉴权,部分接口必须传入")
                        .modelRef(new ModelRef("String"))
                        .parameterType(Dew.dewConfig.getSecurity().isTokenInHeader() ? "header" : "query")
                        .hidden(false)
                        .required(true)
                        .build());
            }})*/
            .pathProvider(new RelativePathProvider(servletContext) {
                @Override
                public String getApplicationBasePath() {
                    return contextPath + super.getApplicationBasePath();
                }
            });
}
 
Example #3
Source File: SwaggerConfig.java    From metron with Apache License 2.0 5 votes vote down vote up
@Bean
public Docket api() {
  List<String> activeProfiles = Arrays.asList(environment.getActiveProfiles());
  Docket docket = new Docket(DocumentationType.SWAGGER_2);
  if (activeProfiles.contains(KNOX_PROFILE)) {
    String knoxRoot = environment.getProperty(MetronRestConstants.KNOX_ROOT_SPRING_PROPERTY, String.class, "");
    docket = docket.pathProvider(new RelativePathProvider (servletContext) {
      @Override
      protected String applicationPath() {
        return knoxRoot;
      }

      @Override
      protected String getDocumentationPath() {
        return knoxRoot;
      }

      @Override
      public String getApplicationBasePath() {
        return knoxRoot;
      }

      @Override
      public String getOperationPath(String operationPath) {
        return knoxRoot + super.getOperationPath(operationPath);
      }
    });
  }
  return docket.select()
          .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
          .paths(PathSelectors.any())
          .build();
}