jhthorsen / json-validator

:cop: Validate data against a JSON schema
https://metacpan.org/release/JSON-Validator
56 stars 58 forks source link

Is JSON::Validator allows to use nullable and oneOf keyword? #241

Closed avkhozov closed 3 years ago

avkhozov commented 3 years ago

Steps to reproduce the behavior

I have a test script with schema where object property use oneOf keyword and one of $ref have nullable attribute.

use JSON::Validator;

my $schema = JSON::Validator->new->schema('data://main/spec.json')->schema;

my $body = {exists => 1, value => {name => undef}};

my @errors = $schema->validate_response([get => "/test"], { body => \&body });
warn "@errors" if @errors;

sub body {$body}

__DATA__
@@ spec.json
{
  "openapi": "3.0.0",
  "info": { "title": "Nullable", "version": "" },
  "paths": {
    "/test": {
      "get": {
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "oneOf": [
                        { "$ref": "#/components/schemas/name1" },
                        { "$ref": "#/components/schemas/name2" }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "name1": { "type": "string", "nullable": "true" },
      "name2": { "type": "integer" } }
  }
}

Expected behavior

There is no errors in output

Actual behavior

I got an error /body/name: /oneOf Expected string/integer - got null. at test.pl line 8.