diff --git a/express-openapi/express-openapi-tests.ts b/express-openapi/express-openapi-tests.ts index ca79c90ed..226f97939 100644 --- a/express-openapi/express-openapi-tests.ts +++ b/express-openapi/express-openapi-tests.ts @@ -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); \ No newline at end of file +// "./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": {} +} \ No newline at end of file diff --git a/express-openapi/express-openapi.d.ts b/express-openapi/express-openapi.d.ts index 633407ee1..a769cc7df 100644 --- a/express-openapi/express-openapi.d.ts +++ b/express-openapi/express-openapi.d.ts @@ -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