类io.swagger.annotations.ApiModel源码实例Demo

下面列出了怎么用io.swagger.annotations.ApiModel的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: BlogManagePlatform   文件: DefaultParamPlugin.java
private void resolveApiParam(ParameterContext context) {
	ResolvedType resolvedType = context.resolvedMethodParameter().getParameterType();
	Class<?> parameterClass = resolveParamType(resolvedType);
	if (parameterClass == null) {
		log.warn(StrUtil.concat(resolvedType.getBriefDescription(), "的类型无法被DefaultParamPlugin解析"));
		@SuppressWarnings("unused") int a = 1;
		return;
	}
	ApiModel apiModel = parameterClass.getAnnotation(ApiModel.class);
	if (apiModel == null) {
		if (!BeanUtils.isSimpleProperty(parameterClass)) {
			warn(context, parameterClass);
		}
		return;
	}
	ParameterBuilder builder = context.parameterBuilder();
	builder.name(apiModel.description());
	builder.description(descriptions.resolve(apiModel.description()));
	builder.allowMultiple(false);
	builder.allowEmptyValue(false);
	builder.hidden(false);
	builder.collectionFormat("");
	builder.order(SWAGGER_PLUGIN_ORDER);
}
 
源代码2 项目: BlogManagePlatform   文件: DefaultModelPlugin.java
private String recursiveResolveList(ResolvedType resolvedType) {
	if (TypeUtil.isSimpleType(resolvedType)) {
		ApiModel apiModel = resolvedType.getErasedType().getAnnotation(ApiModel.class);
		if (apiModel != null) {
			return apiModel.description();
		} else {
			return "";
		}
	} else if (TypeUtil.belongToComplexType(Collection.class, resolvedType)) {
		resolvedType = TypeUtil.resolveGenericType(Collection.class, resolvedType).get(0);
		String result = recursiveResolveList(resolvedType);
		if (result == null) {
			return null;
		} else {
			return StrUtil.concat(result, "的列表");
		}
	} else {
		return null;
	}
}
 
@Override
public String findPropertyDescription(Annotated a)
{
    ApiParam apiParam = a.getAnnotation(ApiParam.class);
    if (apiParam != null) {
        return apiParam.description();
    }

    ApiModel model = a.getAnnotation(ApiModel.class);
    if (model != null && !"".equals(model.description())) {
        return model.description();
    }
    ApiModelProperty prop = a.getAnnotation(ApiModelProperty.class);
    if (prop != null) {
        return prop.value();
    }
    return null;
}
 
@Override
public List<NamedType> findSubtypes(Annotated a)
{
    final ApiModel api = a.getAnnotation(ApiModel.class);
    if (api != null) {
        final Class<?>[] classes = api.subTypes();
        final List<NamedType> names = new ArrayList<>(classes.length);
        for (Class<?> subType : classes) {
            names.add(new NamedType(subType));
        }
        if (!names.isEmpty()) {
            return names;
        }
    }

    return Collections.emptyList();
}
 
源代码5 项目: jsonschema-generator   文件: SwaggerModule.java
/**
 * Look-up a "description" from the given type's {@link ApiModel} annotation's {@code description}.
 *
 * @param scope targeted type
 * @return description (or {@code null})
 */
protected String resolveDescriptionForType(TypeScope scope) {
    return Optional.ofNullable(scope.getType())
            .map(type -> type.getErasedType().getAnnotation(ApiModel.class))
            .map(ApiModel::description)
            .filter(description -> !description.isEmpty())
            .orElse(null);
}
 
源代码6 项目: jsonschema-generator   文件: SwaggerModule.java
/**
 * Look-up a "title" for the given member or its associated getter/field from the member type's {@link ApiModel} annotation's {@code value}.
 *
 * @param scope targeted type
 * @return title (or {@code null})
 */
protected String resolveTitleForType(TypeScope scope) {
    return Optional.ofNullable(scope.getType())
            .map(type -> type.getErasedType().getAnnotation(ApiModel.class))
            .map(ApiModel::value)
            .filter(title -> !title.isEmpty())
            .orElse(null);
}
 
源代码7 项目: swagger-more   文件: ApiMethodModelsProvider.java
private List<ResolvedType> collectAllTypes(RequestMappingContext context, ResolvedMethodParameter parameter) {
    List<ResolvedType> allTypes = newArrayList();
    for (ResolvedType type : collectBindingTypes(context.alternateFor(parameter.getParameterType()), newArrayList())) {
        ApiModel apiModel = AnnotationUtils.getAnnotation(type.getErasedType(), ApiModel.class);
        allTypes.add(type);
        if (apiModel != null) {
            allTypes.addAll(Arrays.stream(apiModel.subTypes())
                    .filter(subType -> subType.getAnnotation(ApiModel.class) != type.getErasedType().getAnnotation(ApiModel.class))
                    .map(typeResolver::resolve).collect(Collectors.toList()));
        }
    }
    return allTypes;
}
 
源代码8 项目: BlogManagePlatform   文件: DefaultModelPlugin.java
@Override
public void apply(ModelPropertyContext context) {
	BeanPropertyDefinition definition = context.getBeanPropertyDefinition().orNull();
	if (definition == null) {
		return;
	}
	Class<?> modelClass = definition.getAccessor().getDeclaringClass();
	Field field = definition.getField().getAnnotated();
	if (!modelClass.isAnnotationPresent(ApiModel.class)) {
		return;
	}
	resolveDescription(context, field);
	resolveMapEnum(context, field);
	resolveExample(context, modelClass, field);
}
 
源代码9 项目: camunda-bpm-swagger   文件: ApiModelProcessor.java
@Override
public void process(final CtClass<?> element) {

  final CtAnnotation<Annotation> annotation = getFactory().Code().createAnnotation(getFactory().Code().createCtTypeReference(ApiModel.class));
  element.addAnnotation(annotation);
  log.debug("Add ApiModel to {}", element.getQualifiedName());
}
 
@Override
public PropertyName findRootName(AnnotatedClass ac) {
    ApiModel model = ac.getAnnotation(ApiModel.class);
    if (model != null) {
        return new PropertyName(model.value());
    } else {
        return super.findRootName(ac);
    }
}
 
源代码11 项目: stategen   文件: EntityWrap.java
public String getApiDescription() {
    if (_apiDescription == null) {
        _apiDescription = AnnotationUtil.getAnnotationValueFormMembers(ApiModel.class, ApiModel::value,"", getClazz());
    }
    return _apiDescription;
}
 
private void resolveImports(TopLevelClass klass, IntrospectedTable table) {
	addImport(klass, Data.class);
	addImport(klass, Id.class);
	addImport(klass, Table.class);
	addImport(klass, Column.class);
	addImport(klass, Entity.class);
	addImport(klass, ApiModel.class);
	addImport(klass, ApiModelProperty.class);
	boolean hasNullable = false;
	boolean hasNotNull = false;
	boolean hasNotBlank = false;
	boolean hasLength = false;
	for (IntrospectedColumn iter : table.getAllColumns()) {
		if (iter.isNullable()) {
			hasNullable = true;
		} else {
			if (iter.isStringColumn()) {
				hasNotBlank = true;
			} else {
				hasNotNull = true;
			}
		}
		if (iter.isStringColumn()) {
			if (iter.getLength() != 0) {
				hasLength = true;
			}
		}
	}
	if (hasNullable) {
		addImport(klass, Nullable.class);
	}
	if (hasNotNull) {
		addImport(klass, NotNull.class);
	}
	if (hasNotBlank) {
		addImport(klass, NotBlank.class);
	}
	if (hasLength) {
		addImport(klass, Length.class);
	}
}