Search in sources :

Example 6 with ResourceSchema

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

the class ResourceSchemaTest method testDefaultSchema.

@Test
public void testDefaultSchema() {
    ResourceSchema schema = ResourceSchema.builderForType(Integer.class).build();
    assertNull(schema.getName());
    assertEquals(Integer.class, schema.getType());
    assertThat(schema.getProperties()).isEmpty();
}
Also used : ResourceSchema(com.google.api.server.spi.config.ResourceSchema) Test(org.junit.Test)

Example 7 with ResourceSchema

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

the class ResourceSchemaProviderTest method testPrivateBeanPropertyWithAnnotation.

@Test
public void testPrivateBeanPropertyWithAnnotation() throws Exception {
    ResourceSchema schema = getResourceSchema(PrivatePropertyBean.class);
    assertEquals(1, schema.getProperties().size());
    assertEquals(String.class, schema.getProperties().get("foo").getJavaType());
}
Also used : ResourceSchema(com.google.api.server.spi.config.ResourceSchema) Test(org.junit.Test)

Example 8 with ResourceSchema

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

the class ResourceSchemaProviderTest method testBeanPropertyWithSetterOnly.

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

Example 9 with ResourceSchema

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

the class ResourceSchemaProviderTest method testCustomSerializedPropertyReturns.

@Test
public void testCustomSerializedPropertyReturns() {
    ResourceSchema schema = getResourceSchema(CustomSerializerParentBean.class);
    assertThat(schema.getProperties().keySet()).containsExactly("foo");
    assertEquals(String.class, schema.getProperties().get("foo").getJavaType());
}
Also used : ResourceSchema(com.google.api.server.spi.config.ResourceSchema) Test(org.junit.Test)

Example 10 with ResourceSchema

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

the class JsonConfigWriter method addBeanProperties.

/**
 * Iterates over the given JavaBean class and adds the following to the given config object
 * (the value of "properties" of a schema object): "<name>": {"type": "<type>"}, where
 * "name" is the name of the JavaBean property and "type" the type of its value.
 */
private void addBeanProperties(ObjectNode schemasNode, ObjectNode node, TypeToken<?> beanType, ApiConfig apiConfig, List<ApiParameterConfig> parameterConfigs) throws ApiConfigException {
    // CollectionResponse<T> is treated as a bean but it is a parameterized type, too.
    ResourceSchema schema = resourceSchemaProvider.getResourceSchema(beanType, apiConfig);
    for (Entry<String, ResourcePropertySchema> entry : schema.getProperties().entrySet()) {
        String propertyName = entry.getKey();
        ObjectNode propertyNode = objectMapper.createObjectNode();
        TypeToken<?> propertyType = entry.getValue().getType();
        if (propertyType != null) {
            addTypeToNode(schemasNode, propertyType, beanType, propertyNode, apiConfig, parameterConfigs);
            node.set(propertyName, propertyNode);
        }
    }
}
Also used : ResourceSchema(com.google.api.server.spi.config.ResourceSchema) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ResourcePropertySchema(com.google.api.server.spi.config.ResourcePropertySchema)

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