Java Code Examples for io.swagger.v3.oas.models.parameters.Parameter#setSchema()
The following examples show how to use
io.swagger.v3.oas.models.parameters.Parameter#setSchema() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericParameterBuilder.java From springdoc-openapi with Apache License 2.0 | 6 votes |
/** * Sets schema. * * @param parameterDoc the parameter doc * @param components the components * @param jsonView the json view * @param parameter the parameter */ private void setSchema(io.swagger.v3.oas.annotations.Parameter parameterDoc, Components components, JsonView jsonView, Parameter parameter) { if (StringUtils.isNotBlank(parameterDoc.ref())) parameter.$ref(parameterDoc.ref()); else { Schema schema = null; try { schema = AnnotationsUtils.getSchema(parameterDoc.schema(), null, false, parameterDoc.schema().implementation(), components, jsonView).orElse(null); } catch (Exception e) { LOGGER.warn(Constants.GRACEFUL_EXCEPTION_OCCURRED, e); } if (schema == null) { if (parameterDoc.content().length > 0) schema = AnnotationsUtils.getSchema(parameterDoc.content()[0], components, jsonView).orElse(null); else schema = AnnotationsUtils.getArraySchema(parameterDoc.array(), components, jsonView).orElse(null); } parameter.setSchema(schema); } }
Example 2
Source File: AbstractRequestBuilder.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Gets headers. * * @param methodAttributes the method attributes * @param map the map * @return the headers */ public static Collection<Parameter> getHeaders(MethodAttributes methodAttributes, Map<String, Parameter> map) { for (Map.Entry<String, String> entry : methodAttributes.getHeaders().entrySet()) { Parameter parameter = new Parameter().in(ParameterIn.HEADER.toString()).name(entry.getKey()).schema(new StringSchema().addEnumItem(entry.getValue())); if (map.containsKey(entry.getKey())) { parameter = map.get(entry.getKey()); parameter.getSchema().addEnumItemObject(entry.getValue()); parameter.setSchema(parameter.getSchema()); } map.put(entry.getKey(), parameter); } return map.values(); }
Example 3
Source File: GenericParameterBuilder.java From springdoc-openapi with Apache License 2.0 | 4 votes |
/** * Merge parameter. * * @param paramCalcul the param calcul * @param paramDoc the param doc */ private static void mergeParameter(Parameter paramCalcul, Parameter paramDoc) { if (StringUtils.isBlank(paramDoc.getDescription())) paramDoc.setDescription(paramCalcul.getDescription()); if (StringUtils.isBlank(paramDoc.getIn())) paramDoc.setIn(paramCalcul.getIn()); if (paramDoc.getExample() == null) paramDoc.setExample(paramCalcul.getExample()); if (paramDoc.getDeprecated() == null) paramDoc.setDeprecated(paramCalcul.getDeprecated()); if (paramDoc.getRequired() == null) paramDoc.setRequired(paramCalcul.getRequired()); if (paramDoc.getAllowEmptyValue() == null) paramDoc.setAllowEmptyValue(paramCalcul.getAllowEmptyValue()); if (paramDoc.getAllowReserved() == null) paramDoc.setAllowReserved(paramCalcul.getAllowReserved()); if (StringUtils.isBlank(paramDoc.get$ref())) paramDoc.set$ref(paramDoc.get$ref()); if (paramDoc.getSchema() == null) paramDoc.setSchema(paramCalcul.getSchema()); if (paramDoc.getExamples() == null) paramDoc.setExamples(paramCalcul.getExamples()); if (paramDoc.getExtensions() == null) paramDoc.setExtensions(paramCalcul.getExtensions()); if (paramDoc.getStyle() == null) paramDoc.setStyle(paramCalcul.getStyle()); if (paramDoc.getExplode() == null) paramDoc.setExplode(paramCalcul.getExplode()); }
Example 4
Source File: DefaultConverter.java From swagger-inflector with Apache License 2.0 | 4 votes |
public Object coerceValue(List<String> arguments, Parameter parameter, Class<?> cls) throws ConversionException { if (arguments == null || arguments.size() == 0) { return null; } LOGGER.debug("casting `" + arguments + "` to " + cls); if (List.class.equals(cls)) { if (parameter.getSchema() != null) { List<Object> output = new ArrayList<>(); if (parameter.getSchema() instanceof ArraySchema) { ArraySchema arraySchema = ((ArraySchema) parameter.getSchema()); Schema inner = arraySchema.getItems(); // TODO: this does not need to be done this way, update the helper method Parameter innerParam = new QueryParameter(); innerParam.setSchema(inner); JavaType innerClass = getTypeFromParameter(innerParam, definitions); for (String obj : arguments) { String[] parts = new String[0]; if (Parameter.StyleEnum.FORM.equals(parameter.getStyle()) && !StringUtils.isEmpty(obj) && parameter.getExplode() == false ) { parts = obj.split(","); } if (Parameter.StyleEnum.PIPEDELIMITED.equals(parameter.getStyle()) && !StringUtils.isEmpty(obj)) { parts = obj.split("|"); } if (Parameter.StyleEnum.SPACEDELIMITED.equals(parameter.getStyle()) && !StringUtils.isEmpty(obj)) { parts = obj.split(" "); } if (Parameter.StyleEnum.FORM.equals(parameter.getStyle()) && !StringUtils.isEmpty(obj) && parameter.getExplode() == true) { parts = new String[1]; parts[0]= obj; } for (String p : parts) { Object ob = cast(p, inner, innerClass); if (ob != null) { output.add(ob); } } } } return output; } } else if (parameter.getSchema() != null) { TypeFactory tf = Json.mapper().getTypeFactory(); return cast(arguments.get(0), parameter.getSchema(), tf.constructType(cls)); } return null; }
Example 5
Source File: InlineModelResolverTest.java From swagger-parser with Apache License 2.0 | 3 votes |
@Test public void resolveInlineParameter() throws Exception { OpenAPI openAPI = new OpenAPI(); ObjectSchema objectSchema = new ObjectSchema(); objectSchema.addProperties("street", new StringSchema()); Schema schema = new Schema(); schema.addProperties("address", objectSchema); schema.addProperties("name", new StringSchema()); Parameter parameter = new Parameter(); parameter.setName("name"); parameter.setSchema(schema); List parameters = new ArrayList(); parameters.add(parameter); Operation operation = new Operation(); operation.setParameters(parameters); PathItem pathItem = new PathItem(); pathItem.setGet(operation); openAPI.path("/hello",pathItem); new InlineModelResolver().flatten(openAPI); Operation getOperation = openAPI.getPaths().get("/hello").getGet(); Parameter param = getOperation.getParameters().get(0); assertTrue(param.getSchema().get$ref() != null); Schema bodySchema = openAPI.getComponents().getSchemas().get("name"); assertTrue(bodySchema instanceof Schema); assertNotNull(bodySchema.getProperties().get("address")); }