Skip to content

lockup endpoint id 'api-docs' in such springboot, then use Swagger-UI create an swagger-webside client.

Notifications You must be signed in to change notification settings

mosence/spring-boot-admin-swagger-view

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spring-boot-admin-swagger-view

lockup endpoint id 'api-docs' in such springboot, then use Swagger-UI create an swagger-webside client.

for example:

using springfox's @EnableSwagger2 and create a bean Docket() to create /v2/api-docs path.

then using @Endpoint(id = "api-docs") to suport an endpoint like this.


@Component
@Endpoint(id = "api-docs")
public class ServletSwaggerApiEndpoint{

    @Resource
    private HttpServletRequest servletRequest;

    private DocumentationCache documentationCache;
    private ServiceModelToSwagger2Mapper mapper;

    public ServletSwaggerApiEndpoint(DocumentationCache documentationCache,
                                      ServiceModelToSwagger2Mapper mapper) {
        this.documentationCache = documentationCache;
        this.mapper = mapper;
    }
	
    @ReadOperation(produces = "application/json")
    public Swagger loadApiDocs() {
        String groupName = Docket.DEFAULT_GROUP_NAME;
        Documentation documentation = documentationCache.documentationByGroup(groupName);
        Swagger swagger = mapper.mapDocumentation(documentation);

        UriComponents uriComponents = componentsFrom(servletRequest, swagger.getBasePath());
        swagger.basePath(Strings.isNullOrEmpty(uriComponents.getPath()) ? "/" : uriComponents.getPath());
        swagger.setHost(uriComponents.getHost()+ ":" +uriComponents.getPort());
        
        return swagger;
    }
}

About

lockup endpoint id 'api-docs' in such springboot, then use Swagger-UI create an swagger-webside client.

Resources

Stars

Watchers

Forks

Packages

No packages published