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; }
BodyParameter bp = new BodyParameter(); bp.setRequired(isParameterRequired(annotations)); bp.schema(model); Parameter parameter = ParameterProcessor.applyAnnotations(new Swagger(), bp, type, annotations); if (parameter != null) { if (parameter instanceof BodyParameter) { ((BodyParameter) parameter).schema(model);
@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)); } }
private Map<String, Path> getPaths() { Map<String, Path> paths = new HashMap<>(); Path path = new Path(); Operation post = new Operation(); post.setOperationId("configure"); post.setConsumes(Arrays.asList("application/json", "application/xml")); post.setProduces(Arrays.asList("application/json", "application/xml")); List<Parameter> parameters = new ArrayList<>(); Parameter in = new BodyParameter().schema(new RefModel("#/definitions/inputs")); in.setRequired(true); in.setName(INPUTS); parameters.add(in); post.setParameters(parameters); Map<String, Response> responses = new HashMap<>(); Response response = new Response().description("Success"); responses.put("200", response); Response failureResponse = new Response().description("Failure"); responses.put("400", failureResponse); post.setResponses(responses); path.setPost(post); paths.put("/operations/config-selfservice-api:configure", path); return paths; }
/** * 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; }
private Parameter buildPOSTBodyParameter(String resourceName, String resourceParentName, OperationEnum operationEnum) { BodyParameter bodyParameter = new BodyParameter(); bodyParameter.setRequired(true); switch (operationEnum) { case postCreate: case postSubresource: bodyParameter.setName("resource"); bodyParameter.setDescription("Resource to create"); break; case postUpdate: case postUpdateSubresouce: bodyParameter.setName("resource"); bodyParameter.setDescription("Resource properties to update"); } bodyParameter.schema(new RefModel(getSchemaRef(resourceName, resourceParentName, operationEnum))); 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() + "'!!!"); }
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);
.response(204, okEmptyResponse) .parameter(new BodyParameter() .schema(new Data(new Relationship(typeName))) .name("relationship")) ); .response(204, okEmptyResponse) .parameter(new BodyParameter() .schema(new Data(new Relationship(typeName))) .name("relationship")) ); .response(201, okPluralResponse) .parameter(new BodyParameter() .schema(new Data(new Relationship(typeName))) .name("relationship")) ); .response(204, okEmptyResponse) .parameter(new BodyParameter() .schema(new Datum(new Relationship(typeName))) .name("relationship")) );
.response(201, okSingularResponse) .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; }
.response(204, okEmptyResponse) .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")); bodyParameter.setRequired(true);