Search in sources :

Example 1 with ArrayModel

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

the class ModelSerializerTest method deserializeArrayModel.

@Test(description = "it should deserialize an array model")
public void deserializeArrayModel() throws IOException {
    final String json = "{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/Pet\"}}";
    final Model p = m.readValue(json, Model.class);
    assertTrue(p instanceof ArrayModel);
    assertEquals(m.writeValueAsString(p), json);
}
Also used : Model(io.swagger.models.Model) RefModel(io.swagger.models.RefModel) ArrayModel(io.swagger.models.ArrayModel) ArrayModel(io.swagger.models.ArrayModel) Test(org.testng.annotations.Test)

Example 2 with ArrayModel

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

the class PropertyBuilderTest method testToModelWithArrayProperty.

@Test
public void testToModelWithArrayProperty() {
    // given
    EmailProperty emailProperty = new EmailProperty();
    ArrayProperty arrayProperty = new ArrayProperty();
    arrayProperty.setItems(emailProperty);
    // when
    Model model = PropertyBuilder.toModel(arrayProperty);
    // then
    assertEquals(((ArrayModel) model).getItems(), emailProperty, "Must contain the items value passed into the property");
}
Also used : Model(io.swagger.models.Model) ArrayModel(io.swagger.models.ArrayModel) Test(org.testng.annotations.Test)

Example 3 with ArrayModel

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

the class PostParamTest method findAPostOperationWithStringsArray.

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

Example 4 with ArrayModel

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

the class PostParamTest method findAPostOperationWithStringsCollection.

@Test(description = "find a Post operation with collection of strings")
public void findAPostOperationWithStringsCollection() {
    Path petPath = getPath("collectionOfStrings");
    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);
}
Also used : Path(io.swagger.models.Path) Model(io.swagger.models.Model) ArrayModel(io.swagger.models.ArrayModel) StringProperty(io.swagger.models.properties.StringProperty) 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) Test(org.testng.annotations.Test)

Example 5 with ArrayModel

use of io.swagger.models.ArrayModel 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)

Aggregations

ArrayModel (io.swagger.models.ArrayModel)27 Test (org.testng.annotations.Test)21 Model (io.swagger.models.Model)17 BodyParameter (io.swagger.models.parameters.BodyParameter)17 Operation (io.swagger.models.Operation)15 RefProperty (io.swagger.models.properties.RefProperty)14 Property (io.swagger.models.properties.Property)10 Path (io.swagger.models.Path)9 RefModel (io.swagger.models.RefModel)9 StringProperty (io.swagger.models.properties.StringProperty)9 Swagger (io.swagger.models.Swagger)7 ArrayProperty (io.swagger.models.properties.ArrayProperty)6 ComposedModel (io.swagger.models.ComposedModel)4 ModelImpl (io.swagger.models.ModelImpl)4 SwaggerDeserializationResult (io.swagger.parser.util.SwaggerDeserializationResult)4 Response (io.swagger.models.Response)3 ApiOperation (io.swagger.annotations.ApiOperation)2 FormParameter (io.swagger.models.parameters.FormParameter)2 HeaderParameter (io.swagger.models.parameters.HeaderParameter)2 Parameter (io.swagger.models.parameters.Parameter)2