-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding vendor extensions to configure middleware.
* Middleware may currently be disabled. * All extensions are scoped. * The following extensions have been added: * x-express-openapi-disable-middleware * x-express-openapi-disable-coercion-middleware * x-express-openapi-disable-defaults-middleware * x-express-openapi-disable-response-validation-middleware * x-express-openapi-disable-validation-middleware
- Loading branch information
Showing
63 changed files
with
3,326 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
test/sample-projects/with-coercion-middleware-disabled-in-methodDoc/api-doc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// args.apiDoc needs to be a js object. This file could be a json file, but we can't add | ||
// comments in json files. | ||
module.exports = { | ||
swagger: '2.0', | ||
|
||
// all routes will now have /v3 prefixed. | ||
basePath: '/v3', | ||
|
||
info: { | ||
title: 'express-openapi sample project', | ||
version: '3.0.0' | ||
}, | ||
|
||
definitions: { | ||
Error: { | ||
additionalProperties: true | ||
}, | ||
User: { | ||
properties: { | ||
name: { | ||
type: 'string' | ||
}, | ||
friends: { | ||
type: 'array', | ||
items: { | ||
$ref: '#/definitions/User' | ||
} | ||
} | ||
}, | ||
required: ['name'] | ||
} | ||
}, | ||
|
||
// paths are derived from args.routes. These are filled in by fs-routes. | ||
paths: {}, | ||
|
||
tags: [ | ||
{name: 'users'} | ||
] | ||
}; |
91 changes: 91 additions & 0 deletions
91
test/sample-projects/with-coercion-middleware-disabled-in-methodDoc/api-routes/users/{id}.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
module.exports = { | ||
// parameters for all operations in this path | ||
parameters: [ | ||
{ | ||
name: 'id', | ||
in: 'path', | ||
type: 'string', | ||
required: true, | ||
description: 'Fred\'s age.' | ||
} | ||
], | ||
// method handlers may just be the method handler... | ||
get: get, | ||
// or they may also be an array of middleware + the method handler. This allows | ||
// for flexible middleware management. express-openapi middleware generated from | ||
// the <path>.parameters + <methodHandler>.apiDoc.parameters is prepended to this | ||
// array. | ||
post: [function(req, res, next) {next();}, function(req, res) { | ||
res.status(200).json({id: req.params.id}); | ||
}] | ||
}; | ||
|
||
module.exports.post.apiDoc = { | ||
description: 'Create a user.', | ||
operationId: 'createUser', | ||
tags: ['users'], | ||
parameters: [ | ||
{ | ||
name: 'user', | ||
in: 'body', | ||
schema: { | ||
$ref: '#/definitions/User' | ||
} | ||
} | ||
], | ||
|
||
responses: { | ||
default: { | ||
$ref: '#/definitions/Error' | ||
} | ||
} | ||
}; | ||
|
||
function get(req, res) { | ||
res.status(200).json({ | ||
id: req.params.id, | ||
name: req.query.name, | ||
age: req.query.age | ||
}); | ||
} | ||
|
||
get.apiDoc = { | ||
'x-express-openapi-disable-coercion-middleware': true, | ||
description: 'Retrieve a user.', | ||
operationId: 'getUser', | ||
tags: ['users'], | ||
parameters: [ | ||
{ | ||
name: 'name', | ||
in: 'query', | ||
type: 'string', | ||
pattern: '^fred$', | ||
description: 'The name of this person. It may only be "fred".' | ||
}, | ||
// showing that operation parameters override path parameters | ||
{ | ||
name: 'id', | ||
in: 'path', | ||
type: 'integer', | ||
required: true, | ||
description: 'Fred\'s age.' | ||
}, | ||
{ | ||
name: 'age', | ||
in: 'query', | ||
type: 'integer', | ||
description: 'Fred\'s age.', | ||
default: 80 | ||
} | ||
], | ||
|
||
responses: { | ||
200: { | ||
$ref: '#/definitions/User' | ||
}, | ||
|
||
default: { | ||
$ref: '#/definitions/Error' | ||
} | ||
} | ||
}; |
Oops, something went wrong.