Skip to content

Commit

Permalink
feat(schema): add full support for "A Vocabulary for the Contents of …
Browse files Browse the repository at this point in the history
…String-Encoded Data"
  • Loading branch information
trieloff committed Dec 16, 2019
1 parent 689c158 commit 96ca3a6
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 5 deletions.
13 changes: 13 additions & 0 deletions lib/markdownBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,19 @@ function build({
constraints.push(paragraph([strong(text(i18n`unknown format`)), text(': '), text(i18n`the value of this string must follow the format: `), inlineCode(String(schema.format))]));
}

if (schema[keyword`contentEncoding`]) {
constraints.push(paragraph([strong(text(i18n`encoding`)), text(': '), text(i18n`the string content must be using the ${schema[keyword`contentEncoding`]} content encoding.`)]));
}
if (schema[keyword`contentMediaType`]) {
constraints.push(paragraph([strong(text(i18n`media type`)), text(': '), text(i18n`the media type of the contents of this string is: `), inlineCode(String(schema[keyword`contentMediaType`]))]));
}
if (schema[keyword`contentSchema`]) {
constraints.push(paragraph([
strong(text(i18n`schema`)), text(': '),
text(i18n`the contents of this string should follow this schema: `),
link(`${schema[keyword`contentSchema`][s.slug]}.md`, i18n`check type definition`, text(gentitle(schema[keyword`contentSchema`][s.titles], schema[keyword`contentSchema`][keyword`type`])))]));
}

// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.4
if (schema[keyword`maxItems`] !== undefined) {
// console.log('maxItems!', schema[s.filename], schema[s.pointer]);
Expand Down
10 changes: 5 additions & 5 deletions schemasupport.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# JSON Schema Spec Coverage Report

This report lists the keywords of the JSON Schema spec that are covered in the tests. The overall coverage is 69%
This report lists the keywords of the JSON Schema spec that are covered in the tests. The overall coverage is 73%

## The JSON Schema Core Vocabulary

Expand Down Expand Up @@ -125,13 +125,13 @@ Coverage for [Defined Formats](https://json-schema.org/draft/2019-09/json-schema

## A Vocabulary for the Contents of String-Encoded Data

Coverage for [A Vocabulary for the Contents of String-Encoded Data](https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.8) is 0%.
Coverage for [A Vocabulary for the Contents of String-Encoded Data](https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.8) is 100%.

| Keyword | Supported |
| :----------------- | --------- |
| `contentEncoding` | No |
| `contentMediaType` | No |
| `contentSchema` | No |
| `contentEncoding` | Yes |
| `contentMediaType` | Yes |
| `contentSchema` | Yes |

## A Vocabulary for Basic Meta-Data Annotations

Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/content/html.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "string",
"title": "HTML",
"contentMediaType": "text/html"
}
26 changes: 26 additions & 0 deletions test/fixtures/content/jwt.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"type": "string",
"title": "JWT",
"contentMediaType": "application/jwt",
"contentSchema": {
"title": "JSON Web Token",
"type": "array",
"minItems": 2,
"items": [
{
"const": {
"typ": "JWT",
"alg": "HS256"
}
},
{
"type": "object",
"required": ["iss", "exp"],
"properties": {
"iss": {"type": "string"},
"exp": {"type": "integer"}
}
}
]
}
}
6 changes: 6 additions & 0 deletions test/fixtures/content/png.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "string",
"title": "PNG",
"contentEncoding": "base64",
"contentMediaType": "image/png"
}
26 changes: 26 additions & 0 deletions test/markdownBuilder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@ const { assertMarkdown, loadschemas } = require('./testUtils');

const build = require('../lib/markdownBuilder');

describe('Testing Markdown Builder: content', () => {
let results;

before(async () => {
const schemas = await loadschemas('content');
const builder = build({ header: false });
results = builder(schemas);
});

it('PNG Schema looks OK', () => {
assertMarkdown(results.png)
.contains('**encoding**: the string content must be using the base64 content encoding.');
});

it('HTML Schema looks OK', () => {
assertMarkdown(results.html)
.contains('**media type**: the media type of the contents of this string is: `text/html`');
});

it('JWT Schema looks OK', () => {
assertMarkdown(results.jwt)
.contains('**schema**: the contents of this string should follow this schema: [JSON Web Token](jwt-json-web-token.md "check type definition")')
.contains('**media type**: the media type of the contents of this string is: `application/jwt`');
});
});

describe('Testing Markdown Builder: not', () => {
let results;

Expand Down

0 comments on commit 96ca3a6

Please sign in to comment.