Search in sources :

Example 6 with IntegerProperty

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

the class PropertySerializationTest method deserializeEnumIntegerProperty.

@Test(description = "it should deserialize an IntegerProperty with enums")
public void deserializeEnumIntegerProperty() throws IOException {
    final String json = "{\"type\":\"integer\",\"format\":\"int32\",\"enum\":[1,2]}";
    final Property p = m.readValue(json, Property.class);
    assertEquals(p.getType(), "integer");
    List<Integer> _enum = ((IntegerProperty) p).getEnum();
    assertNotNull(_enum);
    assertEquals(_enum, Arrays.asList(1, 2));
    assertEquals(p.getClass(), IntegerProperty.class);
    assertEquals(m.writeValueAsString(p), json);
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) FileProperty(io.swagger.models.properties.FileProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 7 with IntegerProperty

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

the class PropertySerializationTest method deserializeIntegerProperty.

@Test(description = "it should deserialize a IntegerProperty")
public void deserializeIntegerProperty() throws IOException {
    final String json = "{\"type\":\"integer\",\"format\":\"int32\"}";
    final Property p = m.readValue(json, Property.class);
    assertEquals(p.getType(), "integer");
    assertEquals(p.getFormat(), "int32");
    assertEquals(p.getClass(), IntegerProperty.class);
    assertEquals(m.writeValueAsString(p), json);
}
Also used : DoubleProperty(io.swagger.models.properties.DoubleProperty) MapProperty(io.swagger.models.properties.MapProperty) FloatProperty(io.swagger.models.properties.FloatProperty) DateProperty(io.swagger.models.properties.DateProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) DateTimeProperty(io.swagger.models.properties.DateTimeProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) BooleanProperty(io.swagger.models.properties.BooleanProperty) LongProperty(io.swagger.models.properties.LongProperty) RefProperty(io.swagger.models.properties.RefProperty) FileProperty(io.swagger.models.properties.FileProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 8 with IntegerProperty

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

the class ModelConverterTest method serializeParameterizedType.

@Test(description = "it should serialize a parameterized type per 606")
public void serializeParameterizedType() {
    final Map<String, Model> schemas = readAll(Employee.class);
    final ModelImpl employee = (ModelImpl) schemas.get("employee");
    final Map<String, Property> props = employee.getProperties();
    final Iterator<String> et = props.keySet().iterator();
    final Property id = props.get(et.next());
    assertTrue(id instanceof IntegerProperty);
    final Property firstName = props.get(et.next());
    assertTrue(firstName instanceof StringProperty);
    final Property lastName = props.get(et.next());
    assertTrue(lastName instanceof StringProperty);
    final Property department = props.get(et.next());
    assertTrue(department instanceof RefProperty);
    final Property manager = props.get(et.next());
    assertTrue(manager instanceof RefProperty);
    final Property team = props.get(et.next());
    assertTrue(team instanceof ArrayProperty);
    final ArrayProperty ap = (ArrayProperty) team;
    assertTrue(ap.getUniqueItems());
    assertNotNull(employee.getXml());
    assertEquals(employee.getXml().getName(), "employee");
}
Also used : BaseIntegerProperty(io.swagger.models.properties.BaseIntegerProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) 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) 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) RefProperty(io.swagger.models.properties.RefProperty) Test(org.testng.annotations.Test)

Example 9 with IntegerProperty

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

the class ParameterProcessorTest method parameterProcessorTest.

@Test(description = "parse parameters from method")
public void parameterProcessorTest() throws NoSuchMethodException {
    final Method method = getClass().getDeclaredMethod("parametrizedMethod", String.class, List.class, String.class, String.class, Integer.class);
    final Type[] genericParameterTypes = method.getGenericParameterTypes();
    final Annotation[][] paramAnnotations = method.getParameterAnnotations();
    final PathParameter p1 = (PathParameter) ParameterProcessor.applyAnnotations(null, new PathParameter(), genericParameterTypes[0], Arrays.asList(paramAnnotations[0]));
    assertNotNull(p1);
    assertEquals(p1.getIn(), "path");
    assertEquals(p1.getName(), "paramName1");
    assertEquals(p1.getDescription(), "paramValue1");
    assertEquals(p1.getDefaultValue(), "value1");
    assertTrue(p1.getRequired());
    assertEquals(p1.getEnum(), Arrays.asList("one", "two", "three"));
    assertNull(p1.getAccess());
    final QueryParameter p2 = (QueryParameter) ParameterProcessor.applyAnnotations(null, new QueryParameter().items(new IntegerProperty()), genericParameterTypes[1], Arrays.asList(paramAnnotations[1]));
    assertNotNull(p2);
    final IntegerProperty items = (IntegerProperty) p2.getItems();
    assertNotNull(items);
    assertEquals(p2.getIn(), "query");
    assertEquals(p2.getName(), "paramName2");
    assertNull(p2.getDescription());
    assertEquals((int) items.getDefault(), 10);
    assertFalse(p2.getRequired());
    assertEquals(p2.getAccess(), "test");
    final Parameter p3 = ParameterProcessor.applyAnnotations(null, null, genericParameterTypes[2], Arrays.asList(paramAnnotations[2]));
    assertNull(p3);
    final Parameter p4 = ParameterProcessor.applyAnnotations(null, null, genericParameterTypes[3], Arrays.asList(paramAnnotations[3]));
    assertNull(p4);
    final BodyParameter p5 = (BodyParameter) ParameterProcessor.applyAnnotations(null, null, genericParameterTypes[4], Arrays.asList(paramAnnotations[4]));
    assertNotNull(p5);
    assertEquals(p5.getIn(), "body");
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) Type(java.lang.reflect.Type) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) Method(java.lang.reflect.Method) BodyParameter(io.swagger.models.parameters.BodyParameter) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.testng.annotations.Test)

