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

db: add allowPrimaryKeyInInput option #2082

Merged
merged 8 commits into from
Feb 12, 2024
Merged

db: add allowPrimaryKeyInInput option #2082

merged 8 commits into from
Feb 12, 2024

Conversation

mcollina
Copy link
Member

@mcollina mcollina commented Feb 9, 2024

No description provided.

Signed-off-by: Matteo Collina <hello@matteocollina.com>

{
"id": 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, if allowIdInInput is set to false it should generate a route schema without an id prop and here it should throw a 400 because data has an ddditional property. And if you do it programatically (with sql-mapper) it also should throw an error. Otherwise it looks like a place for a very nasty bug. wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s how the schemas are generated. However Ajv/Fastify do not error in this case, but they rather filter the additional property.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Then IMHO it should throw an error on a sql-mapper level.
  2. It's easy to create a schema that would fail if some known property exist. Just set false for a property schema.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My problem is that it would be really hard to notice the problem if you pass an id and allowPrimaryKeyInInput set to false. If you think that skipping is the best behavior it should at least log a warn message.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not possible to do it in sql-mapper because I’ve implemented .save() as an upsert.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's easy to create a schema that would fail if some known property exist. Just set false for a property schema.

Oh I’ll try this!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I’ll try this!

Or you can do this. Choose the error message you like more.

{
  "type": "object",
  "not": {
    "required": ["foo"]
  }
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with a slightly different syntax that gave a better error message.

docs/reference/sql-openapi/api.md Outdated Show resolved Hide resolved
docs/reference/sql-openapi/api.md Outdated Show resolved Hide resolved
docs/reference/sql-openapi/api.md Outdated Show resolved Hide resolved
mcollina and others added 7 commits February 11, 2024 09:35
Co-authored-by: Ivan Tymoshenko <ivan@tymoshenko.me>
Co-authored-by: Ivan Tymoshenko <ivan@tymoshenko.me>
Co-authored-by: Ivan Tymoshenko <ivan@tymoshenko.me>
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Copy link
Member

@ivan-tymoshenko ivan-tymoshenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 5792836 into main Feb 12, 2024
86 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants