json-schema-org / json-schema-spec

The JSON Schema specification
http://json-schema.org/
Other
3.65k stars 257 forks source link

format: add uritemplate and jsonpointer #109

Closed handrews closed 7 years ago

handrews commented 7 years ago

We currently have uri and uriref for indicating an expectation of RFC 3986 conformance. While I don't think we should have formats for all RFC-defined things, since hyper-schema itself relies on URI Templates (RFC 6570) and JSON Pointer (RFC 6901), it seems reasonable to include them. It would make our meta-schema more clear as well.

handrews commented 7 years ago

@Relequestual @awwright @epoberezkin any thoughts? This should be a pretty straightforward yes or no, I think. Just a question of "do we want enough defined formats to be able to identify the formats on which JSON Schema itself depends?"

erosb commented 7 years ago

+1 for jsonpointer , I'm neutral about uritemplate .

epoberezkin commented 7 years ago

@erosb same here

handrews commented 7 years ago

@epoberezkin @erosb why less interested in uritemplate? It is a distinct format from uri and urireference and one on which we are entirely dependent for hyper schema (currently in two different keywords, href and base). Being able to express our own usage seems beneficial, particularly given the optional nature of format.

Relequestual commented 7 years ago

@handrews Could you give examples of both? I'm not familiar with either, and therefore how this would look, which makes it difficult to know if I'm for or against.

handrews commented 7 years ago

[edit: haven't had caffeine yet, was using $ref wrong, took it out] @Relequestual uritemplate is what we use for href and base. So in the meta-schema:

{
    "type": "object",
    "properties": {
        ...,
        "href": {
            "type": "string",
            "format": "uritemplate"
        },
        "base": {
            "type": "string",
            "format": "uritemplate"
        },
        ...
    }
}
handrews commented 7 years ago

@Relequestual currently we don't have anything where we only use JSON Pointer, but JSON Pointer is the fragment syntax we use in $ref. Some proposals use JSON Pointers directly instead of as part of URIs.

handrews commented 7 years ago

Here is a better use of JSON Pointer. This is a (probably not quite right) schema for the JSON Patch media type:

{
    "type": "array",
    "items": {
        "type": "object",
        "required": ["op", "path"],
        "properties": {
            "path": {
                "type": "string",
                "format": "jsonpointer"
            }
        },
        "oneOf": [
            {"properties": {"op": {"const": "remove"}}},
            {
                "required": ["value"],
                "properties": {
                    "op": {"enum": ["test", "add", "replace"]},
                    "value": {}
                }
            },
            {
                "required": ["from"],
                "properties": {
                    "op": {"enum": ["move", "copy"]},
                    "from": {"type": "string", "format": "jsonpointer"}
                }
            }
        ]
    }
}
erosb commented 7 years ago

Created a PR for an other way of defining json pointers: #141

Relequestual commented 7 years ago

OK, I feel I understand now. I'm for this! =]

handrews commented 7 years ago

Resolved by PR #150.