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

schema.response without a status code throws a cryptic error message #3932

Closed
2 tasks done
evanshortiss opened this issue May 24, 2022 · 2 comments · Fixed by #3935
Closed
2 tasks done

schema.response without a status code throws a cryptic error message #3932

evanshortiss opened this issue May 24, 2022 · 2 comments · Fixed by #3935
Labels
semver-minor Issue or PR that should land as semver minor

Comments

@evanshortiss
Copy link
Member

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

3.29

Plugin version

No response

Node.js version

16.x

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

12.3.1

Description

The current response schema definition is:

schema: {
  response: {
    $STATUS_CODE: your_schema_here
  }
}

I accidentally typed the following:

schema: {
  response:  your_schema_here
}

This results in an error that is a little cryptic, in my opinion:

FastifyError [Error]: Failed building the serialization schema for GET: /meters, due to error schema is invalid: data.properties should be object

It seems like this mistake could be captured by fastify, and a better error message could be returned to the user? Obviously the best solution is to RTFM correctly, so I understand if this is deemed not worthwhile :)

Steps to Reproduce

Pass a schema directly to response, without specifying a status code:

app.route({
  url: '/',
  method: 'GET',
  schema: {
    response: {
      type: 'array'
    }
  },
  handler: (req, reply) => {
    reply.send([])
  }
})

Expected Behavior

An error message stating "response schemas should be nested under a response code, e.g { 200: { type: 'object' } }" or similar.

@mcollina
Copy link
Member

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@evanshortiss
Copy link
Member Author

@mcollina sure, I can look into it 👍

@climba03003 climba03003 linked a pull request May 26, 2022 that will close this issue
4 tasks
@Eomm Eomm added the semver-minor Issue or PR that should land as semver minor label Apr 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor Issue or PR that should land as semver minor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants