Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit db6fadb

Browse files
committed
Adds draft 6 examples
1 parent b33ca9b commit db6fadb

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

‎index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ function convertSchema(schema, path, parent, parentPath) {
3232
schema = rewriteConst(schema);
3333
schema = convertDependencies(schema);
3434
schema = rewriteIfThenElse(schema);
35-
schema = rewriteExclusiveMinMax(schema);
35+
schema = rewriteExclusiveMinMax(schema);
36+
schema = convertExamples(schema);
3637

3738
if (typeof schema['patternProperties'] === 'object') {
3839
schema = convertPatternProperties(schema);
@@ -148,6 +149,15 @@ function convertPatternProperties(schema) {
148149
return schema;
149150
}
150151

152+
function convertExamples(schema) {
153+
if (schema['examples']) {
154+
schema['example'] = schema['examples'][0];
155+
delete schema['examples'];
156+
}
157+
158+
return schema;
159+
}
160+
151161
function rewriteConst(schema) {
152162
if (schema.const) {
153163
schema.enum = [ schema.const ];
@@ -191,4 +201,3 @@ function rewriteExclusiveMinMax(schema) {
191201
}
192202

193203
module.exports = convert;
194-

‎test/examples.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
const convert = require('../');
4+
const should = require('should');
5+
6+
it('uses the first example from a schema', () => {
7+
const schema = {
8+
$schema: 'http://json-schema.org/draft-06/schema#',
9+
examples: [
10+
'foo',
11+
'bar'
12+
]
13+
};
14+
15+
const result = convert(schema);
16+
17+
should(result).deepEqual({
18+
example: 'foo',
19+
});
20+
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /