Skip to content

Remove schema from external schemas #14

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

Merged

Conversation

ivan-tymoshenko
Copy link
Member

Checklist

It's not needed to pass the target schema in the external schemas.

@mcollina
Copy link
Member

Does this pass all test in Fastify too?

@mcollina mcollina requested a review from Eomm June 14, 2022 15:26
@ivan-tymoshenko
Copy link
Member Author

Does this pass all test in Fastify too?

Yes.

index.js Outdated
@@ -10,6 +10,10 @@ function SerializerSelector () {
}

function responseSchemaCompiler (fjsOpts, { schema /* method, url, httpStatus */ }) {
if (fjsOpts.schema && schema.$id) {
Copy link
Member

Choose a reason for hiding this comment

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

Has this addition a source issue?

The use case is when the same schema is added to the compiler opts and to a route's configuration

Copy link
Member Author

Choose a reason for hiding this comment

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

This happens when we use fastify.getSchema when creating a new schema. fastify/fastify#4023
Here is the same code for the schema validator. https://github.com/fastify/ajv-compiler/blob/10879404784f69aa8c5488f77622b52532a28799/index.js#L80

This PR only solves part of the problem (top level $id). Ajv solves the rest. More about it here. fastify/fastify#4023 (comment)

Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

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

Ok, I get the time to focus on it.

This change removes from the externalSchemas parameter the input schema if it is already in (or a double schema error would be thrown)

added a suggestion and I would like a dedicated test that replicates the error. As said it should be necessary to use the same schema from input and as an external schema.

Then it LGTM!

index.js Outdated
@@ -10,6 +10,10 @@ function SerializerSelector () {
}

function responseSchemaCompiler (fjsOpts, { schema /* method, url, httpStatus */ }) {
if (fjsOpts.schema && schema.$id) {
Copy link
Member

Choose a reason for hiding this comment

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

Adding a condition to avoid unuseful delete call

Suggested change
if (fjsOpts.schema && schema.$id) {
if (fjsOpts.schema && schema.$id && fjsOpts.schema[schema.$id]) {

Copy link
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

@mcollina mcollina merged commit 336f5c1 into fastify:main Jun 22, 2022
@ivan-tymoshenko ivan-tymoshenko deleted the remove-schema-from-external-schemas branch June 22, 2022 14:11
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.

4 participants