Skip to content

Commit 4ae4cb7

Browse files
committed
refactor: remove internal optimization
1 parent 78c6cf5 commit 4ae4cb7

File tree

8 files changed

+11
-343
lines changed

8 files changed

+11
-343
lines changed

src/core/generateOpenApiSpec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ export default async function generateOpenApiSpec(schemas: Record<string, ZodTyp
5858
const metadata = getPackageMetadata();
5959

6060
const pathsAndComponents = {
61-
paths: bundlePaths(validRoutes, schemas),
61+
paths: bundlePaths(validRoutes),
6262
components: {
6363
schemas: bundleSchemas(schemas),
6464
securitySchemes,
6565
},
6666
};
6767

68-
return JSON.parse(JSON.stringify({
68+
const spec = JSON.parse(JSON.stringify({
6969
openapi: "3.1.0",
7070
info: {
7171
title: metadata.serviceName,
@@ -76,5 +76,7 @@ export default async function generateOpenApiSpec(schemas: Record<string, ZodTyp
7676
...(clearUnusedSchemasOption ? clearUnusedSchemasFunction(pathsAndComponents) : pathsAndComponents),
7777
security,
7878
tags: [],
79-
})) as Omit<OpenApiDocument, "components"> & Required<Pick<OpenApiDocument, "components">>;
79+
}));
80+
81+
return (spec) as Omit<OpenApiDocument, "components"> & Required<Pick<OpenApiDocument, "components">>;
8082
}

src/core/mask.test.ts

Lines changed: 0 additions & 123 deletions
This file was deleted.

src/core/mask.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/core/operation-mask.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/core/route.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import getRoutePathName from "./getRoutePathName";
2-
import maskOperationSchemas from "./operation-mask";
32
import type { OperationObject } from "@omer-x/openapi-types/operation";
43
import type { PathsObject } from "@omer-x/openapi-types/paths";
5-
import type { ZodType } from "zod";
64

75
export type RouteRecord = {
86
method: string,
@@ -18,13 +16,13 @@ export function createRouteRecord(method: string, filePath: string, rootPath: st
1816
} as RouteRecord;
1917
}
2018

21-
export function bundlePaths(source: RouteRecord[], storedSchemas: Record<string, ZodType>) {
19+
export function bundlePaths(source: RouteRecord[]) {
2220
source.sort((a, b) => a.path.localeCompare(b.path));
2321
return source.reduce((collection, route) => ({
2422
...collection,
2523
[route.path]: {
2624
...collection[route.path],
27-
[route.method]: maskOperationSchemas(route.apiData, storedSchemas),
25+
[route.method]: route.apiData,
2826
},
2927
}), {} as PathsObject);
3028
}

src/core/schema.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
import maskWithReference from "./mask";
21
import convertToOpenAPI from "./zod-to-openapi";
3-
import type { SchemaObject } from "@omer-x/json-schema-types";
42
import type { ZodType } from "zod";
53

64
export function bundleSchemas(schemas: Record<string, ZodType>) {
7-
const bundledSchemas = Object.keys(schemas).reduce((collection, schemaName) => {
8-
return {
9-
...collection,
10-
[schemaName]: convertToOpenAPI(schemas[schemaName], false),
11-
} as Record<string, SchemaObject>;
12-
}, {} as Record<string, SchemaObject>);
13-
14-
return Object.entries(bundledSchemas).reduce((bundle, [schemaName, schema]) => ({
15-
...bundle,
16-
[schemaName]: maskWithReference(schema, schemas, false),
17-
}), {} as Record<string, SchemaObject>);
5+
const entries = Object.entries(schemas).map(([schemaName, schema]) => {
6+
return [schemaName, convertToOpenAPI(schema, false)] as const;
7+
});
8+
return Object.fromEntries(entries);
189
}

src/utils/deepEqual.test.ts

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)