openapi-enforcer
Advanced tools
Comparing version 1.13.1 to 1.13.2
@@ -7,2 +7,10 @@ # Change Log | ||
## 1.13.2 | ||
### Fixed | ||
- **Read / Write Required Property May Not Exist** | ||
Fixed an error when checking for required schema properties that should not be included due to being read-only or write only. | ||
## 1.13.1 | ||
@@ -9,0 +17,0 @@ |
{ | ||
"name": "openapi-enforcer", | ||
"version": "1.13.1", | ||
"version": "1.13.2", | ||
"description": "Library for validating, parsing, and formatting data against open api schemas.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -150,4 +150,4 @@ /** | ||
schema.required.filter(name => { | ||
if (!options.readWriteMode) return true | ||
const prop = properties[name] | ||
if (!options.readWriteMode || !prop) return true | ||
if (options.readWriteMode === 'write' && !prop.readOnly) return true | ||
@@ -154,0 +154,0 @@ if (options.readWriteMode === 'read' && !prop.writeOnly) return true |
@@ -111,2 +111,68 @@ const expect = require('chai').expect; | ||
describe('issue-108 - attempting to validate an object without discriminator field results in exception', () => { | ||
const def = { | ||
openapi: '3.0.0', | ||
info: { title: '', version: '' }, | ||
paths: {}, | ||
components: { | ||
schemas: { | ||
'content.text': { | ||
type: 'object', | ||
properties: { | ||
type: { | ||
type: 'string' | ||
}, | ||
content: { | ||
type: 'string' | ||
} | ||
} | ||
}, | ||
'content.file': { | ||
type: 'object', | ||
properties: { | ||
type: { | ||
type: 'string' | ||
}, | ||
content: { | ||
type: 'string', | ||
format: 'byte' | ||
} | ||
} | ||
}, | ||
content: { | ||
oneOf: [ | ||
{ $ref: '#/components/schemas/content.text' }, | ||
{ $ref: '#/components/schemas/content.file' } | ||
], | ||
discriminator: { | ||
propertyName: 'type', | ||
mapping: { | ||
text: '#/components/schemas/content.text', | ||
file: '#/components/schemas/content.file' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
it('should validate correctly with valid discriminator property name', async () => { | ||
const openapi = await Enforcer(def, { hideWarnings: true }) | ||
const err = openapi.components.schemas.content.validate({ | ||
type: 'text', | ||
content: 'hello' | ||
}) | ||
expect(err).to.equal(undefined) | ||
}) | ||
it('should produce a valid exception with invalid discriminator property name', async () => { | ||
const openapi = await Enforcer(def, { hideWarnings: true }) | ||
const err = openapi.components.schemas.content.validate({ | ||
type: 'audio', | ||
content: 'hello' | ||
}) | ||
expect(err).to.match(/Discriminator property "type" as "audio" did not map to a schema/) | ||
}) | ||
}) | ||
}); |
1504251
20436