From faf51708cfb624b6163d1b9e9cc8fb678d945b88 Mon Sep 17 00:00:00 2001 From: Satoshi OHKI Date: Sat, 16 Dec 2023 18:21:33 +0900 Subject: [PATCH] fix data structure to merge --- packages/next-rest-framework/src/cli.ts | 26 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/next-rest-framework/src/cli.ts b/packages/next-rest-framework/src/cli.ts index 7ab2374..0cb34cc 100644 --- a/packages/next-rest-framework/src/cli.ts +++ b/packages/next-rest-framework/src/cli.ts @@ -81,12 +81,15 @@ const generatePathsFromBuild = async ({ const getCleanedRpcApiRoutes = (files: string[]) => files.filter((file) => file.endsWith('rpc/[operationId].ts')); - const isPathItem = ( - obj: unknown - ): obj is Record => - typeof obj === 'object'; + const isNrfOasData = (x: unknown): x is NrfOasData => { + if (typeof x !== 'object' || x === null) { + return false; + } + return 'paths' in x; + }; let paths: OpenAPIV3_1.PathsObject = {}; + let schemas: Record = {}; try { // Scan `app` folder. @@ -108,8 +111,9 @@ const generatePathsFromBuild = async ({ .forEach(([_key, handler]: [string, any]) => { const data = handler._getPaths(getRouteName(route)); - if (isPathItem(data)) { - paths = { ...paths, ...data }; + if (isNrfOasData(data)) { + paths = { ...paths, ...data.paths }; + schemas = { ...schemas, ...data.schemas }; } }); }) @@ -136,8 +140,9 @@ const generatePathsFromBuild = async ({ const data = res.default._getPaths(getApiRouteName(apiRoute)); - if (isPathItem(data)) { - paths = { ...paths, ...data }; + if (isNrfOasData(data)) { + paths = { ...paths, ...data.paths }; + schemas = { ...schemas, ...data.schemas }; } }) ); @@ -150,7 +155,10 @@ const generatePathsFromBuild = async ({ logIgnoredPaths(ignoredPaths); } - return { paths }; + return { + paths, + schemas + }; }; const findConfig = async ({