Skip to content

Commit 76fd1b7

Browse files
committed
feat: json formatを実行可能にする
1 parent 0e7680f commit 76fd1b7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@ export class CodeGenerator {
1212
private rootSchema: Types.OpenApi.Document;
1313
private resolvedReferenceDocument: Types.OpenApi.Document;
1414
private parser: Api.OpenApiTools.Parser;
15-
constructor(private readonly entryPoint: string, private option?: Option) {
16-
this.rootSchema = Api.FileSystem.loadJsonOrYaml(entryPoint);
17-
this.resolvedReferenceDocument = Api.ResolveReference.resolve(entryPoint, entryPoint, JSON.parse(JSON.stringify(this.rootSchema)));
15+
constructor(private readonly entryPointOrDocument: string | Types.OpenApi.Document, private option?: Option) {
16+
if (typeof entryPointOrDocument === 'string') {
17+
this.rootSchema = Api.FileSystem.loadJsonOrYaml(entryPointOrDocument);
18+
this.resolvedReferenceDocument = Api.ResolveReference.resolve(entryPointOrDocument, entryPointOrDocument, JSON.parse(JSON.stringify(this.rootSchema)));
19+
} else {
20+
this.rootSchema = entryPointOrDocument
21+
this.resolvedReferenceDocument = entryPointOrDocument
22+
}
1823
this.parser = this.createParser();
1924
}
2025

2126
private createParser(): Api.OpenApiTools.Parser {
22-
return new Api.OpenApiTools.Parser(this.entryPoint, this.rootSchema, this.resolvedReferenceDocument, this.option?.convertOption);
27+
const entryPoint = typeof this.entryPointOrDocument === 'string' ? this.entryPointOrDocument : '.'
28+
return new Api.OpenApiTools.Parser(entryPoint, this.rootSchema, this.resolvedReferenceDocument, this.option?.convertOption);
2329
}
2430

2531
/**

0 commit comments

Comments
 (0)