Skip to content

Commit ddc2782

Browse files
authored
Merge pull request #5 from mikunn/4-types-are-incorrect
Remove conversion from common name to type/format
2 parents 2f29ba6 + 41ab002 commit ddc2782

9 files changed

+55
-249
lines changed

index.js

Lines changed: 2 additions & 51 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,60 +130,14 @@ 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
}
185136

186137
if (schema.nullable === true) {
187138
schema.type = [schema.type, 'null'];
188139
}
189-
140+
190141
return schema;
191142
}
192143

test/combination_keywords.js

Lines changed: 25 additions & 25 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
}
@@ -56,11 +58,11 @@ test('iterates allOfs and converts types', function(assert) {
5658
}
5759
]
5860
};
59-
61+
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,19 +117,18 @@ test('iterates anyOfs and converts types', function(assert) {
116117
properties: {
117118
bar: {
118119
type: 'number',
119-
format: 'double'
120120
}
121121
}
122122
}
123123
]
124124
}
125125
]
126126
};
127-
127+
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,15 +183,14 @@ test('iterates oneOfs and converts types', function(assert) {
184183
properties: {
185184
bar: {
186185
type: 'number',
187-
format: 'double'
188186
}
189187
}
190188
}
191189
]
192190
}
193191
]
194192
};
195-
193+
196194
assert.deepEqual(result, expected, 'oneOfs iterated');
197195
});
198196

@@ -208,8 +206,9 @@ test('converts types in not', function(assert) {
208206
type: 'object',
209207
properties: {
210208
not: {
211-
type: 'password',
212-
minLength: 8
209+
type: 'string',
210+
format: 'password',
211+
minLength: 8
213212
}
214213
}
215214
};
@@ -223,11 +222,11 @@ test('converts types in not', function(assert) {
223222
not: {
224223
type: 'string',
225224
format: 'password',
226-
minLength: 8
225+
minLength: 8
227226
}
228227
}
229228
};
230-
229+
231230
assert.deepEqual(result, expected, 'not handled');
232231
});
233232

@@ -241,8 +240,9 @@ test('converts types in not', function(assert) {
241240

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

@@ -253,10 +253,10 @@ test('converts types in not', function(assert) {
253253
not: {
254254
type: 'string',
255255
format: 'password',
256-
minLength: 8
256+
minLength: 8
257257
}
258258
};
259-
259+
260260
assert.deepEqual(result, expected, 'not handled');
261261
});
262262

@@ -349,6 +349,6 @@ test('nested combination keywords', function(assert) {
349349
}
350350
]
351351
};
352-
352+
353353
assert.deepEqual(result, expected, 'nested combination keywords');
354354
});

test/complex_schemas.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test('complex schema', function(assert) {
1414

1515
schema = getSchema('schema-1.json');
1616
result = convert(schema);
17-
expected = getSchema('schema-1-expected.json');
17+
expected = getSchema('schema-1-expected.json');
1818

1919
assert.deepEqual(result, expected, 'converted');
2020
});
@@ -27,15 +27,15 @@ test('converting complex schema in place', function(assert) {
2727

2828
assert.plan(2);
2929

30-
schema = getSchema('schema-1.json');
30+
schema = getSchema('schema-1.json');
3131
result = convert(schema, {cloneSchema: false});
32-
expected = getSchema('schema-1-expected.json');
32+
expected = getSchema('schema-1-expected.json');
3333

3434
assert.equal(schema, result, 'changed schema in place');
3535
assert.deepEqual(result, expected, 'converted');
3636
});
3737

3838
function getSchema(file) {
3939
var path = join(__dirname, 'schemas', file);
40-
return JSON.parse(fs.readFileSync(path));
40+
return JSON.parse(fs.readFileSync(path));
4141
}

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
};

0 commit comments

Comments
 (0)