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

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

Open
Yuutakasan opened this issue Mar 15, 2024 · 3 comments

Comments

@Yuutakasan
Copy link

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 Yuutakasan changed the title To validate CRUD of table information with a single Json-Schema, we propose an attribute for @PrimaryKey. To validate CRUD of table information with a single Json-Schema, we propose an attribute for PrimaryKey. Mar 15, 2024
@Era-cell
Copy link

Era-cell commented Mar 17, 2024

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

@Yuutakasan
Copy link
Author

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

@Era-cell
Copy link

Era-cell commented Mar 18, 2024

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

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

2 participants