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

Ajv validation inside allOf #481

Closed
2 tasks done
ivan-tymoshenko opened this issue Jun 29, 2022 · 7 comments · Fixed by #482
Closed
2 tasks done

Ajv validation inside allOf #481

ivan-tymoshenko opened this issue Jun 29, 2022 · 7 comments · Fixed by #482
Labels
bug Confirmed bug

Comments

@ivan-tymoshenko
Copy link
Member

Prerequisites

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

Issue

There is a fastify issue fastify/fastify#4092
I reduced the test example.

test('anyOf inside allOf', (t) => {
  t.plan(1)

  const schema = {
    anyOf: [
      {
        type: 'object',
        allOf: [
          {
            properties: {
              a: {
                anyOf: [
                  { const: 'A1' },
                  { const: 'A2' }
                ]
              }
            }
          },
          {
            properties: {
              b: { const: 'B' }
            }
          }
        ]
      }
    ]
  }

  const object = { a: 'A1', b: 'B' }
  const stringify = build(schema)
  const output = stringify(object)

  t.equal(output, JSON.stringify(object))
})

I'm working on that.

@ivan-tymoshenko ivan-tymoshenko added the bug Confirmed bug label Jun 29, 2022
@climba03003
Copy link
Member

Will it be fixed by #480

@ivan-tymoshenko
Copy link
Member Author

@climba03003 No, it's a different issue.

@ivan-tymoshenko
Copy link
Member Author

This problem happens when we add a schema that contains allOf property to the Ajv, and then we merge allOf and use json pointer that doesn't contain allOf.

@ivan-tymoshenko
Copy link
Member Author

@climba03003 It turns out that #480 fixed this, despite the fact that they are different problems. #480 has a small bug. I fixed it here #482.

@smonn
Copy link

smonn commented Jun 29, 2022

FWIW, I think I encountered this issue too while using a schema similar to this (observed in 5.0.4, unrelated to #479):

{
  "type": "object",
  "required": [
    "list"
  ],
  "properties": {
    "list": {
      "type": "array",
      "items": {
        "type": "object",
        "allOf": [
          {
            "type": "object",
            "required": [
              "value"
            ],
            "properties": {
              "value": {
                "anyOf": [
                  {
                    "type": "string",
                    "const": "one"
                  },
                  {
                    "type": "string",
                    "const": "two"
                  }
                ]
              }
            }
          }
        ]
      }
    }
  }
}
Error: no schema with key or ref "merged_d63d76d2-7f36-4b28-8997-579e7e46cfdb#/properties/list/items/properties/value/anyOf/0"
    at Ajv.validate (..../node_modules/ajv/lib/core.ts:359:21)
    at anonymous2 (eval at build (..../node_modules/fast-json-stringify/index.js:177:23), <anonymous>:30:20)
    at anonymous1 (eval at build (..../node_modules/fast-json-stringify/index.js:177:23), <anonymous>:64:17)
    at anonymous0 (eval at build (..../node_modules/fast-json-stringify/index.js:177:23), <anonymous>:92:15)
    at main (eval at build (..../node_modules/fast-json-stringify/index.js:177:23), <anonymous>:6:15)
    at Object.<anonymous> (..../src/index.ts:345:27)
    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)

@ivan-tymoshenko
Copy link
Member Author

FWIW, I think I encountered this issue too while using a schema similar to this (observed in 5.0.4, unrelated to #479):

Does it work with this fix?

@smonn
Copy link

smonn commented Jun 29, 2022

Does it work with this fix?

Yep! #482 fixes it for me too.

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

Successfully merging a pull request may close this issue.

3 participants