Skip to content

Commit

Permalink
fix: fix renderTmpl.utils context
Browse files Browse the repository at this point in the history
  • Loading branch information
zWingz committed Jun 28, 2024
1 parent 537ebdd commit dc787a1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
8 changes: 8 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,14 @@ export interface GenerateApiConfiguration {
typeName?: string,
formattersMap?: Record<MAIN_SCHEMA_TYPES, (content: ModelType) => string>,
) => ModelType;
safeAddNullToType: (
schema: { type: string; nullable?: boolean; "x-nullable"?: boolean },
type: unknown,
) => string;
isNeedToAddNull: (
schema: { type: string; nullable?: boolean; "x-nullable"?: boolean },
type: unknown,
) => boolean;
formatters: Record<
MAIN_SCHEMA_TYPES,
(content: string | object | string[] | object[]) => string
Expand Down
26 changes: 14 additions & 12 deletions src/code-gen-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,28 +208,30 @@ class CodeGenProcess {
utils: {
Ts: this.config.Ts,
formatDescription:
this.schemaParserFabric.schemaFormatters.formatDescription,
this.schemaParserFabric.schemaFormatters.formatDescription.bind(
this.schemaParserFabric.schemaFormatters,
),
internalCase: internalCase,
classNameCase: pascalCase,
pascalCase: pascalCase,
getInlineParseContent: this.schemaParserFabric.getInlineParseContent,
getParseContent: this.schemaParserFabric.getParseContent,
getComponentByRef: this.schemaComponentsMap.get,
parseSchema: this.schemaParserFabric.parseSchema,
checkAndAddNull: this.schemaParserFabric.schemaUtils.safeAddNullToType,
getInlineParseContent: this.schemaParserFabric.getInlineParseContent.bind(this.schemaParserFabric),
getParseContent: this.schemaParserFabric.getParseContent.bind(this.schemaParserFabric),
getComponentByRef: this.schemaComponentsMap.get.bind(this.schemaComponentsMap),
parseSchema: this.schemaParserFabric.parseSchema.bind(this.schemaParserFabric),
checkAndAddNull: this.schemaParserFabric.schemaUtils.safeAddNullToType.bind(this.schemaParserFabric.schemaUtils),
safeAddNullToType:
this.schemaParserFabric.schemaUtils.safeAddNullToType,
this.schemaParserFabric.schemaUtils.safeAddNullToType.bind(this.schemaParserFabric.schemaUtils),
isNeedToAddNull:
this.schemaParserFabric.schemaUtils.isNullMissingInType,
inlineExtraFormatters: this.schemaParserFabric.schemaFormatters.inline,
formatters: this.schemaParserFabric.schemaFormatters.base,
formatModelName: this.typeNameFormatter.format,
this.schemaParserFabric.schemaUtils.isNullMissingInType.bind(this.schemaParserFabric.schemaUtils),
inlineExtraFormatters: this.schemaParserFabric.schemaFormatters.inline.bind(this.schemaParserFabric.schemaFormatters),
formatters: this.schemaParserFabric.schemaFormatters.base.bind(this.schemaParserFabric.schemaFormatters),
formatModelName: this.typeNameFormatter.format.bind(this.typeNameFormatter),
fmtToJSDocLine: function fmtToJSDocLine(line, { eol = true }) {
return ` * ${line}${eol ? "\n" : ""}`;
},
NameResolver: NameResolver,
_,
require: this.templatesWorker.requireFnFromTemplate,
require: this.templatesWorker.requireFnFromTemplate.bind(this.templatesWorker),
},
config: this.config,
};
Expand Down

0 comments on commit dc787a1

Please sign in to comment.