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();
}
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());
}
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());
}
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());
}
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);
}
}
}
Aggregations