io.swagger.annotations.ApiModel Java Examples

The following examples show how to use io.swagger.annotations.ApiModel. 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: DefaultParamPlugin.java    From BlogManagePlatform with 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 File: DefaultModelPlugin.java    From BlogManagePlatform with 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
Source File: SwaggerJacksonAnnotationIntrospector.java    From netty-rest with Apache License 2.0 6 votes vote down vote up
@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
Source File: SwaggerJacksonAnnotationIntrospector.java    From netty-rest with Apache License 2.0 6 votes vote down vote up
@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 File: SwaggerModule.java    From jsonschema-generator with 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 File: SwaggerModule.java    From jsonschema-generator with 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 File: ApiMethodModelsProvider.java    From swagger-more with 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 File: DefaultModelPlugin.java    From BlogManagePlatform with 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 File: ApiModelProcessor.java    From camunda-bpm-swagger with 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
Source File: EnhancedSwaggerAnnotationIntrospector.java    From swagger-maven-plugin with Apache License 2.0 5 votes vote down vote up
@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 File: EntityWrap.java    From stategen with 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 File: CustomCommentGenerator.java    From BlogManagePlatform with 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);
	}
}