private QueryParameter extractQueryParam(Type type, String defaultValue, QueryParam param) { QueryParameter queryParameter = new QueryParameter().name(param.value()); if (!Strings.isNullOrEmpty(defaultValue)) { queryParameter.setDefaultValue(defaultValue); } Property schema = ModelConverters.getInstance().readAsProperty(type); if (schema != null) { queryParameter.setProperty(schema); } String parameterType = queryParameter.getType(); if (parameterType == null || parameterType.equals("ref")) { queryParameter.setType("string"); } return queryParameter; }
private Parameter extractRequestParam(Type type, RequestParam requestParam) { if (requestParam == null) { requestParam = DEFAULT_REQUEST_PARAM; } String paramName = StringUtils.defaultIfEmpty(requestParam.value(), requestParam.name()); QueryParameter queryParameter = new QueryParameter().name(paramName) .required(requestParam.required()); if (!DEFAULT_VALUE.equals(requestParam.defaultValue())) { queryParameter.setDefaultValue(requestParam.defaultValue()); // Supplying a default value implicitly sets required() to false. queryParameter.setRequired(false); } Property schema = readAsPropertyIfPrimitive(type); if (schema != null) { queryParameter.setProperty(schema); } return queryParameter; }
private static Collection<QueryParameter> transformMappings(final Iterable<SearchMapping> searchMappings) { // NOSONAR return StreamSupport.stream(searchMappings.spliterator(), false) .map(m -> new QueryParameter().name(m.getAlias()).type("string").description(m.getDescription())) .collect(toList()); } }
private List<Parameter> buildPagingParameters() { List<Parameter> params = new ArrayList<Parameter>(); Parameter limit = new QueryParameter().name("limit") .description("The number of results to return").type("integer"); Parameter startIndex = new QueryParameter().name("startIndex") .description("The offset at which to start").type("integer"); params.add(limit); params.add(startIndex); return params; }
/** * @return the JSON-API 'sort' query parameter for some GET operations. */ private Parameter getSortParameter() { List<String> filterAttributes = dictionary.getAttributes(type).stream() .filter((name) -> { Class<?> attributeClass = dictionary.getType(type, name); return (attributeClass.isPrimitive() || String.class.isAssignableFrom(attributeClass)); }) .map((name) -> Arrays.asList(name, "-" + name)) .flatMap(Collection::stream) .collect(Collectors.toList()); return new QueryParameter() .name("sort") .type("array") .description("Sorts the collection on the selected attributes. A prefix of '-' sorts descending") .items(new StringProperty()._enum(filterAttributes)) .collectionFormat("csv"); }
.name("page[number]") .description("Number of pages to return. Can be used with page[size]") .type("integer") .name("page[size]") .description("Number of elements per page. Can be used with page[number]") .type("integer") .name("page[offset]") .description("Offset from 0 to start paginating. Can be used with page[limit]") .type("integer") .name("page[limit]") .description("Maximum number of items to return. Can be used with page[offset]") .type("integer") .name("page[totals]") .description("For requesting total pages/records be included in the response page meta data")
.name("filter[" + typeName + "]") .description("Filters the collection of " + typeName + " using a 'disjoint' RSQL expression")); .name("filter") .description("Filters the collection of " + typeName + " using a 'joined' RSQL expression")); params.add(new QueryParameter() .type("string") .name("filter[" + typeName + "." + name + "][" + op.getNotation() + "]") .description("Filters the collection of " + typeName + " by the attribute " + name + " " + "using the operator " + op.getNotation()));
protected Parameter generateGetOperationParam(Pair<String, String> param) { boolean paramIsArray = param.getSecond() != null && param.getSecond().contains(ARRAY_SIGNATURE); return new QueryParameter() .name(param.getFirst()) .required(true) .type(paramIsArray ? "array" : "string") .items(paramIsArray ? new StringProperty() : null); }
protected List<Parameter> generateOptionalQueryParams() { return Arrays.asList( new QueryParameter() .name("dynamicAttributes") .description("Specifies whether entity dynamic attributes should be returned.") .property(new BooleanProperty()), new QueryParameter() .name("returnCount") .description("Specifies whether the total count of entities should be returned in the " + "'X-Total-Count' header.") .property(new BooleanProperty()), new QueryParameter() .name("returnNulls") .description("Specifies whether null fields will be written to the result JSON.") .property(new BooleanProperty()), new QueryParameter() .name("view") .description("Name of the view which is used for loading the entity. Specify this parameter " + "if you want to extract entities with the view other than it is defined in the REST " + .property(new StringProperty()), new QueryParameter() .name("offset") .description("Position of the first result to retrieve.") .property(new StringProperty()), new QueryParameter() .name("limit") .description("Number of extracted entities.") .property(new StringProperty())
protected List<Parameter> generateEntityOptionalParams(boolean singleEntityOperation) { List<Parameter> singleEntityParams = Arrays.asList( new QueryParameter() .name("dynamicAttributes") .description("Specifies whether entity dynamic attributes should be returned.") .property(new BooleanProperty()), new QueryParameter() .name("returnNulls") .description("Specifies whether null fields will be written to the result JSON.") .property(new BooleanProperty()), new QueryParameter() .name("view") .description("Name of the view which is used for loading the entity.") .property(new StringProperty()) .name("returnCount") .description("Specifies whether the total count of entities should be returned in the " + "'X-Total-Count' header.") .property(new BooleanProperty()), new QueryParameter() .name("offset") .description("Position of the first result to retrieve.") .property(new StringProperty()), new QueryParameter() .name("limit") .description("Number of extracted entities.") .property(new StringProperty()), new QueryParameter() .name("sort") .description("Name of the field to be sorted by. If the name is preceding by the '+' " +
/** * @return the JSON-API 'include' query parameter for some GET operations. */ private Parameter getIncludeParameter() { List<String> relationshipNames = dictionary.getRelationships(type); return new QueryParameter() .type("array") .name("include") .description("Selects the set of relationships that should be expanded as a compound document in " + "the result.") .items(new StringProperty()._enum(relationshipNames)) .collectionFormat("csv"); }
/** * Build a {@link QueryParameter} Swagger object defined by {@link ApiImplicitParam} * to use for documentation. * * @param apiParam The annotation which documents the parameter. * @return The {@link QueryParameter} object to be used in {@link Swagger} */ public static QueryParameter queryParameter(ApiImplicitParam apiParam) { return new QueryParameter() .name(apiParam.name()) .description(apiParam.value()) .required(apiParam.required()) .type(apiParam.dataType()); }
/** * @return the JSON-API 'field' query parameter for some GET operations. */ private Parameter getSparseFieldsParameter() { String typeName = dictionary.getJsonAliasFor(type); List<String> fieldNames = dictionary.getAllFields(type); return new QueryParameter() .type("array") .name("fields[" + typeName + "]") .description("Selects the set of " + typeName + " fields that should be returned in the result.") .items(new StringProperty()._enum(fieldNames)) .collectionFormat("csv"); }
operation.addParameter(pathParameter); } else if (paramType.equals("query")) { QueryParameter pathParameter = new QueryParameter().name(paramName).type(dataType); pathParameter.setRequired(param.required()); operation.addParameter(pathParameter); final String type = getSwaggerDataType(parameterType); final String paramName = (annotation != null) ? annotation.name() : endpointParamNames[i]; final QueryParameter param = new QueryParameter().type(type).name(paramName); if (annotation != null) { param.description(annotation.value());
operation.addParameter(pathParameter); } else if (paramType.equals("query")) { QueryParameter pathParameter = new QueryParameter().name(paramName).type(dataType); pathParameter.setRequired(param.required()); operation.addParameter(pathParameter); final String type = getSwaggerDataType(parameterType); final String paramName = (annotation != null) ? annotation.name() : endpointParamNames[i]; final QueryParameter param = new QueryParameter().type(type).name(paramName); if (annotation != null) { param.description(annotation.value());
QueryParameter queryParameter = new QueryParameter(); queryParameter.name(requestParamAnnotationSource.getStringValue("value").trim()); queryParameter.setRequired(BooleanUtils.toBoolean(requestParamAnnotationSource.getStringValue("required"))); setParameterType(parameterSource, queryParameter);
deleteOperation.setDescription("The resource will be voided/retired unless purge = 'true'"); QueryParameter purgeParam = new QueryParameter().name("purge").type("boolean"); deleteOperation.parameter(purgeParam); } else {
QueryParam param = (QueryParam) annotation; QueryParameter qp = new QueryParameter() .name(param.value());
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; }
.name(QUERY_PARAM_NAME) .description(QUERY_PARAM_VALUE) .required(true)