Java Code Examples for io.swagger.annotations.ApiModel

The following examples show how to use io.swagger.annotations.ApiModel. These examples are extracted from open source projects. 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 Project: BlogManagePlatform   Source File: DefaultParamPlugin.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source Project: BlogManagePlatform   Source File: DefaultModelPlugin.java    License: Apache License 2.0 6 votes vote down vote up
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;
	}
}
 
Example 3
@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;
}
 
Example 4
@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();
}
 
Example 5
Source Project: jsonschema-generator   Source File: SwaggerModule.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 6
Source Project: jsonschema-generator   Source File: SwaggerModule.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 7
Source Project: swagger-more   Source File: ApiMethodModelsProvider.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 8
Source Project: BlogManagePlatform   Source File: DefaultModelPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 9
Source Project: camunda-bpm-swagger   Source File: ApiModelProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 10
@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);
    }
}
 
Example 11
Source Project: stategen   Source File: EntityWrap.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
public String getApiDescription() {
    if (_apiDescription == null) {
        _apiDescription = AnnotationUtil.getAnnotationValueFormMembers(ApiModel.class, ApiModel::value,"", getClazz());
    }
    return _apiDescription;
}
 
Example 12
Source Project: BlogManagePlatform   Source File: CustomCommentGenerator.java    License: Apache License 2.0 4 votes vote down vote up
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);
	}
}