Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix data structure to merge #113

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions packages/next-rest-framework/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, OpenAPIV3_1.PathItemObject> =>
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<string, OpenAPIV3_1.SchemaObject> = {};

try {
// Scan `app` folder.
Expand All @@ -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 };
}
});
})
Expand All @@ -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 };
}
})
);
Expand All @@ -150,7 +155,10 @@ const generatePathsFromBuild = async ({
logIgnoredPaths(ignoredPaths);
}

return { paths };
return {
paths,
schemas
};
};

const findConfig = async ({
Expand Down