first
This commit is contained in:
commit
8538ab969a
434 changed files with 44051 additions and 0 deletions
45
packages/api/src/lib/openapi-schema.ts
Normal file
45
packages/api/src/lib/openapi-schema.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { type MergeInput, isErrorResult, merge } from "openapi-merge";
|
||||
|
||||
export function mergeOpenApiSchemas({
|
||||
appSchema,
|
||||
authSchema,
|
||||
}: {
|
||||
appSchema: MergeInput[number]["oas"];
|
||||
authSchema: MergeInput[number]["oas"];
|
||||
}) {
|
||||
const mergedSchema = merge([
|
||||
{
|
||||
oas: appSchema,
|
||||
},
|
||||
{
|
||||
oas: authSchema,
|
||||
pathModification: {
|
||||
prepend: "/api/auth",
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
if (isErrorResult(mergedSchema)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const output = mergedSchema.output;
|
||||
|
||||
Object.entries(output.paths).forEach(([path, pathItem]) => {
|
||||
if (path.startsWith("/api/auth")) {
|
||||
const methods = ["post", "get", "put", "delete", "patch"];
|
||||
methods.forEach((method) => {
|
||||
const methodItem = pathItem[method as keyof typeof pathItem];
|
||||
if (
|
||||
methodItem &&
|
||||
typeof methodItem === "object" &&
|
||||
!Array.isArray(methodItem)
|
||||
) {
|
||||
methodItem.tags = ["Auth"];
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return output;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue