Skip to content

fix: set default value for route schema to match type#5395

Closed
nflaig wants to merge 3 commits intofastify:mainfrom
nflaig:schema-default
Closed

fix: set default value for route schema to match type#5395
nflaig wants to merge 3 commits intofastify:mainfrom
nflaig:schema-default

Conversation

@nflaig
Copy link
Copy Markdown
Contributor

@nflaig nflaig commented Apr 9, 2024

Alternative to #5394 which changes runtime behavior instead of updating type

Closes #5393

Checklist

@nflaig nflaig mentioned this pull request Apr 9, 2024
2 tasks
Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Can you add a test for this change?

@mcollina
Copy link
Copy Markdown
Member

I personally prefer this to #5394.

@nflaig
Copy link
Copy Markdown
Contributor Author

nflaig commented Apr 23, 2024

Can you add a test for this change?

done

@nflaig nflaig closed this Apr 23, 2024
@nflaig nflaig reopened this Apr 23, 2024
@nflaig
Copy link
Copy Markdown
Contributor Author

nflaig commented Apr 23, 2024

I personally prefer this to #5394.

yeah, I like it more as well since updating the type might annoy some people, and it's really just an edge case inside hooks

Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

},
schema: {
get: () => context.schema
get: () => context.schema ?? {}
Copy link
Copy Markdown
Member

@gurgunday gurgunday May 5, 2024

Choose a reason for hiding this comment

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

Isn't this enough to not get undefined?

Nope it's the deprecated version, sorry!

Copy link
Copy Markdown
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

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

lgtm

I think in next we should fix the type instead and it should be undefined

Comment on lines +90 to +91
t.not(req.routeSchema, undefined)
t.not(req.routeOptions.schema, undefined)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TBH I don't like this default.

How do the user know if a schema has been set?

Now: if(req.routeSchema==null)

Then: if(req.routeSchema.id==null) + the overhead to create a new empty object

Why don't we fix the types instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reopened #5394, both PRs fix the issue I reported but you guys know best what other use cases to consider.

I go with whatever is decided here :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we go with this in v4, I’d say right after we should revert this in v5 and merge your other (type) PR there

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If we go with this in v4, I’d say right after we should revert this in v5 and merge your other (type) PR there

sounds like a plan, do you want the revert of this to be part of the type PR then? (needs rebase on next first)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@gurgunday @Eomm then we go with the other PR. Let's not land and revert.

@nflaig
Copy link
Copy Markdown
Contributor Author

nflaig commented May 7, 2024

Closing as #5394 has been merged to main

@nflaig nflaig closed this May 7, 2024
@github-actions
Copy link
Copy Markdown

github-actions bot commented May 8, 2025

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Route schema might be undefined

5 participants