Skip to content

Commit 89c57fd

Browse files
committed
_
Signed-off-by: Sora Morimoto <[email protected]>
1 parent 43a8cda commit 89c57fd

File tree

2 files changed

+4
-46
lines changed

2 files changed

+4
-46
lines changed

src/schema-parser/schema-utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export class SchemaUtils {
4646

4747
getSchemaRefType = (schema) => {
4848
if (!this.isRefSchema(schema)) return null;
49-
// const resolved = this.schemaWalker.findByRef(schema.$ref);
5049
return this.schemaComponentsMap.get(schema.$ref);
5150
};
5251

src/schema-walker.ts

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { consola } from "consola";
21
import lodash from "lodash";
32
import type { CodeGenConfig } from "./configuration.js";
43
import type { SwaggerSchemaResolver } from "./swagger-schema-resolver.js";
@@ -19,59 +18,19 @@ export class SchemaWalker {
1918
this.swaggerSchemaResolver = swaggerSchemaResolver;
2019
}
2120

22-
addSchema = (name: string, schema: Record<string, any>) => {
21+
addSchema = (name: string, schema: Record<string, unknown>) => {
2322
this.schemas.set(name, structuredClone(schema));
2423
};
2524

26-
findByRef = (ref: string) => {
27-
consola.debug("try to resolve ref by path", ref);
28-
29-
if (this.caches.has(ref)) {
30-
return this.caches.get(ref);
31-
}
32-
33-
const schemas = Array.from(this.schemas.values());
34-
if (this._isLocalRef(ref)) {
35-
for (const schema of schemas) {
36-
const refData = this._getRefDataFromSchema(schema, ref);
37-
if (refData) {
38-
return refData;
39-
}
40-
}
41-
} else if (this._isRemoteRef(ref)) {
42-
consola.debug("remote refs not supported", ref);
43-
return null;
44-
} else {
45-
// @ts-expect-error TS(2448) FIXME: Block-scoped variable 'path' used before its decla... Remove this comment to see the full error message
46-
const [address, path] = path.split("#");
47-
let swaggerSchemaObject;
48-
49-
if (this.schemas.has(address)) {
50-
swaggerSchemaObject = this.schemas.get(address);
51-
} else {
52-
const pathToSchema = path.resolve(process.cwd(), address);
53-
const swaggerSchemaFile =
54-
this.swaggerSchemaResolver.getSwaggerSchemaByPath(pathToSchema);
55-
swaggerSchemaObject =
56-
this.swaggerSchemaResolver.processSwaggerSchemaFile(
57-
swaggerSchemaFile,
58-
);
59-
this.schemas.set(address, swaggerSchemaObject);
60-
}
61-
62-
return this._getRefDataFromSchema(swaggerSchemaObject, path);
63-
}
64-
};
65-
66-
_isLocalRef = (ref) => {
25+
_isLocalRef = (ref: string) => {
6726
return ref.startsWith("#");
6827
};
6928

70-
_isRemoteRef = (ref) => {
29+
_isRemoteRef = (ref: string) => {
7130
return ref.startsWith("http://") || ref.startsWith("https://");
7231
};
7332

74-
_getRefDataFromSchema = (schema, ref) => {
33+
_getRefDataFromSchema = (schema: Record<string, unknown>, ref: string) => {
7534
const path = ref.replace("#", "").split("/");
7635
const refData = lodash.get(schema, path);
7736
if (refData) {

0 commit comments

Comments
 (0)