From a490bf87b979cdeef030cae33e5ae045c6dd3bc4 Mon Sep 17 00:00:00 2001 From: liangsky <640634387@qq.com> Date: Sat, 13 May 2023 21:23:00 +0800 Subject: [PATCH] feat(mock): support all openapi method --- packages/mock/src/http/mock/utils.ts | 14 ++++++++++++-- packages/mock/test/mock.config.ts | 2 +- packages/mock/test/server.ts | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/mock/src/http/mock/utils.ts b/packages/mock/src/http/mock/utils.ts index aca7237..c6e6ad7 100644 --- a/packages/mock/src/http/mock/utils.ts +++ b/packages/mock/src/http/mock/utils.ts @@ -8,8 +8,18 @@ import multer from 'multer'; import { join } from 'path'; import { pathToRegexp } from 'path-to-regexp'; -const VALID_METHODS = ['get', 'post', 'put', 'patch', 'delete']; -const BODY_PARSED_METHODS = ['post', 'put', 'patch', 'delete']; +// support all openapi method +const VALID_METHODS = [ + 'get', + 'put', + 'post', + 'delete', + 'options', + 'head', + 'patch', + 'trace', +]; +const BODY_PARSED_METHODS = VALID_METHODS.filter((item) => item !== 'get'); const debug = createDebug('mock:utils'); diff --git a/packages/mock/test/mock.config.ts b/packages/mock/test/mock.config.ts index 7460d20..5afe7d4 100644 --- a/packages/mock/test/mock.config.ts +++ b/packages/mock/test/mock.config.ts @@ -4,7 +4,7 @@ import type { IOpts } from '../src/http/server/server'; const config: IOpts = { mockDir: path.join(__dirname, '/'), //mockDir: path.join(__dirname, '/gen-mock'), - //mockDir: path.join(__dirname, '../../http-mock-gen/test/gen-mock/'), + //mockDir: path.join(__dirname, '../../http-mock-gen/test/all-gen-dirs/gen-mock/'), port: 8002, socketConfig: { enable: true, diff --git a/packages/mock/test/server.ts b/packages/mock/test/server.ts index 41058db..6b7e5dd 100644 --- a/packages/mock/test/server.ts +++ b/packages/mock/test/server.ts @@ -22,8 +22,8 @@ mockServer({ }); //mockServer({port: 9001 }); //mockServer({hostname: '127.0.0.1',port: 9001 }); -//console.log(path.join(__dirname, '../../http-mock-gen/test/gen-mock/')); +//console.log(path.join(__dirname, '../../http-mock-gen/test/all-gen-dirs/gen-mock/')); /*mockServer({ port: 7010, - mockDir: path.join(__dirname, '../../http-mock-gen/test/gen-mock/'), + mockDir: path.join(__dirname, '../../http-mock-gen/test/all-gen-dirs/gen-mock/'), });*/