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

Support $ref in anyOf/oneOf #169

Closed
Kricket opened this issue Nov 22, 2023 · 1 comment
Closed

Support $ref in anyOf/oneOf #169

Kricket opened this issue Nov 22, 2023 · 1 comment
Assignees
Labels
invalid This doesn't seem right

Comments

@Kricket
Copy link

Kricket commented Nov 22, 2023

Given the following schema:

{
  "type": "object",
  "definitions": {
    "type_1": {
      "type": "string",
      "pattern": "^[0-9]+$"
    },
    "type_2": {
      "enum": ["blabla"]
    }
  },
  "properties": {
    "someProperty": {
      "oneOf": [
        {
          "$ref": "#/definitions/type_1"
        },
        {
          "$ref": "#/definitions/type_2"
        }
      ]
    }
  }
}

Validation fails when given an object that is valid for this schema.
However, validation passes if the $refs are replaced with their actual schemas.

@ChALkeR
Copy link
Contributor

ChALkeR commented Nov 24, 2023

Can't reproduce:

const schema1 = {
  "type": "object",
  "definitions": {
    "type_1": {
      "type": "string",
      "pattern": "^[0-9]+$"
    },
    "type_2": {
      "enum": ["blabla"]
    }
  },
  "properties": {
    "someProperty": {
      "oneOf": [
        {
          "$ref": "#/definitions/type_1"
        },
        {
          "$ref": "#/definitions/type_2"
        }
      ]
    }
  }
}

const v1 = validator(schema1)
console.log(v1({ someProperty: 10 })) // false
console.log(v1({ someProperty: "---" })) // false
console.log(v1({ someProperty: "012345" })) // true
console.log(v1({ someProperty: "blabla" })) // true
console.log(v1({ someProperty: "blablabla" })) // false

Could you share a complete testcase and the version that you are using?

@ChALkeR ChALkeR self-assigned this Nov 24, 2023
@ChALkeR ChALkeR added the invalid This doesn't seem right label Dec 21, 2023
@ChALkeR ChALkeR closed this as completed Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants