Skip to content

Commit 108ce3a

Browse files
authored
feat: changed so that options can be specified on a case-by-case basis (#41)
1 parent 6961bab commit 108ce3a

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

src/index.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ export class CodeGenerator {
1414
constructor(private readonly entryPoint: string, option?: Option) {
1515
this.rootSchema = Api.FileSystem.loadJsonOrYaml(entryPoint);
1616
this.resolvedReferenceDocument = Api.ResolveReference.resolve(entryPoint, entryPoint, JSON.parse(JSON.stringify(this.rootSchema)));
17-
this.parser = this.createParser(option?.allowOperationIds);
17+
this.parser = this.createParser();
1818
}
1919

20-
private createParser(allowOperationIds?: string[]): Api.OpenApiTools.Parser {
21-
return new Api.OpenApiTools.Parser(this.entryPoint, this.rootSchema, this.resolvedReferenceDocument, {
22-
allowOperationIds: allowOperationIds,
23-
});
20+
private createParser(): Api.OpenApiTools.Parser {
21+
return new Api.OpenApiTools.Parser(this.entryPoint, this.rootSchema, this.resolvedReferenceDocument);
2422
}
2523

2624
/**
@@ -40,11 +38,11 @@ export class CodeGenerator {
4038
* @param generatorTemplate Template for when you want to change the code following a type definition
4139
* @returns String of generated code
4240
*/
43-
public generateTypeDefinition(generatorTemplates?: Types.CodeGenerator.CustomGenerator<any>[]): string {
41+
public generateTypeDefinition(generatorTemplates?: Types.CodeGenerator.CustomGenerator<any>[], allowOperationIds?: string[]): string {
4442
const create = () => {
4543
const statements = this.parser.getOpenApiTypeDefinitionStatements();
4644
generatorTemplates?.forEach(generatorTemplate => {
47-
const payload = this.parser.getCodeGeneratorParamsArray();
45+
const payload = this.parser.getCodeGeneratorParamsArray(allowOperationIds);
4846
const extraStatements = Api.TsGenerator.Utils.convertIntermediateCodes(generatorTemplate.generator(payload, generatorTemplate.option));
4947
statements.push(...extraStatements);
5048
});
@@ -59,8 +57,8 @@ export class CodeGenerator {
5957
* @param generatorTemplate
6058
* @returns String of generated code
6159
*/
62-
public generateCode(generatorTemplates: Types.CodeGenerator.CustomGenerator<any>[]): string {
63-
const payload = this.parser.getCodeGeneratorParamsArray();
60+
public generateCode(generatorTemplates: Types.CodeGenerator.CustomGenerator<any>[], allowOperationIds?: string[]): string {
61+
const payload = this.parser.getCodeGeneratorParamsArray(allowOperationIds);
6462
const create = () => {
6563
return generatorTemplates
6664
.map(generatorTemplate => {
@@ -74,8 +72,8 @@ export class CodeGenerator {
7472
/**
7573
* Provides parameters extracted from OpenApi Schema
7674
*/
77-
public getCodeGeneratorParamsArray(): Types.CodeGenerator.Params[] {
78-
return this.parser.getCodeGeneratorParamsArray();
75+
public getCodeGeneratorParamsArray(allowOperationIds?: string[]): Types.CodeGenerator.Params[] {
76+
return this.parser.getCodeGeneratorParamsArray(allowOperationIds);
7977
}
8078

8179
/**

src/internal/OpenApiTools/Parser.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ import * as Paths from "./paths";
1313
import { Store } from "./store";
1414
import * as TypeNodeContext from "./TypeNodeContext";
1515

16-
export interface Option {
17-
/**
18-
* List of operationId to be used
19-
*/
20-
allowOperationIds?: string[];
21-
}
22-
2316
export class Parser {
2417
private currentPoint: string;
2518
private convertContext: ConvertContext.Types;
@@ -29,7 +22,6 @@ export class Parser {
2922
private entryPoint: string,
3023
private rootSchema: OpenApi.Document,
3124
noReferenceOpenApiSchema: OpenApi.Document,
32-
private option: Option,
3325
) {
3426
this.currentPoint = entryPoint;
3527
this.convertContext = ConvertContext.create();
@@ -126,8 +118,8 @@ export class Parser {
126118
}
127119
}
128120

129-
public getCodeGeneratorParamsArray(): CodeGenerator.Params[] {
130-
return Extractor.generateCodeGeneratorParamsArray(this.store, this.convertContext, this.option.allowOperationIds);
121+
public getCodeGeneratorParamsArray(allowOperationIds?: string[]): CodeGenerator.Params[] {
122+
return Extractor.generateCodeGeneratorParamsArray(this.store, this.convertContext, allowOperationIds);
131123
}
132124

133125
public getOpenApiTypeDefinitionStatements(): ts.Statement[] {

0 commit comments

Comments
 (0)