'How to display Spring Security login interface on Swagger3

I am learning Spring Security 5 and built a project using Spring Boot and Spring Security, now the login interface needs to be displayed on Swagger, what should I do? All I found are swagger2.x tutorials, but I can't find anything about Swagger3. x. I tried it myself, but it didn't work。

My English is not good, so I rely on Google Translate

There are no arguments and return values

@Component
public class SwaggerAdditional implements ApiListingScannerPlugin {
    String tags = "login";
    String groupName = "client-interface";
    @Override
    public List<ApiDescription> apply(DocumentationContext context) {

        ApiDescription commonUserLogin = new ApiDescription(
                groupName,
                "/login",
                "common_user_login",
                "common_user_login",
                Collections.singletonList(commonUserLogin()),
                false)
        ;

        return Collections.singletonList(commonUserLogin);

    }

    @Override
    public boolean supports( @NotNull DocumentationType documentationType) {
        return DocumentationType.OAS_30.equals(documentationType);
    }

    private Operation commonUserLogin(){
        List<RequestParameter> list =new ArrayList<>();
        list.add(new RequestParameterBuilder()
                .name("username")
                .description("username")
                .required(true)
                .in(ParameterType.BODY)
                .build()
        );
        list.add(new RequestParameterBuilder()
                .name("password")
                .description("password")
                .required(true)
                .in(ParameterType.BODY)
                .build()
        );

        return new OperationBuilder(new CachingOperationNameGenerator())
                .method(HttpMethod.POST)
                .uniqueId("login")
                .summary("common_user_login")
                .notes("username/password,/login")
                .consumes(Sets.newHashSet(MediaType.APPLICATION_JSON_VALUE))
                .produces(Sets.newHashSet(MediaType.APPLICATION_JSON_VALUE))
                .tags(Sets.newHashSet(tags))
                .requestParameters(list)
                .responses(Collections.singleton(
                        new ResponseBuilder().code("200").description("success").build()))
                .build();
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source