Skip to content

Commit 7d86816

Browse files
author
Phil Sturgeon
committed
strictMode: true by default, false avoids throwing
1 parent 10273ce commit 7d86816

File tree

6 files changed

+358
-387
lines changed

6 files changed

+358
-387
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ function convertFromParameter(parameter, options) {
1010
} else if (parameter.content !== undefined) {
1111
return convertFromContents(parameter, options);
1212
} else {
13-
throw new InvalidInputError('OpenAPI parameter must have either a \'schema\' or a \'content\' property');
13+
if (options.strictMode) {
14+
throw new InvalidInputError('OpenAPI parameter must have either a \'schema\' or a \'content\' property');
15+
}
1416
}
1517
}
1618

lib/converters/schema.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function convertFromSchema(schema, options) {
1414
function convertSchema(schema, options) {
1515
var structs = options._structs
1616
, notSupported = options._notSupported
17+
, strictMode = options.strictMode
1718
, i = 0
1819
, j = 0
1920
, struct = null
@@ -47,7 +48,10 @@ function convertSchema(schema, options) {
4748

4849
}
4950

50-
validateType(schema.type);
51+
if (strictMode) {
52+
validateType(schema.type);
53+
}
54+
5155
schema = convertTypes(schema);
5256
schema = convertFormat(schema, options);
5357

@@ -64,7 +68,7 @@ function convertSchema(schema, options) {
6468
}
6569

6670
function validateType(type) {
67-
var validTypes = ['integer', 'number', 'string', 'boolean', 'object', 'array'];
71+
var validTypes = ['integer', 'number', 'string', 'boolean', 'object', 'array', 'null'];
6872

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

0 commit comments

Comments
 (0)