io.swagger.v3.oas.models.media.BooleanSchema Java Examples

The following examples show how to use io.swagger.v3.oas.models.media.BooleanSchema. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArraySerializableParamExtractionTest.java    From swagger-inflector with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertBooleanArrayCSVValue() throws Exception {
    List<String> values = Arrays.asList("true false true");

    Parameter parameter = new QueryParameter()
            .style(Parameter.StyleEnum.SPACEDELIMITED)
            .schema(new ArraySchema()
                    .items(new BooleanSchema()));

    Object o = utils.cast(values, parameter, tf.constructArrayType(Boolean.class), null);

    assertTrue(o instanceof List);

    @SuppressWarnings("unchecked")
    List<Boolean> objs = (List<Boolean>) o;

    assertTrue(objs.size() == 3);
    assertEquals(objs.get(0), Boolean.TRUE);
    assertEquals(objs.get(1), Boolean.FALSE);
    assertEquals(objs.get(2), Boolean.TRUE);
}
 
Example #2
Source File: OASUtilsTest.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
@Test
public void testBoolean() {
  MetaPrimitiveType type = new MetaPrimitiveType();
  type.setName("boolean");
  Schema schema = OASUtils.transformMetaResourceField(type);
  Assert.assertTrue(schema instanceof BooleanSchema);
}
 
Example #3
Source File: InputModeller.java    From tcases with MIT License 5 votes vote down vote up
/**
 * Returns the enumerated boolean values defined by the given schema.
 */
private Set<Boolean> getBooleanEnum( Schema<?> schema)
  {
  return
    schema instanceof BooleanSchema
    ? asOrderedSet( ((BooleanSchema) schema).getEnum())
    : getBooleanEnum( schema.getEnum());
  }
 
Example #4
Source File: DataGenerator.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
public boolean isSupported(Schema<?> schema) {
    return schema instanceof ArraySchema
            || schema instanceof BooleanSchema
            || schema instanceof FileSchema
            || schema instanceof IntegerSchema
            || schema instanceof MapSchema
            || schema instanceof NumberSchema
            || schema instanceof StringSchema;
}
 
Example #5
Source File: SchemaResolver.java    From flow with Apache License 2.0 5 votes vote down vote up
Schema parseResolvedTypeToSchema(ResolvedType resolvedType) {
    if (resolvedType.isArray()) {
        return createArraySchema(resolvedType);
    }
    if (isNumberType(resolvedType)) {
        return new NumberSchema();
    } else if (isStringType(resolvedType)) {
        return new StringSchema();
    } else if (isCollectionType(resolvedType)) {
        return createCollectionSchema(resolvedType.asReferenceType());
    } else if (isBooleanType(resolvedType)) {
        return new BooleanSchema();
    } else if (isMapType(resolvedType)) {
        return createMapSchema(resolvedType);
    } else if (isDateType(resolvedType)) {
        return new DateSchema();
    } else if (isDateTimeType(resolvedType)) {
        return new DateTimeSchema();
    } else if (isOptionalType(resolvedType)) {
        return createOptionalSchema(resolvedType.asReferenceType());
    } else if (isUnhandledJavaType(resolvedType)) {
        return new ObjectSchema();
    } else if (isTypeOf(resolvedType, Enum.class)) {
        return createEnumTypeSchema(resolvedType);
    }
    return createUserBeanSchema(resolvedType);
}
 
Example #6
Source File: SchemaResolverTest.java    From flow with Apache License 2.0 5 votes vote down vote up
@Test
public void should_ReturnNotNullableBoolean_When_GivenTypeIsAPrimitiveBoolean() {
    ResolvedType resolvedType = mockPrimitiveTypeOf(
            ResolvedPrimitiveType.BOOLEAN);

    Schema schema = schemaResolver.parseResolvedTypeToSchema(resolvedType);

    Assert.assertTrue(schema instanceof BooleanSchema);
    Assert.assertNull(schema.getNullable());
    Assert.assertTrue(schemaResolver.getFoundTypes().isEmpty());
}
 
Example #7
Source File: SchemaResolverTest.java    From flow with Apache License 2.0 5 votes vote down vote up
@Test
public void should_ReturnNotNullableBoolean_When_GivenTypeIsABoxedBoolean() {
    ResolvedType resolvedType = mockReferencedTypeOf(Boolean.class);

    Schema schema = schemaResolver.parseResolvedTypeToSchema(resolvedType);

    Assert.assertTrue(schema instanceof BooleanSchema);
    Assert.assertNull(schema.getNullable());
    Assert.assertTrue(schemaResolver.getFoundTypes().isEmpty());
}
 
