-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
docs: Extend TypeBox documentation #3437
Conversation
ajv: { | ||
customOptions: { | ||
strict: 'log', | ||
keywords: ['kind', 'modifier'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be great to inform in which cases specifying the keywords is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow that was quick :) I've added the following informations:
TypeBox uses the properties kind
and modifier
internally. Those are not strictly valid JSON schema and will throw an AJV error. To remove the error it's either necessary to omit the properties by using Type.strict()
or use the AJV options for adding custom keywords.
cc @sinclairzx81 :) |
docs/Type-Providers.md
Outdated
@@ -85,4 +85,6 @@ server.get('/route', { | |||
}) | |||
``` | |||
|
|||
TypeBox uses the properties `kind` and `modifier` internally. Those are not strictly valid JSON schema and will throw an AJV error. To remove the error it's either necessary to omit the properties by using [`Type.strict()`](https://github.com/sinclairzx81/typebox#strict) or use the AJV options for adding custom keywords. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type.strict()
should be capitalized as Type.Strict()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly rephrase
Those are not strictly valid JSON schema and will throw an AJV error
as
These properties are not strictly valid JSON schema which will cause AJV to throw an invalid schema error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Comments are incorporated now :)
@Jnig Looks good to me. Nice work :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sinclairzx81 I'm assuming that those changes are also necessary if the user would like to work with typebox (even without type-providers) on v4, is that right?
I'm wondering if we can do something to make it built-in in order to avoid the needs of the user to set up it by themselves.
@RafaelGSS Hi. The requirement to specify the There's only two options I can think of to make this automatic for users:
Option 1 is not really workable as it would require Fastify to have knowledge of an external libraries internals. But Option 2 could be worth exploring. The In the context of Fastify, internally implementing this serialize / deserialize pass to clean schemas prior to AJV compilation may prove workable given that schema compilation only happens once at start up. Such a step would permit users an escape hatch to include additional metadata on their schemas, (with the rule being that the metadata MUST NOT be serializable to JSON). I wouldn't expect the serialize/deserialize step to be much of an added cost over the existing AJV compilation pass (tho it would be worth measuring for larger schemas). Hope this helps! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's explicitly define the version of ajv which those settings are needed.
Having a solution which works without additional configuration would be perfect. Than it would be the same as for fastify 3. |
Co-authored-by: Rafael Gonzaga <rafael.nunu@hotmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
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. |
Hi,
the following PR closes #3421 and adds additional documentation how to use TypeBox with fastify v4.
Checklist
and the Code of conduct