Skip to content

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

@yangliu817

Description

@yangliu817

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);
}

}
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions