Search in sources :

Example 71 with Model

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

the class ByteConverterTest method testDeserializeByteProperty.

@Test
public void testDeserializeByteProperty() throws Exception {
    String json = "{\n" + "  \"properties\" : {\n" + "    \"byteProperty\" : {\n" + "      \"type\" : \"string\",\n" + "      \"format\" : \"byte\"\n" + "    }\n" + "  }\n" + "}";
    Model model = Json.mapper().readValue(json, Model.class);
    assertNotNull(model);
}
Also used : Model(io.swagger.models.Model) Test(org.testng.annotations.Test)

Example 72 with Model

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

the class ByteConverterTest method testByteArray.

@Test
public void testByteArray() {
    Model model = new ModelImpl().property("byteArray", new ArrayProperty(new BinaryProperty()));
    assertEquals(Json.pretty(model), "{" + NEWLINE + "  \"properties\" : {" + NEWLINE + "    \"byteArray\" : {" + NEWLINE + "      \"type\" : \"array\"," + NEWLINE + "      \"items\" : {" + NEWLINE + "        \"type\" : \"string\"," + NEWLINE + "        \"format\" : \"binary\"" + NEWLINE + "      }" + NEWLINE + "    }" + NEWLINE + "  }" + NEWLINE + "}");
}
Also used : ByteArrayProperty(io.swagger.models.properties.ByteArrayProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Model(io.swagger.models.Model) BinaryProperty(io.swagger.models.properties.BinaryProperty) ModelImpl(io.swagger.models.ModelImpl) Test(org.testng.annotations.Test)

Example 73 with Model

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

the class ModelConverterTest method scanModelWithNumbers.

@Test(description = "it should scan a model with numbers")
public void scanModelWithNumbers() throws IOException {
    final Map<String, Model> models = readAll(ModelWithNumbers.class);
    assertEquals(models.size(), 1);
    final Model model = models.get("ModelWithNumbers");
    // Check if we get required properties after building models from classes.
    checkModel(model);
    // Check if we get required properties after deserialization from JSON
    checkModel(Json.mapper().readValue(Json.pretty(model), Model.class));
}
Also used : AbstractModelWithApiModel(io.swagger.models.composition.AbstractModelWithApiModel) Model(io.swagger.models.Model) ModelWithApiModel(io.swagger.models.ModelWithApiModel) EmptyModel(io.swagger.models.EmptyModel) JodaDateTimeModel(io.swagger.models.JodaDateTimeModel) JacksonReadonlyModel(io.swagger.models.JacksonReadonlyModel) Test(org.testng.annotations.Test)

Example 74 with Model

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

the class RequiredFieldModelTest method testApiModelPropertyFirstPosition.

@Test(description = "it should apply read only flag when ApiProperty annotation first")
public void testApiModelPropertyFirstPosition() {
    final Map<String, Model> models = ModelConverters.getInstance().readAll(ApiFirstRequiredFieldModel.class);
    final Model model = models.get("aaa");
    final Property prop = model.getProperties().get("a");
    assertTrue(prop.getRequired());
}
Also used : ApiFirstRequiredFieldModel(io.swagger.models.ApiFirstRequiredFieldModel) XmlFirstRequiredFieldModel(io.swagger.models.XmlFirstRequiredFieldModel) Model(io.swagger.models.Model) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 75 with Model

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

the class RequiredFieldModelTest method testApiModelPropertySecondPosition.

@Test(description = "it should apply read only flag when XmlElement annotation first")
public void testApiModelPropertySecondPosition() {
    final Map<String, Model> models = ModelConverters.getInstance().readAll(XmlFirstRequiredFieldModel.class);
    final Model model = models.get("aaa");
    final Property prop = model.getProperties().get("a");
    assertTrue(prop.getRequired());
}
Also used : ApiFirstRequiredFieldModel(io.swagger.models.ApiFirstRequiredFieldModel) XmlFirstRequiredFieldModel(io.swagger.models.XmlFirstRequiredFieldModel) Model(io.swagger.models.Model) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Aggregations

Model (io.swagger.models.Model)108 Test (org.testng.annotations.Test)90 Property (io.swagger.models.properties.Property)52 StringProperty (io.swagger.models.properties.StringProperty)34 ArrayModel (io.swagger.models.ArrayModel)30 ArrayProperty (io.swagger.models.properties.ArrayProperty)27 ModelImpl (io.swagger.models.ModelImpl)24 RefProperty (io.swagger.models.properties.RefProperty)23 RefModel (io.swagger.models.RefModel)20 ApiModelProperty (io.swagger.annotations.ApiModelProperty)19 ApiModel (io.swagger.annotations.ApiModel)16 BodyParameter (io.swagger.models.parameters.BodyParameter)15 IntegerProperty (io.swagger.models.properties.IntegerProperty)15 Operation (io.swagger.models.Operation)14 MapProperty (io.swagger.models.properties.MapProperty)14 Path (io.swagger.models.Path)13 LongProperty (io.swagger.models.properties.LongProperty)13 ComposedModel (io.swagger.models.ComposedModel)12 EmptyModel (io.swagger.models.EmptyModel)12 JacksonReadonlyModel (io.swagger.models.JacksonReadonlyModel)12