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

Improve data type determination for the key words “oneOf” and “allOf” #224

Open
Markus-Elfring opened this issue Nov 15, 2022 · 0 comments

Comments

@Markus-Elfring
Copy link

Markus-Elfring commented Nov 15, 2022

I constructed the following JSON schema file.

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Calculation information",
  "description": "settings for calculations",
  "$id": "https://example.com/schemas/calculation_preferences",
  "type": "object",
  "required": ["context"],
  "properties":
  {
    "context":
    {
      "type": "object",
      "oneOf":
      [
        {
          "allOf":
          [
            {
              "properties":
              {
                "label": {"const": "GTIN"}
              }
            },
            {
              "type": "array",
              "minItems": 1,
              "items":
              {
                "type": "string",
                "pattern": "^[0-9]{13}$"
              }
            }
          ]
        },
        {
          "allOf":
          [
            {
              "properties":
              {
                "label": {"const": "selection group"}
              }
            },
            {
              "type": "array",
              "minItems": 1,
              "items":
              {
                "type": "string",
                "minLength": 1
              }
            }
          ]
        }
      ]
    }
  }
}

Test data example:

{
  "context":
  {
    "GTIN": [ "1234567890123" ]
  }
}

💭 Now I am wondering about the following error information.

Markus_Elfring@…:…> ajv validate --strict=false --spec=draft2020 -s Berechnung-Kontext-Testfragment1-Schema2 -d Context-test_fragment1.json
Context-test_fragment1.json invalid
[
  {
    instancePath: '/context',
    schemaPath: '#/properties/context/oneOf/0/allOf/1/type',
    keyword: 'type',
    params: { type: 'array' },
    message: 'must be array'
  },
  {
    instancePath: '/context',
    schemaPath: '#/properties/context/oneOf/1/allOf/1/type',
    keyword: 'type',
    params: { type: 'array' },
    message: 'must be array'
  },
  {
    instancePath: '/context',
    schemaPath: '#/properties/context/oneOf',
    keyword: 'oneOf',
    params: { passingSchemas: null },
    message: 'must match exactly one schema in oneOf'
  }
]

🤔 I would appreciate further advices and solution ideas for safer data processing.

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

No branches or pull requests

1 participant