Skip to content

Commit cf750d3

Browse files
Decorators fix
1 parent 2e73f5d commit cf750d3

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/Response.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Response extends Writable {
2121
this.master_context = route.app
2222
this.app_options = route.app._options
2323

24-
this.decorators = route.requestDecorators
24+
this.decorators = route.responseDecorators
2525

2626
this.locals = {}
2727

src/Server.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -281,20 +281,22 @@ class Server extends Router {
281281
// Mark route as temporary if specified from options
282282
if (record.options._temporary === true) route._temporary = true
283283

284-
// JSON Schema validators
284+
// JSON Schema validation
285285
if (record.options.has('schema')) {
286286
const schema = record.options.get('schema')
287-
if (schema.request) {
288-
route.setRequestDecorator({
289-
name: 'JSONParse',
290-
fn: this.ajv.compileParser(schema.request)
291-
})
292-
}
293-
if (schema.response) {
294-
route.setResponseDecorator({
295-
name: 'JSONSerialize',
296-
fn: this.ajv.compileSerializer(schema.response)
297-
})
287+
if (typeof schema === 'object') {
288+
if (typeof schema.request === 'object') {
289+
route.setRequestDecorator({
290+
name: 'JSONParse',
291+
fn: this.ajv.compileParser(schema.request)
292+
})
293+
}
294+
if (typeof schema.response === 'object') {
295+
route.setResponseDecorator({
296+
name: 'JSONSerialize',
297+
fn: this.ajv.compileSerializer(schema.response)
298+
})
299+
}
298300
}
299301
}
300302

0 commit comments

Comments
 (0)