Skip to content

Commit e1e8c1a

Browse files
committed
revert: only support v3, which requires schema
1 parent d2c92d8 commit e1e8c1a

8 files changed

+20
-10
lines changed

src/ajv-openapi-validator.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,10 @@ export class AjvOpenApiValidator {
379379
}
380380

381381
// TODO could also add support for other parameters such as headers here
382-
if (resolvedParam?.in === 'query') {
382+
if (resolvedParam?.in === 'query' && resolvedParam.schema) {
383383
const schemaName = `#/paths${path.replace(/[{}]/g, '')}/${method}/parameters/${resolvedParam.name}`
384384
this.validatorOpts.log(`Adding parameter validator '${path}', '${method}', '${resolvedParam.name}'`)
385-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
386-
const schema = resolvedParam.schema ?? { type: (resolvedParam as any).type } // stricly speaking this isn't valid, but we support it
387-
this.ajv.addSchema(schema ?? resolvedParam, schemaName)
385+
this.ajv.addSchema(resolvedParam.schema, schemaName)
388386
const validator = this.ajv.compile({ $ref: schemaName })
389387

390388
this.paramsValidators.push({

test/fixtures/accept-a-required-query-param.js.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ module.exports = {
77
{
88
in: 'path',
99
name: 'path1',
10-
type: 'string',
10+
schema: {
11+
type: 'string',
12+
},
1113
required: true,
1214
},
1315
{
1416
in: 'query',
1517
name: 'foo',
16-
type: 'string',
18+
schema: {
19+
type: 'string',
20+
},
1721
required: true,
1822
},
1923
],

test/fixtures/accept-an-additional-query-param.js.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ module.exports = {
77
{
88
in: 'query',
99
name: 'foo',
10-
type: 'string',
10+
schema: {
11+
type: 'string',
12+
},
1113
required: true,
1214
},
1315
],

test/fixtures/accept-an-optional-query-param.js.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ module.exports = {
77
{
88
in: 'query',
99
name: 'foo',
10-
type: 'string',
10+
schema: {
11+
type: 'string',
12+
},
1113
required: false,
1214
},
1315
],

test/fixtures/fail-a-missing-query-param.js.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ module.exports = {
77
{
88
in: 'query',
99
name: 'foo',
10-
type: 'string',
10+
schema: {
11+
type: 'string',
12+
},
1113
required: true,
1214
},
1315
],

test/fixtures/fail-reject-an-additional-query-param.js.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ module.exports = {
77
{
88
in: 'query',
99
name: 'foo',
10-
type: 'string',
10+
schema: {
11+
type: 'string',
12+
},
1113
required: true,
1214
},
1315
],

0 commit comments

Comments
 (0)