Example 10 with IntegerProperty

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

the class ParameterProcessorTest method resourceWithParamRangeTest.

@Test
public void resourceWithParamRangeTest() throws NoSuchMethodException {
    final Method method = getClass().getDeclaredMethod("rangedParametrizedMethod", Integer.class, Double.class, Integer.class, Integer.class);
    final Type[] genericParameterTypes = method.getGenericParameterTypes();
    final Annotation[][] paramAnnotations = method.getParameterAnnotations();
    final PathParameter param0 = (PathParameter) ParameterProcessor.applyAnnotations(null, new PathParameter(), genericParameterTypes[0], Arrays.asList(paramAnnotations[0]));
    assertNotNull(param0);
    assertEquals(param0.getDefaultValue(), "5");
    assertEquals(param0.getMinimum(), new BigDecimal(0.0));
    assertEquals(param0.getMaximum(), new BigDecimal(10.0));
    assertEquals(param0.getCollectionFormat(), "multi");
    final PathParameter param1 = (PathParameter) ParameterProcessor.applyAnnotations(null, new PathParameter(), genericParameterTypes[1], Arrays.asList(paramAnnotations[1]));
    assertNotNull(param1);
    assertEquals(param1.getMinimum(), new BigDecimal(0.0));
    assertNull(param1.getMaximum(), null);
    assertTrue(param1.isExclusiveMinimum());
    assertTrue(param1.isExclusiveMaximum());
    final PathParameter param2 = (PathParameter) ParameterProcessor.applyAnnotations(null, new PathParameter(), genericParameterTypes[2], Arrays.asList(paramAnnotations[2]));
    assertNotNull(param2);
    assertNull(param2.getMinimum());
    assertEquals(param2.getMaximum(), new BigDecimal(100.0));
    final PathParameter param3 = (PathParameter) ParameterProcessor.applyAnnotations(null, new PathParameter().items(new IntegerProperty()), genericParameterTypes[3], Arrays.asList(paramAnnotations[3]));
    assertNotNull(param3);
    final IntegerProperty items = (IntegerProperty) param3.getItems();
    assertNotNull(items);
    assertEquals(items.getMinimum(), new BigDecimal(0.0));
    assertEquals(items.getMaximum(), new BigDecimal(5.0));
    assertTrue(items.getExclusiveMinimum());
    assertTrue(items.getExclusiveMaximum());
}
Also used : IntegerProperty(io.swagger.models.properties.IntegerProperty) Type(java.lang.reflect.Type) Method(java.lang.reflect.Method) PathParameter(io.swagger.models.parameters.PathParameter) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

IntegerProperty (io.swagger.models.properties.IntegerProperty)23 Test (org.testng.annotations.Test)20 Property (io.swagger.models.properties.Property)13 StringProperty (io.swagger.models.properties.StringProperty)11 ArrayProperty (io.swagger.models.properties.ArrayProperty)9 DoubleProperty (io.swagger.models.properties.DoubleProperty)9 LongProperty (io.swagger.models.properties.LongProperty)8 RefProperty (io.swagger.models.properties.RefProperty)7 BigDecimal (java.math.BigDecimal)7 FloatProperty (io.swagger.models.properties.FloatProperty)6 PathParameter (io.swagger.models.parameters.PathParameter)5 BooleanProperty (io.swagger.models.properties.BooleanProperty)5 MapProperty (io.swagger.models.properties.MapProperty)5 Model (io.swagger.models.Model)4 ModelImpl (io.swagger.models.ModelImpl)4 Response (io.swagger.models.Response)3 BodyParameter (io.swagger.models.parameters.BodyParameter)3 Parameter (io.swagger.models.parameters.Parameter)3 QueryParameter (io.swagger.models.parameters.QueryParameter)3 DateProperty (io.swagger.models.properties.DateProperty)3