@Bean public Docket createRestApi() { ParameterBuilder tokenPar = new ParameterBuilder(); List<Parameter> parameters = new ArrayList<>(); tokenPar.name("xmall-Token") .description("token") .defaultValue("admin") .modelRef(new ModelRef("string")) .parameterType("header") .required(false) .build(); parameters.add(tokenPar.build()); Docket docket = new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .useDefaultResponseMessages(false) .globalOperationParameters(parameters) .select() .apis(RequestHandlerSelectors.basePackage("com.jeiker.mall.controller")) .paths(PathSelectors.any()) .build(); return docket; }
@Bean public Docket productsApi() { return new Docket(DocumentationType.SWAGGER_2) .globalOperationParameters( newArrayList(new ParameterBuilder() .name("Authorization") .description("Bearer your_token ") .modelRef(new ModelRef("string")) .parameterType("header") .build())) .apiInfo(apiInfo()) //.pathMapping("/") .select() //.apis(RequestHandlerSelectors.any()) .paths(PathSelectors.regex("/api.*")) .paths(PathSelectors.any()) .build(); }
@Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.regex("/documents(.*)")) .build() .globalOperationParameters( Stream.of(new ParameterBuilder() .name("Authorization") .description("User Auth") .modelRef(new ModelRef("string")) .parameterType("header") .required(true) .build()).collect(Collectors.toList())) .globalOperationParameters( Stream.of(new ParameterBuilder() .name("ServiceAuthorization") .description("Service Auth. Use it when accessing the API on App Tier level.") .modelRef(new ModelRef("string")) .parameterType("header") .required(true) .build()).collect(Collectors.toList())) .apiInfo(apiInfo()); }
@Bean public Docket swaggerDocket() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(getApiInfo()) .globalOperationParameters(Collections.singletonList( new ParameterBuilder() .name("Authorization") .description("Provide if necessary") .modelRef(new ModelRef("string")) .parameterType("header") .build())) .forCodeGeneration(true) .select() .paths(regex(DEFAULT_INCLUDE_PATTERN)) .build(); }
private List<Parameter> buildGlobalOperationParametersFromSwaggerProperties( List<SwaggerProperties.GlobalOperationParameter> globalOperationParameters) { List<Parameter> parameters = Lists.newArrayList(); if (Objects.isNull(globalOperationParameters)) { return parameters; } for (SwaggerProperties.GlobalOperationParameter globalOperationParameter : globalOperationParameters) { parameters.add(new ParameterBuilder() .name(globalOperationParameter.getName()) .description(globalOperationParameter.getDescription()) .modelRef(new ModelRef(globalOperationParameter.getModelRef())) .parameterType(globalOperationParameter.getParameterType()) .required(Boolean.parseBoolean(globalOperationParameter.getRequired())) .build()); } return parameters; }
@Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build() .globalOperationParameters( Collections.singletonList(new ParameterBuilder() .name("x-auth-token") .description("sesion token") .modelRef(new ModelRef("string")) .parameterType("header") .required(false) .build()) ); }
@Bean public Docket myApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.any()) .paths(paths()) .build() .globalOperationParameters( newArrayList( new ParameterBuilder() .name("Authorization: Bearer") .description("Authorization Token") .modelRef(new ModelRef("string")) .parameterType("header") .required(true) .build())); }
/** * ApiImplicitParam 与 ApiParam 的区别 * ApiImplicitParam: This is the only way to define parameters when using Servlets or other non-JAX-RS environments. * <p> * 对Servlets或者非 JAX-RS的环境,只能使用 ApiImplicitParam。 * 在使用上,ApiImplicitParam比ApiParam具有更少的代码侵入性,只要写在方法上就可以了,但是需要提供具体的属性才能配合swagger ui解析使用。 * ApiParam只需要较少的属性,与swagger ui配合更好。 * 传递复杂对象 By ModelAttribute * (1) ModelAttribute 是Spring mvc的注解,这里Swagger可以解析这个注解,获得User的属性描述--good * 原文链接:http://www.jianshu.com/p/b730b969b6a2 * (2)传递复杂对象 By RequestBody * json格式传递对象使用RequestBody注解 * (3) PathVariable是Spring 的注解,对于这种简单的参数,就可以不用写ApiParam来描述接口参数。 * <p> * <p> * Every Docket bean is picked up by the swagger-mvc framework - allowing for multiple * swagger groups i.e. same code base multiple swagger resource listings. * http://springfox.github.io/springfox/docs/current */ @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2)//Docket, Springfox’s, primary api configuration mechanism is initialized for swagger specification 2.0 .groupName("springboot-jwt-jpa")//分组,在html页面展示时有用。启用group选项会更改api json的访问路径。可以在/swagger-resources中location字段中找到 .select()//select() returns an instance of ApiSelectorBuilder to give fine grained control over the endpoints exposed via swagger. .apis(RequestHandlerSelectors.basePackage("com.web")) .paths(PathSelectors.any())// .paths(Predicates.or(PathSelectors.regex("/api/.*")))//过滤的接口,此片过滤掉/api/打头的接口 .build()//The selector requires to be built after configuring the api and path selectors. Out of the box we provide predicates for regex, ant, any, none .globalOperationParameters( newArrayList(new ParameterBuilder() .name("Authorization") .description("token") .modelRef(new ModelRef("string")) /** * paramType(参数放在哪个地方): header-->请求参数的获取:@RequestHeader query-->请求参数的获取:@RequestParam path(用于restful接口)-->请求参数的获取:@PathVariable body(不常用) form(不常用) */ .parameterType("header") .build())) // .ignoredParameterTypes(Student.class)//swagger-ui.html中如果有返回值是Student时,就会显示 Response Class (Status 200) OK <span class="strong">Student is not defined!</span> .genericModelSubstitutes(DeferredResult.class)//异步http请求 .forCodeGeneration(true)//By default, types with generics will be labeled with '\u00ab'(<<), '\u00bb'(>>), and commas. This can be problematic with things like swagger-codegen. You can override this behavior by implementing your own GenericTypeNamingStrategy. .pathMapping("/")// 在这里可以设置请求的统一前缀;默认请求都是以 / 根路径开始,如果我们的应用不是部署在根路径,比如以/platform(应用名)部署,则可以通过一下方式设置请求的统一前缀。 .apiInfo(apiInfo()) .useDefaultResponseMessages(false)//使用默认的响应信息true:默认响应信息将会回到全局的响应信息中;false:不加到全局的响应信息中 ; }
public static Parameter activity() { return new ParameterBuilder() .name("activity") .description("Activity to filter by.") .modelRef(new ModelRef("string")) .parameterType("query") .required(false) .build(); }
public static Parameter analyticalmethod() { return new ParameterBuilder() .name("analyticalmethod") .description("One or more Analytical Methods.") .modelRef(new ModelRef("", new ModelRef("string"))) .parameterType("query") .required(false) .allowMultiple(true) .build(); }
public static Parameter assemblage() { return new ParameterBuilder() .name("assemblage") .description("One or more Assemblage.") .modelRef(new ModelRef("", new ModelRef("string"))) .parameterType("query") .required(false) .allowMultiple(true) .build(); }
public static Parameter bBox() { return new ParameterBuilder() .name("bBox") .description("Western-most longitude, Southern-most latitude, Eastern-most longitude, and Northern-most longitude separated by commas," + "expressed in decimal degrees, WGS84, and longitudes west of Greenwich are negative. (Example: bBox=-92.8,44.2,-88.9,46.0)") .modelRef(new ModelRef("string")) .parameterType("query") .required(false) .build(); }
public static Parameter characteristicName() { return new ParameterBuilder() .name("characteristicName") .description("One or more case-sensitive Characteristic Names.") .modelRef(new ModelRef("", new ModelRef("string"))) .parameterType("query") .required(false) .allowMultiple(true) .build(); }
public static Parameter characteristicType() { return new ParameterBuilder() .name("characteristicType") .description("One or more case-sensitive Characteristic Types (groupings).") .modelRef(new ModelRef("", new ModelRef("string"))) .parameterType("query") .required(false) .allowMultiple(true) .build(); }
public static Parameter countrycode() { return new ParameterBuilder() .name("countrycode") .description("One or more two-character Federal Information Processing Standard (FIPS) Country Codes.") .modelRef(new ModelRef("", new ModelRef("string"))) .parameterType("query") .required(false) .allowMultiple(true) .build(); }
public static Parameter countycode() { return new ParameterBuilder() .name("countycode") .description("One or more two-character Federal Information Processing Standard (FIPS) Country Code, followed by a URL-encoded colon (\"%3A\")," + " followed by a two-digit FIPS State Code, followed by a URL-encoded colon (\"%3A\"), followed by a three-digit FIPS County Code") .modelRef(new ModelRef("", new ModelRef("string"))) .parameterType("query") .required(false) .allowMultiple(true) .build(); }
public static Parameter dataProfile() { return new ParameterBuilder() .name("dataProfile") .description("Data Profile (column set) of the download. For use with the results enpoint.") .modelRef(new ModelRef("string")) .parameterType("query") .required(false) .allowableValues(new AllowableListValues(Arrays.asList(Profile.BIOLOGICAL.toString(), Profile.PC_RESULT.toString(), Profile.NARROW_RESULT.toString()), "LIST")) .build(); }
public static Parameter huc() { return new ParameterBuilder() .name("huc") .description("One or more two-, four-, six-, or eight-digit Hydrologic Units.") .modelRef(new ModelRef("", new ModelRef("string"))) .parameterType("query") .required(false) .allowMultiple(true) .build(); }
public static Parameter lat() { return new ParameterBuilder() .name("lat") .description("Latitude for radial search, expressed in decimal degrees, WGS84.") .modelRef(new ModelRef("string")) .parameterType("query") .required(false) .build(); }
public static Parameter longitude() { return new ParameterBuilder() .name("long") .description("Longitude for radial search, expressed in decimal degrees, WGS84.") .modelRef(new ModelRef("string")) .parameterType("query") .required(false) .build(); }
public static Parameter mimeType() { return new ParameterBuilder() .name("mimeType") .description("Can be used in place of the 'Accept' header. See 'Response Content Type' for the valid subset of these values.") .modelRef(new ModelRef("string")) .parameterType("query") .required(false) .allowableValues(new AllowableListValues(Arrays.asList(csv.getExtension(), tsv.getExtension(), xml.getExtension(), json.getExtension(), xlsx.getExtension(), kml.getExtension(), kmz.getExtension(), geojson.getExtension(), text.getExtension()), "LIST")) .build(); }
public static Parameter minactivities() { return new ParameterBuilder() .name("minactivities") .description("The minimum number of Sampling Activities at a site for inclusion in the dataset.") .modelRef(new ModelRef("string")) .parameterType("query") .required(false) .build(); }
public static Parameter minresults() { return new ParameterBuilder() .name("minresults") .description("The minimum number of Results at a site for inclusion in the dataset.") .modelRef(new ModelRef("string")) .parameterType("query") .required(false) .build(); }
public static Parameter nldiurl() { return new ParameterBuilder() .name("nldiurl") .description("The navigation query from NLDI for a list of sites to select data from.") .modelRef(new ModelRef("string")) .parameterType("query") .required(false) .build(); }
public static Parameter organization() { return new ParameterBuilder() .name("organization") .description("One or more case-sensitive Organizations.") .modelRef(new ModelRef("", new ModelRef("string"))) .parameterType("query") .required(false) .allowMultiple(true) .build(); }
public static Parameter pCode() { return new ParameterBuilder() .name("pCode") .description("One or more five-digit USGS parameter codes.") .modelRef(new ModelRef("", new ModelRef("string"))) .parameterType("query") .required(false) .allowMultiple(true) .build(); }
public static Parameter project() { return new ParameterBuilder() .name("project") .description("One or more case-sensitive Projects.") .modelRef(new ModelRef("", new ModelRef("string"))) .parameterType("query") .required(false) .allowMultiple(true) .build(); }
public static Parameter providers() { return new ParameterBuilder() .name("providers") .description("One or more case-sensitive Providers.") .modelRef(new ModelRef("", new ModelRef("string"))) .parameterType("query") .required(false) .allowMultiple(true) .build(); }
public static Parameter result() { return new ParameterBuilder() .name("result") .description("Result to filter by.") .modelRef(new ModelRef("string")) .parameterType("query") .required(false) .build(); }
public static Parameter sampleMedia() { return new ParameterBuilder() .name("sampleMedia") .description("One or more case-sensitive Sample Media.") .modelRef(new ModelRef("", new ModelRef("string"))) .parameterType("query") .required(false) .allowMultiple(true) .build(); }
public static Parameter siteid() { return new ParameterBuilder() .name("siteid") .description("One or more case-sensitive Site IDs.") .modelRef(new ModelRef("", new ModelRef("string"))) .parameterType("query") .required(false) .allowMultiple(true) .build(); }
public static Parameter siteType() { return new ParameterBuilder() .name("siteType") .description("One or more case-sensitive Site Types.") .modelRef(new ModelRef("", new ModelRef("string"))) .parameterType("query") .required(false) .allowMultiple(true) .build(); }
public static Parameter sorted() { return new ParameterBuilder() .name("sorted") .description("Should the data be sorted. Response times may be improved by not sorting.") .modelRef(new ModelRef("string")) .parameterType("query") .required(false) .allowableValues(new AllowableListValues(Arrays.asList("yes", "no"), "LIST")) .build(); }
public static Parameter startDateHi() { return new ParameterBuilder() .name("startDateHi") .description("Date of last desired data-collection activity, expressed as MM-DD-YYYY") .modelRef(new ModelRef("string")) .parameterType("query") .required(false) .build(); }
public static Parameter startDateLo() { return new ParameterBuilder() .name("startDateLo") .description("Date of earliest desired data-collection activity, expressed as MM-DD-YYYY") .modelRef(new ModelRef("string")) .parameterType("query") .required(false) .build(); }
public static Parameter statecode() { return new ParameterBuilder() .name("statecode") .description("One or more two-character Federal Information Processing Standard (FIPS) country code, followed by a URL-encoded colon (\"%3A\"), followed by a two-digit FIPS state code.") .modelRef(new ModelRef("", new ModelRef("string"))) .parameterType("query") .required(false) .allowMultiple(true) .build(); }
public static Parameter subjectTaxonomicName() { return new ParameterBuilder() .name("subjectTaxonomicName") .description("One or more case-sensitive Taxonomic Names.") .modelRef(new ModelRef("", new ModelRef("string"))) .parameterType("query") .required(false) .allowMultiple(true) .build(); }
public static Parameter within() { return new ParameterBuilder() .name("within") .description("Distance for radial search, expressed in decimal miles.") .modelRef(new ModelRef("string")) .parameterType("query") .required(false) .build(); }
public static Parameter zip() { return new ParameterBuilder() .name("zip") .description("Should the data be compressed. Compression often greatly increases throughput, thus expediting the request.") .modelRef(new ModelRef("string")) .parameterType("query") .required(false) .allowableValues(new AllowableListValues(Arrays.asList("yes", "no"), "LIST")) .build(); }