Skip to content

Commit c8aec60

Browse files
author
Phil Sturgeon
committed
2 parents 3221e49 + 9692af1 commit c8aec60

File tree

7 files changed

+397
-403
lines changed

7 files changed

+397
-403
lines changed

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function resolveOptions(options) {
3939
options.cloneSchema = options.cloneSchema == false ? false : true;
4040
options.supportPatternProperties = options.supportPatternProperties || false;
4141
options.keepNotSupported = options.keepNotSupported || [];
42+
options.strictMode = options.strictMode == false ? false : true;
4243

4344
if (typeof options.patternPropertiesHandler !== 'function') {
4445
options.patternPropertiesHandler = patternPropertiesHandler;

lib/converters/parameter.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,34 @@ module.exports = convertFromParameter;
55

66
// Convert from OpenAPI 3.0 `ParameterObject` to JSON schema v4
77
function convertFromParameter(parameter, options) {
8-
if (parameter.schema !== undefined) {
9-
return convertParameterSchema(parameter, parameter.schema, options);
10-
} else if (parameter.content !== undefined) {
11-
return convertFromContents(parameter, options);
12-
} else {
13-
throw new InvalidInputError('OpenAPI parameter must have either a \'schema\' or a \'content\' property');
14-
}
8+
if (parameter.schema !== undefined) {
9+
return convertParameterSchema(parameter, parameter.schema, options);
10+
} else if (parameter.content !== undefined) {
11+
return convertFromContents(parameter, options);
12+
} else {
13+
if (options.strictMode) {
14+
throw new InvalidInputError('OpenAPI parameter must have either a \'schema\' or a \'content\' property');
15+
}
16+
return convertParameterSchema(parameter, {}, options);
17+
}
1518
}
1619

1720
function convertFromContents(parameter, options) {
18-
var schemas = {};
21+
var schemas = {};
1922

20-
for (var mime in parameter.content) {
21-
schemas[mime] = convertParameterSchema(parameter, parameter.content[mime].schema, options);
22-
}
23+
for (var mime in parameter.content) {
24+
schemas[mime] = convertParameterSchema(parameter, parameter.content[mime].schema, options);
25+
}
2326

24-
return schemas;
27+
return schemas;
2528
}
2629

2730
function convertParameterSchema(parameter, schema, options) {
28-
var jsonSchema = convertFromSchema(schema || {}, options);
31+
var jsonSchema = convertFromSchema(schema || {}, options);
2932

30-
if (parameter.description) {
31-
jsonSchema.description = parameter.description;
32-
}
33+
if (parameter.description) {
34+
jsonSchema.description = parameter.description;
35+
}
3336

34-
return jsonSchema;
37+
return jsonSchema;
3538
}

lib/converters/schema.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function convertFromSchema(schema, options) {
1515
function convertSchema(schema, options) {
1616
var structs = options._structs
1717
, notSupported = options._notSupported
18+
, strictMode = options.strictMode
1819
, i = 0
1920
, j = 0
2021
, struct = null
@@ -55,7 +56,10 @@ function convertSchema(schema, options) {
5556
}
5657
}
5758

58-
validateType(schema.type);
59+
if (strictMode) {
60+
validateType(schema.type);
61+
}
62+
5963
schema = convertTypes(schema);
6064
schema = convertFormat(schema, options);
6165

@@ -71,7 +75,7 @@ function convertSchema(schema, options) {
7175
}
7276

7377
function validateType(type) {
74-
var validTypes = ['integer', 'number', 'string', 'boolean', 'object', 'array'];
78+
var validTypes = ['integer', 'number', 'string', 'boolean', 'object', 'array', 'null'];
7579

7680
if (validTypes.indexOf(type) < 0 && type !== undefined) {
7781
throw new InvalidTypeError('Type ' + JSON.stringify(type) + ' is not a valid type');

0 commit comments

Comments
 (0)