DATAREST-113 - Fixed glitches in JSON schema creation.
PersistentEntityToJsonSchemaConverter looks up the ResourceMetadata correctly and builds up URIs in a proper way.
This commit is contained in:
@@ -3,7 +3,6 @@ package org.springframework.data.rest.webmvc.json;
|
||||
import static org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module.*;
|
||||
import static org.springframework.util.StringUtils.*;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -79,7 +78,7 @@ public class PersistentEntityToJsonSchemaConverter implements ConditionalGeneric
|
||||
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
|
||||
PersistentEntity<?, ?> persistentEntity = repositories.getPersistentEntity((Class<?>) source);
|
||||
final ResourceMetadata metadata = mappings.getMappingFor(persistentEntity.getClass());
|
||||
final ResourceMetadata metadata = mappings.getMappingFor(persistentEntity.getType());
|
||||
String entityDesc = persistentEntity.getType().isAnnotationPresent(Description.class) ? persistentEntity.getType()
|
||||
.getAnnotation(Description.class).value() : null;
|
||||
|
||||
@@ -122,7 +121,7 @@ public class PersistentEntityToJsonSchemaConverter implements ConditionalGeneric
|
||||
return;
|
||||
}
|
||||
|
||||
RepositoryLinkBuilder builder = new RepositoryLinkBuilder(metadata, URI.create("{id}"));
|
||||
RepositoryLinkBuilder builder = new RepositoryLinkBuilder(metadata, null).slash("{id}");
|
||||
maybeAddAssociationLink(builder, mappings, persistentProperty, links);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -168,5 +168,27 @@ public abstract class AbstractWebIntegrationTests {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREST-113
|
||||
*/
|
||||
@Test
|
||||
public void exposesSchemasForResourcesExposed() throws Exception {
|
||||
|
||||
MockHttpServletResponse response = request("/");
|
||||
|
||||
for (String rel : expectedRootLinkRels()) {
|
||||
|
||||
Link link = assertHasLinkWithRel(rel, response);
|
||||
|
||||
// Resource
|
||||
request(link);
|
||||
|
||||
// Schema - TODO:Improve by using hypermedia
|
||||
mvc.perform(get(link.getHref() + "/schema").//
|
||||
accept(MediaType.parseMediaType("application/schema+json"))).//
|
||||
andExpect(status().isOk());
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Iterable<String> expectedRootLinkRels();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user