Example #8
Source File: ValueCoercionTest.java    From swagger-inflector with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertBooleanValue() throws Exception {
    List<String> values = Arrays.asList("true");

    Parameter parameter = new QueryParameter().schema(new BooleanSchema());
    Object o = utils.cast(values, parameter, tf.constructType(Boolean.class), null);

    assertTrue(o instanceof Boolean);
}
 
Example #9
Source File: ValueCoercionTest.java    From swagger-inflector with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertBooleanValue1() throws Exception {
    List<String> values = Arrays.asList("1");

    Parameter parameter = new QueryParameter().schema(new BooleanSchema());
    Object o = utils.cast(values, parameter, tf.constructType(Boolean.class), null);

    assertTrue(o instanceof Boolean);
    assertTrue((Boolean) o);
}
 
Example #10
Source File: ValueCoercionTest.java    From swagger-inflector with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertBooleanValue2() throws Exception {
    List<String> values = Arrays.asList("0");

    Parameter parameter = new QueryParameter().schema(new BooleanSchema());
    Object o = utils.cast(values, parameter, tf.constructType(Boolean.class), null);

    assertTrue(o instanceof Boolean);
    assertFalse((Boolean) o);
}
 
Example #11
Source File: ExampleBuilderTest.java    From swagger-inflector with Apache License 2.0 5 votes vote down vote up
@Test
public void testXmlBoolean() throws Exception {
    BooleanSchema sp = new BooleanSchema();
    Example ex = ExampleBuilder.fromSchema(sp, null);
    String xmlString = new XmlExampleSerializer().serialize(ex);
    assertEqualsIgnoreLineEnding(xmlString, "<?xml version='1.1' encoding='UTF-8'?><boolean>true</boolean>");
}
 
Example #12
Source File: V2ConverterTest.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
@Test(description = "OpenAPI v2 converter - uses specialized schema subclasses where available")
public void testIssue1164() throws Exception {
    final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1164_YAML);
    assertNotNull(oas);
    assertNotNull(oas.getPaths());
    assertNotNull(oas.getPaths().get("/foo"));
    assertNotNull(oas.getPaths().get("/foo").getGet());
    assertNotNull(oas.getPaths().get("/foo").getGet().getRequestBody());
    assertNotNull(oas.getPaths().get("/foo").getGet().getRequestBody().getContent());
    assertNotNull(oas.getPaths().get("/foo").getGet().getRequestBody().getContent().get("multipart/form-data"));
    Schema formSchema = oas.getPaths().get("/foo").getGet().getRequestBody().getContent().get("multipart/form-data").getSchema();
    assertNotNull(formSchema);
    assertNotNull(formSchema.getProperties());
    assertEquals(4, formSchema.getProperties().size());
    assertTrue(formSchema.getProperties().get("first") instanceof StringSchema);

    assertTrue(formSchema.getProperties().get("second") instanceof BooleanSchema);

    assertTrue(formSchema.getProperties().get("third") instanceof StringSchema);
    StringSchema third = (StringSchema) formSchema.getProperties().get("third");
    assertNotNull(third.getFormat());
    assertTrue("password".equals(third.getFormat()));

    assertTrue(formSchema.getProperties().get("fourth") instanceof BooleanSchema);
    Schema fourth = (Schema) formSchema.getProperties().get("fourth");
    assertNotNull(fourth.getType());
    assertNotNull(fourth.getFormat());
    assertTrue("completely-custom".equals(fourth.getFormat()));
}
 
