Search in sources :

Example 16 with ResourceSchema

use of com.google.api.server.spi.config.ResourceSchema in project endpoints-java by cloudendpoints.

the class ResourceSchemaProviderTest method testMissingPropertyType.

@Test
public void testMissingPropertyType() {
    ResourceSchema schema = getResourceSchema(MissingPropertyTypeBean.class);
    assertThat(schema.getProperties().keySet()).containsExactly("bar");
}
Also used : ResourceSchema(com.google.api.server.spi.config.ResourceSchema) Test(org.junit.Test)

Example 17 with ResourceSchema

use of com.google.api.server.spi.config.ResourceSchema in project endpoints-java by cloudendpoints.

the class ResourceSchemaProviderTest method testIgnoredPropertyNotReturned.

@Test
public void testIgnoredPropertyNotReturned() {
    ResourceSchema schema = getResourceSchema(IgnoredPropertyBean.class);
    assertThat(schema.getProperties().keySet()).containsExactly("foo");
}
Also used : ResourceSchema(com.google.api.server.spi.config.ResourceSchema) Test(org.junit.Test)

Example 18 with ResourceSchema

use of com.google.api.server.spi.config.ResourceSchema in project endpoints-java by cloudendpoints.

the class ResourceSchemaProviderTest method testGenericJsonEntity.

@Test
public void testGenericJsonEntity() throws Exception {
    ResourceSchema schema = getResourceSchema(GenericJsonEntity.class);
    assertThat(schema.getProperties().keySet()).containsExactly("foo");
    assertThat(schema.getProperties().get("foo").getJavaType()).isEqualTo(String.class);
}
Also used : ResourceSchema(com.google.api.server.spi.config.ResourceSchema) Test(org.junit.Test)

Example 19 with ResourceSchema

use of com.google.api.server.spi.config.ResourceSchema in project endpoints-java by cloudendpoints.

the class SchemaRepository method createBeanSchema.

private Schema createBeanSchema(TypeToken<?> type, Map<TypeToken<?>, Schema> typesForConfig, ApiConfig config) {
    Schema.Builder builder = Schema.builder().setName(Types.getSimpleName(type, config.getSerializationConfig())).setType("object");
    ResourceSchema schema = resourceSchemaProvider.getResourceSchema(type, config);
    for (Entry<String, ResourcePropertySchema> entry : schema.getProperties().entrySet()) {
        String propertyName = entry.getKey();
        ResourcePropertySchema propertySchema = entry.getValue();
        TypeToken<?> propertyType = propertySchema.getType();
        if (propertyType != null) {
            Field.Builder fieldBuilder = Field.builder().setName(propertyName);
            fillInFieldInformation(fieldBuilder, propertyType, propertySchema.getDescription(), typesForConfig, config);
            builder.addField(propertyName, fieldBuilder.build());
        }
    }
    return builder.build();
}
Also used : Field(com.google.api.server.spi.config.model.Schema.Field) ResourceSchema(com.google.api.server.spi.config.ResourceSchema) ResourceSchema(com.google.api.server.spi.config.ResourceSchema) ResourcePropertySchema(com.google.api.server.spi.config.ResourcePropertySchema) ResourcePropertySchema(com.google.api.server.spi.config.ResourcePropertySchema)

Example 20 with ResourceSchema

use of com.google.api.server.spi.config.ResourceSchema in project endpoints-java by cloudendpoints.

the class ResourceSchemaProviderTest method testDescribedProperty.

@Test
public void testDescribedProperty() {
    ResourceSchema schema = getResourceSchema(DescribedPropertyBean.class);
    assertEquals("description of foo", schema.getProperties().get("foo").getDescription());
    assertEquals("description of bar", schema.getProperties().get("bar").getDescription());
    assertEquals("description of choice", schema.getProperties().get("choice").getDescription());
}
Also used : ResourceSchema(com.google.api.server.spi.config.ResourceSchema) Test(org.junit.Test)

Aggregations

ResourceSchema (com.google.api.server.spi.config.ResourceSchema)21 Test (org.junit.Test)18 ResourcePropertySchema (com.google.api.server.spi.config.ResourcePropertySchema)3 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Field (com.google.api.server.spi.config.model.Schema.Field)1