1
resposta

Header authorizaction nao aparece para colocar Token swagger

ola pessoal, tentei fazer a autenticacao mas nao aparece; achei na internet alguns codigos diferentes mas nao funciona ainda. o codigo globalOperation Parameters são decreprete então nao funcionam.

@Configuration public class SwaggerConfigurations {

/* private ApiKey apiKey() { return new ApiKey("JWT", "Authorization", "header"); }

private SecurityContext securityContext() {
    return SecurityContext.builder().securityReferences(defaultAuth()).build();
}

private List<SecurityReference> defaultAuth() {
    AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
    AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
    authorizationScopes[0] = authorizationScope;
    return Arrays.asList(new SecurityReference("JWT", authorizationScopes));
}*/

@Bean
public Docket forumApi() {

    return new Docket(DocumentationType.SWAGGER_2)
       ///     .securityContexts(Arrays.asList(securityContext()))
        //    .securitySchemes(Arrays.asList(apiKey()))
            .select()
            .apis(RequestHandlerSelectors.basePackage("br.com.alura.forum"))
            .paths(PathSelectors.ant("/**")) //url raiz
            .build()
            .ignoredParameterTypes(Usuario.class);

}

@Bean
public InitializingBean removeSpringfoxHandlerProvider(DocumentationPluginsBootstrapper bootstrapper) {
    return () -> bootstrapper.getHandlerProviders().removeIf(WebMvcRequestHandlerProvider.class::isInstance);
}

@Bean
public RequestHandlerProvider customRequestHandlerProvider(Optional<ServletContext> servletContext, HandlerMethodResolver methodResolver, List<RequestMappingInfoHandlerMapping> handlerMappings) {
    String contextPath = servletContext.map(ServletContext::getContextPath).orElse(ROOT);
    return () -> handlerMappings.stream()
            .filter(mapping -> !mapping.getClass().getSimpleName().equals("IntegrationRequestMappingHandlerMapping"))
            .map(mapping -> mapping.getHandlerMethods().entrySet())
            .flatMap(Set::stream)
            .map(entry -> new WebMvcRequestHandler(contextPath, methodResolver, tweakInfo(entry.getKey()), entry.getValue()))
            .sorted(byPatternsCondition())
            .collect(toList());
}

RequestMappingInfo tweakInfo(RequestMappingInfo info) {
    if (info.getPathPatternsCondition() == null) return info;
    String[] patterns = info.getPathPatternsCondition().getPatternValues().toArray(String[]::new);
    return info.mutate().options(new RequestMappingInfo.BuilderConfiguration()).paths(patterns).build();
}

}

1 resposta

Oi!

Vou fechar o tópico, pois esse curso foi desabilitado e tem uma nova versão. Qualquer coisa você pode abrir um novo tópico no novo curso.

Bons estudos!