/** * Build a {@link Model} Swagger object defined by {@link ApiModel} to use for * documentation. The model is described by the {@code clazz} object and contains * fields, of which only the ones annotated with {@link ApiModelProperty} are * going to appear in the documentation. * * @param clazz The class defining the model. * @return The {@link Model} object to be used in {@link Swagger} */ public static Model model(Class<?> clazz) { ApiModel annotation = clazz.getAnnotation(ApiModel.class); ModelImpl model = new ModelImpl() .name(annotation.value()) .description(annotation.description()); Arrays.asList(clazz.getFields()) .stream() .filter(field -> field.isAnnotationPresent(ApiModelProperty.class)) .forEach(field -> { model.property(field.getName(), property(field)); }); return model; }
protected ModelImpl createModel(Property property) { return new ModelImpl().type(property.getType()).format(property.getFormat()) .description(property.getDescription()); }
@Override public Model mToModel(Framework.Mapping<?> mapping) { String refName = attach(mapping).refName(); if (!isEmpty(refName)) { return new RefModel(refName); } if (mapping.meta().targetType == List.class) { ArrayModel model = new ArrayModel() .description(attach(mapping).desc()) .items(items(mapping)); model.setExample(attach(mapping).example()); return model; } ModelImpl model = new ModelImpl() .type(targetType(mapping)) .format(format(mapping)) .description(attach(mapping).desc()) .example(attach(mapping).example()); if (mapping instanceof Framework.GroupMapping) { ((Framework.GroupMapping) mapping).fields().forEach(m -> { model.addProperty(m.getKey(), mToProperty(m.getValue())); if (required(m.getValue())) { model.required(m.getKey()); } }); } return model; }
.type(SwaggerDocumentation.DataTypes.DATA_TYPE_STRING); model = new ModelImpl().name(API_MODEL_NAME).description(API_MODEL_DESCRIPTION); model.setProperties(initProperties());