openapi-enforcer
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -27,3 +27,3 @@ /** | ||
if (major === 2) { | ||
const def = base.extractSchemaDefinition(this); | ||
const def = base.extractSchemaDefinition({}, this); | ||
const [schema, error, warning] = context.Schema(def); | ||
@@ -30,0 +30,0 @@ if (schema) this.schema = schema; |
@@ -40,3 +40,3 @@ /** | ||
// TODO: type might be file which is not really supported in Schema - shouldn't be a problem but I need to test it | ||
const def = Base.extractSchemaDefinition(this); | ||
const def = Base.extractSchemaDefinition({}, this); | ||
if (def.type === 'file') def.type = 'string'; | ||
@@ -43,0 +43,0 @@ const [ schema, err, warning ] = new context.Schema(def); |
@@ -47,3 +47,7 @@ /** | ||
default: { allowed: true }, | ||
enum: { allowed: true }, | ||
enum: { | ||
allowed: true, | ||
type: 'array', | ||
items: { freeForm: true } | ||
}, | ||
exclusiveMaximum: { allowed: true }, | ||
@@ -90,3 +94,3 @@ exclusiveMinimum: { allowed: true }, | ||
}, | ||
example: {}, | ||
example: EnforcerRef('Example'), | ||
examples: { | ||
@@ -115,13 +119,14 @@ type: 'object', | ||
function extractSchemaDefinition(definition) { | ||
const result = {}; | ||
function extractSchemaDefinition(result, definition) { | ||
schemaProperties.forEach(key => { | ||
if (definition.hasOwnProperty(key)) { | ||
const value = definition[key]; | ||
if (Array.isArray(value)) { | ||
result[key] = value.map(extractSchemaDefinition) | ||
} else if (value && typeof value === 'object') { | ||
result[key] = extractSchemaDefinition(value); | ||
} else { | ||
result[key] = value; | ||
switch (key) { | ||
case 'items': | ||
result[key] = extractSchemaDefinition({}, value); | ||
break; | ||
default: | ||
result[key] = value; | ||
break; | ||
} | ||
@@ -128,0 +133,0 @@ } |
@@ -37,3 +37,3 @@ /** | ||
let openapi; | ||
let warnings; | ||
let warnings = Exception('One or more warnings exist int he OpenAPI definition'); | ||
@@ -43,2 +43,3 @@ // normalize options | ||
if (!options.hasOwnProperty('hideWarnings')) options.hideWarnings = false; | ||
if (!options.hasOwnProperty('fullResult')) options.fullResult = false; | ||
@@ -68,3 +69,4 @@ const refParser = new RefParser(); | ||
if (!options.hideWarnings && warnings) console.warn(warnings.toString()); | ||
if (options.fullResult) return new Result(openapi, exception, warnings); | ||
if (!options.hideWarnings && warnings && warnings.hasException) console.warn(warnings.toString()); | ||
if (exception && exception.hasException) throw Error(exception.toString()); | ||
@@ -71,0 +73,0 @@ return openapi; |
{ | ||
"name": "openapi-enforcer", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Library for validating, parsing, and formatting data against open api schemas.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -238,2 +238,32 @@ /** | ||
describe('enum', () => { | ||
describe('v2', () => { | ||
it('can have enum', () => { | ||
const [ , err ] = Enforcer.v2_0.Parameter({ | ||
name: 'hi', | ||
in: 'query', | ||
type: 'string', | ||
enum: ['hero', 'normal', 'villain'] | ||
}); | ||
expect(err).to.be.undefined; | ||
}); | ||
it('must have valid enum values', () => { | ||
const [ , err ] = Enforcer.v2_0.Parameter({ | ||
name: 'hi', | ||
in: 'query', | ||
type: 'string', | ||
enum: ['hero', true, 5] | ||
}); | ||
expect(err).to.match(/at: 1\s+Value must be a string/); | ||
expect(err).to.match(/at: 2\s+Value must be a string/); | ||
expect(err.count).to.equal(2); | ||
}); | ||
}); | ||
}); | ||
describe('examples', () => { | ||
@@ -240,0 +270,0 @@ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
715969
15143
1