Example #13
Source File: AbstractEndpointGenerationTest.java    From flow with Apache License 2.0 4 votes vote down vote up
private void assertSchema(Schema actualSchema,
        Class<?> expectedSchemaClass) {
    if (assertSpecificJavaClassSchema(actualSchema, expectedSchemaClass)) {
        return;
    }

    if (actualSchema.get$ref() != null) {
        assertNull(actualSchema.getProperties());
        schemaReferences.add(actualSchema.get$ref());
    } else {
        if (actualSchema instanceof StringSchema) {
            assertTrue(String.class.isAssignableFrom(expectedSchemaClass)
                    || Enum.class.isAssignableFrom(expectedSchemaClass));
        } else if (actualSchema instanceof BooleanSchema) {
            assertTrue((boolean.class.isAssignableFrom(expectedSchemaClass)
                    || Boolean.class
                            .isAssignableFrom(expectedSchemaClass)));
        } else if (actualSchema instanceof NumberSchema) {
            assertTrue(JSON_NUMBER_CLASSES.stream()
                    .anyMatch(jsonNumberClass -> jsonNumberClass
                            .isAssignableFrom(expectedSchemaClass)));
        } else if (actualSchema instanceof ArraySchema) {
            if (expectedSchemaClass.isArray()) {
                assertSchema(((ArraySchema) actualSchema).getItems(),
                        expectedSchemaClass.getComponentType());
            } else {
                assertTrue(Collection.class
                        .isAssignableFrom(expectedSchemaClass));
            }
        } else if (actualSchema instanceof MapSchema) {
            assertTrue(Map.class.isAssignableFrom(expectedSchemaClass));
        } else if (actualSchema instanceof DateTimeSchema) {
            assertTrue(Instant.class.isAssignableFrom(expectedSchemaClass)
                    || LocalDateTime.class
                            .isAssignableFrom(expectedSchemaClass));
        } else if (actualSchema instanceof DateSchema) {
            assertTrue(Date.class.isAssignableFrom(expectedSchemaClass)
                    || LocalDate.class
                            .isAssignableFrom(expectedSchemaClass));
        } else if (actualSchema instanceof ComposedSchema) {
            List<Schema> allOf = ((ComposedSchema) actualSchema).getAllOf();
            if (allOf.size() > 1) {
                // Inherited schema
                for (Schema schema : allOf) {
                    if (expectedSchemaClass.getCanonicalName()
                            .equals(schema.getName())) {
                        assertSchemaProperties(expectedSchemaClass, schema);
                        break;
                    }
                }
            } else {
                // Nullable schema for referring schema object
                assertEquals(1, allOf.size());
                assertEquals(expectedSchemaClass.getCanonicalName(),
                        allOf.get(0).getName());
            }
        } else if (actualSchema instanceof ObjectSchema) {
            assertSchemaProperties(expectedSchemaClass, actualSchema);
        } else {
            throw new AssertionError(
                    String.format("Unknown schema '%s' for class '%s'",
                            actualSchema.getClass(), expectedSchemaClass));
        }
    }
}
 
Example #14
Source File: SerializableParamExtractionTest.java    From swagger-inflector with Apache License 2.0 4 votes vote down vote up
@Test
public void getBooleanParameterClassTest() throws Exception {
    JavaType jt = utils.getTypeFromParameter(new QueryParameter().schema(new BooleanSchema()), null);
    assertEquals(jt.getRawClass(), Boolean.class);
}
 
Example #15
Source File: SchemaTypeUtil.java    From swagger-parser with Apache License 2.0 4 votes vote down vote up
public static Schema createSchema(String type, String format) {

        if(INTEGER_TYPE.equals(type)) {
            if(StringUtils.isBlank(format)){
                return new IntegerSchema().format(null);
            }else {
                return new IntegerSchema().format(format);
            }
        }
        else if(NUMBER_TYPE.equals(type)) {
            if (StringUtils.isBlank(format)){
                return new NumberSchema();
            } else {
                return new NumberSchema().format(format);
            }
        }
        else if(BOOLEAN_TYPE.equals(type)) {
            if (StringUtils.isBlank(format)){
                return new BooleanSchema();
            } else {
                return new BooleanSchema().format(format);
            }
        }
        else if(STRING_TYPE.equals(type)) {
            if(BYTE_FORMAT.equals(format)) {
                return new ByteArraySchema();
            }
            else if(BINARY_FORMAT.equals(format)) {
                return new BinarySchema();
            }
            else if(DATE_FORMAT.equals(format)) {
                return new DateSchema();
            }
            else if(DATE_TIME_FORMAT.equals(format)) {
                return new DateTimeSchema();
            }
            else if(PASSWORD_FORMAT.equals(format)) {
                return new PasswordSchema();
            }
            else if(EMAIL_FORMAT.equals(format)) {
                return new EmailSchema();
            }
            else if(UUID_FORMAT.equals(format)) {
                return new UUIDSchema();
            }
            else {
                if (StringUtils.isBlank(format)){
                    return new StringSchema().format(null);
                }else {
                    return new StringSchema().format(format);
                }
            }
        }
        else if(OBJECT_TYPE.equals(type)) {
            return new ObjectSchema();
        }
        else {
            return new Schema();
        }
    }