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

Validation schema is incorrect #1

Open
elb98rm opened this issue Jan 20, 2020 · 0 comments
Open

Validation schema is incorrect #1

elb98rm opened this issue Jan 20, 2020 · 0 comments

Comments

@elb98rm
Copy link

elb98rm commented Jan 20, 2020

Overview

The id field is optional in the specification. The validator has enforced id. This causes issues for POST requests, which is one of the main methods used in a RESTful api.

Documentation reference

The current spec of the JSON schema defines the "id" requirements for resource objects as follows:

“Resource objects” appear in a JSON:API document to represent resources.

A resource object MUST contain at least the following top-level members:

   id
   type

Exception: The id member is not required when the resource object originates at the client and represents a new resource to be created on the server.

This exception is not accounted for with a resource schema.

Steps to reproduce:

Test the following json using the validator:

{
  "data": {
    "type": "test",
    "id" : "212",
    "attributes": {
    	"content": {
    		"test":1
    		}
    	}
	}
}

This will validate as expected.

Remove the id element, as follows:

{
  "data": {
    "type": "test",
    "attributes": {
    	"content": {
    		"test":1
    		}
    	}
	}
}

This fails validation, with the first error being:

Data does not match any schemas from "oneOf"

Suggestions for fix

  • Make the id field optional
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant