Search in sources :

Example 6 with BodyParameter

use of io.swagger.models.parameters.BodyParameter in project swagger-core by swagger-api.

the class PostParamTest method findAPostOperationWithObjectsArray.

@Test(description = "find a Post operation with an array of objects")
public void findAPostOperationWithObjectsArray() {
    Path petPath = getPath("arrayOfObjects");
    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);
}
Also used : Path(io.swagger.models.Path) Model(io.swagger.models.Model) ArrayModel(io.swagger.models.ArrayModel) Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter) ArrayModel(io.swagger.models.ArrayModel) StringProperty(io.swagger.models.properties.StringProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 7 with BodyParameter

use of io.swagger.models.parameters.BodyParameter in project swagger-core by swagger-api.

the class PostParamTest method findPostOperationWithObjectsList.

@Test(description = "find a Post operation with list of objects")
public void findPostOperationWithObjectsList() {
    Path petPath = getPath("listOfObjects");
    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);
}
Also used : Path(io.swagger.models.Path) Model(io.swagger.models.Model) ArrayModel(io.swagger.models.ArrayModel) Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter) ArrayModel(io.swagger.models.ArrayModel) StringProperty(io.swagger.models.properties.StringProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 8 with BodyParameter

use of io.swagger.models.parameters.BodyParameter in project swagger-core by swagger-api.

the class PostParamTest method findPostOperationWithSingleObject.

@Test(description = "find a Post operation with single object")
public void findPostOperationWithSingleObject() {
    Path petPath = getPath("singleObject");
    assertNotNull(petPath);
    assertNull(petPath.getGet());
    Operation petPost = petPath.getPost();
    assertNotNull(petPost);
    assertEquals(petPost.getParameters().size(), 1);
    BodyParameter petPostBodyParam = (BodyParameter) petPost.getParameters().get(0);
    assertEquals(petPostBodyParam.getName(), BODY);
    assertTrue(petPostBodyParam.getSchema() instanceof Model);
    assertEquals(swagger.getDefinitions().get(PET).getProperties().get("status").getAccess(), "public");
}
Also used : Path(io.swagger.models.Path) Model(io.swagger.models.Model) ArrayModel(io.swagger.models.ArrayModel) Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.testng.annotations.Test)

Example 9 with BodyParameter

use of io.swagger.models.parameters.BodyParameter in project swagger-core by swagger-api.

the class ChildTypeTest method testChildTypeParameter.

@Test(description = "Tests schema ref is correctly set up for child type parameter")
public void testChildTypeParameter() {
    Operation op = swagger.getPath("/childType/testChildTypeParameter").getPost();
    BodyParameter parameter = getBodyParameter(op, 0);
    Model schema = parameter.getSchema();
    assertEquals(schema.getClass().getName(), RefModel.class.getName());
    assertEquals(((RefModel) schema).getSimpleRef(), "Sub1Bean");
}
Also used : RefModel(io.swagger.models.RefModel) RefModel(io.swagger.models.RefModel) Model(io.swagger.models.Model) Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter) Test(org.testng.annotations.Test)

Example 10 with BodyParameter

use of io.swagger.models.parameters.BodyParameter in project swagger-core by swagger-api.

the class GenericsTest method check2DArrayAsBodyParameter.

@Test(description = "check 2D array as body parameter")
public void check2DArrayAsBodyParameter() {
    Operation op = getOperation("test2DInBody");
    assertEquals(op.getParameters().size(), 1);
    BodyParameter p = getBodyParameter(op, 0);
    ArrayModel ddArray = (ArrayModel) p.getSchema();
    assertEquals(((RefProperty) ((ArrayProperty) ddArray.getItems()).getItems()).getSimpleRef(), "Tag");
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) Operation(io.swagger.models.Operation) BodyParameter(io.swagger.models.parameters.BodyParameter) ArrayModel(io.swagger.models.ArrayModel) Test(org.testng.annotations.Test)

Aggregations

BodyParameter (io.swagger.models.parameters.BodyParameter)45 Test (org.testng.annotations.Test)34 Operation (io.swagger.models.Operation)20 Parameter (io.swagger.models.parameters.Parameter)16 ArrayModel (io.swagger.models.ArrayModel)15 Model (io.swagger.models.Model)14 PathParameter (io.swagger.models.parameters.PathParameter)14 Path (io.swagger.models.Path)13 QueryParameter (io.swagger.models.parameters.QueryParameter)13 StringProperty (io.swagger.models.properties.StringProperty)12 Swagger (io.swagger.models.Swagger)11 RefProperty (io.swagger.models.properties.RefProperty)11 Property (io.swagger.models.properties.Property)10 RefModel (io.swagger.models.RefModel)7 HeaderParameter (io.swagger.models.parameters.HeaderParameter)7 ModelImpl (io.swagger.models.ModelImpl)6 SerializableParameter (io.swagger.models.parameters.SerializableParameter)6 ArrayProperty (io.swagger.models.properties.ArrayProperty)5 PendingBodyParameter (io.servicecomb.swagger.extend.parameter.PendingBodyParameter)4 Response (io.swagger.models.Response)4