Search in sources :

Example 6 with Property

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

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

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

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

the class SpecFilter method locateReferencedDefinitions.

private void locateReferencedDefinitions(Map<String, Property> props, Set<String> nestedReferencedDefinitions, Swagger swagger) {
    if (props == null)
        return;
    for (String keyProp : props.keySet()) {
        Property p = props.get(keyProp);
        String ref = getPropertyRef(p);
        if (ref != null) {
            locateReferencedDefinitions(ref, nestedReferencedDefinitions, swagger);
        }
    }
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty)

Example 10 with Property

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

the class ServletReaderExtension method parseResponseHeaders.

private static Map<String, Property> parseResponseHeaders(ReaderContext context, ResponseHeader[] headers) {
    Map<String, Property> responseHeaders = null;
    for (ResponseHeader header : headers) {
        final String name = header.name();
        if (StringUtils.isNotEmpty(name)) {
            if (responseHeaders == null) {
                responseHeaders = new HashMap<String, Property>();
            }
            final Class<?> cls = header.response();
            if (!ReflectionUtils.isVoid(cls)) {
                final Property property = ModelConverters.getInstance().readAsProperty(cls);
                if (property != null) {
                    final Property responseProperty = ContainerWrapper.wrapContainer(header.responseContainer(), property, ContainerWrapper.ARRAY, ContainerWrapper.LIST, ContainerWrapper.SET);
                    responseProperty.setDescription(header.description());
                    responseHeaders.put(name, responseProperty);
                    appendModels(context.getSwagger(), cls);
                }
            }
        }
    }
    return responseHeaders;
}
Also used : ResponseHeader(io.swagger.annotations.ResponseHeader) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty) RefProperty(io.swagger.models.properties.RefProperty)

Aggregations

Property (io.swagger.models.properties.Property)143 Test (org.testng.annotations.Test)96 ArrayProperty (io.swagger.models.properties.ArrayProperty)85 StringProperty (io.swagger.models.properties.StringProperty)73 RefProperty (io.swagger.models.properties.RefProperty)64 MapProperty (io.swagger.models.properties.MapProperty)59 Model (io.swagger.models.Model)51 IntegerProperty (io.swagger.models.properties.IntegerProperty)48 LongProperty (io.swagger.models.properties.LongProperty)35 DoubleProperty (io.swagger.models.properties.DoubleProperty)32 FloatProperty (io.swagger.models.properties.FloatProperty)27 BooleanProperty (io.swagger.models.properties.BooleanProperty)25 ObjectProperty (io.swagger.models.properties.ObjectProperty)25 Operation (io.swagger.models.Operation)24 DateTimeProperty (io.swagger.models.properties.DateTimeProperty)23 DateProperty (io.swagger.models.properties.DateProperty)22 ApiModelProperty (io.swagger.annotations.ApiModelProperty)20 FileProperty (io.swagger.models.properties.FileProperty)18 ModelImpl (io.swagger.models.ModelImpl)16 Response (io.swagger.models.Response)16