Skip to content

Handle missing schema/handler#6

Merged
mcollina merged 3 commits intomasterfrom
missing-schema
Oct 11, 2016
Merged

Handle missing schema/handler#6
mcollina merged 3 commits intomasterfrom
missing-schema

Conversation

@delvedor
Copy link
Copy Markdown
Member

No description provided.

fastify.js Outdated
if (!opts.handler && typeof opts.schema === 'function') {
opts.handler = opts.schema
opts.schema = {}
}
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.

This is not ok. This block should go within the get/post/put etc code. This does the same job, but it is unreadable, and it might allow further bugs down the road.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok initially that code was inside the shorthand functions but then I put it there and not in the shorthand function to avoid code repeat.
I'll update this :)

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.

You should also add a missing schema test in post/put and get.

if (!handler && typeof schema === 'function') {
handler = schema
schema = {}
}
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.

we can probably put this into a little helper, something like route(fill({ method: 'PUT', url }, schema, handler)).
Or _route({ method: 'PUT', url }, schema, handler), which contains this logic.

The important piece is that it should not be applied to the options, but to the function arguments.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok! I'll go with _route.

fastify.js Outdated
}
return route({
method: 'PUT',
method: method,
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.

you can use the shorthands for the options route({ method, url, schema, handler }).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We haven't talked about this, the Node support will be ≥ v4?

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.

yes. We might even choose v6+ if needed. Currently the codebase only run on v6 because of the destructuring in tests.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've run the tests under node v4 and only throw.test.js failed (because of the destructuring assignment), with a super tiny fix we can make the code base v4 compatible.
Should we support v4? In my opinion, yes.

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.

let's finish this off (shorthands for properties works on v4 and v6), and send a PR to add v4 support to travis (I've just added it in master).

@mcollina mcollina merged commit 6e37cb7 into master Oct 11, 2016
@mcollina mcollina deleted the missing-schema branch October 11, 2016 06:31
jcaowml pushed a commit to jcaowml/fastify that referenced this pull request Dec 19, 2019
* update/cleanup tests

* stop server in afterEach

* fix verify
haggholm pushed a commit to haggholm/fastify that referenced this pull request Jun 12, 2021
….20.0

Update fastify-cli to the latest version 🚀
@github-actions
Copy link
Copy Markdown

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 Feb 25, 2022
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.

2 participants