Skip to content

Commit f68f368

Browse files
committed
Remove conversion from common name to type/format (closes #4)
1 parent e298f5f commit f68f368

File tree

6 files changed

+35
-229
lines changed

6 files changed

+35
-229
lines changed

index.js

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,7 @@ function convertProperties(properties, options) {
120120
}
121121

122122
function convertTypes(schema, options) {
123-
var newType
124-
, newFormat
125-
, toDateTime = options.dateToDateTime
126-
;
123+
var toDateTime = options.dateToDateTime;
127124

128125
if (schema.type === undefined) {
129126
return schema;
@@ -133,52 +130,6 @@ function convertTypes(schema, options) {
133130
schema.format = 'date-time';
134131
}
135132

136-
switch(schema.type) {
137-
case 'integer':
138-
newType = 'integer';
139-
break;
140-
case 'long':
141-
newType = 'integer';
142-
newFormat = 'int64';
143-
break;
144-
case 'float':
145-
newType = 'number';
146-
newFormat = 'float';
147-
break;
148-
case 'double':
149-
newType = 'number';
150-
newFormat = 'double';
151-
break;
152-
case 'byte':
153-
newType = 'string';
154-
newFormat = 'byte';
155-
break;
156-
case 'binary':
157-
newType = 'string';
158-
newFormat = 'binary';
159-
break;
160-
case 'date':
161-
newType = 'string';
162-
newFormat = 'date';
163-
if (toDateTime === true) {
164-
newFormat = 'date-time';
165-
}
166-
break;
167-
case 'dateTime':
168-
newType = 'string';
169-
newFormat = 'date-time';
170-
break;
171-
case 'password':
172-
newType = 'string';
173-
newFormat = 'password';
174-
break;
175-
default:
176-
newType = schema.type;
177-
}
178-
179-
schema.type = newType;
180-
schema.format = typeof newFormat === 'string' ? newFormat : schema.format;
181-
182133
if (! schema.format) {
183134
delete schema.format;
184135
}

test/combination_keywords.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var test = require('tape')
22
, convert = require('../')
33
;
44

5-
test('iterates allOfs and converts types', function(assert) {
5+
test('iterates allOfs', function(assert) {
66
var schema
77
, result
88
, expected
@@ -17,14 +17,16 @@ test('iterates allOfs and converts types', function(assert) {
1717
required: ['foo'],
1818
properties: {
1919
foo: {
20-
type: 'long'
20+
type: 'integer',
21+
format: 'int64'
2122
}
2223
}
2324
},
2425
{
2526
allOf: [
2627
{
27-
type: 'double'
28+
type: 'number',
29+
format: 'double'
2830
}
2931
]
3032
}
@@ -60,7 +62,7 @@ test('iterates allOfs and converts types', function(assert) {
6062
assert.deepEqual(result, expected, 'iterated allOfs');
6163
});
6264

63-
test('iterates anyOfs and converts types', function(assert) {
65+
test('iterates anyOfs', function(assert) {
6466
var schema
6567
, result
6668
, expected
@@ -75,7 +77,7 @@ test('iterates anyOfs and converts types', function(assert) {
7577
required: ['foo'],
7678
properties: {
7779
foo: {
78-
type: 'long'
80+
type: 'integer'
7981
}
8082
}
8183
},
@@ -85,7 +87,7 @@ test('iterates anyOfs and converts types', function(assert) {
8587
type: 'object',
8688
properties: {
8789
bar: {
88-
type: 'double'
90+
type: 'number'
8991
}
9092
}
9193
}
@@ -105,7 +107,6 @@ test('iterates anyOfs and converts types', function(assert) {
105107
properties: {
106108
foo: {
107109
type: 'integer',
108-
format: 'int64'
109110
}
110111
}
111112
},
@@ -116,7 +117,6 @@ test('iterates anyOfs and converts types', function(assert) {
116117
properties: {
117118
bar: {
118119
type: 'number',
119-
format: 'double'
120120
}
121121
}
122122
}
@@ -128,7 +128,7 @@ test('iterates anyOfs and converts types', function(assert) {
128128
assert.deepEqual(result, expected, 'anyOfs iterated');
129129
});
130130

131-
test('iterates oneOfs and converts types', function(assert) {
131+
test('iterates oneOfs', function(assert) {
132132
var schema
133133
, result
134134
, expected
@@ -143,7 +143,7 @@ test('iterates oneOfs and converts types', function(assert) {
143143
required: ['foo'],
144144
properties: {
145145
foo: {
146-
type: 'long'
146+
type: 'integer'
147147
}
148148
}
149149
},
@@ -153,7 +153,7 @@ test('iterates oneOfs and converts types', function(assert) {
153153
type: 'object',
154154
properties: {
155155
bar: {
156-
type: 'double'
156+
type: 'number'
157157
}
158158
}
159159
}
@@ -173,7 +173,6 @@ test('iterates oneOfs and converts types', function(assert) {
173173
properties: {
174174
foo: {
175175
type: 'integer',
176-
format: 'int64'
177176
}
178177
}
179178
},
@@ -184,7 +183,6 @@ test('iterates oneOfs and converts types', function(assert) {
184183
properties: {
185184
bar: {
186185
type: 'number',
187-
format: 'double'
188186
}
189187
}
190188
}
@@ -208,7 +206,8 @@ test('converts types in not', function(assert) {
208206
type: 'object',
209207
properties: {
210208
not: {
211-
type: 'password',
209+
type: 'string',
210+
format: 'password',
212211
minLength: 8
213212
}
214213
}
@@ -241,7 +240,8 @@ test('converts types in not', function(assert) {
241240

242241
schema = {
243242
not: {
244-
type: 'password',
243+
type: 'string',
244+
format: 'password',
245245
minLength: 8
246246
}
247247
};

test/items.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ test('items', function(assert) {
1313
schema = {
1414
type: 'array',
1515
items: {
16-
type: 'dateTime',
16+
type: 'string',
17+
format: 'date-time',
1718
example: '2017-01-01T12:34:56Z'
1819
}
1920
};

test/numeric_types.js

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ var test = require('tape')
22
, convert = require('../')
33
;
44

5-
test('converts integer types', function(assert) {
5+
test('handles integer types', function(assert) {
66
var schema
77
, result
88
, expected
99
;
1010

11-
assert.plan(3);
11+
assert.plan(2);
1212

1313
schema = {
1414
type: 'integer',
@@ -21,73 +21,31 @@ test('converts integer types', function(assert) {
2121
type: 'integer',
2222
};
2323

24-
assert.deepEqual(result, expected, 'plain integer not changed');
24+
assert.deepEqual(result, expected, 'integer type untouched');
2525

2626
schema = {
2727
type: 'integer',
28-
format: 'int64'
28+
format: 'int32',
2929
};
3030

3131
result = convert(schema);
3232

3333
expected = {
3434
$schema: 'http://json-schema.org/draft-04/schema#',
3535
type: 'integer',
36-
format: 'int64'
36+
format: 'int32'
3737
};
3838

39-
assert.deepEqual(result, expected, 'respects integer format');
40-
41-
schema = {
42-
type: 'long',
43-
};
44-
45-
result = convert(schema);
46-
47-
expected = {
48-
$schema: 'http://json-schema.org/draft-04/schema#',
49-
type: 'integer',
50-
format: 'int64'
51-
};
52-
53-
assert.deepEqual(result, expected, 'long converted');
39+
assert.deepEqual(result, expected, 'integer type and format untouched');
5440
});
5541

56-
test('converts number types', function(assert) {
42+
test('handles number types', function(assert) {
5743
var schema
5844
, result
5945
, expected
6046
;
6147

62-
assert.plan(4);
63-
64-
schema = {
65-
type: 'float',
66-
};
67-
68-
result = convert(schema);
69-
70-
expected = {
71-
$schema: 'http://json-schema.org/draft-04/schema#',
72-
type: 'number',
73-
format: 'float'
74-
};
75-
76-
assert.deepEqual(result, expected, 'float converted');
77-
78-
schema = {
79-
type: 'double',
80-
};
81-
82-
result = convert(schema);
83-
84-
expected = {
85-
$schema: 'http://json-schema.org/draft-04/schema#',
86-
type: 'number',
87-
format: 'double'
88-
};
89-
90-
assert.deepEqual(result, expected, 'double converted');
48+
assert.plan(2);
9149

9250
schema = {
9351
type: 'number',
@@ -100,7 +58,7 @@ test('converts number types', function(assert) {
10058
type: 'number',
10159
};
10260

103-
assert.deepEqual(result, expected, 'number untouched');
61+
assert.deepEqual(result, expected, 'number type untouched');
10462

10563
schema = {
10664
type: 'number',
@@ -115,5 +73,5 @@ test('converts number types', function(assert) {
11573
format: 'float'
11674
};
11775

118-
assert.deepEqual(result, expected, 'number and format untouched');
76+
assert.deepEqual(result, expected, 'number type and format untouched');
11977
});

test/properties.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ test('additionalProperties is an object', function(assert) {
134134
type: 'object',
135135
properties: {
136136
foo: {
137-
type: 'dateTime'
137+
type: 'string',
138+
format: 'date-time'
138139
}
139140
}
140141
}

0 commit comments

Comments
 (0)