Skip to content

Draft-06 formats #173

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

Merged
merged 5 commits into from
Mar 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ runTest(4);
runTest(6);

function runTest(draft) {
var opts = {};
var opts = {format: 'full'};
if (draft == 4) opts.meta = false;
var ajv = new Ajv(opts);
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"homepage": "https://github.com/json-schema-org/JSON-Schema-Test-Suite#readme",
"devDependencies": {
"ajv": "^5.0.4-beta.0",
"ajv": "^5.0.4-beta.1",
"json-schema-test": "^1.3.0",
"mocha": "^3.2.0"
}
Expand Down
110 changes: 110 additions & 0 deletions tests/draft6/optional/format.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"data": "//foo.bar/?baz=qux#quux",
"valid": false
},
{
"description": "an invalid relative URI Reference",
"data": "/abc",
"valid": false
},
{
"description": "an invalid URI",
"data": "\\\\WINDOWS\\fileshare",
Expand All @@ -46,6 +51,75 @@
}
]
},
{
"description": "validation of URI References",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add a fragment-only URI reference, "#frag" or whatever.

"schema": {"format": "uri-reference"},
"tests": [
{
"description": "a valid URI",
"data": "http://foo.bar/?baz=qux#quux",
"valid": true
},
{
"description": "a valid protocol-relative URI Reference",
"data": "//foo.bar/?baz=qux#quux",
"valid": true
},
{
"description": "a valid relative URI Reference",
"data": "/abc",
"valid": true
},
{
"description": "an invalid URI Reference",
"data": "\\\\WINDOWS\\fileshare",
"valid": false
},
{
"description": "a valid URI Reference",
"data": "abc",
"valid": true
},
{
"description": "a valid URI fragment",
"data": "#fragment",
"valid": true
},
{
"description": "an invalid URI fragment",
"data": "#frag\\ment",
"valid": false
}
]
},
{
"description": "format: uri-template",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a URI Template that doesn't have any variables in it?

And also a URI Template that is a templated relative reference?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is templated relative reference? I don't see anything here: https://tools.ietf.org/html/rfc6570

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's not obvious but it's there. It just means that the template can look like a relative uRI reference in addition to a full URI.

At the top of page 3 in the introduction there's this:

template processor: A program or library that, given a URI Template
and a set of variables with values, transforms the template string
into a URI reference by parsing the template for expressions and
substituting each one with its corresponding expansion.

(emphasis added).

In the expansion section:

If an error occurs, the result returned might not be a valid URI
reference
; it will be an incompletely expanded template string that
is only intended for diagnostic use.

It's mentioned in several other places but I think that gets the point across :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So a templatized URI reference would be something like

/foos/{id}
/foos{?offset,limit,query}

etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Actually the spec only defines interpolation ({...}), everything outside curly braces can be anything, it doesn't have to be URI reference according to the syntax in RFC.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I can add relative reference

"schema": {
"format": "uri-template"
},
"tests": [
{
"description": "a valid uri-template",
"data": "http://example.com/dictionary/{term:1}/{term}",
"valid": true
},
{
"description": "an invalid uri-template",
"data": "http://example.com/dictionary/{term:1}/{term",
"valid": false
},
{
"description": "a valid uri-template without variables",
"data": "http://example.com/dictionary",
"valid": true
},
{
"description": "a valid relative uri-template",
"data": "dictionary/{term:1}/{term}",
"valid": true
}
]
},
{
"description": "validation of e-mail addresses",
"schema": {"format": "email"},
Expand Down Expand Up @@ -144,5 +218,41 @@
"valid": false
}
]
},
{
"description": "validation of JSON-pointers",
"schema": {"format": "json-pointer"},
"tests": [
{
"description": "a valid JSON-pointer",
"data": "/foo/bar~0/baz~1/%a",
"valid": true
},
{
"description": "empty string is valid",
"data": "",
"valid": true
},
{
"description": "/ is valid",
"data": "/",
"valid": true
},
{
"description": "not a valid JSON-pointer (~ not escaped)",
"data": "/foo/bar~",
"valid": false
},
{
"description": "valid JSON-pointer with empty segment",
"data": "/foo//bar",
"valid": true
},
{
"description": "valid JSON-pointer with the last empty segment",
"data": "/foo/bar/",
"valid": true
}
]
}
]