use of io.swagger.models.parameters.RefParameter in project swagger-parser by swagger-api.
the class SwaggerConverter method convertFormDataToRequestBody.
private RequestBody convertFormDataToRequestBody(List<io.swagger.models.parameters.Parameter> formParams, List<String> consumes) {
RequestBody body = new RequestBody();
Schema formSchema = new Schema();
for (io.swagger.models.parameters.Parameter param : formParams) {
SerializableParameter sp;
Schema schema;
String name;
if (param instanceof RefParameter) {
RefParameter refParameter = (RefParameter) param;
String simpleRef = refParameter.getSimpleRef();
sp = (SerializableParameter) globalV2Parameters.get(simpleRef);
name = components.getSchemas().get("formData_" + simpleRef).getName();
schema = new Schema().$ref("#/components/schemas/formData_" + simpleRef);
} else {
sp = (SerializableParameter) param;
schema = convert(sp);
name = schema.getName();
}
if (sp.getRequired()) {
formSchema.addRequiredItem(sp.getName());
}
formSchema.addProperties(name, schema);
}
List<String> mediaTypes = new ArrayList<>(globalConsumes);
if (consumes != null && consumes.size() > 0) {
mediaTypes.clear();
mediaTypes.addAll(consumes);
}
// Assume multipart/form-data if nothing is specified
if (mediaTypes.size() == 0) {
mediaTypes.add("multipart/form-data");
}
Content content = new Content();
for (String type : mediaTypes) {
content.addMediaType(type, new MediaType().schema(formSchema));
}
body.content(content);
return body;
}
Aggregations