use of io.swagger.v3.oas.models.parameters.RequestBody in project swagger-parser by swagger-api.
the class SwaggerConverter method convertParameterToRequestBody.
private RequestBody convertParameterToRequestBody(io.swagger.models.parameters.Parameter param, List<String> consumes) {
RequestBody body = new RequestBody();
BodyParameter bp = (BodyParameter) param;
List<String> mediaTypes = new ArrayList<>(globalConsumes);
if (consumes != null && consumes.size() > 0) {
mediaTypes.clear();
mediaTypes.addAll(consumes);
}
if (mediaTypes.size() == 0) {
mediaTypes.add("*/*");
}
if (StringUtils.isNotBlank(param.getDescription())) {
body.description(param.getDescription());
}
body.required(param.getRequired());
Content content = new Content();
for (String type : mediaTypes) {
content.addMediaType(type, new MediaType().schema(convert(bp.getSchema())));
if (StringUtils.isNotBlank(bp.getDescription())) {
body.setDescription(bp.getDescription());
}
}
convertExamples(((BodyParameter) param).getExamples(), content);
body.content(content);
return body;
}
use of io.swagger.v3.oas.models.parameters.RequestBody in project swagger-parser by swagger-api.
the class V2ConverterTest method testIssue600.
@Test(description = "OpenAPI v2 converter - required Form parameters are converted as optional ")
public void testIssue600() throws Exception {
OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_600_JSON);
RequestBody requestBody = oas.getPaths().get(LOGIN_PATH).getPost().getRequestBody();
assertNotNull(requestBody);
assertTrue(requestBody.getRequired());
Schema schema = requestBody.getContent().get(CONTENT_TYPE).getSchema();
List required = schema.getRequired();
assertNotNull(required);
assertEquals(required.size(), REQUIRED_SIZE);
}
use of io.swagger.v3.oas.models.parameters.RequestBody in project swagger-parser by swagger-api.
the class V2ConverterTest method testIssue19.
@Test(description = "Request Body Completions")
public void testIssue19() throws Exception {
OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_19_JSON);
RequestBody requestBody = oas.getPaths().get(POST_PATH).getPost().getRequestBody();
assertNotNull(requestBody);
Schema schema = requestBody.getContent().get(URLENCODED_CONTENT).getSchema();
assertNotNull(schema);
Map properties = schema.getProperties();
assertEquals(PROPERTIES_SIZE, properties.size());
ArraySchema ids = (ArraySchema) properties.get("ids");
assertEquals(new Integer(MIN_ITEMS), ids.getMinItems());
assertEquals(new Integer(MAXIMUM), ids.getMaxItems());
// Fixed from Issue 19
assertEquals(Boolean.TRUE, ids.getUniqueItems());
Schema login = (Schema) properties.get("login");
assertEquals(new Integer(MIN_LENGTH), login.getMinLength());
assertEquals(new Integer(MAX_LENGTH), login.getMaxLength());
assertEquals(PATTERN, login.getPattern());
Schema favNumber = (Schema) properties.get("favNumber");
assertEquals(new BigDecimal(MAXIMUM), favNumber.getMinimum());
assertEquals(new BigDecimal(MAXIMUM), favNumber.getMaximum());
assertEquals(Boolean.TRUE, favNumber.getExclusiveMinimum());
assertEquals(Boolean.TRUE, favNumber.getExclusiveMaximum());
assertEquals(new BigDecimal(MULTIPLE_OF_VALUE), new BigDecimal(favNumber.getMultipleOf().doubleValue()));
Schema dayOfWeek = (Schema) properties.get("dayOfWeek");
assertEquals(MONDAY_TUESDAY_VALUE, dayOfWeek.getDefault());
assertEquals(MONDAY_TUESDAY_VALUE, dayOfWeek.getEnum().get(0));
assertEquals(TUESDAY_WEDNESDAY_VALUE, dayOfWeek.getEnum().get(1));
assertEquals(WEDNESDAY_THURSDAY_VALUE, dayOfWeek.getEnum().get(2));
}
use of io.swagger.v3.oas.models.parameters.RequestBody in project swagger-parser by swagger-api.
the class V2ConverterTest method testIssue17.
@Test(description = "Referenced parameters are converted incorrectly")
public void testIssue17() throws Exception {
OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_17_JSON);
Map<String, RequestBody> requestBodies = oas.getComponents().getRequestBodies();
Map<String, Schema> schemas = oas.getComponents().getSchemas();
assertNotNull(schemas.get("formData_formEmail"));
assertNotNull(schemas.get("formData_formPassword"));
assertNotNull(requestBodies.get("bodyParam").getContent().get("*/*"));
assertNull(oas.getPaths().get("/formPost").getPost().getParameters());
assertNotNull(oas.getPaths().get("/formPost").getPost().getRequestBody());
assertNotNull(oas.getPaths().get("/report/{userId}").getGet().getRequestBody().getContent().get("multipart/form-data").getSchema().getProperties().get("limitForm"));
}
use of io.swagger.v3.oas.models.parameters.RequestBody in project swagger-parser by swagger-api.
the class V2ConverterTest method testIssue765.
@Test(description = "requestBody not correctly populated when Parameters is a list of $refs (OAS 2 to 3 conversion)")
public void testIssue765() throws Exception {
final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_765_YAML);
assertNotNull(oas);
RequestBody requestBody = oas.getPaths().get("/ping/{ActivityTypePath}").getPost().getRequestBody();
assertNotNull(requestBody);
assertEquals("#/components/requestBodies/Block", requestBody.get$ref());
}
Aggregations