@Override public List<Parameter> mToParameters(String name, Framework.Mapping<?> mapping) { if ("body".equalsIgnoreCase( attach(mapping).in() )) { return Arrays.asList(new BodyParameter() .schema(mToModel(mapping)) .name(name) .description(attach(mapping).desc())); } if (isEmpty( attach(mapping).in() ) && mapping instanceof Framework.GroupMapping) { return ((Framework.GroupMapping) mapping).fields().stream().flatMap(m -> { if (isEmpty(attach(m.getValue()).in())) throw new IllegalArgumentException("in is required!!!"); return mToParameters(concatName(name, m.getKey()), m.getValue()).stream(); }).collect(Collectors.toList()); } if (isEmpty(attach(mapping).in())) throw new IllegalArgumentException("in is required!!!"); if (mapping instanceof Framework.GroupMapping) { return ((Framework.GroupMapping) mapping).fields().stream().flatMap(m -> { Framework.Mapping<?> fMapping = mergeAttach(m.getValue(), attach(mapping)); return mToParameters(concatName(name, m.getKey()), fMapping).stream(); }).collect(Collectors.toList()); } else { if (!isPrimitive(mapping)) throw new IllegalArgumentException("must be primitives or primitive list!!!"); return Arrays.asList(mToParameter(name, mapping)); } }
/** * Build a {@link BodyParameter} Swagger object defined by {@link ApiImplicitParam} * to use for documentation. * * @param apiParam The annotation which documents the parameter. * @return The {@link BodyParameter} object to be used in {@link Swagger} */ public static BodyParameter bodyParameter(ApiImplicitParam apiParam) { BodyParameter bodyParameter = new BodyParameter() .name(apiParam.name()) .description(apiParam.value()) .schema(new RefModel().asDefault(apiParam.dataTypeClass().getSimpleName())); bodyParameter.setRequired(apiParam.required()); return bodyParameter; }
@Override public Parameter mToParameter(String name, Framework.Mapping<?> mapping) { if (isEmpty( attach(mapping).in() )) throw new IllegalArgumentException("in is required!!!"); if ("body".equalsIgnoreCase(attach(mapping).in())) { return new BodyParameter() .schema(mToModel(mapping)) .name(name) .description(attach(mapping).desc()); } if (isEmpty(name)) throw new IllegalArgumentException("name is required!!!"); if (!isPrimitive(mapping)) throw new IllegalArgumentException("must be primitives or primitive list!!!"); if ("form".equalsIgnoreCase( attach(mapping).in() ) || "formData".equalsIgnoreCase( attach(mapping).in() )) { return fillParameter(new FormParameter(), mapping).name(name); } if ("path".equalsIgnoreCase( attach(mapping).in() )) { return fillParameter(new PathParameter(), mapping).name(name).required(true); } if ("query".equalsIgnoreCase( attach(mapping).in() )) { return fillParameter(new QueryParameter(), mapping).name(name); } if ("cookie".equalsIgnoreCase( attach(mapping).in())) { return fillParameter(new CookieParameter(), mapping).name(name); } if ("header".equalsIgnoreCase( attach(mapping).in() )) { return fillParameter(new HeaderParameter(), mapping).name(name); } throw new IllegalArgumentException("Unsupported in type: '" + attach(mapping).in() + "'!!!"); }
protected Operation generateEntityCreateOperation(ModelImpl entityModel) { Operation operation = new Operation() .tag(entityModel.getName()) .produces(APPLICATION_JSON_VALUE) .summary("Creates new entity: " + entityModel.getName()) .description("The method expects a JSON with entity object in the request body. " + "The entity object may contain references to other entities.") .response(201, new Response() .description("Entity created. The created entity is returned in the response body.") .schema(new RefProperty(ENTITY_DEFINITION_PREFIX + entityModel.getName()))) .response(400, getErrorResponse("Bad request. For example, the entity may have a reference to the non-existing entity.")) .response(403, getErrorResponse("Forbidden. The user doesn't have permissions to create the entity.")) .response(404, getErrorResponse("Not found. MetaClass for the entity with the given name not found.")); BodyParameter entityParam = new BodyParameter() .name("entityJson") .description("JSON object with the entity") .schema(new RefModel(ENTITY_DEFINITION_PREFIX + entityModel.getName())); entityParam.setRequired(true); operation.parameter(entityParam); return operation; }
protected Operation generateEntityUpdateOperation(ModelImpl entityModel) { BodyParameter entityParam = new BodyParameter() .name("entityJson") .description("JSON object with the entity") .schema(new RefModel(ENTITY_DEFINITION_PREFIX + entityModel.getName())); entityParam.setRequired(true); PathParameter entityIdParam = new PathParameter() .name("entityId") .description("Entity identifier") .required(true) .property(new StringProperty().description("Entity identifier")); return new Operation() .tag(entityModel.getName()) .produces(APPLICATION_JSON_VALUE) .summary("Updates the entity: " + entityModel.getName()) .description("Updates the entity. Only fields that are passed in the JSON object " + "(the request body) are updated.") .parameter(entityIdParam) .parameter(entityParam) .response(200, new Response() .description("Success. The updated entity is returned in the response body.") .schema(new RefProperty(ENTITY_DEFINITION_PREFIX + entityModel.getName()))) .response(403, getErrorResponse("Forbidden. The user doesn't have permissions to update the entity.")) .response(404, getErrorResponse("Not found. MetaClass for the entity with the given name not found.")); }
.description(BODY_PARAM_VALUE) .schema(new RefModel().asDefault("AnnotatedServiceDocumentMock")); bodyParameter.setRequired(true);