springfox.documentation.spi.schema.contexts.ModelPropertyContext Java Examples
The following examples show how to use
springfox.documentation.spi.schema.contexts.ModelPropertyContext.
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: SmartSwaggerApiModelEnumPlugin.java From smart-admin with MIT License | 6 votes |
@Override public void apply(ModelPropertyContext context) { Optional<ApiModelPropertyEnum> annotation = Optional.absent(); if (context.getAnnotatedElement().isPresent()) { annotation = annotation.or(findApiModePropertyAnnotation(context.getAnnotatedElement().get())); } if (context.getBeanPropertyDefinition().isPresent()) { annotation = annotation.or(findPropertyAnnotation(context.getBeanPropertyDefinition().get(), ApiModelPropertyEnum.class)); } if (annotation.isPresent()) { Class<? extends BaseEnum> aClass = annotation.get().value(); String enumInfo = BaseEnum.getInfo(aClass); String enumDesc = annotation.get().enumDesc(); context.getBuilder().required(annotation.transform(toIsRequired()).or(false)) .description(enumDesc +":"+enumInfo) .example(annotation.transform(toExample()).orNull()); } }
Example #2
Source File: DefaultRequiredPlugin.java From BlogManagePlatform with Apache License 2.0 | 6 votes |
private void resolveAnnotatedElement(ModelPropertyContext context) { AnnotatedElement annotated = context.getAnnotatedElement().orNull(); if (annotated == null) { return; } if (AnnotationUtils.findAnnotation(annotated, NotNull.class) != null) { context.getBuilder().required(true); } else if (AnnotationUtils.findAnnotation(annotated, NotEmpty.class) != null) { context.getBuilder().required(true); } else if (AnnotationUtils.findAnnotation(annotated, NotBlank.class) != null) { context.getBuilder().required(true); } else { ApiModelProperty annotation = AnnotationUtils.findAnnotation(annotated, ApiModelProperty.class); if (annotation != null && annotation.required()) { //如果ApiModelProperty上强制要求required为true,则为true context.getBuilder().required(true); } else { context.getBuilder().required(false); } } }
Example #3
Source File: DefaultRequiredPlugin.java From BlogManagePlatform with Apache License 2.0 | 5 votes |
private void resolveBeanPropertyDefinition(ModelPropertyContext context) { BeanPropertyDefinition beanPropertyDefinition = context.getBeanPropertyDefinition().orNull(); if (beanPropertyDefinition == null) { return; } if (Annotations.findPropertyAnnotation(beanPropertyDefinition, NotNull.class).isPresent()) { context.getBuilder().required(true); } else if (Annotations.findPropertyAnnotation(beanPropertyDefinition, NotEmpty.class).isPresent()) { context.getBuilder().required(true); } else if (Annotations.findPropertyAnnotation(beanPropertyDefinition, NotBlank.class).isPresent()) { context.getBuilder().required(true); } else { context.getBuilder().required(false); } }
Example #4
Source File: DefaultModelPlugin.java From BlogManagePlatform with Apache License 2.0 | 5 votes |
@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 #5
Source File: DefaultModelPlugin.java From BlogManagePlatform with Apache License 2.0 | 5 votes |
private void resolveMapEnum(ModelPropertyContext context, Field field) { MapEnum legalEnum = field.getAnnotation(MapEnum.class); if (legalEnum != null) { String descs = MapEnumHelper.getDescs(legalEnum.value(), legalEnum.descMethod()); Object defaultValue = MapEnumHelper.getDefaultValue(legalEnum.value()); ModelPropertyBuilder builder = context.getBuilder(); builder.description(descs); builder.example(defaultValue); builder.allowableValues(MapEnumHelper.getAllowableValues(legalEnum.value())); builder.defaultValue(defaultValue == null ? DefStr.EMPTY : defaultValue.toString()); } }
Example #6
Source File: DefaultModelPlugin.java From BlogManagePlatform with Apache License 2.0 | 5 votes |
private void resolveExample(ModelPropertyContext context, Class<?> modelClass, Field field) { Object retVal = ReflectUtil.get(field, ReflectUtil.instance(modelClass)); if (retVal != null) { ModelPropertyBuilder builder = context.getBuilder(); ApiModelProperty modelProperty = field.getAnnotation(ApiModelProperty.class); if (modelProperty != null && EmptyUtil.no(modelProperty.example())) { return; } builder.example(retVal); builder.defaultValue(String.valueOf(retVal)); } }
Example #7
Source File: EmailAnnotationPlugin.java From tutorials with MIT License | 5 votes |
/** * read Email annotation */ @Override public void apply(ModelPropertyContext context) { Optional<Email> email = annotationFromBean(context, Email.class); if (email.isPresent()) { context.getBuilder().pattern(email.get().regexp()); context.getBuilder().example("[email protected]"); } }
Example #8
Source File: DefaultRequiredPlugin.java From BlogManagePlatform with Apache License 2.0 | 4 votes |
@Override public void apply(ModelPropertyContext context) { resolveAnnotatedElement(context); resolveBeanPropertyDefinition(context); }
Example #9
Source File: DefaultModelPlugin.java From BlogManagePlatform with Apache License 2.0 | 4 votes |
private void resolveDescription(ModelPropertyContext context, Field field) { ModelPropertyBuilder builder = context.getBuilder(); String description = StrUtil.orEmpty((String) ReflectUtil.get(ModelPropertyBuilder.class, "description", builder)); String resolve = recursiveResolveList(TypeUtil.resolve(field.getGenericType())); if (resolve != null) { //如果还是有ApiModelProperty,就不在原描述后增加列表的描述 if (!field.isAnnotationPresent(ApiModelProperty.class)) { description = StrUtil.concat(description, resolve); } } resolve = resolveRange(field); if (resolve != null) { description = String.join(",", description, resolve); } resolve = resolveSize(field); if (resolve != null) { description = String.join(",", description, resolve); } resolve = resolveRegex(field); if (resolve != null) { description = String.join(",", description, resolve); } resolve = resolveDate(field); if (resolve != null) { description = String.join(",", description, resolve); } resolve = resolveNull(field); if (resolve != null) { description = String.join(",", description, resolve); } resolve = resolveEmail(field); if (resolve != null) { description = String.join(",", description, resolve); } resolve = resolveIDCard(field); if (resolve != null) { description = String.join(",", description, resolve); } resolve = resolveMobile(field); if (resolve != null) { description = String.join(",", description, resolve); } builder.description(description); }