From 9f1a08d412483c7260a9d443e0ccc7dc7ff3461a Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 10 Apr 2014 09:23:41 +0200 Subject: [PATCH] DATAREST-288 - Removed javax.validation dependency from schema controller. --- .../webmvc/RepositorySchemaController.java | 19 +++++++++++-------- ...PersistentEntityToJsonSchemaConverter.java | 8 ++------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositorySchemaController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositorySchemaController.java index 3b9f3c2e6..369cf7c84 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositorySchemaController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositorySchemaController.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2014 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. @@ -15,13 +15,16 @@ */ package org.springframework.data.rest.webmvc; +import static org.springframework.web.bind.annotation.RequestMethod.*; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.rest.webmvc.json.JsonSchema; import org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.util.Assert; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; /** * Controller to expose a JSON schema via {@code / repository}/schema}. @@ -54,10 +57,10 @@ class RepositorySchemaController { * @param resourceInformation will never be {@literal null}. * @return */ - @RequestMapping(value = BASE_MAPPING + "/schema", method = RequestMethod.GET, - produces = { "application/schema+json" }) - @ResponseBody - public JsonSchema schema(RootResourceInformation resourceInformation) { - return jsonSchemaConverter.convert(resourceInformation.getPersistentEntity().getType()); + @RequestMapping(value = BASE_MAPPING + "/schema", method = GET, produces = { "application/schema+json" }) + public HttpEntity schema(RootResourceInformation resourceInformation) { + + JsonSchema schema = jsonSchemaConverter.convert(resourceInformation.getPersistentEntity().getType()); + return new ResponseEntity(schema, HttpStatus.OK); } } diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverter.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverter.java index 8f3aeea79..8df9795b4 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverter.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverter.java @@ -20,8 +20,6 @@ import static org.springframework.util.StringUtils.*; import java.util.HashSet; import java.util.Set; -import javax.validation.constraints.NotNull; - import org.springframework.context.support.MessageSourceAccessor; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; @@ -132,14 +130,12 @@ public class PersistentEntityToJsonSchemaConverter implements ConditionalGeneric String type = uncapitalize(propertyType.getSimpleName()); ResourceMapping propertyMapping = metadata.getMappingFor(persistentProperty); - - boolean notNull = persistentProperty.isAnnotationPresent(NotNull.class); ResourceDescription description = propertyMapping.getDescription(); String message = accessor.getMessage(description); Property property = persistentProperty.isCollectionLike() ? // - new ArrayProperty("array", message, notNull) - : new Property(type, message, notNull); + new ArrayProperty("array", message, false) + : new Property(type, message, false); jsonSchema.addProperty(persistentProperty.getName(), property); }