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

Couldn't resolve URI - json_schema-0.20.6/lib/json_schema/reference_expander.rb:43:in `expand!' #117

Open
jerko-culina opened this issue Jul 18, 2019 · 1 comment

Comments

@jerko-culina
Copy link

Hi,
sorry if this is not the right place for this error bellow.
Ruby 2.5.5
Rails 2.5.3
json_schema-0.20.6

I got next error.
When I try to match occupancy.json, everything works fine.
When I try to match occupancies.json I got this error.

Schema files are bellow. Can't figure why it's happening!!

Error:

JsonSchema::AggregateError: #/properties/data/items: Couldn't resolve URI: file:///occupancy.json. #: Couldn't resolve references: file:///occupancy.json#/definitions/occupancy.
from /Users/pc/.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/json_schema-0.20.6/lib/json_schema/reference_expander.rb:43:in `expand!'

Schema files:
occupancies.json

{
  "properties": {
    "data": {
      "type": "array",
      "items": { "$ref": "file:/occupancy.json#/definitions/occupancy" }
    },
    "meta": {
      "type": "object",
      "properties":{
        "current_page": { "type": "number" },
        "total_pages": { "type": "number" },
        "total_count": { "type": "number" },
        "max_page_size": { "type": "number" }
      }
    }
  }
}

occupancy.json

{
  "$id": "file:/occupancy.json#",
  "definitions": {
    "occupancy": {
      "type": "object",
      "properties": {
        "id": { "type": "string" },
        "type": { "type": "string" },
        "attributes": {
          "type": "object",
          "properties": {
            "type": { "type": "string" },
            "updated_at": {
              "type": "string",
              "format": "date-time"
            }
          }
        }
      }
    }
  },
  "properties": {
    "data": { "$ref": "#/definitions/occupancy" }
  }
}
@kytrinyx
Copy link
Contributor

I think I've run into something similar, and I didn't have the time to debug it properly at the time, so I made a workaround that used a fake URL for the $id. Something like this:

"$id": "https://schemas.yourdomain.com/occupancy.json",

And then reference it in items:

"items": { "$ref": "https://schemas.yourdomain.com/occupancy.json#/definitions/occupancy" }

Let me know if that works—if it doesn't I'll try to make a failing test so we can debug.

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

No branches or pull requests

2 participants