Skip to content

Commit dc787a1

Browse files
committedJun 28, 2024·
fix: fix renderTmpl.utils context
1 parent 537ebdd commit dc787a1

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed
 

‎index.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,14 @@ export interface GenerateApiConfiguration {
718718
typeName?: string,
719719
formattersMap?: Record<MAIN_SCHEMA_TYPES, (content: ModelType) => string>,
720720
) => ModelType;
721+
safeAddNullToType: (
722+
schema: { type: string; nullable?: boolean; "x-nullable"?: boolean },
723+
type: unknown,
724+
) => string;
725+
isNeedToAddNull: (
726+
schema: { type: string; nullable?: boolean; "x-nullable"?: boolean },
727+
type: unknown,
728+
) => boolean;
721729
formatters: Record<
722730
MAIN_SCHEMA_TYPES,
723731
(content: string | object | string[] | object[]) => string

‎src/code-gen-process.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -208,28 +208,30 @@ class CodeGenProcess {
208208
utils: {
209209
Ts: this.config.Ts,
210210
formatDescription:
211-
this.schemaParserFabric.schemaFormatters.formatDescription,
211+
this.schemaParserFabric.schemaFormatters.formatDescription.bind(
212+
this.schemaParserFabric.schemaFormatters,
213+
),
212214
internalCase: internalCase,
213215
classNameCase: pascalCase,
214216
pascalCase: pascalCase,
215-
getInlineParseContent: this.schemaParserFabric.getInlineParseContent,
216-
getParseContent: this.schemaParserFabric.getParseContent,
217-
getComponentByRef: this.schemaComponentsMap.get,
218-
parseSchema: this.schemaParserFabric.parseSchema,
219-
checkAndAddNull: this.schemaParserFabric.schemaUtils.safeAddNullToType,
217+
getInlineParseContent: this.schemaParserFabric.getInlineParseContent.bind(this.schemaParserFabric),
218+
getParseContent: this.schemaParserFabric.getParseContent.bind(this.schemaParserFabric),
219+
getComponentByRef: this.schemaComponentsMap.get.bind(this.schemaComponentsMap),
220+
parseSchema: this.schemaParserFabric.parseSchema.bind(this.schemaParserFabric),
221+
checkAndAddNull: this.schemaParserFabric.schemaUtils.safeAddNullToType.bind(this.schemaParserFabric.schemaUtils),
220222
safeAddNullToType:
221-
this.schemaParserFabric.schemaUtils.safeAddNullToType,
223+
this.schemaParserFabric.schemaUtils.safeAddNullToType.bind(this.schemaParserFabric.schemaUtils),
222224
isNeedToAddNull:
223-
this.schemaParserFabric.schemaUtils.isNullMissingInType,
224-
inlineExtraFormatters: this.schemaParserFabric.schemaFormatters.inline,
225-
formatters: this.schemaParserFabric.schemaFormatters.base,
226-
formatModelName: this.typeNameFormatter.format,
225+
this.schemaParserFabric.schemaUtils.isNullMissingInType.bind(this.schemaParserFabric.schemaUtils),
226+
inlineExtraFormatters: this.schemaParserFabric.schemaFormatters.inline.bind(this.schemaParserFabric.schemaFormatters),
227+
formatters: this.schemaParserFabric.schemaFormatters.base.bind(this.schemaParserFabric.schemaFormatters),
228+
formatModelName: this.typeNameFormatter.format.bind(this.typeNameFormatter),
227229
fmtToJSDocLine: function fmtToJSDocLine(line, { eol = true }) {
228230
return ` * ${line}${eol ? "\n" : ""}`;
229231
},
230232
NameResolver: NameResolver,
231233
_,
232-
require: this.templatesWorker.requireFnFromTemplate,
234+
require: this.templatesWorker.requireFnFromTemplate.bind(this.templatesWorker),
233235
},
234236
config: this.config,
235237
};

0 commit comments

Comments
 (0)