Search in sources :

Example 6 with StringProperty

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

the class HiddenFieldTest method testHiddenField.

@Test(description = "it should ignore a hidden field")
public void testHiddenField() {
    final Map<String, Model> models = ModelConverters.getInstance().read(ModelWithHiddenFields.class);
    final Model model = models.get("ModelWithHiddenFields");
    assertNotNull(model);
    assertEquals(model.getProperties().size(), 2);
    final Property idValue = model.getProperties().get("id");
    assertTrue(idValue instanceof LongProperty);
    assertTrue(idValue.getRequired());
    final Property nameValue = model.getProperties().get("name");
    assertTrue(nameValue instanceof StringProperty);
}
Also used : LongProperty(io.swagger.models.properties.LongProperty) Model(io.swagger.models.Model) StringProperty(io.swagger.models.properties.StringProperty) StringProperty(io.swagger.models.properties.StringProperty) LongProperty(io.swagger.models.properties.LongProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 7 with StringProperty

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

the class JodaDateTimeConverterTest method testJodaDateTime.

@Test
public void testJodaDateTime() {
    final Map<String, Model> models = ModelConverters.getInstance().read(ModelWithJodaDateTime.class);
    // don't create a Joda DateTime object
    assertEquals(models.size(), 1);
    final Model model = models.get("ModelWithJodaDateTime");
    final Property dateTimeProperty = model.getProperties().get("createdAt");
    assertTrue(dateTimeProperty instanceof DateTimeProperty);
    assertEquals((int) dateTimeProperty.getPosition(), 1);
    assertTrue(dateTimeProperty.getRequired());
    assertEquals(dateTimeProperty.getDescription(), "creation timestamp");
    final Property nameProperty = model.getProperties().get("name");
    assertTrue(nameProperty instanceof StringProperty);
    assertEquals((int) nameProperty.getPosition(), 2);
    assertEquals(nameProperty.getDescription(), "name of the model");
}
Also used : DateTimeProperty(io.swagger.models.properties.DateTimeProperty) Model(io.swagger.models.Model) StringProperty(io.swagger.models.properties.StringProperty) StringProperty(io.swagger.models.properties.StringProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 8 with StringProperty

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

the class JodaLocalDateConverterTest method testJodaLocalDate.

@Test
public void testJodaLocalDate() {
    final Map<String, Model> models = ModelConverters.getInstance().read(ModelWithJodaLocalDate.class);
    assertEquals(models.size(), 1);
    final Model model = models.get("ModelWithJodaLocalDate");
    final Property dateTimeProperty = model.getProperties().get("createdAt");
    assertTrue(dateTimeProperty instanceof DateProperty);
    assertEquals((int) dateTimeProperty.getPosition(), 1);
    assertTrue(dateTimeProperty.getRequired());
    assertEquals(dateTimeProperty.getDescription(), "creation localDate");
    final Property nameProperty = model.getProperties().get("name");
    assertTrue(nameProperty instanceof StringProperty);
    assertEquals((int) nameProperty.getPosition(), 2);
    assertEquals(nameProperty.getDescription(), "name of the model");
}
Also used : DateProperty(io.swagger.models.properties.DateProperty) Model(io.swagger.models.Model) StringProperty(io.swagger.models.properties.StringProperty) DateProperty(io.swagger.models.properties.DateProperty) StringProperty(io.swagger.models.properties.StringProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 9 with StringProperty

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

the class AbstractSerializableParameterTest method testGettersAndSetters.

/*
     * Tests getters and setters methods on {@link
     * AbstractSerializableParameter} It was not possible to cove it with {@link
     * io.swagger.PojosTest} so a manual implementation is provided for now TODO
     * improve PojosTest to test getters and setters for abstracts classes
     */
@Test
public void testGettersAndSetters() {
    // given
    String type = "type";
    // when
    instance.setType(type);
    // then
    assertEquals(instance.getType(), type, "The get type must be the same as the set one");
    // given
    String format = "format";
    // when
    instance.setFormat(format);
    // then
    assertEquals(instance.getFormat(), format, "The get format must be the same as the set one");
    // given
    String collectionFormat = "collectionFormat";
    // when
    instance.setCollectionFormat(collectionFormat);
    // then
    assertEquals(instance.getCollectionFormat(), collectionFormat, "The get collectionFormat must be the same as the set one");
    // given
    Property items = new BooleanProperty();
    // when
    instance.setItems(items);
    // then
    assertEquals(instance.getItems(), items, "The get items must be the same as the set one");
    // given
    List<String> _enum = Arrays.asList("_enum");
    // when
    instance._enum(_enum);
    instance.setEnum(_enum);
    // then
    assertEquals(instance.getEnum(), _enum, "The get _enum must be the same as the set one");
    // given
    Boolean exclusiveMaximum = true;
    // when
    instance.setExclusiveMaximum(exclusiveMaximum);
    // then
    assertEquals(instance.isExclusiveMaximum(), exclusiveMaximum, "The get exclusiveMaximum must be the same as the set one");
    // given
    Double maximum = 1.0;
    // when
    instance.setMaximum(new BigDecimal(maximum));
    // then
    assertEquals(instance.getMaximum(), new BigDecimal(maximum), "The get maximum must be the same as the set one");
    // given
    Boolean exclusiveMinimum = true;
    // when
    instance.setExclusiveMinimum(exclusiveMinimum);
    // then
    assertEquals(instance.isExclusiveMinimum(), exclusiveMinimum, "The get exclusiveMinimum must be the same as the set one");
    // given
    Double minimum = 0.1;
    // when
    instance.setMinimum(new BigDecimal(minimum));
    // then
    assertEquals(instance.getMinimum(), new BigDecimal(minimum), "The get minimum must be the same as the set one");
    // given
    String example = "example";
    // when
    instance.setExample(example);
    // then
    assertEquals(instance.getExample(), example, "The get example must be the same as the set one");
    // given
    Integer maxItems = 100;
    // when
    instance.setMaxItems(maxItems);
    // then
    assertEquals(instance.getMaxItems(), maxItems, "The get maxItems must be the same as the set one");
    // given
    Integer minItems = 10;
    // when
    instance.setMinItems(minItems);
    // then
    assertEquals(instance.getMinItems(), minItems, "The get minItems must be the same as the set one");
    // given
    Integer maxLength = 500;
    // when
    instance.setMaxLength(maxLength);
    // then
    assertEquals(instance.getMaxLength(), maxLength, "The get maxLength must be the same as the set one");
    // given
    Integer minLength = 25;
    // when
    instance.setMinLength(minLength);
    // then
    assertEquals(instance.getMinLength(), minLength, "The get minLength must be the same as the set one");
    // given
    String pattern = "String pattern";
    // when
    instance.setPattern(pattern);
    // then
    assertEquals(instance.getPattern(), pattern, "The get pattern must be the same as the set one");
    // given
    Boolean uniqueItems = true;
    // when
    instance.setUniqueItems(uniqueItems);
    // then
    assertEquals(instance.isUniqueItems(), uniqueItems, "The get uniqueItems must be the same as the set one");
    // given
    Number multipleOf = 5;
    // when
    instance.setMultipleOf(multipleOf);
    // then
    assertEquals(instance.getMultipleOf(), multipleOf, "The get multipleOf must be the same as the set one");
    // given
    String defaultValue = "defaultValue";
    // when
    instance.setDefaultValue(defaultValue);
    // then
    assertEquals(instance.getDefaultValue(), defaultValue, "The get defaultValue must be the same as the set one");
    // when
    instance.required(true);
    // then
    assertTrue(instance.getRequired(), "The get required must be the same as the set one");
    // given
    StringProperty property = new StringProperty();
    property._enum(_enum);
    // when
    instance.property(property);
    // then
    assertEquals(instance.getEnum(), _enum, "The get _enum must be the same as the set one");
    assertEquals(instance.getType(), property.getType(), "The get type must be the same as the set property type");
    // given
    ArrayProperty arrayProperty = new ArrayProperty();
    // when
    arrayProperty.items(items);
    instance.property(arrayProperty);
    // then
    assertEquals(instance.getItems(), items, "The get items must be the same as the set one");
    assertEquals(instance.getType(), arrayProperty.getType(), "The get type must be the same as the set property type");
    assertEquals(instance.getDefaultCollectionFormat(), "csv", "The get collection format must be csv");
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) StringProperty(io.swagger.models.properties.StringProperty) BaseIntegerProperty(io.swagger.models.properties.BaseIntegerProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 10 with StringProperty

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

Aggregations

StringProperty (io.swagger.models.properties.StringProperty)60 Test (org.testng.annotations.Test)47 Property (io.swagger.models.properties.Property)29 ArrayProperty (io.swagger.models.properties.ArrayProperty)21 Model (io.swagger.models.Model)20 IntegerProperty (io.swagger.models.properties.IntegerProperty)16 LongProperty (io.swagger.models.properties.LongProperty)16 RefProperty (io.swagger.models.properties.RefProperty)16 DoubleProperty (io.swagger.models.properties.DoubleProperty)14 ModelImpl (io.swagger.models.ModelImpl)9 FloatProperty (io.swagger.models.properties.FloatProperty)9 BooleanProperty (io.swagger.models.properties.BooleanProperty)8 ApiModelProperty (io.swagger.annotations.ApiModelProperty)7 BodyParameter (io.swagger.models.parameters.BodyParameter)7 MapProperty (io.swagger.models.properties.MapProperty)7 Operation (io.swagger.models.Operation)6 Path (io.swagger.models.Path)6 PathParameter (io.swagger.models.parameters.PathParameter)6 ObjectProperty (io.swagger.models.properties.ObjectProperty)6 QueryParameter (io.swagger.models.parameters.QueryParameter)5