We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1d2804c commit 10b2db2Copy full SHA for 10b2db2
src/index.js
@@ -1,7 +1,51 @@
1
'use strict';
2
3
function convert (json, options = {}) {
4
- return {};
+
5
+ if (json === undefined) {
6
+ return {};
7
+ }
8
9
+ // primitives
10
+ if (typeof json === 'string') {
11
12
+ // TODO: date format
13
+ return {type: 'string'};
14
15
16
+ if (typeof json === 'boolean') {
17
+ return {type: 'boolean'};
18
19
20
+ if (typeof json === 'number') {
21
+ if (Number.isInteger(json)) {
22
+ return {type: 'integer'};
23
+ } else {
24
+ return {type: 'number'};
25
26
27
28
+ if (json === null) {
29
+ return {type: 'null'};
30
31
32
+ if (Array.isArray(json)) {
33
+ let schema = {type: 'array'};
34
35
+ if (!json.length) {
36
+ return schema;
37
38
39
+ // TODO: array items
40
41
42
+ let schema = {type: 'object'};
43
44
+ if (!Object.keys(json).length) {
45
46
47
48
49
}
50
51
export {convert};
test/driver.js
@@ -7,7 +7,7 @@ import expect from './expect.js';
describe('end to end', ()=> {
- readdirSync(join(__dirname, 'end-to-end')).forEach(testCase=> {
+ readdirSync(join(__dirname, 'input-output')).forEach(testCase=> {
it(`preserves comments and styling for test case ${testCase}`, ()=> {
test/expect.js
@@ -7,4 +7,4 @@ export default function expecter(json, jsonSchema) {
it('produces correct JSON Schema', ()=> {
expect(convert(json)).to.deep.equal(jsonSchema);
});
-};
+};
test/primitives.js
@@ -5,12 +5,37 @@ import expect from './expect';
describe('primitives', ()=> {
+ describe('undefined', ()=> {
+ expect(undefined, {});
+ });
describe('string', ()=> {
+ expect('', {type: 'string'});
expect('a string', {type: 'string'});
describe('boolean', ()=> {
expect(true, {type: 'boolean'});
+ describe('integer number', ()=> {
+ expect(100, {type: 'integer'});
+ expect(0, {type: 'integer'});
+ describe('float number', ()=> {
+ expect(100.0001, {type: 'number'});
+ describe('infinity number', ()=> {
+ expect(Infinity, {type: 'number'});
+ describe('empty array', ()=> {
+ expect([], {type: 'array'});
+ describe('empty object', ()=> {
+ expect({}, {type: 'object'});
0 commit comments