json-schema-spec icon indicating copy to clipboard operation
json-schema-spec copied to clipboard

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

Open Yuutakasan opened this issue 1 year ago • 4 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.

Yuutakasan avatar Mar 15 '24 10:03 Yuutakasan

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

suprith-hub avatar Mar 17 '24 19:03 suprith-hub

@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 avatar Mar 18 '24 03:03 Yuutakasan

@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"

suprith-hub avatar Mar 18 '24 03:03 suprith-hub

@Yuutakasan please confirm, but I think this is a duplicate of #1488.

gregsdennis avatar Jun 18 '24 22:06 gregsdennis