use of com.google.api.server.spi.config.ResourceSchema in project endpoints-java by cloudendpoints.
the class JacksonResourceSchemaProvider method getResourceSchema.
@Override
public ResourceSchema getResourceSchema(TypeToken<?> type, ApiConfig config) {
ResourceSchema schema = super.getResourceSchema(type, config);
if (schema != null) {
return schema;
}
ObjectMapper objectMapper = ObjectMapperUtil.createStandardObjectMapper(config.getSerializationConfig());
JavaType javaType = objectMapper.getTypeFactory().constructType(type.getRawType());
BeanDescription beanDescription = objectMapper.getSerializationConfig().introspect(javaType);
ResourceSchema.Builder schemaBuilder = ResourceSchema.builderForType(type.getRawType());
Set<String> genericDataFieldNames = getGenericDataFieldNames(type);
for (BeanPropertyDefinition definition : beanDescription.findProperties()) {
TypeToken<?> propertyType = getPropertyType(type, toMethod(definition.getGetter()), toMethod(definition.getSetter()), definition.getField(), config);
String name = definition.getName();
if (genericDataFieldNames == null || genericDataFieldNames.contains(name)) {
if (hasUnresolvedType(propertyType)) {
logger.warning("skipping field '" + name + "' of type '" + propertyType + "' because it is unresolved.");
continue;
}
if (propertyType != null) {
ResourcePropertySchema propertySchema = ResourcePropertySchema.of(propertyType);
propertySchema.setDescription(definition.getMetadata().getDescription());
schemaBuilder.addProperty(name, propertySchema);
} else {
logger.warning("No type found for property '" + name + "' on class '" + type + "'.");
}
} else {
logger.fine("skipping field '" + name + "' because it's not a Java client model field.");
}
}
return schemaBuilder.build();
}
use of com.google.api.server.spi.config.ResourceSchema in project endpoints-java by cloudendpoints.
the class ResourceSchemaProviderTest method testConfigCustomResourceSerializedPropertyReturnsSchema.
@Test
public void testConfigCustomResourceSerializedPropertyReturnsSchema() {
config.getSerializationConfig().addSerializationConfig(SinglePropertyResourceSerializer.class);
ResourceSchema schema = getResourceSchema(SinglePropertyBean.class);
String name = SinglePropertyBean.class.getSimpleName();
assertThat(schema.getProperties().keySet()).containsExactly(name);
assertEquals(Long.class, schema.getProperties().get(name).getJavaType());
}
use of com.google.api.server.spi.config.ResourceSchema in project endpoints-java by cloudendpoints.
the class ResourceSchemaProviderTest method testRenamedProperty.
@Test
public void testRenamedProperty() {
ResourceSchema schema = getResourceSchema(RenamedPropertyBean.class);
assertThat(schema.getProperties().keySet()).containsExactly("bar");
}
use of com.google.api.server.spi.config.ResourceSchema in project endpoints-java by cloudendpoints.
the class ResourceSchemaProviderTest method testAnnotationCustomResourceSerializedPropertyReturnsSchema.
@Test
public void testAnnotationCustomResourceSerializedPropertyReturnsSchema() {
ResourceSchema schema = getResourceSchema(CustomResourceSerializerBean.class);
assertEquals("CustomizedName", schema.getName());
assertThat(schema.getProperties().keySet()).containsExactly("baz", "qux");
assertEquals(Integer.class, schema.getProperties().get("baz").getJavaType());
assertEquals(Boolean.class, schema.getProperties().get("qux").getJavaType());
}
use of com.google.api.server.spi.config.ResourceSchema in project endpoints-java by cloudendpoints.
the class ResourceSchemaProviderTest method testNoClassPropertyReturned.
@Test
public void testNoClassPropertyReturned() {
ResourceSchema schema = getResourceSchema(SinglePropertyBean.class);
assertThat(schema.getProperties().keySet()).containsExactly("foo");
}
Aggregations