json-schema-org / json-schema-spec

The JSON Schema specification

Home Page:http://json-schema.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

To validate CRUD of table information with a single Json-Schema, we propose an attribute for PrimaryKey.

Yuutakasan opened this issue · comments

I am currently defining an API in OpenAPI Spec, and it is great that Json-Schema can validate data structures, but I am having trouble separating Json-Schema from Json-Schema for INSERT, SELECT, UPDATE, and DELETE, because the handling of required items changes. However, I am having trouble separating Json-Schema for INSERT, SELECT, UPDATE, and DELETE because the handling of required fields changes.

I propose that the PrimaryKey attribute be set so that the same Json-schema can be used to validate each CRUD operation and the corresponding HTTP Method request.

We would like the PrimaryKey attribute to be ignored for INSERT and evaluated as required for UPDATE, PATHCH, and DELETE operations when the validator is told which CRUD operation is being processed.

It is painful that in the case of Entity definitions in ORM, one definition can manage all CRUDs, but Json-Schema does not.

Again, if anyone knows of a good solution, please let me know.

Hi, @Yuutakasan can you provide an example, there isn't a reserved keyword for primary key but can help you with a solution:
As per my present understanding you can use

 if : {
   properties: name:{enum:[ "patch", "update", "delete"]},
}then{
  properties: primarykey: { your conastraints on primary key goes here}
  required: ["primarykey"]
}else{
  not {required: ["primarykey"]}
}

you can use else if you do not want "primarykey" attribute at any case during insert opearation

@Era-cell
Oh Thanx!
I see. My editor just doesn't support the if else syntax, so my lack of understanding was the problem.
Then it's not a problem with the Json-shema specification.

Thanks for the very clear explanation.

This reserved word itself should be there if possible.

@Yuutakasan I didn't get it do you want another way of implementing the same,
or if you got the solution I guess you can close the issue. 😁
And I guess authors are working on primary key, looks like its been asked by many people: "primarykey"