Skip to content

Expected type not working #69

@loganripplinger

Description

@loganripplinger

Repro steps

I am using schemas generated from protobufs via protoc-gen-jsonschema.

I am using JSON4 not JSON5.

Use this schema to reproduce the problem show below:

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

I further narrowed it down to this schema (in JS/JSON5 instead of JSON4, though I am still using the JSON4 plugin):

{
  $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',
    },
  ],
}

Of note if you remove properties.oneOf and instead just use type: 'object' it will correctly show the error:

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

Expected Behavior

An error should appear.

image

Actual Behavior

No error appears.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingupstream

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions