json-schema icon indicating copy to clipboard operation
json-schema copied to clipboard

Problems with $ref schema urls in Rails test environment

Open apsoto opened this issue 12 years ago • 1 comments

Here's my situation:

I have a Rails controller that generates various schemas.

In one such schema, I $ref another schema. The $ref url is generated using the typical Rails url helpers.

The problem arises when I try to run some tests that try to validate some data against the schemas. Since it's running in Rails TEST environment, the generated url's have 'www.example.com' as the HOST. When json-schema tries to open the $ref'ed URL, it gets a 404.

{
  "properties": {
    "foo" : { "$ref" : "http://www.example.com/schemas/foo.json" }
  }
}

I've come up with a hack to work around this, but I think the 'right' solution would be if json-schema had a means of providing pluggable URL resolvers for this type of situation.

I'm considering submitting a patch for this, but I'd like to hear anyone's thoughts on this idea or alternative solutions.

apsoto avatar Jul 31 '13 12:07 apsoto

I think that's a great idea. I'd really like to take some time and clean up the external schema referencing anyway, and provide some security flags / options around it to avoid following links, etc.

hoxworth avatar Dec 31 '13 22:12 hoxworth