protected Parameter generateQueryPostOpParam(List<RestQueriesConfiguration.QueryParamInfo> params) { Map<String, Property> modelProps = params.stream() .collect(Collectors.toMap( RestQueriesConfiguration.QueryParamInfo::getName, p -> getPropertyFromJavaType(p.getType()))); ModelImpl parameterModel = new ModelImpl(); parameterModel.setProperties(modelProps); BodyParameter parameter = new BodyParameter() .name("paramsObject"); parameter.setRequired(true); return parameter.schema(parameterModel); }
protected Parameter generateServicePostOpParam(List<RestMethodParamInfo> params) { Map<String, Property> modelProps = params.stream() .collect(Collectors.toMap( RestMethodParamInfo::getName, p -> getPropertyFromJavaType(p.getType()))); ModelImpl parameterModel = new ModelImpl(); parameterModel.setProperties(modelProps); BodyParameter parameter = new BodyParameter() .name("paramsObject") .schema(parameterModel); parameter.setRequired(true); return parameter; }
@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; }
bodyParameter.name(name); bodyParameter.setSchema(new RefModel(model.getName()));
bodyParameter.name(name); bodyParameter.setSchema(new RefModel(model.getName())); bodyParameter.setRequired(true);
@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() + "'!!!"); }
XmlType xmlType = getXmlType(Class.forName(parameterSource.getType().getQualifiedName())); String name = xmlType.name().trim(); bodyParameter.name(name); bodyParameter.setRequired(true); bodyParameter.setSchema(new RefModel(name));
BodyParameter bodyParameter = new BodyParameter().name(paramName).schema(model.values().iterator().next()); bodyParameter.setRequired(true); operation.addParameter(bodyParameter);
BodyParameter bodyParameter = new BodyParameter().name(paramName).schema(model.values().iterator().next()); bodyParameter.setRequired(true); operation.addParameter(bodyParameter);
.parameter(new BodyParameter() .schema(new Data(new Relationship(typeName))) .name("relationship")) ); path.delete(new JsonApiOperation() .parameter(new BodyParameter() .schema(new Data(new Relationship(typeName))) .name("relationship")) ); path.post(new JsonApiOperation() .parameter(new BodyParameter() .schema(new Data(new Relationship(typeName))) .name("relationship")) ); } else { .parameter(new BodyParameter() .schema(new Datum(new Relationship(typeName))) .name("relationship")) );
.parameter(new BodyParameter() .schema(new Datum(typeName)) .name(typeName)) );
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 generateEntitySearchOperation(ModelImpl entityModel, RequestMethod method) { Operation operation = new Operation() .tag(entityModel.getName()) .produces(APPLICATION_JSON_VALUE) .summary("Find entities by filter conditions: " + entityModel.getName()) .description("Finds entities by filter conditions. The filter is defined by JSON object " + "that is passed as in URL parameter.") .response(200, new Response() .description("Success. Entities that conforms filter conditions are returned in the response body.") .schema(new ArrayProperty(new RefProperty(ENTITY_DEFINITION_PREFIX + entityModel.getName())))) .response(400, getErrorResponse("Bad request. For example, the condition value cannot be parsed.")) .response(403, getErrorResponse("Forbidden. The user doesn't have permissions to read the entity.")) .response(404, getErrorResponse("Not found. MetaClass for the entity with the given name not found.")); if (RequestMethod.GET == method) { QueryParameter parameter = new QueryParameter() .name("filter") .required(true) .property(new StringProperty().description("JSON with filter definition")); operation.parameter(parameter); } else { BodyParameter parameter = new BodyParameter() .name("filter") .schema(new ModelImpl() .property("JSON with filter definition", new StringProperty())); parameter.setRequired(true); operation.parameter(parameter); } operation.getParameters().addAll(generateEntityOptionalParams(false)); return operation; }
.parameter(new BodyParameter() .schema(new Datum(typeName)) .name(typeName)) );
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.")); }
.name(BODY_PARAM_NAME) .description(BODY_PARAM_VALUE) .schema(new RefModel().asDefault("AnnotatedServiceDocumentMock"));