Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

oneOf with $ref seems not be working #185

Closed
philippecarle opened this issue Aug 20, 2016 · 4 comments
Closed

oneOf with $ref seems not be working #185

philippecarle opened this issue Aug 20, 2016 · 4 comments

Comments

@philippecarle
Copy link

Hi,

I've played with GeoJson schema validation and can't figure out why I keep getting Failed to match exactly one schema error.

I guess it may be due to a wrong handling of "oneOf" in combination of "$ref" ?

Here is my schema :

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Geo JSON object",
  "description": "Schema for a Geo JSON object",
  "type": "object",
  "required": [ "type" ],
  "oneOf": [
    { "$ref": "#/definitions/feature" },
    { "$ref": "#/definitions/featureCollection" }
  ],
  "definitions": {
    "feature": {
      "title": "Feature",
      "description": "A Geo JSON feature object",
      "required": [ "geometry", "properties" ],
      "properties": {
        "type": { "enum": [ "Feature" ] },
        "geometry": {
          "type": [ "array","null" ]
        },
        "properties": {
          "type": [ "object", "null" ]
        }
      }
    },
    "featureCollection": {
      "title": "FeatureCollection",
      "description": "A Geo JSON feature collection",
      "required": [ "features" ],
      "properties": {
        "type": { "enum": [ "FeatureCollection" ] },
        "features": {
          "type": "array",
          "items": { "$ref": "#/definitions/feature" }
        }
      }
    }
  }
}

It's working when I try to do this against a GeoJson feature :

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Geo JSON object",
  "description": "Schema for a Geo JSON object",
  "type": "object",
  "required": [ "type" ],
  "oneOf": [
    {
      "title": "Feature",
      "description": "A Geo JSON feature object",
      "required": [ "geometry", "properties" ],
      "properties": {
        "type": { "enum": [ "Feature" ] },
        "geometry": {
          "type": [ "array","null" ]
        },
        "properties": {
          "type": [ "object", "null" ]
        }
      }
    }
  ]
}
@sanpii
Copy link
Member

sanpii commented Aug 29, 2016

Hi,

Have you try to valide your json with the validate-json command line tool? Json context is just a bridge to https://github.com/justinrainbow/json-schema.

@philippecarle
Copy link
Author

Ok I've been working once again on this and it validates with the justinrainbow's package.

Here are the files used for my tests :
example.zip

I really can't figure out what I'm doing wrong :(

@philippecarle
Copy link
Author

Ok i got it working by pointing on the dev-master of this repo… now i'm getting a "The maximum stack depth has been exceeded" error from justinrainbow/json-schema which has been fixed since more than one year. I should really consider coding these tests with a very verbose set of PHPunit tests, as this package, regarding to its very outdated dependencies and to the lack of patched versions, can't meet production requirements… :(
(i'm not whining here, just saying the purpose of this can't fit to "real-life" testing)

@sanpii
Copy link
Member

sanpii commented Oct 10, 2016

Ok, it’s related to #181

@sanpii sanpii closed this as completed Oct 10, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants