express-openapi: Add definition for path item module

This commit is contained in:
MugeSo
2016-02-16 18:10:12 +09:00
parent cbe236ec27
commit 1d3b1d6a61
2 changed files with 61 additions and 4 deletions
+39 -4
View File
@@ -13,8 +13,43 @@ api = openapi.initialize({
routes: './api-routes'
});
app.use(function (err, req, res, next) {
res.status(err.status).json(err);
});
app.listen(3000);
app.listen(3000);
// "./api-routes/user/{id}.ts"
export var get: openapi.Operation = (req, res, next) => {
};
export var post: openapi.Operation = [(req, res, next) => {}];
export var parameters = [
{
name: 'id',
in: 'path',
type: 'string'
}
];
get.apiDoc = {
description: 'get user information',
operationId: 'getUser',
parameters: [
{
name: 'includeDetail',
in: 'query',
type: 'boolean'
}
],
responses: {
default: {$ref: '#/definitions/error'}
},
"x-some-vendor-property": {}
};
post.apiDoc = {
description: 'post to user',
operationId: 'postToUser',
responses: {
default: {$ref: '#/definitions/error'}
},
"x-some-vendor-property": {}
}
+22
View File
@@ -251,6 +251,28 @@ declare module "express-openapi" {
routes: string
}
export interface OperationFunction extends express.RequestHandler {
apiDoc?: OpenApi.OperationObject;
}
export interface OperationHandlerArray {
apiDoc?: OpenApi.OperationObject;
[index: number]: express.RequestHandler;
}
export type Operation = OperationFunction | OperationHandlerArray;
export interface PathModule {
parameters?: OpenApi.Parameters;
get?: Operation;
put?: Operation;
post?: Operation;
delete?: Operation;
patch?: Operation;
options?: Operation;
head?: Operation;
}
interface IJsonSchema {
id?: string
$schema?: string