Search in sources :

Example 76 with Property

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

the class ParameterProcessorTest method beanValidationArrayParametrizedMethodTest.

@Test
public void beanValidationArrayParametrizedMethodTest() throws NoSuchMethodException {
    final Method method = getClass().getDeclaredMethod("beanValidationArrayParametrizedMethod", List.class, List.class, List.class, String.class);
    final Type[] genericParameterTypes = method.getGenericParameterTypes();
    final Annotation[][] paramAnnotations = method.getParameterAnnotations();
    //First param - items specified
    HeaderParameter headerParam1 = new HeaderParameter().type(ArrayProperty.TYPE).items(new LongProperty());
    HeaderParameter param1 = (HeaderParameter) ParameterProcessor.applyAnnotations(null, headerParam1, genericParameterTypes[0], Arrays.asList(paramAnnotations[0]));
    assertNotNull(param1);
    assertEquals((int) param1.getMinItems(), 5);
    assertEquals((int) param1.getMaxItems(), 10);
    Property items1 = param1.getItems();
    assertTrue(items1 instanceof LongProperty);
    LongProperty longItems = (LongProperty) items1;
    assertEquals(longItems.getMinimum(), new BigDecimal(5));
    assertNull(longItems.getExclusiveMinimum());
    assertEquals(longItems.getMaximum(), new BigDecimal(10));
    assertNull(longItems.getExclusiveMaximum());
    //Second param - items specified
    HeaderParameter headerParam2 = new HeaderParameter().type(ArrayProperty.TYPE).items(new DoubleProperty());
    HeaderParameter param2 = (HeaderParameter) ParameterProcessor.applyAnnotations(null, headerParam2, genericParameterTypes[1], Arrays.asList(paramAnnotations[1]));
    assertNotNull(param2);
    assertEquals((int) param2.getMinItems(), 5);
    assertEquals((int) param2.getMaxItems(), 10);
    Property items2 = param2.getItems();
    assertTrue(items2 instanceof DoubleProperty);
    DoubleProperty doubleItems = (DoubleProperty) items2;
    assertEquals(doubleItems.getMinimum(), new BigDecimal(5.5));
    assertTrue(doubleItems.getExclusiveMinimum());
    assertEquals(doubleItems.getMaximum(), new BigDecimal(10.5));
    assertTrue(doubleItems.getExclusiveMaximum());
    //Third param - items specified
    HeaderParameter headerParam3 = new HeaderParameter().type(ArrayProperty.TYPE).items(new StringProperty());
    HeaderParameter param3 = (HeaderParameter) ParameterProcessor.applyAnnotations(null, headerParam3, genericParameterTypes[2], Arrays.asList(paramAnnotations[2]));
    assertNotNull(param3);
    assertEquals((int) param3.getMinItems(), 5);
    assertEquals((int) param3.getMaxItems(), 10);
    Property items3 = param3.getItems();
    assertTrue(items3 instanceof StringProperty);
    StringProperty stringItems = (StringProperty) items3;
    assertEquals(stringItems.getPattern(), TEST_PATTERN_REGXP);
    //Fourth param - items specified
    HeaderParameter headerParam4 = new HeaderParameter().type(StringProperty.TYPE);
    HeaderParameter param4 = (HeaderParameter) ParameterProcessor.applyAnnotations(null, headerParam4, genericParameterTypes[3], Arrays.asList(paramAnnotations[3]));
    assertNotNull(param4);
    assertEquals(param4.getType(), ArrayProperty.TYPE);
    assertEquals((int) param4.getMinItems(), 5);
    assertEquals((int) param4.getMaxItems(), 10);
    Property items4 = param4.getItems();
    assertTrue(items4 instanceof StringProperty);
}
Also used : Type(java.lang.reflect.Type) LongProperty(io.swagger.models.properties.LongProperty) StringProperty(io.swagger.models.properties.StringProperty) Method(java.lang.reflect.Method) HeaderParameter(io.swagger.models.parameters.HeaderParameter) DoubleProperty(io.swagger.models.properties.DoubleProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 77 with Property

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

the class ModelConverterTest method scanModelWithOffset.

@Test(description = "it tests a model with java offset")
public void scanModelWithOffset() throws IOException {
    final Map<String, Model> models = readAll(ModelWithOffset.class);
    assertEquals(models.size(), 1);
    final Model model = models.get("ModelWithOffset");
    Property property = model.getProperties().get("offset");
    assertEquals(property.getType(), "string");
    assertEquals(property.getFormat(), "date-time");
}
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) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) BaseIntegerProperty(io.swagger.models.properties.BaseIntegerProperty) ModelWithUrlProperty(io.swagger.models.composition.ModelWithUrlProperty) RefProperty(io.swagger.models.properties.RefProperty) FloatProperty(io.swagger.models.properties.FloatProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) Test(org.testng.annotations.Test)

Example 78 with Property

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

the class ModelConverterTest method setReadOnly.

@Test(description = "it should set readOnly per #854")
public void setReadOnly() {
    final Map<String, Model> schemas = readAll(JacksonReadonlyModel.class);
    final ModelImpl model = (ModelImpl) schemas.get("JacksonReadonlyModel");
    final Property prop = model.getProperties().get("count");
    assertTrue(prop.getReadOnly());
}
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) ModelImpl(io.swagger.models.ModelImpl) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) BaseIntegerProperty(io.swagger.models.properties.BaseIntegerProperty) ModelWithUrlProperty(io.swagger.models.composition.ModelWithUrlProperty) RefProperty(io.swagger.models.properties.RefProperty) FloatProperty(io.swagger.models.properties.FloatProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) Test(org.testng.annotations.Test)

