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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Schema Error: missing id schema when set $schema #1353

Closed
Eomm opened this issue Dec 24, 2018 · 3 comments
Closed

JSON Schema Error: missing id schema when set $schema #1353

Eomm opened this issue Dec 24, 2018 · 3 comments
Labels
bug Confirmed bug

Comments

@Eomm
Copy link
Member

Eomm commented Dec 24, 2018

馃悰 Bug Report

I'm working on issue 1329 and so I'm trying the docs I'm writing, but I got this error when using the following schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "someKey": {
      "type": "string"
    }
  }
}

Error:
FastifyError [FST_ERR_SCH_NOT_PRESENT]: FST_ERR_SCH_NOT_PRESENT: Schema with id 'http://json-schema.org/draft-07/schema' does not exist!
    at Schemas.resolve (C:\Users\behem\workspace\fastify\lib\schemas.js:30:11)
    at Schemas.traverse (C:\Users\behem\workspace\fastify\lib\schemas.js:76:26)
    at Schemas.traverse (C:\Users\behem\workspace\fastify\lib\schemas.js:80:12)
    at Schemas.resolveRefs (C:\Users\behem\workspace\fastify\lib\schemas.js:49:10)
    at build (C:\Users\behem\workspace\fastify\lib\validation.js:29:28)
    at afterRouteAdded (C:\Users\behem\workspace\fastify\fastify.js:636:9)
    at C:\Users\behem\workspace\fastify\fastify.js:596:7

To Reproduce

const fastify = require('fastify')({ logger: true })
const { FluentSchema } = require('fluent-schema')

const bodySchema = FluentSchema()
  .prop(
    'someKey',
    FluentSchema()
      .asString()
  )

const schema = { body: bodySchema.valueOf() }

fastify.post('/the/url', { schema }, (request, reply) => {
  reply.send({ hello: 'world' })
})

fastify.listen(3000, (err, address) => {
  if (err) throw err
  fastify.log.info(`server listening on ${address}`)
})

Expected behavior

I don't expect the thrown's error. The $schema is raccomended by the standard so, maybe I'm missing something or this field should be ignored?

If I remove the $schema field, all is working:

delete schema.body.$schema

Your Environment

  • node version: 8.14.0
  • fastify version: 2.0.0-rc.3
  • os: Windows 10
  • fluent-schema: 0.4.0
@mcollina
Copy link
Member

This is actually a bug in fastify! Good spot.

I think $schema must be ignored in

if (typeof schema[key] === 'string' && schema[key].slice(-1) === '#') {
. Would you like to send a PR for this as well?

@mcollina mcollina transferred this issue from fastify/help Dec 25, 2018
@mcollina
Copy link
Member

I've moved this issue from fastify/help聽 to fastify/fastify聽 as it's actually a bug.

@mcollina mcollina added the bug Confirmed bug label Dec 25, 2018
@Eomm
Copy link
Member Author

Eomm commented Dec 25, 2018

Would you like to send a PR for this as well?

Sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

2 participants