DATAREST-644 - Improvements to JSON Schema output.

Fixed JSON Schema output use "definitions" keyword instead of the previously used wrong "descriptors".

We now also include the title attribute for properties, using rest.description.$type.$property._title as i18n key. Titles are now also defaulted to the camel-case property name split up, lowercased and capitalized, e.g. "orderDate" will become "Order date".

JacksonMetadata now allows obtaining the Jackson serializer being used for a given type and exposes whether a property is considered read-only for Jackson.

Introduced JsonSchemaPropertyCustomizer to potentially tweak the JSON schema property definition. This is helpful in case custom JsonSerializers are implemented to also reflect the change in representation in the schema.
This commit is contained in:
Oliver Gierke
2015-08-14 18:48:30 +02:00
parent 14df6fcbc0
commit d4dbeb93a0
10 changed files with 523 additions and 106 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation to descibe semantics of a resource.
* Annotation to describe semantics of a resource.
*
* @author Jon Brisbin
* @author Oliver Gierke

View File

@@ -24,7 +24,7 @@ import org.springframework.util.StringUtils;
*/
public class SimpleResourceDescription extends ResolvableResourceDescriptionSupport {
protected static final String DEFAULT_KEY_PREFIX = "rest.description";
public static final String DEFAULT_KEY_PREFIX = "rest.description";
protected static final MediaType DEFAULT_MEDIA_TYPE = MediaType.TEXT_PLAIN;
private final String message;

View File

@@ -47,9 +47,13 @@ public class TypedResourceDescription extends SimpleResourceDescription {
}
public static ResourceDescription defaultFor(String rel, PersistentProperty<?> property) {
return defaultFor(rel, property.getName(), property.getType());
}
String message = String.format("%s.%s.%s", DEFAULT_KEY_PREFIX, rel, property.getName());
return new TypedResourceDescription(message, DEFAULT_MEDIA_TYPE, property.getType());
public static ResourceDescription defaultFor(String rel, String name, Class<?> type) {
String message = String.format("%s.%s.%s", DEFAULT_KEY_PREFIX, rel, name);
return new TypedResourceDescription(message, DEFAULT_MEDIA_TYPE, type);
}
public static ResourceDescription defaultFor(String rel, Class<?> type) {