Skip to content

Commit a976451

Browse files
committed
fix: fix renderTmpl.utils context
1 parent ec190c9 commit a976451

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

index.d.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,15 @@ export interface GenerateApiConfiguration {
555555
getInlineParseContent: (rawTypeData: SchemaComponent["rawTypeData"], typeName?: string) => string;
556556
getParseContent: (rawTypeData: SchemaComponent["rawTypeData"], typeName?: string) => ModelType;
557557
getComponentByRef: (ref: string) => SchemaComponent;
558-
parseSchema: (
559-
rawSchema: string | SchemaComponent["rawTypeData"],
560-
typeName?: string,
561-
formattersMap?: Record<MAIN_SCHEMA_TYPES, (content: ModelType) => string>,
562-
) => ModelType;
558+
parseSchema: (rawSchema: string | SchemaComponent["rawTypeData"], typeName?: string) => ModelType;
559+
safeAddNullToType: (
560+
schema: { type: string; nullable?: boolean; "x-nullable"?: string | boolean },
561+
type: unknown,
562+
) => string;
563+
isNeedToAddNull: (
564+
schema: { type: string; nullable?: boolean; "x-nullable"?: string | boolean },
565+
type: unknown,
566+
) => boolean;
563567
formatters: Record<MAIN_SCHEMA_TYPES, (content: string | object | string[] | object[]) => string>;
564568
inlineExtraFormatters: Record<Exclude<MAIN_SCHEMA_TYPES, SCHEMA_TYPES.PRIMITIVE>, (schema: ModelType) => string>;
565569
formatModelName: (name: string) => string;

src/code-gen-process.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,26 +228,28 @@ class CodeGenProcess {
228228
return {
229229
utils: {
230230
Ts: this.config.Ts,
231-
formatDescription: this.schemaParser.schemaFormatters.formatDescription,
231+
formatDescription: this.schemaParser.schemaFormatters.formatDescription.bing(
232+
this.schemaParser.schemaFormatters,
233+
),
232234
internalCase: internalCase,
233235
classNameCase: pascalCase,
234236
pascalCase: pascalCase,
235-
getInlineParseContent: this.schemaParser.getInlineParseContent,
236-
getParseContent: this.schemaParser.getParseContent,
237-
getComponentByRef: this.schemaComponentMap.get,
238-
parseSchema: this.schemaParser.parseSchema,
239-
checkAndAddNull: this.schemaParser.schemaUtils.safeAddNullToType,
240-
safeAddNullToType: this.schemaParser.schemaUtils.safeAddNullToType,
241-
isNeedToAddNull: this.schemaParser.schemaUtils.isNullMissingInType,
242-
inlineExtraFormatters: this.schemaParser.schemaFormatters.inline,
243-
formatters: this.schemaParser.schemaFormatters.base,
244-
formatModelName: this.typeName.format,
237+
getInlineParseContent: this.schemaParser.getInlineParseContent.bind(this.schemaParser),
238+
getParseContent: this.schemaParser.getParseContent.bind(this.schemaParser),
239+
getComponentByRef: this.schemaComponentMap.get.bind(this.schemaComponentMap),
240+
parseSchema: this.schemaParser.parseSchema.bind(this.schemaParser),
241+
checkAndAddNull: this.schemaParser.schemaUtils.safeAddNullToType.bind(this.schemaParser.schemaUtils),
242+
safeAddNullToType: this.schemaParser.schemaUtils.safeAddNullToType.bind(this.schemaParser.schemaUtils),
243+
isNeedToAddNull: this.schemaParser.schemaUtils.isNullMissingInType.bind(this.schemaParser.schemaUtils),
244+
inlineExtraFormatters: this.schemaParser.schemaFormatters.inline.bind(this.schemaParser.schemaFormatters),
245+
formatters: this.schemaParser.schemaFormatters.base.bind(this.schemaParser.schemaFormatters),
246+
formatModelName: this.typeName.format.bind(this.typeName),
245247
fmtToJSDocLine: function fmtToJSDocLine(line, { eol = true }) {
246248
return ` * ${line}${eol ? "\n" : ""}`;
247249
},
248250
NameResolver: NameResolver,
249251
_,
250-
require: this.templates.requireFnFromTemplate,
252+
require: this.templates.requireFnFromTemplate.bind(this.templates),
251253
},
252254
config: this.config,
253255
};

src/schema-parser/schema-parser.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ class SchemaParser {
363363
*
364364
* @param schema {any}
365365
* @param typeName {null | string}
366-
* @param formatter {"inline" | "base"}
367366
* @return {Record<string, any>}
368367
*/
369368
parseSchema = (schema, typeName = null) => {

0 commit comments

Comments
 (0)