Skip to content

Commit

Permalink
Use only a warning code with a dynamic message
Browse files Browse the repository at this point in the history
  • Loading branch information
franher committed Mar 30, 2023
1 parent 73e6793 commit a3094e7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
8 changes: 4 additions & 4 deletions lib/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,25 @@ function compileSchemasForValidation (context, compile, isCustom) {
}
context[headersSchema] = compile({ schema: headersSchemaLowerCase, method, url, httpPart: 'headers' })
} else if (Object.hasOwnProperty.call(schema, 'headers')) {
warning.emit('FSTDEP015')
warning.emit('FSTDEP015', 'headers')
}

if (schema.body) {
context[bodySchema] = compile({ schema: schema.body, method, url, httpPart: 'body' })
} else if (Object.hasOwnProperty.call(schema, 'body')) {
warning.emit('FSTDEP016')
warning.emit('FSTDEP015', 'body')
}

if (schema.querystring) {
context[querystringSchema] = compile({ schema: schema.querystring, method, url, httpPart: 'querystring' })
} else if (Object.hasOwnProperty.call(schema, 'querystring')) {
warning.emit('FSTDEP017')
warning.emit('FSTDEP015', 'querystring')
}

if (schema.params) {
context[paramsSchema] = compile({ schema: schema.params, method, url, httpPart: 'params' })
} else if (Object.hasOwnProperty.call(schema, 'params')) {
warning.emit('FSTDEP018')
warning.emit('FSTDEP015', 'params')
}
}

Expand Down
8 changes: 1 addition & 7 deletions lib/warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ warning.create('FastifyDeprecation', 'FSTDEP013', 'Direct return of "trailers" f

warning.create('FastifyDeprecation', 'FSTDEP014', 'You are trying to set/access the default route. This property is deprecated. Please, use setNotFoundHandler if you want to custom a 404 handler or the wildcard (*) to match all routes.')

warning.create('FastifyDeprecation', 'FSTDEP015', 'The headers schema for the route is undefined. This may indicate the schema is not valid or missing.')

warning.create('FastifyDeprecation', 'FSTDEP016', 'The body schema for the route is undefined. This may indicate the schema is not valid or missing.')

warning.create('FastifyDeprecation', 'FSTDEP017', 'The querystring schema for the route is undefined. This may indicate the schema is not valid or missing.')

warning.create('FastifyDeprecation', 'FSTDEP018', 'The params schema for the route is undefined. This may indicate the schema is not valid or missing.')
warning.create('FastifyDeprecation', 'FSTDEP015', 'The %s schema for the route is undefined. This may indicate the schema is not valid or missing.')

module.exports = warning
12 changes: 6 additions & 6 deletions test/schema-feature.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,12 @@ test('Should emit warning if the schema body is undefined', t => {
process.on('warning', onWarning)
function onWarning (warning) {
t.equal(warning.name, 'FastifyDeprecation')
t.equal(warning.code, 'FSTDEP016')
t.equal(warning.code, 'FSTDEP015')
}

t.teardown(() => {
process.removeListener('warning', onWarning)
warning.emitted.set('FSTDEP016', false)
warning.emitted.set('FSTDEP015', false)
})

fastify.get('/:id', {
Expand All @@ -311,12 +311,12 @@ test('Should emit warning if the schema query is undefined', t => {
process.on('warning', onWarning)
function onWarning (warning) {
t.equal(warning.name, 'FastifyDeprecation')
t.equal(warning.code, 'FSTDEP017')
t.equal(warning.code, 'FSTDEP015')
}

t.teardown(() => {
process.removeListener('warning', onWarning)
warning.emitted.set('FSTDEP017', false)
warning.emitted.set('FSTDEP015', false)
})

fastify.get('/:id', {
Expand All @@ -336,12 +336,12 @@ test('Should emit warning if the schema params is undefined', t => {
process.on('warning', onWarning)
function onWarning (warning) {
t.equal(warning.name, 'FastifyDeprecation')
t.equal(warning.code, 'FSTDEP018')
t.equal(warning.code, 'FSTDEP015')
}

t.teardown(() => {
process.removeListener('warning', onWarning)
warning.emitted.set('FSTDEP018', false)
warning.emitted.set('FSTDEP015', false)
})

fastify.get('/:id', {
Expand Down

0 comments on commit a3094e7

Please sign in to comment.