Example 79 with Property

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

the class ModelConverterTest method processModelWithPairProperties.

@Test(description = "it should process a model with org.apache.commons.lang3.tuple.Pair properties")
public void processModelWithPairProperties() {
    final ModelWithTuple2.TupleAsMapModelConverter asMapConverter = new ModelWithTuple2.TupleAsMapModelConverter(Json.mapper());
    ModelConverters.getInstance().addConverter(asMapConverter);
    final Map<String, Model> asMap = readAll(ModelWithTuple2.class);
    ModelConverters.getInstance().removeConverter(asMapConverter);
    assertEquals(asMap.size(), 4);
    for (String item : Arrays.asList("MapOfString", "MapOfComplexLeft")) {
        ModelImpl model = (ModelImpl) asMap.get(item);
        assertEquals(model.getType(), "object");
        assertNull(model.getProperties());
        assertNotNull(model.getAdditionalProperties());
    }
    final ModelWithTuple2.TupleAsMapPropertyConverter asPropertyConverter = new ModelWithTuple2.TupleAsMapPropertyConverter(Json.mapper());
    ModelConverters.getInstance().addConverter(asPropertyConverter);
    final Map<String, Model> asProperty = readAll(ModelWithTuple2.class);
    ModelConverters.getInstance().removeConverter(asPropertyConverter);
    assertEquals(asProperty.size(), 2);
    for (Map.Entry<String, Property> entry : asProperty.get("ModelWithTuple2").getProperties().entrySet()) {
        String name = entry.getKey();
        Property property = entry.getValue();
        if ("timesheetStates".equals(name)) {
            assertEquals(property.getClass(), MapProperty.class);
        } else if ("manyPairs".equals(name)) {
            assertEquals(property.getClass(), ArrayProperty.class);
            Property items = ((ArrayProperty) property).getItems();
            assertNotNull(items);
            assertEquals(items.getClass(), MapProperty.class);
            Property stringProperty = ((MapProperty) items).getAdditionalProperties();
            assertNotNull(stringProperty);
            assertEquals(stringProperty.getClass(), StringProperty.class);
        } else if ("complexLeft".equals(name)) {
            assertEquals(property.getClass(), ArrayProperty.class);
            Property items = ((ArrayProperty) property).getItems();
            assertNotNull(items);
            assertEquals(items.getClass(), MapProperty.class);
            Property additionalProperty = ((MapProperty) items).getAdditionalProperties();
            assertNotNull(additionalProperty);
            assertEquals(additionalProperty.getClass(), RefProperty.class);
            assertEquals(((RefProperty) additionalProperty).getSimpleRef(), "ComplexLeft");
        } else {
            fail(String.format("Unexpected property: %s", name));
        }
    }
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) ModelWithTuple2(io.swagger.models.ModelWithTuple2) MapProperty(io.swagger.models.properties.MapProperty) StringProperty(io.swagger.models.properties.StringProperty) 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) ModelImpl(io.swagger.models.ModelImpl) Map(java.util.Map) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) BaseIntegerProperty(io.swagger.models.properties.BaseIntegerProperty) ModelWithUrlProperty(io.swagger.models.composition.ModelWithUrlProperty) RefProperty(io.swagger.models.properties.RefProperty) FloatProperty(io.swagger.models.properties.FloatProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) Test(org.testng.annotations.Test)

Example 80 with Property

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

the class ModelConverterTest method checkModel.

private void checkModel(Model model) {
    for (Map.Entry<String, Property> entry : model.getProperties().entrySet()) {
        final String name = entry.getKey();
        final Property property = entry.getValue();
        if (Arrays.asList("shortPrimitive", "shortObject", "intPrimitive", "intObject").contains(name)) {
            checkType(property, IntegerProperty.class, "integer", "int32");
        } else if (Arrays.asList("longPrimitive", "longObject").contains(name)) {
            checkType(property, LongProperty.class, "integer", "int64");
        } else if (Arrays.asList("floatPrimitive", "floatObject").contains(name)) {
            checkType(property, FloatProperty.class, "number", "float");
        } else if (Arrays.asList("doublePrimitive", "doubleObject").contains(name)) {
            checkType(property, DoubleProperty.class, "number", "double");
        } else if ("bigInteger".equals(name)) {
            checkType(property, BaseIntegerProperty.class, "integer", null);
        } else if ("bigDecimal".equals(name)) {
            checkType(property, DecimalProperty.class, "number", null);
        } else {
            fail(String.format("Unexpected property: %s", name));
        }
    }
}
Also used : LongProperty(io.swagger.models.properties.LongProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) Map(java.util.Map) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) LongProperty(io.swagger.models.properties.LongProperty) DecimalProperty(io.swagger.models.properties.DecimalProperty) Property(io.swagger.models.properties.Property) DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) BaseIntegerProperty(io.swagger.models.properties.BaseIntegerProperty) ModelWithUrlProperty(io.swagger.models.composition.ModelWithUrlProperty) RefProperty(io.swagger.models.properties.RefProperty) FloatProperty(io.swagger.models.properties.FloatProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty)

Aggregations

Property (io.swagger.models.properties.Property)145 Test (org.testng.annotations.Test)96 ArrayProperty (io.swagger.models.properties.ArrayProperty)86 StringProperty (io.swagger.models.properties.StringProperty)75 RefProperty (io.swagger.models.properties.RefProperty)65 MapProperty (io.swagger.models.properties.MapProperty)59 Model (io.swagger.models.Model)52 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)17 Response (io.swagger.models.Response)16