Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid JSON Schema for properties pointing to association resources [DATAREST-690] #1062

Closed
spring-projects-issues opened this issue Sep 30, 2015 · 1 comment
Assignees

Comments

@spring-projects-issues
Copy link

Dominik Münch opened DATAREST-690 and commented

I am using a Spring Data REST version of Spring Boot's PetClinic application for playing around with the JSON Schema support. I noticed the following:

A property which represents a one-to-many association is of type string and format uri. However, it also contains the properties uniqueItems and items, which, according to the JSON Schema validation docs, only exist for array types. Below is an excerpt of the JSON Schema for the Owner class:

{
  "title": "Owner",
  "properties": {
    "pets": {
      "title": "Pets",
      "readOnly": false,
      "type": "string",
      "format": "uri",
      "uniqueItems": true,
      "items": {
        "type": "object"
      }
    },
    ...
  }
}

I think the correct representation would be the following, do you agree?

{
  "title": "Owner",
  "properties": {
    "pets": {
      "title": "Pets",
      "readOnly": false,
      "type": "array",
      "uniqueItems": true,
      "items": {
        "type": "string",
        "format": "uri"
      }
    },
    ...
  }
}

Affects: 2.4 GA (Gosling)

Backported to: 2.4.1 (Gosling SR1)

@spring-projects-issues
Copy link
Author

Oliver Drotbohm commented

I agree that the current arrangement is invalid. But I don't agree on the arrangement you propose. For a association resource that's pointing to a collection, there's a single URI pointing to a resource that manages the collection association.

So we basically need to make sure that for resources, that are not embedded, we treat the property a string with format URI. For embedded resources (i.e. associations that do not point to a repository managed type) your suggested arrangement is valid and already works correctly (see PersistentEntityToJsonSchemaConverterUnitTests)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants