Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use ApiListingScannerPlugin to add a web api? Could you offer a demo with version 3.0? #138

Open
yangliu817 opened this issue Jan 28, 2021 · 0 comments

Comments

@yangliu817
Copy link

as title, SwaggerConfig impl implements ApiListingScannerPlugin with swagger2-3.0.x.
But some classes are annotated with @declaration

`
@configuration
public class SwaggerConfig implements ApiListingScannerPlugin {

@OverRide
public List apply(
DocumentationContext documentationContext) {
return Arrays.asList(buildLogin());
}

private ApiDescription buildLogin() {

    List<Parameter> parameters = new ArrayList<>();
    parameters.add(new ParameterBuilder()
            .description("用户名")
            .type(new TypeResolver()
                    .resolve(String.class))
            .name("username")
            .parameterType(QUERY_PARAMETER_TYPE)
            .parameterAccess(PARAMETER_ACCESS)
            .required(true)
            .modelRef(new ModelRef(MODEL_REF))
            .build());

    parameters.add(new ParameterBuilder().description("密码")
            .type(new TypeResolver()
                    .resolve(String.class))
            .name("password")
            .parameterType(
                    QUERY_PARAMETER_TYPE)
            .parameterAccess(
                    PARAMETER_ACCESS)
            .required(true)
            .modelRef(
                    new ModelRef(MODEL_REF))
            .build());

    return new ApiDescription("登录",
            "/login", "登录","登录",
            Collections.singletonList(new OperationBuilder(
                    new CachingOperationNameGenerator())
                    /** HTTP请求类型 */
                    .method(HttpMethod.POST)
                    .produces(Sets.newHashSet(
                            MediaType.APPLICATION_JSON_VALUE))
                    .summary("登录接口")
                    /** 方法描述 */
                    .notes("登录接口")
                    /** 归类标签 */
                    .tags(Sets.newHashSet("认证控制"))
                    .parameters(parameters)
                    .uniqueId("login")
                    .build()),
            false);
}

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

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant