@Override public Schema createProperty() { return new IntegerSchema().format("int64"); } },
@Test(description = "it should serialize a LongProperty") public void serializeLongProperty() throws IOException { final IntegerSchema p = new IntegerSchema() .format("int64") ._default(8675309); final String json = "{\"type\":\"integer\",\"format\":\"int64\",\"default\":8675309}"; assertEquals(m.writeValueAsString(p), json); }
@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 Schema p = m.readValue(json, Schema.class); assertEquals(p.getType(), "integer"); List<Number> _enum = ((IntegerSchema) p).getEnum(); assertNotNull(_enum); assertEquals(_enum, Arrays.asList(1, 2)); assertEquals(p.getClass(), IntegerSchema.class); assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should serialize an IntegerProperty") public void serializeIntegerProperty() throws IOException { final IntegerSchema p = new IntegerSchema() ._default(32); final String json = "{\"type\":\"integer\",\"format\":\"int32\",\"default\":32}"; assertEquals(m.writeValueAsString(p), json); }
@Override protected Schema processAsProperty(String propertyName, AnnotatedType type, ModelConverterContext context, ObjectMapper mapper) { Schema id = new IntegerSchema(); return process(id, propertyName, type, context); }
@Test(description = "it should create a model") public void createModel() { ObjectSchema model = new ObjectSchema(); model.addProperties("name", new StringSchema().example("Tony")); model.addProperties("id", new IntegerSchema().example(123)); assertNotNull(model); }
@Test(description = "convert a model with Guava optionals") public void convertModelWithGuavaOptionals() { final Map<String, Schema> schemas = ModelConverters.getInstance().read(ModelWithJaxBDefaultValues.class); final Map<String, Schema> properties = schemas.get("ModelWithJaxBDefaultValues").getProperties(); assertEquals(properties.size(), 2); assertEquals(((StringSchema) properties.get("name")).getDefault(), "Tony"); assertEquals((int) ((IntegerSchema) properties.get("age")).getDefault(), 100); } }
break; case "integer": IntegerSchema integerSchema = new IntegerSchema(); integerSchema.setMinimum(queryParameter.getSchema().getMinimum()); integerSchema.setMaximum(queryParameter.getSchema().getMaximum()); property = integerSchema; break;
@Override public IntegerSchema createProperty() { return new IntegerSchema(); } },
@Test(description = "it should create a model with example") public void createModelWithExample() { ObjectSchema model = new ObjectSchema(); model.addProperties("name", new StringSchema().example("Tony")); model.addProperties("id", new IntegerSchema().example(123)); model.example("{\"name\":\"Fred\",\"id\":123456\"}"); assertEquals(model.getExample(), "{\"name\":\"Fred\",\"id\":123456\"}"); } }
@Override public String toDefaultValue(Schema propertySchema) { if (propertySchema instanceof StringSchema) { StringSchema sp = (StringSchema) propertySchema; if (sp.getDefault() != null) { return "\"" + sp.getDefault() + "\""; } return UNDEFINED_VALUE; } else if (propertySchema instanceof BooleanSchema) { return UNDEFINED_VALUE; } else if (propertySchema instanceof DateSchema) { return UNDEFINED_VALUE; } else if (propertySchema instanceof DateTimeSchema) { return UNDEFINED_VALUE; } else if (propertySchema instanceof NumberSchema) { NumberSchema dp = (NumberSchema) propertySchema; if (dp.getDefault() != null) { return dp.getDefault().toString(); } return UNDEFINED_VALUE; } else if (propertySchema instanceof IntegerSchema) { IntegerSchema ip = (IntegerSchema) propertySchema; if (ip.getDefault() != null) { return ip.getDefault().toString(); } return UNDEFINED_VALUE; } else { return UNDEFINED_VALUE; } }
@Override public Schema createProperty() { return new IntegerSchema().format(null); } },
@Override protected Schema processAsId(String propertyName, AnnotatedType type, ModelConverterContext context, ObjectMapper mapper) { return new IntegerSchema(); } },
@Override public String toDefaultValue(Schema propertySchema) { if (propertySchema instanceof StringSchema) { StringSchema sp = (StringSchema) propertySchema; if (sp.getDefault() != null) { return "\"" + sp.getDefault() + "\""; } return UNDEFINED_VALUE; } else if (propertySchema instanceof BooleanSchema) { return UNDEFINED_VALUE; } else if (propertySchema instanceof DateSchema) { return UNDEFINED_VALUE; } else if (propertySchema instanceof DateTimeSchema) { return UNDEFINED_VALUE; } else if (propertySchema instanceof NumberSchema) { NumberSchema dp = (NumberSchema) propertySchema; if (dp.getDefault() != null) { return dp.getDefault().toString(); } return UNDEFINED_VALUE; } else if (propertySchema instanceof IntegerSchema) { IntegerSchema ip = (IntegerSchema) propertySchema; if (ip.getDefault() != null) { return ip.getDefault().toString(); } return UNDEFINED_VALUE; } else { return UNDEFINED_VALUE; } }
@Test(description = "it should generate an integer field with enum") public void integerEnumGeneration() throws IOException { final String json = "{\n" + " \"properties\":{\n" + " \"id\":{\n" + " \"description\":\"fun!\",\n" + " \"type\":\"integer\",\n" + " \"format\":\"int32\",\n" + " \"readOnly\":true,\n" + " \"enum\": [ 0, 1]\n" + " }\n" + " }\n" + "}"; final Schema model = Json.mapper().readValue(json, Schema.class); IntegerSchema p = (IntegerSchema) model.getProperties().get("id"); assertNotNull(p.getEnum()); assertEquals(p.getEnum().get(0), new Integer(0)); assertEquals(p.getEnum().get(1), new Integer(1)); }
@Test(description = "it should serialize a long MapProperty") public void serializeLongMapProperty() throws IOException { final Schema p = new MapSchema().additionalProperties(new IntegerSchema().format("int64")); final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int64\"}}"; assertEquals(m.writeValueAsString(p), json); }
@Test(description = "it should serialize a integer MapProperty") public void serializeIntegerMapProperty() throws IOException { final Schema p = new MapSchema().additionalProperties(new IntegerSchema()); final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}"; assertEquals(m.writeValueAsString(p), json); }
if (integerSchema.getDefault() != null) { return integerSchema.getDefault().toString();
@Test public void testIssue1743() { final Map<String, Schema> models = ModelConverters.getInstance().readAll(ModelWithBooleanProperty.class); final Schema model = models.get("ModelWithBooleanProperty"); assertNotNull(model); BooleanSchema bp = (BooleanSchema) model.getProperties().get("isGreat"); assertTrue(bp.getEnum().size() == 1); assertEquals(bp.getEnum().get(0), Boolean.TRUE); IntegerSchema is = (IntegerSchema) model.getProperties().get("intValue"); assertTrue(is.getEnum().size() == 2); assertEquals(is.getEnum().get(0), new Integer(1)); assertEquals(is.getEnum().get(1), new Integer(2)); }
@Test(description = "should not serialize incorrect long value") public void testIncorrectLong() { final QueryParameter param = (QueryParameter) new QueryParameter().required(false); Schema schema = new IntegerSchema().format("int64"); schema.setDefault("test"); param.setSchema(schema); final String json = "{" + " \"in\":\"query\"," + " \"required\":false," + " \"schema\":{" + " \"type\":\"integer\"," + " \"format\":\"int64\"" + " }" + "}"; SerializationMatchers.assertEqualsToJson(param, json); }