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 that worked in v4 no longer works in v5 #479

Closed
2 tasks done
smonn opened this issue Jun 29, 2022 · 0 comments · Fixed by #480
Closed
2 tasks done

Schema that worked in v4 no longer works in v5 #479

smonn opened this issue Jun 29, 2022 · 0 comments · Fixed by #480

Comments

@smonn
Copy link

smonn commented Jun 29, 2022

Prerequisites

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

Fastify version

4.2.0

Plugin version

5.0.3

Node.js version

16.15.1

Operating system

macOS

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

12.4

Description

I encountered this error after upgrading to Fastify v4.2.0 which included v5 of fast-json-stringify. This error is thrown:

Error: no schema with key or ref "schema#/properties/union/anyOf/0"
    at Ajv.validate (.../node_modules/ajv/lib/core.ts:359:21)
    at anonymous0 (eval at build (.../node_modules/fast-json-stringify/index.js:177:23), <anonymous>:45:20)
    at main (eval at build (.../node_modules/fast-json-stringify/index.js:177:23), <anonymous>:6:15)
    at Object.<anonymous> (.../src/index.ts:80:5)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module.m._compile (.../node_modules/ts-node/src/index.ts:1597:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Object.require.extensions.<computed> [as .ts] (.../node_modules/ts-node/src/index.ts:1600:12)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)

For reference, I also reported an issue over in the TypeBox repo: sinclairzx81/typebox#184

Steps to Reproduce

Use the following schema to validate { name: 'foo', union: 'a8f1cc50-5530-5c62-9109-5ba9589a6ae1' } and you should see the error. In v4 there is no error and it stringifies things correctly.

{
  "$id": "schema",
  "type": "object",
  "allOf": [
    {
      "$id": "base",
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        }
      },
      "required": [
        "name"
      ]
    },
    {
      "$id": "inner_schema",
      "type": "object",
      "properties": {
        "union": {
          "$id": "id",
          "anyOf": [
            {
              "format": "uuid",
              "$id": "guid",
              "type": "string"
            },
            {
              "format": "email",
              "$id": "email",
              "type": "string"
            }
          ]
        }
      },
      "required": [
        "union"
      ]
    }
  ]
}

Expected Behavior

It should work the same as before using v4 of fast-json-stringify.

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 a pull request may close this issue.

1 participant