Search in sources :

Example 1 with BooleanSchema

use of io.swagger.v3.oas.models.media.BooleanSchema in project swagger-core by swagger-api.

the class ModelPropertyTest method testIssue1743.

@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));
}
Also used : BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) Schema(io.swagger.v3.oas.models.media.Schema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) Test(org.testng.annotations.Test)

Example 2 with BooleanSchema

use of io.swagger.v3.oas.models.media.BooleanSchema in project swagger-core by swagger-api.

the class PropertySerializationTest method deserializeBooleanSchema.

@Test(description = "it should deserialize a BooleanSchema")
public void deserializeBooleanSchema() throws IOException {
    final String json = "{\"type\":\"boolean\",\"default\":false}";
    final Schema p = m.readValue(json, Schema.class);
    assertEquals(p.getType(), "boolean");
    assertNull(p.getFormat());
    assertEquals(p.getClass(), BooleanSchema.class);
    assertEquals(((BooleanSchema) p).getDefault(), Boolean.FALSE);
    assertEquals(m.writeValueAsString(p), json);
}
Also used : FileSchema(io.swagger.v3.oas.models.media.FileSchema) BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Schema(io.swagger.v3.oas.models.media.Schema) Test(org.testng.annotations.Test)

Example 3 with BooleanSchema

use of io.swagger.v3.oas.models.media.BooleanSchema in project swagger-core by swagger-api.

the class PropertySerializationTest method serializeBooleanSchema.

@Test(description = "it should serialize a BooleanSchema")
public void serializeBooleanSchema() throws IOException {
    final BooleanSchema p = new BooleanSchema()._default(true);
    final String json = "{\"type\":\"boolean\",\"default\":true}";
    assertEquals(m.writeValueAsString(p), json);
}
Also used : BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) Test(org.testng.annotations.Test)

Example 4 with BooleanSchema

use of io.swagger.v3.oas.models.media.BooleanSchema in project flow by vaadin.

the class SchemaResolverTest method should_ReturnNullableBoolean_When_GivenTypeIsABoxedBoolean.

@Test
public void should_ReturnNullableBoolean_When_GivenTypeIsABoxedBoolean() {
    ResolvedType resolvedType = mockReferencedTypeOf(Boolean.class);
    Map<String, GeneratorType> usedTypes = new HashMap<>();
    SchemaResolver schemaResolver = new SchemaResolver(new GeneratorType(resolvedType), usedTypes);
    Schema schema = schemaResolver.resolve();
    Assert.assertTrue(schema instanceof BooleanSchema);
    Assert.assertTrue(schema.getNullable());
    Assert.assertTrue(usedTypes.isEmpty());
}
Also used : BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) HashMap(java.util.HashMap) BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) Test(org.junit.Test)

Example 5 with BooleanSchema

use of io.swagger.v3.oas.models.media.BooleanSchema in project flow by vaadin.

the class SchemaResolverTest method should_ReturnNotNullableBoolean_When_GivenTypeIsAPrimitiveBoolean.

@Test
public void should_ReturnNotNullableBoolean_When_GivenTypeIsAPrimitiveBoolean() {
    ResolvedType resolvedType = mockPrimitiveTypeOf(ResolvedPrimitiveType.BOOLEAN);
    Map<String, GeneratorType> usedTypes = new HashMap<>();
    SchemaResolver schemaResolver = new SchemaResolver(new GeneratorType(resolvedType), usedTypes);
    Schema schema = schemaResolver.resolve();
    Assert.assertTrue(schema instanceof BooleanSchema);
    Assert.assertNull(schema.getNullable());
    Assert.assertTrue(usedTypes.isEmpty());
}
Also used : BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) HashMap(java.util.HashMap) BooleanSchema(io.swagger.v3.oas.models.media.BooleanSchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) NumberSchema(io.swagger.v3.oas.models.media.NumberSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ResolvedType(com.github.javaparser.resolution.types.ResolvedType) Test(org.junit.Test)

Aggregations

BooleanSchema (io.swagger.v3.oas.models.media.BooleanSchema)5 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)4 Schema (io.swagger.v3.oas.models.media.Schema)4 StringSchema (io.swagger.v3.oas.models.media.StringSchema)4 DateSchema (io.swagger.v3.oas.models.media.DateSchema)3 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)3 MapSchema (io.swagger.v3.oas.models.media.MapSchema)3 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)3 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)3 Test (org.testng.annotations.Test)3 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)2 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)2 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 FileSchema (io.swagger.v3.oas.models.media.FileSchema)1