springfox.documentation.service.Documentation Java Examples
The following examples show how to use
springfox.documentation.service.Documentation.
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: SpringCloudDocumentationSwaggerMapper.java From spring-cloud-huawei with Apache License 2.0 | 6 votes |
@Override public Map<String, Swagger> documentationToSwaggers(Documentation documentation) { Map<String, Swagger> result = new HashMap<>(); documentation.getApiListings().entries().forEach(entry -> result.put(mapSchemaId(entry.getKey()), mapper.mapDocumentation(new Documentation(documentation.getGroupName(), documentation.getBasePath(), Collections.emptySet(), // ignore all tags toMultiMap(entry), documentation.getResourceListing(), toSet(documentation.getProduces()), toSet(documentation.getConsumes()), documentation.getHost(), toSet(documentation.getSchemes()), documentation.getVendorExtensions() )))); return result; }
Example #2
Source File: ServiceCombDocumentationSwaggerMapper.java From spring-cloud-huawei with Apache License 2.0 | 6 votes |
@Override public Map<String, Swagger> documentationToSwaggers(Documentation documentation) { Map<String, Swagger> result = new HashMap<>(); documentation.getApiListings().entries().forEach(entry -> { Swagger swagger = mapper.mapDocumentation(new Documentation( documentation.getGroupName(), documentation.getBasePath(), Collections.emptySet(), // 01: ignore all tags filteringApiListings(entry), // 02: filtering ApiListings, there are sub tasks documentation.getResourceListing(), toSet(documentation.getProduces()), toSet(documentation.getConsumes()), documentation.getHost(), toSet(documentation.getSchemes()), documentation.getVendorExtensions() )); changeSwaggerInfo(entry.getKey(), swagger); // 03: change swagger info addXJavaClass(swagger); // 04: add x-java-class result.put(mapSchemaId(entry.getKey()), swagger); }); return result; }
Example #3
Source File: SwaggerHandlerImplTest.java From spring-cloud-huawei with Apache License 2.0 | 6 votes |
private void init() { mockMap.put("xxxx", apiListing); mockDoc = new Documentation("xx", "/xx", null, mockMap, null, Collections.emptySet(), Collections.emptySet(), null, Collections.emptySet(), Collections.emptyList()); mockSwagger = new Swagger(); mockSwagger.setInfo(new Info()); Map<String, Model> defMap = new HashMap<>(); defMap.put("xx", new ModelImpl()); mockSwagger.setDefinitions(defMap); Map<String, Path> pathMap = new HashMap<>(); pathMap.put("xx", new Path()); mockSwagger.setPaths(pathMap); new Expectations() { { documentationCache.documentationByGroup(anyString); result = mockDoc; DefinitionCache.getClassNameBySchema(anyString); result = "app"; mapper.mapDocumentation((Documentation) any); result = mockSwagger; } }; }
Example #4
Source File: SpringBootWrapper.java From funcatron with Apache License 2.0 | 6 votes |
public String dumpSwagger() { try { String groupName = Docket.DEFAULT_GROUP_NAME; Documentation documentation = documentationCache.documentationByGroup(groupName); if (documentation == null) { if (documentationCache.all().isEmpty()) return "{}"; documentation = documentationCache.all().values().stream().findFirst().get(); } Swagger swagger = mapper.mapDocumentation(documentation); basePath = swagger.getBasePath(); return jsonSerializer.toJson(swagger).value(); } catch (RuntimeException re) { throw re; } catch (Exception e) { throw new RuntimeException("Failed to dump the Swagger", e); } }
Example #5
Source File: ServiceModelToSwagger2MapperImpl.java From datax-web with MIT License | 5 votes |
@Override public Swagger mapDocumentation(Documentation from) { if (from == null) { return null; } Swagger swagger = new Swagger(); swagger.setVendorExtensions(vendorExtensionsMapper.mapExtensions(from.getVendorExtensions())); swagger.setSchemes(mapSchemes(from.getSchemes())); swagger.setPaths(mapApiListings(from.getApiListings())); swagger.setHost(from.getHost()); swagger.setDefinitions(modelsFromApiListings( from.getApiListings() ) ); swagger.setSecurityDefinitions(securityMapper.toSecuritySchemeDefinitions(from.getResourceListing())); ApiInfo info = fromResourceListingInfo(from); if (info != null) { swagger.setInfo(mapApiInfo(info)); } swagger.setBasePath(from.getBasePath()); swagger.setTags(tagSetToTagList(from.getTags())); List<String> list2 = from.getConsumes(); if (list2 != null) { swagger.setConsumes(new ArrayList<String>(list2)); } else { swagger.setConsumes(null); } List<String> list3 = from.getProduces(); if (list3 != null) { swagger.setProduces(new ArrayList<String>(list3)); } else { swagger.setProduces(null); } return swagger; }
Example #6
Source File: ServiceModelToSwagger2MapperImpl.java From datax-web with MIT License | 5 votes |
private ApiInfo fromResourceListingInfo(Documentation documentation) { if (documentation == null) { return null; } ResourceListing resourceListing = documentation.getResourceListing(); if (resourceListing == null) { return null; } ApiInfo info = resourceListing.getInfo(); if (info == null) { return null; } return info; }
Example #7
Source File: Knife4jController.java From yshopmall with Apache License 2.0 | 5 votes |
@RequestMapping(value = DEFAULT_SORT_URL, method = RequestMethod.GET, produces = {APPLICATION_JSON_VALUE, HAL_MEDIA_TYPE}) @ResponseBody public ResponseEntity<Json> apiSorts(@RequestParam(value = "group",required = false) String swaggerGroup, HttpServletRequest request) { String groupName = Optional.ofNullable(swaggerGroup).orElse("default"); Documentation documentation = this.documentationCache.documentationByGroup(groupName); if (documentation == null) { LOGGER.warn("Unable to find specification for group {},use default", groupName); documentation = this.documentationCache.documentationByGroup("default"); if (documentation == null) { LOGGER.warn("Unable to find specification for group default"); return new ResponseEntity<>(HttpStatus.NOT_FOUND); } } Swagger swagger = this.mapper.mapDocumentation(documentation); UriComponents uriComponents = null; try { uriComponents = HostNameProvider.componentsFrom(request, swagger.getBasePath()); } catch (Throwable var9) { LOGGER.error(var9.getClass().getName() + ":" + var9.getMessage()); if (var9 instanceof NoClassDefFoundError) { String msg = var9.getMessage(); if (msg != null && !"".equals(msg) && msg.endsWith("HostNameProvider")) { uriComponents = SwaggerBootstrapUiHostNameProvider.componentsFrom(request, swagger.getBasePath()); } } } swagger.basePath(Strings.isNullOrEmpty(uriComponents.getPath()) ? "/" : uriComponents.getPath()); if (Strings.isNullOrEmpty(swagger.getHost())) { swagger.host(this.hostName(uriComponents)); } extend(swagger); SwaggerExt swaggerExt = new SwaggerExt(swagger); swaggerExt.setSwaggerBootstrapUi(this.initSwaggerBootstrapUi(request, documentation, swaggerExt)); return new ResponseEntity<>(this.jsonSerializer.toJson(swaggerExt), HttpStatus.OK); }
Example #8
Source File: Swagger2Controller.java From yshopmall with Apache License 2.0 | 5 votes |
@RequestMapping( value = {DEFAULT_URL}, method = {RequestMethod.GET}, produces = {APPLICATION_JSON_VALUE, HAL_MEDIA_TYPE} ) @PropertySourcedMapping( value = "${springfox.documentation.swagger.v2.path}", propertyKey = "springfox.documentation.swagger.v2.path" ) @ResponseBody public ResponseEntity getDocumentation(@RequestParam(value = "group",required = false) String swaggerGroup, HttpServletRequest servletRequest) { String groupName = (String) Optional.ofNullable(swaggerGroup).orElse("default"); Documentation documentation = this.documentationCache.documentationByGroup(groupName); if (documentation == null) { LOGGER.warn("Unable to find specification for group {}", groupName); return new ResponseEntity(HttpStatus.NOT_FOUND); } else { Swagger swagger = this.mapper.mapDocumentation(documentation); UriComponents uriComponents = HostNameProvider.componentsFrom(servletRequest, swagger.getBasePath()); swagger.basePath(Strings.isNullOrEmpty(uriComponents.getPath()) ? "/" : uriComponents.getPath()); if (Strings.isNullOrEmpty(swagger.getHost())) { swagger.host(this.hostName(uriComponents)); } // 扩展 swagger = extend(swagger); return new ResponseEntity(this.jsonSerializer.toJson(swagger), HttpStatus.OK); } }
Example #9
Source File: DocumentationSwaggerMapper.java From spring-cloud-huawei with Apache License 2.0 | votes |
Map<String, Swagger> documentationToSwaggers(Documentation documentation);