sagold / json-schema-library

Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation
MIT License
164 stars 19 forks source link

Expected number type error not being returned from validation #58

Closed imolorhe closed 4 weeks ago

imolorhe commented 1 month ago

This issue was raised originally in https://github.com/acao/codemirror-json-schema/issues/69

While trying to tackle the issue, I discovered that the issue comes from json-schema-library.

Here's a diff showing a test case I added to reproduce the issue. https://github.com/sagold/json-schema-library/compare/main...imolorhe:json-schema-library:main

I'm not sure if this is expected (or perhaps there's some additional config that can be passed to force it to strictly validate the property type) but given the following schema:

{
  $schema: 'http://json-schema.org/draft-04/schema#',
  properties: {
    foo: {
      additionalProperties: false,
      properties: {
        number: {
          type: 'integer',
        },
      },
      oneOf: [
        {
          type: 'null',
        },
        {
          type: 'object'
        },
      ],
    },
  },
  additionalProperties: false,
  oneOf: [
    {
      type: 'null',
    },
    {
      type: 'object',
    },
  ],
}

and given the following data:

{
    foo: {
        number: "d"
    }
}

foo.number should fail with a type error (expected "number", got "string") but it doesn't.

sagold commented 1 month ago

Hi Samuel,

thank you for reporting this issue. I can reproduce it and will fix it asap.

Regards, Sascha

sagold commented 1 month ago

The issue has been fixed and a patch is released with json-schema-library@v9.3.5. Can you verify that this solves your problem?

Thank you!

imolorhe commented 4 weeks ago

I've confirmed that the issue is fixed. Thanks!