use of io.swagger.v3.oas.models.media.NumberSchema in project swagger-parser by swagger-api.
the class OpenAPIDeserializerTest method testAnyOfSchema.
@Test
public void testAnyOfSchema(@Injectable List<AuthorizationValue> auths) {
String yaml = "openapi: '3.0'\n" + "components:\n" + " schemas:\n" + " id:\n" + " anyOf: \n" + " - type: string\n" + " - type: number\n";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
SwaggerParseResult result = parser.readContents(yaml, auths, options);
List<String> messageList = result.getMessages();
Set<String> messages = new HashSet<>(messageList);
Schema idSchema = result.getOpenAPI().getComponents().getSchemas().get("id");
assertTrue(idSchema != null);
assertTrue(idSchema instanceof ComposedSchema);
ComposedSchema idCompSchema = (ComposedSchema) idSchema;
List<Schema> anyOfSchemas = idCompSchema.getAnyOf();
assertTrue(anyOfSchemas != null);
assertEquals(anyOfSchemas.size(), 2);
Schema stringSchema = anyOfSchemas.get(0);
assertTrue(stringSchema != null);
assertEquals(stringSchema.getType(), "string");
Schema numberSchema = anyOfSchemas.get(1);
assertTrue(numberSchema != null);
assertEquals(numberSchema.getType(), "number");
}
use of io.swagger.v3.oas.models.media.NumberSchema in project swagger-core by swagger-api.
the class ModelWithRangesTest method modelWithRangesTest.
@Test(description = "test model with @ApiModelProperty.allowableValues")
public void modelWithRangesTest() {
final Map<String, Schema> properties = ModelConverters.getInstance().read(ModelWithRanges.class).get("ModelWithRanges").getProperties();
final IntegerSchema inclusiveRange = (IntegerSchema) properties.get("inclusiveRange");
assertEquals(inclusiveRange.getMinimum(), new BigDecimal(1));
assertEquals(inclusiveRange.getMaximum(), new BigDecimal(5));
assertNull(inclusiveRange.getExclusiveMaximum());
assertNull(inclusiveRange.getExclusiveMinimum());
final IntegerSchema exclusiveRange = (IntegerSchema) properties.get("exclusiveRange");
assertEquals(exclusiveRange.getMinimum(), new BigDecimal(1));
assertEquals(exclusiveRange.getMaximum(), new BigDecimal(5));
assertEquals(exclusiveRange.getExclusiveMinimum(), Boolean.TRUE);
assertEquals(exclusiveRange.getExclusiveMaximum(), Boolean.TRUE);
final IntegerSchema positiveInfinityRange = (IntegerSchema) properties.get("positiveInfinityRange");
assertEquals(positiveInfinityRange.getMinimum(), new BigDecimal(1.0));
assertNull(positiveInfinityRange.getMaximum());
assertNull(positiveInfinityRange.getExclusiveMaximum());
assertNull(positiveInfinityRange.getExclusiveMinimum());
final IntegerSchema negativeInfinityRange = (IntegerSchema) properties.get("negativeInfinityRange");
assertNull(negativeInfinityRange.getMinimum());
assertEquals(negativeInfinityRange.getMaximum(), new BigDecimal(5.0));
assertNull(negativeInfinityRange.getExclusiveMaximum());
assertNull(negativeInfinityRange.getExclusiveMinimum());
final StringSchema stringValues = (StringSchema) properties.get("stringValues");
assertEquals(stringValues.getEnum(), Arrays.asList("str1", "str2"));
final NumberSchema doubleValues = (NumberSchema) properties.get("doubleValues");
assertEquals(doubleValues.getMinimum(), new BigDecimal("1.0"));
assertEquals(doubleValues.getMaximum(), new BigDecimal("8.0"));
assertEquals(doubleValues.getExclusiveMaximum(), Boolean.TRUE);
assertNull(doubleValues.getExclusiveMinimum());
final IntegerSchema intAllowableValues = (IntegerSchema) properties.get("intAllowableValues");
assertEquals(intAllowableValues.getEnum(), Arrays.asList(1, 2));
final IntegerSchema intAllowableValuesWithNull = (IntegerSchema) properties.get("intAllowableValuesWithNull");
assertEquals(intAllowableValuesWithNull.getEnum(), Arrays.asList(1, 2, null));
}
use of io.swagger.v3.oas.models.media.NumberSchema in project swagger-core by swagger-api.
the class PropertySerializationTest method serializeDoubleProperty.
@Test(description = "it should serialize a DoubleProperty")
public void serializeDoubleProperty() throws IOException {
final NumberSchema p = new NumberSchema()._default(new BigDecimal("3.14159"));
p.format("double");
final String json = "{\"type\":\"number\",\"format\":\"double\",\"default\":3.14159}";
assertEquals(m.writeValueAsString(p), json);
}
use of io.swagger.v3.oas.models.media.NumberSchema in project swagger-core by swagger-api.
the class ParameterSerializationTest method testFloatValue.
@Test(description = "should serialize float value")
public void testFloatValue() {
final QueryParameter param = new QueryParameter();
param.setSchema(new NumberSchema()._default(new BigDecimal("12.34")).format("float"));
final String json = "{\"in\":\"query\",\"schema\":{\"type\":\"number\",\"format\":\"float\",\"default\":12.34}}";
SerializationMatchers.assertEqualsToJson(param, json);
}
use of io.swagger.v3.oas.models.media.NumberSchema in project swagger-core by swagger-api.
the class ParameterSerializationTest method testIncorrectDouble.
@Test(description = "should not serialize incorrect double value")
public void testIncorrectDouble() {
final QueryParameter param = (QueryParameter) new QueryParameter().required(false);
Schema schema = new NumberSchema().format("double");
schema.setDefault("test");
param.setSchema(schema);
final String json = "{" + " \"in\":\"query\"," + " \"required\":false," + " \"schema\":{" + " \"type\":\"number\"," + " \"format\":\"double\"" + " }" + "}";
SerializationMatchers.assertEqualsToJson(param, json);
}
Aggregations