Skip to content

Instantly share code, notes, and snippets.

@jadeallenx
Last active January 4, 2018 21:21
Show Gist options
  • Select an option

  • Save jadeallenx/c49eaa48dbe8fc3f69ae44defbc287b3 to your computer and use it in GitHub Desktop.

Select an option

Save jadeallenx/c49eaa48dbe8fc3f69ae44defbc287b3 to your computer and use it in GitHub Desktop.

Revisions

  1. Mark Allen revised this gist Jan 4, 2018. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions refs.md
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,8 @@ I tried to make things as simple as possible. I had a file with the "base" schem
    "type": "number"
    }
    }
    }```
    }
    ```

    And then I had another file which took a collection of these items. It looked like this:

    @@ -32,7 +33,8 @@ And then I had another file which took a collection of these items. It looked li
    "items": { "$ref": "record" }
    }
    }
    }```
    }
    ```

    The intention here is clear - I want to reuse the schema for record as the elements in an array. For example, this is a valid input against the schema:

    @@ -48,7 +50,8 @@ The intention here is clear - I want to reuse the schema for record as the eleme
    "bar": 19.2
    }
    ]
    }```
    }
    ```

    But how to communicate this to jesse? Well, it turns out that jesse canonicalizes your references - it insists on prefixing your ids with a URL - either "http://" or "file://". So to make this work in jesse, I needed to prefix both my ids with "file://" and then always reuse "file://record" anytime I wanted to use it elsewhere.

  2. Mark Allen created this gist Jan 4, 2018.
    57 changes: 57 additions & 0 deletions refs.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    If you use the [jesse][1] application for JSON schema validation, you will no doubt be mystified by the byzantine way that references are handled in the application. I spent well over 30 hours trying to figure it out, since it is totally undocumented what the format should be.

    I tried to make things as simple as possible. I had a file with the "base" schema for an item. I called it `record.json` It looked something like this:

    ```json
    {
    "id": "record",
    "description": "Base schema for a valid record",
    "type": "object",

    "properties": {
    "foo": {
    "type": "string"
    },
    "bar": {
    "type": "number"
    }
    }
    }```

    And then I had another file which took a collection of these items. It looked like this:

    ```json
    {
    "id": "records-bulk",
    "description": "A collection of records",
    "type": "object",

    "properties": {
    "records": {
    "type": "array",
    "items": { "$ref": "record" }
    }
    }
    }```

    The intention here is clear - I want to reuse the schema for record as the elements in an array. For example, this is a valid input against the schema:

    ```json
    {
    "records": [
    {
    "foo": "hoge",
    "bar": 42
    },
    {
    "foo": "qux",
    "bar": 19.2
    }
    ]
    }```

    But how to communicate this to jesse? Well, it turns out that jesse canonicalizes your references - it insists on prefixing your ids with a URL - either "http://" or "file://". So to make this work in jesse, I needed to prefix both my ids with "file://" and then always reuse "file://record" anytime I wanted to use it elsewhere.

    Apparently it is not possible to have "naked" references for reasons I can't possibly fathom. I might open a PR about this because it almost beggars imagination.

    [1]: https://github.com/for-GET/jesse