Skip to content

Commit 8abb985

Browse files
author
Phil Sturgeon
committed
Added some more examples
1 parent d4ee76e commit 8abb985

File tree

9 files changed

+137
-30
lines changed

9 files changed

+137
-30
lines changed

test/complex_schemas.test.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ const convert = require('../');
44
const should = require('should');
55
const getSchema = require('./helpers').getSchema;
66

7-
it('complex schema', () => {
8-
const schema = getSchema('json-schema-expected.json');
9-
const result = convert(schema);
10-
const expected = getSchema('openapi-schema.json');
7+
['basic', 'address', 'calendar'].forEach(test => {
8+
it(`converts ${test}/openapi.json`, () => {
9+
const schema = getSchema(test + '/json-schema.json');
10+
const result = convert(schema);
11+
const expected = getSchema(test + '/openapi.json');
1112

12-
should(result).deepEqual(expected, 'converted');
13-
});
13+
should(result).deepEqual(expected, 'converted');
14+
});
1415

15-
it('converting complex schema in place', () => {
16-
const schema = getSchema('json-schema-expected.json');
17-
const result = convert(schema, { cloneSchema: false });
18-
const expected = getSchema('openapi-schema.json');
16+
it(`converting ${test}/openapi.json in place`, () => {
17+
const schema = getSchema(test + '/json-schema.json');
18+
const result = convert(schema, { cloneSchema: false });
19+
const expected = getSchema(test + '/openapi.json');
1920

20-
should(schema).deepEqual(result, 'changed schema in place');
21-
should(result).deepEqual(expected, 'converted');
21+
should(schema).deepEqual(result, 'changed schema in place');
22+
should(result).deepEqual(expected, 'converted');
23+
});
2224
});

test/invalid_types.test.js

+11-18
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,18 @@ const convert = require('../');
44
const should = require('should');
55
const getSchema = require('./helpers').getSchema;
66

7-
it('invalid types', () => {
8-
var schema, msg;
9-
10-
schema = {
11-
type: 'dateTime'
12-
};
13-
14-
msg = 'dateTime is invalid type';
15-
should.throws(() => { convert(schema); }, /InvalidTypeError/, msg);
16-
17-
schema = {
18-
type: 'foo'
19-
};
7+
it('dateTime is invalid type', () => {
8+
const schema = { type: 'dateTime' };
9+
should.throws(() => { convert(schema); }, /InvalidTypeError/);
10+
});
2011

21-
msg = 'foo is invalid type';
22-
should.throws(() => { convert(schema); }, /InvalidTypeError/, msg);
2312

24-
schema = getSchema('schema-2-invalid-type.json');
13+
it('foo is invalid type', () => {
14+
const schema = { type: 'foo' };
15+
should.throws(() => { convert(schema); }, /InvalidTypeError/);
16+
});
2517

26-
msg = 'invalid type inside complex schema';
27-
should.throws(() => { convert(schema); }, /InvalidTypeError.*invalidtype/, msg);
18+
it('invalid type inside complex schema', () => {
19+
const schema = getSchema('invalid/json-schema.json');
20+
should.throws(() => { convert(schema); }, /InvalidTypeError.*invalidtype/);
2821
});

test/schemas/address/json-schema.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-06/schema#",
3+
"description": "An Address following the convention of http://microformats.org/wiki/hcard",
4+
"type": "object",
5+
"properties": {
6+
"post-office-box": { "type": "string" },
7+
"extended-address": { "type": "string" },
8+
"street-address": { "type": "string" },
9+
"locality":{ "type": "string" },
10+
"region": { "type": "string" },
11+
"postal-code": { "type": "string" },
12+
"country-name": { "type": "string"}
13+
},
14+
"required": ["locality", "region", "country-name"],
15+
"dependencies": {
16+
"post-office-box": ["street-address"],
17+
"extended-address": ["street-address"]
18+
}
19+
}

test/schemas/address/openapi.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"description": "An Address following the convention of http://microformats.org/wiki/hcard",
3+
"type": "object",
4+
"properties": {
5+
"post-office-box": { "type": "string" },
6+
"extended-address": { "type": "string" },
7+
"street-address": { "type": "string" },
8+
"locality":{ "type": "string" },
9+
"region": { "type": "string" },
10+
"postal-code": { "type": "string" },
11+
"country-name": { "type": "string"}
12+
},
13+
"required": ["locality", "region", "country-name"],
14+
"x-json-schema-dependencies": {
15+
"post-office-box": ["street-address"],
16+
"extended-address": ["street-address"]
17+
}
18+
}
File renamed without changes.
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-06/schema#",
3+
"description": "A representation of an event",
4+
"type": "object",
5+
"required": [ "dtstart", "summary" ],
6+
"properties": {
7+
"dtstart": {
8+
"format": "date-time",
9+
"type": "string",
10+
"description": "Event starting time"
11+
},
12+
"dtend": {
13+
"format": "date-time",
14+
"type": "string",
15+
"description": "Event ending time"
16+
},
17+
"summary": { "type": "string" },
18+
"location": { "type": "string" },
19+
"url": { "type": "string", "format": "uri" },
20+
"duration": {
21+
"format": "time",
22+
"type": "string",
23+
"description": "Event duration"
24+
},
25+
"rdate": {
26+
"format": "date-time",
27+
"type": "string",
28+
"description": "Recurrence date"
29+
},
30+
"rrule": {
31+
"type": "string",
32+
"description": "Recurrence rule"
33+
},
34+
"category": { "type": "string" },
35+
"description": { "type": "string" },
36+
"geo": { "$ref": "http://json-schema.org/geo" }
37+
}
38+
}

test/schemas/calendar/openapi.json

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"description": "A representation of an event",
3+
"type": "object",
4+
"required": [ "dtstart", "summary" ],
5+
"properties": {
6+
"dtstart": {
7+
"format": "date-time",
8+
"type": "string",
9+
"description": "Event starting time"
10+
},
11+
"dtend": {
12+
"format": "date-time",
13+
"type": "string",
14+
"description": "Event ending time"
15+
},
16+
"summary": { "type": "string" },
17+
"location": { "type": "string" },
18+
"url": { "type": "string", "format": "uri" },
19+
"duration": {
20+
"format": "time",
21+
"type": "string",
22+
"description": "Event duration"
23+
},
24+
"rdate": {
25+
"format": "date-time",
26+
"type": "string",
27+
"description": "Recurrence date"
28+
},
29+
"rrule": {
30+
"type": "string",
31+
"description": "Recurrence rule"
32+
},
33+
"category": { "type": "string" },
34+
"description": { "type": "string" },
35+
"geo": { "$ref": "http://json-schema.org/geo" }
36+
}
37+
}

0 commit comments

Comments
 (0)