use of io.swagger.models.parameters.BodyParameter in project swagger-core by swagger-api.
the class PostParamTest method findPostOperationWithObjectsCollection.
@Test(description = "find a Post operation with collection of objects")
public void findPostOperationWithObjectsCollection() {
Path petPath = getPath("collectionOfObjects");
assertNotNull(petPath);
Operation petPost = petPath.getPost();
assertNotNull(petPost);
assertEquals(petPost.getParameters().size(), 1);
BodyParameter petPostBodyParam = (BodyParameter) petPost.getParameters().get(0);
assertEquals(petPostBodyParam.getName(), BODY);
Model inputModel = petPostBodyParam.getSchema();
assertTrue(inputModel instanceof ArrayModel);
ArrayModel ap = (ArrayModel) inputModel;
Property inputSchema = ap.getItems();
assertTrue(inputSchema instanceof RefProperty);
RefProperty rm = (RefProperty) inputSchema;
assertEquals(rm.getSimpleRef(), PET);
}
use of io.swagger.models.parameters.BodyParameter in project swagger-core by swagger-api.
the class PostParamTest method findAPostOperationWithStringsList.
@Test(description = "find a Post operation with list of strings")
public void findAPostOperationWithStringsList() {
Path petPath = getPath("listOfStrings");
assertNotNull(petPath);
Operation petPost = petPath.getPost();
assertNotNull(petPost);
assertEquals(petPost.getParameters().size(), 1);
BodyParameter petPostBodyParam = (BodyParameter) petPost.getParameters().get(0);
assertEquals(petPostBodyParam.getName(), BODY);
Model inputModel = petPostBodyParam.getSchema();
assertTrue(inputModel instanceof ArrayModel);
ArrayModel ap = (ArrayModel) inputModel;
Property inputSchema = ap.getItems();
assertTrue(inputSchema instanceof StringProperty);
}
use of io.swagger.models.parameters.BodyParameter in project swagger-core by swagger-api.
the class ReaderTest method scanImplicitParam.
@Test(description = "scan implicit params")
public void scanImplicitParam() {
Swagger swagger = getSwagger(ResourceWithImplicitParams.class);
List<Parameter> params = swagger.getPath("/testString").getPost().getParameters();
assertNotNull(params);
assertEquals(params.size(), 7);
assertEquals(params.get(0).getName(), "sort");
assertEquals(params.get(0).getIn(), "query");
PathParameter pathParam = (PathParameter) params.get(1);
assertEquals(pathParam.getName(), "type");
assertEquals(pathParam.getIn(), "path");
assertEquals(pathParam.getEnum().size(), 3);
assertEquals(pathParam.getType(), "string");
HeaderParameter headerParam = (HeaderParameter) params.get(2);
assertEquals(headerParam.getName(), "size");
assertEquals(headerParam.getIn(), "header");
assertEquals(headerParam.getMinimum(), new BigDecimal(1.0));
FormParameter formParam = (FormParameter) params.get(3);
assertEquals(formParam.getName(), "width");
assertEquals(formParam.getIn(), "formData");
assertEquals(formParam.getMaximum(), new BigDecimal(1.0));
assertEquals(params.get(4).getName(), "width");
assertEquals(params.get(4).getIn(), "formData");
QueryParameter queryParam = (QueryParameter) params.get(5);
assertEquals(queryParam.getName(), "height");
assertEquals(queryParam.getIn(), "query");
assertEquals(queryParam.getMinimum(), new BigDecimal(3.0));
assertEquals(queryParam.getMaximum(), new BigDecimal(4.0));
BodyParameter bodyParam = (BodyParameter) params.get(6);
assertEquals(bodyParam.getName(), "body");
assertEquals(bodyParam.getIn(), "body");
assertTrue(bodyParam.getRequired());
}
use of io.swagger.models.parameters.BodyParameter in project swagger-core by swagger-api.
the class ImplicitParametersTest method detailedTest.
@Test
public void detailedTest() throws NoSuchMethodException {
final Operation operation = new Operation();
final ReaderContext context = createDefaultContext();
extension.applyImplicitParameters(context, operation, findMethod(context, "testMethod3"));
final List<Parameter> parameters = operation.getParameters();
final Parameter parameter1 = parameters.get(0);
Assert.assertNotNull(parameter1);
Assert.assertTrue(parameter1 instanceof PathParameter);
Assert.assertEquals(parameter1.getName(), "param1");
Assert.assertEquals(parameter1.getIn(), "path");
Assert.assertEquals(parameter1.getDescription(), "Param 1");
Assert.assertTrue(parameter1.getRequired());
final Parameter parameter5 = parameters.get(4);
Assert.assertNotNull(parameter5);
Assert.assertTrue(parameter5 instanceof BodyParameter);
Assert.assertEquals(parameter5.getName(), "param5");
Assert.assertEquals(parameter5.getIn(), "body");
Assert.assertEquals(parameter5.getDescription(), "Param 5");
Assert.assertFalse(parameter5.getRequired());
}
use of io.swagger.models.parameters.BodyParameter in project java-chassis by ServiceComb.
the class ParamUtils method createBodyParameter.
public static BodyParameter createBodyParameter(Swagger swagger, String paramName, Type paramType) {
addDefinitions(swagger, paramType);
Property property = ModelConverters.getInstance().readAsProperty(paramType);
Model model = PropertyBuilder.toModel(property);
BodyParameter bodyParameter = new BodyParameter();
bodyParameter.setName(paramName);
bodyParameter.setSchema(model);
return bodyParameter;
}
Aggregations