springfox.documentation.builders.OperationBuilder Java Examples

The following examples show how to use springfox.documentation.builders.OperationBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SwaggerManualApiPlugin.java    From java-starthere with MIT License 6 votes vote down vote up
@Override
public List<ApiDescription> apply(DocumentationContext documentationContext)
{
    return new ArrayList<>(Arrays.asList(new ApiDescription(null,
                                                            "/login",
                                                            "login",
                                                            Arrays.asList(new OperationBuilder(operationNames).authorizations(new ArrayList<>())
                                                                                                              .summary("login")
                                                                                                              .codegenMethodNameStem("userLogin")
                                                                                                              .method(HttpMethod.POST)
                                                                                                              .notes("This is the login endpoint to request an authentication token")
                                                                                                              .responseMessages(responseMessages())
                                                                                                              .parameters(Arrays.asList(new ParameterBuilder().description("Login Parameter")
                                                                                                                                                              .type(new TypeResolver().resolve(UserLogin.class))
                                                                                                                                                              .name("userLogin")
                                                                                                                                                              .parameterType("body")
                                                                                                                                                              .parameterAccess("access")
                                                                                                                                                              .required(true)
                                                                                                                                                              .modelRef(new ModelRef("UserLogin"))
                                                                                                                                                              .build()))
                                                                                                              .build()),
                                                            false)));

}
 
Example #2
Source File: ApiMethodReader.java    From swagger-more with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(OperationContext context) {
    Optional<ApiMethod> optional = context.findAnnotation(ApiMethod.class);
    if (optional.isPresent()) {
        OperationBuilder builder = context.operationBuilder();
        ApiMethod apiMethod = optional.get();
        if (StringUtils.hasText(apiMethod.notes())) {
            builder.notes(resolver.resolve(apiMethod.notes()));
        }
        if (StringUtils.hasText(apiMethod.value())) {
            builder.summary(resolver.resolve(apiMethod.value()));
        }
        builder.deprecated(String.valueOf(apiMethod.deprecated()));
        builder.hidden(apiMethod.hidden());
        builder.uniqueId(context.getGroupName() + context.getName());
        readTags(context);
        readReturnDescription(context, apiMethod);
    }
}
 
Example #3
Source File: DefaultEndPointPlugin.java    From BlogManagePlatform with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(OperationContext context) {
	if (context.findAnnotation(ApiOperation.class).isPresent()) {
		return;
	}
	EndPointInfo info = resolveNameAttribute(context);
	if (info == null) {
		log.warn(StrUtil.concat(context.requestMappingPattern(), "的信息未配置"));
		return;
	}
	OperationBuilder builder = context.operationBuilder();
	builder.summary(descriptions.resolve(info.name));
	builder.tags(Set.of(info.controllerName));
	ReflectUtil.set(OperationBuilder.class, "consumes", builder, Set.of(info.consumes));
	ReflectUtil.set(OperationBuilder.class, "produces", builder, Set.of(info.produces));
}
 
Example #4
Source File: PageableParameterBuilderPluginTest.java    From jhipster with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    Method method = this.getClass().getMethod("test", new Class<?>[]{Pageable.class, Integer.class});
    resolver = new TypeResolver();
    RequestHandler handler = new WebMvcRequestHandler(new HandlerMethodResolver(resolver), null, new
        HandlerMethod(this, method));
    DocumentationContext docContext = mock(DocumentationContext.class);
    RequestMappingContext reqContext = new RequestMappingContext(docContext, handler);
    builder = spy(new OperationBuilder(null));
    context = new OperationContext(builder, RequestMethod.GET, reqContext, 0);
    List<TypeNameProviderPlugin> plugins = new LinkedList<>();
    extractor = new TypeNameExtractor(resolver, SimplePluginRegistry.create(plugins), new
        JacksonEnumTypeDeterminer());
    plugin = new PageableParameterBuilderPlugin(extractor, resolver);
}
 
Example #5
Source File: RequestToPoOperationBuilder.java    From jframework with Apache License 2.0 5 votes vote down vote up
private void readRequestFormToPojo(OperationContext context, ResolvedMethodParameter methodParameter) {

        List<RawField> fields = methodParameter.getParameterType().getMemberFields();
        List<RawField> parentRawFields = methodParameter.getParameterType().getParentClass().getMemberFields();

        List<RawField> fieldList = Lists.newArrayList();
        if (!CollectionUtils.isEmpty(fields)) {
            fieldList.addAll(fields);
        }
        if (!CollectionUtils.isEmpty(parentRawFields)) {
            fieldList.addAll(parentRawFields);
        }
        List<Parameter> requestMapParameters = Lists.newArrayList();
        for (RawField rawField : fieldList) {
            String name = CaseUtil.snakeCase(rawField.getName());
            Class itemClass = rawField.getRawMember().getType();
            if (itemClass != null) {
                String itemTypeName = typeNameFor(itemClass);
                if (ObjectUtils.isEmpty(itemTypeName)) {
                    // 解析出这个类型的所有成员加到文档里
                    requestMapParameters.addAll(addFieldsToDoc(rawField.getRawMember(), name, null));
                } else {
                    requestMapParameters.add(genPrimaryTypeDoc(rawField.getRawMember(), "", itemTypeName));
                }
            }
        }

        try {
            OperationBuilder operationBuilder = context.operationBuilder();
            Field parametersField = context.operationBuilder().getClass().getDeclaredField("parameters");
            parametersField.setAccessible(true);
            parametersField.set(operationBuilder, requestMapParameters);
        } catch (Exception e) {
            log.debug("swagger RequestToPo error", e);
        }
    }