diff --git a/src/generators/AbstractGenerator.ts b/src/generators/AbstractGenerator.ts index 670aef726c..1637b7b315 100644 --- a/src/generators/AbstractGenerator.ts +++ b/src/generators/AbstractGenerator.ts @@ -43,25 +43,6 @@ export const defaultGeneratorOptions: CommonGeneratorOptions = { } }; -export interface AbstractGeneratorRenderArgs< - Options extends CommonGeneratorOptions, - ConstrainedModel = ConstrainedMetaModel -> { - constrainedModel: ConstrainedModel; - inputModel: InputMetaModel; - options?: DeepPartial; -} - -export interface AbstractGeneratorRenderCompleteModelArgs< - Options extends CommonGeneratorOptions, - RenderCompleteModelOptions -> { - constrainedModel: ConstrainedMetaModel; - inputModel: InputMetaModel; - completeOptions: Partial; - options?: DeepPartial; -} - /** * Abstract generator which must be implemented by each language */ @@ -75,13 +56,15 @@ export abstract class AbstractGenerator< ) {} public abstract render( - args: AbstractGeneratorRenderArgs + model: MetaModel, + inputModel: InputMetaModel, + options?: DeepPartial ): Promise; public abstract renderCompleteModel( - args: AbstractGeneratorRenderCompleteModelArgs< - Options, - RenderCompleteModelOptions - > + model: MetaModel, + inputModel: InputMetaModel, + completeOptions: Partial, + options?: DeepPartial ): Promise; public abstract constrainToMetaModel( model: MetaModel, @@ -199,12 +182,12 @@ export abstract class AbstractGenerator< return Promise.all( this.getConstrainedModels(inputModel).map( async ({ constrainedModel, dependencyManager }) => { - const renderedOutput = await this.renderCompleteModel({ + const renderedOutput = await this.renderCompleteModel( constrainedModel, inputModel, completeOptions, - options: { dependencyManager } as DeepPartial - }); + { dependencyManager } as DeepPartial + ); return OutputModel.toOutputModel({ result: renderedOutput.result, modelName: renderedOutput.renderedName, @@ -226,13 +209,13 @@ export abstract class AbstractGenerator< return Promise.all( this.getConstrainedModels(inputModel).map( async ({ constrainedModel, dependencyManager }) => { - const renderedOutput = await this.render({ + const renderedOutput = await this.render( constrainedModel, inputModel, - options: { + { dependencyManager } as DeepPartial - }); + ); return OutputModel.toOutputModel({ result: renderedOutput.result, modelName: renderedOutput.renderedName, diff --git a/src/generators/cplusplus/CplusplusGenerator.ts b/src/generators/cplusplus/CplusplusGenerator.ts index 77654d8e24..d3d2e57604 100644 --- a/src/generators/cplusplus/CplusplusGenerator.ts +++ b/src/generators/cplusplus/CplusplusGenerator.ts @@ -1,7 +1,5 @@ import { AbstractGenerator, - AbstractGeneratorRenderArgs, - AbstractGeneratorRenderCompleteModelArgs, CommonGeneratorOptions, defaultGeneratorOptions } from '../AbstractGenerator'; @@ -123,32 +121,26 @@ export class CplusplusGenerator extends AbstractGenerator< * @param inputModel */ render( - args: AbstractGeneratorRenderArgs + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + options?: DeepPartial ): Promise { const optionsToUse = CplusplusGenerator.getOptions({ ...this.options, - ...args.options + ...options }); if (isReservedCplusplusKeyword(optionsToUse.namespace)) { throw new Error( `You cannot use reserved C++ keyword (${optionsToUse.namespace}) as namespace, please use another.` ); } - if (args.constrainedModel instanceof ConstrainedObjectModel) { - return this.renderClass( - args.constrainedModel, - args.inputModel, - optionsToUse - ); - } else if (args.constrainedModel instanceof ConstrainedEnumModel) { - return this.renderEnum( - args.constrainedModel, - args.inputModel, - optionsToUse - ); + if (model instanceof ConstrainedObjectModel) { + return this.renderClass(model, inputModel, optionsToUse); + } else if (model instanceof ConstrainedEnumModel) { + return this.renderEnum(model, inputModel, optionsToUse); } Logger.warn( - `C++ generator, cannot generate this type of model, ${args.constrainedModel.name}` + `C++ generator, cannot generate this type of model, ${model.name}` ); return Promise.resolve( RenderOutput.toRenderOutput({ @@ -169,35 +161,30 @@ export class CplusplusGenerator extends AbstractGenerator< * @param options used to render the full output */ async renderCompleteModel( - args: AbstractGeneratorRenderCompleteModelArgs< - CplusplusOptions, - CplusplusRenderCompleteModelOptions - > + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + completeModelOptions: Partial, + options: DeepPartial ): Promise { // eslint-disable-next-line @typescript-eslint/no-unused-vars const completeModelOptionsToUse = mergePartialAndDefault( CplusplusGenerator.defaultCompleteModelOptions, - args.completeOptions + completeModelOptions ) as CplusplusRenderCompleteModelOptions; const optionsToUse = CplusplusGenerator.getOptions({ ...this.options, - ...args.options + ...options }); const dependencyManagerToUse = this.getDependencyManager(optionsToUse); - const outputModel = await this.render({ - ...args, - options: { - ...optionsToUse, - dependencyManager: dependencyManagerToUse - } + const outputModel = await this.render(model, inputModel, { + ...optionsToUse, + dependencyManager: dependencyManagerToUse }); - const imports = args.constrainedModel - .getNearestDependencies() - .map((model) => { - return `#include "${model.name}.hpp"`; - }); + const imports = model.getNearestDependencies().map((model) => { + return `#include "${model.name}.hpp"`; + }); const formattedOutputResult = FormatHelpers.indent( outputModel.result, 2, diff --git a/src/generators/csharp/CSharpGenerator.ts b/src/generators/csharp/CSharpGenerator.ts index 39d14f7c2e..b9018b88eb 100644 --- a/src/generators/csharp/CSharpGenerator.ts +++ b/src/generators/csharp/CSharpGenerator.ts @@ -1,7 +1,5 @@ import { AbstractGenerator, - AbstractGeneratorRenderArgs, - AbstractGeneratorRenderCompleteModelArgs, CommonGeneratorOptions, defaultGeneratorOptions } from '../AbstractGenerator'; @@ -148,18 +146,18 @@ export class CSharpGenerator extends AbstractGenerator< * @param options used to render the full output */ async renderCompleteModel( - args: AbstractGeneratorRenderCompleteModelArgs< - CSharpOptions, - CSharpRenderCompleteModelOptions - > + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + completeModelOptions: DeepPartial, + options: DeepPartial ): Promise { const completeModelOptionsToUse = mergePartialAndDefault( CSharpGenerator.defaultCompleteModelOptions, - args.completeOptions + completeModelOptions ) as CSharpRenderCompleteModelOptions; const optionsToUse = CSharpGenerator.getCSharpOptions({ ...this.options, - ...args.options + ...options }); if (isReservedCSharpKeyword(completeModelOptionsToUse.namespace)) { throw new Error( @@ -167,10 +165,7 @@ export class CSharpGenerator extends AbstractGenerator< ); } - const outputModel = await this.render({ - ...args, - options: optionsToUse - }); + const outputModel = await this.render(model, inputModel); const outputDependencies = outputModel.dependencies.length === 0 @@ -194,34 +189,24 @@ ${FormatHelpers.indent( } render( - args: AbstractGeneratorRenderArgs + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + options?: DeepPartial ): Promise { const optionsToUse = CSharpGenerator.getCSharpOptions({ ...this.options, - ...args.options + ...options }); - if (args.constrainedModel instanceof ConstrainedObjectModel) { + if (model instanceof ConstrainedObjectModel) { if (this.options.modelType === 'record') { - return this.renderRecord( - args.constrainedModel, - args.inputModel, - optionsToUse - ); + return this.renderRecord(model, inputModel, optionsToUse); } - return this.renderClass( - args.constrainedModel, - args.inputModel, - optionsToUse - ); - } else if (args.constrainedModel instanceof ConstrainedEnumModel) { - return this.renderEnum( - args.constrainedModel, - args.inputModel, - optionsToUse - ); + return this.renderClass(model, inputModel, optionsToUse); + } else if (model instanceof ConstrainedEnumModel) { + return this.renderEnum(model, inputModel, optionsToUse); } Logger.warn( - `C# generator, cannot generate this type of model, ${args.constrainedModel.name}` + `C# generator, cannot generate this type of model, ${model.name}` ); return Promise.resolve( RenderOutput.toRenderOutput({ diff --git a/src/generators/dart/DartGenerator.ts b/src/generators/dart/DartGenerator.ts index c924f851ca..5fdf6280c9 100644 --- a/src/generators/dart/DartGenerator.ts +++ b/src/generators/dart/DartGenerator.ts @@ -1,7 +1,5 @@ import { AbstractGenerator, - AbstractGeneratorRenderArgs, - AbstractGeneratorRenderCompleteModelArgs, CommonGeneratorOptions, defaultGeneratorOptions } from '../AbstractGenerator'; @@ -123,27 +121,21 @@ export class DartGenerator extends AbstractGenerator< * @param inputModel */ render( - args: AbstractGeneratorRenderArgs + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + options?: DeepPartial ): Promise { const optionsToUse = DartGenerator.getDartOptions({ ...this.options, - ...args.options + ...options }); - if (args.constrainedModel instanceof ConstrainedObjectModel) { - return this.renderClass( - args.constrainedModel, - args.inputModel, - optionsToUse - ); - } else if (args.constrainedModel instanceof ConstrainedEnumModel) { - return this.renderEnum( - args.constrainedModel, - args.inputModel, - optionsToUse - ); + if (model instanceof ConstrainedObjectModel) { + return this.renderClass(model, inputModel, optionsToUse); + } else if (model instanceof ConstrainedEnumModel) { + return this.renderEnum(model, inputModel, optionsToUse); } Logger.warn( - `Dart generator, cannot generate this type of model, ${args.constrainedModel.name}` + `Dart generator, cannot generate this type of model, ${model.name}` ); return Promise.resolve( RenderOutput.toRenderOutput({ @@ -164,18 +156,18 @@ export class DartGenerator extends AbstractGenerator< * @param options used to render the full output */ async renderCompleteModel( - args: AbstractGeneratorRenderCompleteModelArgs< - DartOptions, - DartRenderCompleteModelOptions - > + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + completeModelOptions: Partial, + options: DeepPartial ): Promise { const completeModelOptionsToUse = mergePartialAndDefault( DartGenerator.defaultCompleteModelOptions, - args.completeOptions + completeModelOptions ) as DartRenderCompleteModelOptions; const optionsToUse = DartGenerator.getDartOptions({ ...this.options, - ...args.options + ...options }); const dependencyManagerToUse = this.getDependencyManager(optionsToUse); if (isReservedDartKeyword(completeModelOptionsToUse.packageName)) { @@ -184,9 +176,9 @@ export class DartGenerator extends AbstractGenerator< ); } - const outputModel = await this.render({ ...args, options: optionsToUse }); + const outputModel = await this.render(model, inputModel, optionsToUse); const modelDependencies = dependencyManagerToUse.renderAllModelDependencies( - args.constrainedModel, + model, completeModelOptionsToUse.packageName ); const outputContent = `${modelDependencies} diff --git a/src/generators/go/GoGenerator.ts b/src/generators/go/GoGenerator.ts index 8fc5f5b3d3..c4c494ae2e 100644 --- a/src/generators/go/GoGenerator.ts +++ b/src/generators/go/GoGenerator.ts @@ -1,7 +1,5 @@ import { AbstractGenerator, - AbstractGeneratorRenderArgs, - AbstractGeneratorRenderCompleteModelArgs, CommonGeneratorOptions, defaultGeneratorOptions } from '../AbstractGenerator'; @@ -115,26 +113,22 @@ export class GoGenerator extends AbstractGenerator< ); } - render(args: AbstractGeneratorRenderArgs): Promise { + render( + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + options?: DeepPartial + ): Promise { const optionsToUse = GoGenerator.getGoOptions({ ...this.options, - ...args.options + ...options }); - if (args.constrainedModel instanceof ConstrainedObjectModel) { - return this.renderStruct( - args.constrainedModel, - args.inputModel, - optionsToUse - ); - } else if (args.constrainedModel instanceof ConstrainedEnumModel) { - return this.renderEnum( - args.constrainedModel, - args.inputModel, - optionsToUse - ); + if (model instanceof ConstrainedObjectModel) { + return this.renderStruct(model, inputModel, optionsToUse); + } else if (model instanceof ConstrainedEnumModel) { + return this.renderEnum(model, inputModel, optionsToUse); } Logger.warn( - `Go generator, cannot generate this type of model, ${args.constrainedModel.name}` + `Go generator, cannot generate this type of model, ${model.name}` ); return Promise.resolve( RenderOutput.toRenderOutput({ @@ -153,23 +147,20 @@ export class GoGenerator extends AbstractGenerator< * @param options */ async renderCompleteModel( - args: AbstractGeneratorRenderCompleteModelArgs< - GoOptions, - GoRenderCompleteModelOptions - > + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + completeModelOptions: Partial, + options: DeepPartial ): Promise { const completeModelOptionsToUse = mergePartialAndDefault( GoGenerator.defaultCompleteModelOptions, - args.completeOptions + completeModelOptions ) as GoRenderCompleteModelOptions; const optionsToUse = GoGenerator.getGoOptions({ ...this.options, - ...args.options - }); - const outputModel = await this.render({ - ...args, - options: optionsToUse + ...options }); + const outputModel = await this.render(model, inputModel, optionsToUse); let importCode = ''; if (outputModel.dependencies.length > 0) { const dependencies = outputModel.dependencies diff --git a/src/generators/java/JavaGenerator.ts b/src/generators/java/JavaGenerator.ts index 00407aed48..364f663261 100644 --- a/src/generators/java/JavaGenerator.ts +++ b/src/generators/java/JavaGenerator.ts @@ -1,7 +1,5 @@ import { AbstractGenerator, - AbstractGeneratorRenderArgs, - AbstractGeneratorRenderCompleteModelArgs, CommonGeneratorOptions, defaultGeneratorOptions } from '../AbstractGenerator'; @@ -127,36 +125,26 @@ export class JavaGenerator extends AbstractGenerator< * @param inputModel */ render( - args: AbstractGeneratorRenderArgs + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + options?: DeepPartial ): Promise { const optionsToUse = JavaGenerator.getJavaOptions({ ...this.options, - ...args.options + ...options }); - if (args.constrainedModel instanceof ConstrainedObjectModel) { - return this.renderClass({ - ...args, - constrainedModel: args.constrainedModel, - options: optionsToUse - }); - } else if (args.constrainedModel instanceof ConstrainedEnumModel) { - return this.renderEnum( - args.constrainedModel, - args.inputModel, - optionsToUse - ); + if (model instanceof ConstrainedObjectModel) { + return this.renderClass(model, inputModel, optionsToUse); + } else if (model instanceof ConstrainedEnumModel) { + return this.renderEnum(model, inputModel, optionsToUse); } else if ( - args.constrainedModel instanceof ConstrainedUnionModel && - !unionIncludesBuiltInTypes(args.constrainedModel) + model instanceof ConstrainedUnionModel && + !unionIncludesBuiltInTypes(model) ) { - return this.renderUnion( - args.constrainedModel, - args.inputModel, - optionsToUse - ); + return this.renderUnion(model, inputModel, optionsToUse); } Logger.warn( - `Java generator, cannot generate this type of model, ${args.constrainedModel.name}` + `Java generator, cannot generate this type of model, ${model.name}` ); return Promise.resolve( RenderOutput.toRenderOutput({ @@ -177,30 +165,27 @@ export class JavaGenerator extends AbstractGenerator< * @param options used to render the full output */ async renderCompleteModel( - args: AbstractGeneratorRenderCompleteModelArgs< - JavaOptions, - JavaRenderCompleteModelOptions - > + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + completeModelOptions: Partial, + options: DeepPartial ): Promise { const completeModelOptionsToUse = mergePartialAndDefault( JavaGenerator.defaultCompleteModelOptions, - args.completeOptions + completeModelOptions ); const optionsToUse = JavaGenerator.getJavaOptions({ ...this.options, - ...args.options + ...options }); const dependencyManagerToUse = this.getDependencyManager(optionsToUse); this.assertPackageIsValid(completeModelOptionsToUse); - const outputModel = await this.render({ - ...args, - options: optionsToUse - }); + const outputModel = await this.render(model, inputModel, optionsToUse); const modelDependencies = dependencyManagerToUse.renderAllModelDependencies( - args.constrainedModel, + model, completeModelOptionsToUse.packageName ); const outputContent = `package ${completeModelOptionsToUse.packageName}; @@ -231,11 +216,13 @@ ${outputModel.result}`; } async renderClass( - args: AbstractGeneratorRenderArgs + model: ConstrainedObjectModel, + inputModel: InputMetaModel, + options?: DeepPartial ): Promise { const optionsToUse = JavaGenerator.getJavaOptions({ ...this.options, - ...args.options + ...options }); const dependencyManagerToUse = this.getDependencyManager(optionsToUse); const presets = this.getPresets('class'); @@ -243,14 +230,14 @@ ${outputModel.result}`; optionsToUse, this, presets, - args.constrainedModel, - args.inputModel, + model, + inputModel, dependencyManagerToUse ); const result = await renderer.runSelfPreset(); return RenderOutput.toRenderOutput({ result, - renderedName: args.constrainedModel.name, + renderedName: model.name, dependencies: dependencyManagerToUse.dependencies }); } diff --git a/src/generators/javascript/JavaScriptGenerator.ts b/src/generators/javascript/JavaScriptGenerator.ts index 84b8d9cd32..480f8ac76b 100644 --- a/src/generators/javascript/JavaScriptGenerator.ts +++ b/src/generators/javascript/JavaScriptGenerator.ts @@ -1,7 +1,5 @@ import { AbstractGenerator, - AbstractGeneratorRenderArgs, - AbstractGeneratorRenderCompleteModelArgs, CommonGeneratorOptions, defaultGeneratorOptions } from '../AbstractGenerator'; @@ -102,22 +100,19 @@ export class JavaScriptGenerator extends AbstractGenerator< */ // eslint-disable-next-line @typescript-eslint/no-unused-vars async renderCompleteModel( - args: AbstractGeneratorRenderCompleteModelArgs< - JavaScriptOptions, - JavaScriptRenderCompleteModelOptions - > + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + completeModelOptions: Partial, + options: DeepPartial ): Promise { //const completeModelOptionsToUse = mergePartialAndDefault(JavaScriptGenerator.defaultCompleteModelOptions, completeModelOptions) as JavaScriptRenderCompleteModelOptions; const optionsToUse = JavaScriptGenerator.getJavaScriptOptions({ ...this.options, - ...args.options + ...options }); const dependencyManagerToUse = this.getDependencyManager(optionsToUse); - const outputModel = await this.render({ - ...args, - options: optionsToUse - }); - const modelDependencies = args.constrainedModel.getNearestDependencies(); + const outputModel = await this.render(model, inputModel, optionsToUse); + const modelDependencies = model.getNearestDependencies(); //Ensure model dependencies have their rendered name const modelDependencyImports = modelDependencies.map((dependencyModel) => { return dependencyManagerToUse.renderDependency( @@ -146,22 +141,18 @@ ${modelCode}`; } render( - args: AbstractGeneratorRenderArgs + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + options?: DeepPartial ): Promise { const optionsToUse = JavaScriptGenerator.getJavaScriptOptions({ ...this.options, - ...args.options + ...options }); - if (args.constrainedModel instanceof ConstrainedObjectModel) { - return this.renderClass( - args.constrainedModel, - args.inputModel, - optionsToUse - ); + if (model instanceof ConstrainedObjectModel) { + return this.renderClass(model, inputModel, optionsToUse); } - Logger.warn( - `JS generator, cannot generate model for '${args.constrainedModel.name}'` - ); + Logger.warn(`JS generator, cannot generate model for '${model.name}'`); return Promise.resolve( RenderOutput.toRenderOutput({ result: '', diff --git a/src/generators/kotlin/KotlinGenerator.ts b/src/generators/kotlin/KotlinGenerator.ts index c055149897..1f647bffd9 100644 --- a/src/generators/kotlin/KotlinGenerator.ts +++ b/src/generators/kotlin/KotlinGenerator.ts @@ -1,7 +1,5 @@ import { AbstractGenerator, - AbstractGeneratorRenderArgs, - AbstractGeneratorRenderCompleteModelArgs, CommonGeneratorOptions, defaultGeneratorOptions } from '../AbstractGenerator'; @@ -128,27 +126,21 @@ export class KotlinGenerator extends AbstractGenerator< * @param inputModel */ render( - args: AbstractGeneratorRenderArgs + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + options?: DeepPartial ): Promise { const optionsToUse = KotlinGenerator.getKotlinOptions({ ...this.options, - ...args.options + ...options }); - if (args.constrainedModel instanceof ConstrainedObjectModel) { - return this.renderClass( - args.constrainedModel, - args.inputModel, - optionsToUse - ); - } else if (args.constrainedModel instanceof ConstrainedEnumModel) { - return this.renderEnum( - args.constrainedModel, - args.inputModel, - optionsToUse - ); + if (model instanceof ConstrainedObjectModel) { + return this.renderClass(model, inputModel, optionsToUse); + } else if (model instanceof ConstrainedEnumModel) { + return this.renderEnum(model, inputModel, optionsToUse); } Logger.warn( - `Kotlin generator, cannot generate this type of model, ${args.constrainedModel.name}` + `Kotlin generator, cannot generate this type of model, ${model.name}` ); return Promise.resolve( RenderOutput.toRenderOutput({ @@ -169,22 +161,16 @@ export class KotlinGenerator extends AbstractGenerator< * @param options used to render the full output */ async renderCompleteModel( - args: AbstractGeneratorRenderCompleteModelArgs< - KotlinOptions, - KotlinRenderCompleteModelOptions - > + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + options: KotlinRenderCompleteModelOptions ): Promise { const optionsToUse = KotlinGenerator.getKotlinOptions({ ...this.options, - ...args.options - }); - const outputModel = await this.render({ - ...args, - options: optionsToUse + ...options }); - const packageName = this.sanitizePackageName( - args.completeOptions.packageName || 'Asyncapi.Models' - ); + const outputModel = await this.render(model, inputModel, optionsToUse); + const packageName = this.sanitizePackageName(options.packageName); const outputContent = `package ${packageName} ${outputModel.dependencies.join('\n')} diff --git a/src/generators/php/PhpGenerator.ts b/src/generators/php/PhpGenerator.ts index 833b9ebfdc..63cedd3c08 100644 --- a/src/generators/php/PhpGenerator.ts +++ b/src/generators/php/PhpGenerator.ts @@ -1,7 +1,5 @@ import { AbstractGenerator, - AbstractGeneratorRenderArgs, - AbstractGeneratorRenderCompleteModelArgs, CommonGeneratorOptions, defaultGeneratorOptions } from '../AbstractGenerator'; @@ -119,14 +117,17 @@ export class PhpGenerator extends AbstractGenerator< * @param model * @param inputModel */ - render(args: AbstractGeneratorRenderArgs): Promise { - if (args.constrainedModel instanceof ConstrainedObjectModel) { - return this.renderClass(args.constrainedModel, args.inputModel); - } else if (args.constrainedModel instanceof ConstrainedEnumModel) { - return this.renderEnum(args.constrainedModel, args.inputModel); + render( + model: ConstrainedMetaModel, + inputModel: InputMetaModel + ): Promise { + if (model instanceof ConstrainedObjectModel) { + return this.renderClass(model, inputModel); + } else if (model instanceof ConstrainedEnumModel) { + return this.renderEnum(model, inputModel); } Logger.warn( - `PHP generator, cannot generate this type of model, ${args.constrainedModel.name}` + `PHP generator, cannot generate this type of model, ${model.name}` ); return Promise.resolve( RenderOutput.toRenderOutput({ @@ -145,16 +146,14 @@ export class PhpGenerator extends AbstractGenerator< * @param options used to render the full output */ async renderCompleteModel( - args: AbstractGeneratorRenderCompleteModelArgs< - PhpOptions, - PhpRenderCompleteModelOptions - > + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + options: PhpRenderCompleteModelOptions ): Promise { - const completeModelOptionsToUse = - mergePartialAndDefault( - PhpGenerator.defaultCompleteModelOptions, - args.completeOptions - ); + const completeModelOptionsToUse = mergePartialAndDefault( + PhpGenerator.defaultCompleteModelOptions, + options + ); if (isReservedPhpKeyword(completeModelOptionsToUse.namespace)) { throw new Error( @@ -165,8 +164,8 @@ export class PhpGenerator extends AbstractGenerator< const declares: string = completeModelOptionsToUse.declareStrictTypes ? 'declare(strict_types=1);' : ''; - const outputModel: RenderOutput = await this.render(args); - const modelDependencies: string[] = args.constrainedModel + const outputModel: RenderOutput = await this.render(model, inputModel); + const modelDependencies: string[] = model .getNearestDependencies() .map((dependencyModel) => { return `use ${completeModelOptionsToUse.namespace}\\${dependencyModel.name};`; diff --git a/src/generators/python/PythonGenerator.ts b/src/generators/python/PythonGenerator.ts index 2d20bd0e5f..63d7e4aa01 100644 --- a/src/generators/python/PythonGenerator.ts +++ b/src/generators/python/PythonGenerator.ts @@ -1,8 +1,6 @@ /* eslint-disable no-console */ import { AbstractGenerator, - AbstractGeneratorRenderArgs, - AbstractGeneratorRenderCompleteModelArgs, CommonGeneratorOptions, defaultGeneratorOptions } from '../AbstractGenerator'; @@ -131,27 +129,21 @@ export class PythonGenerator extends AbstractGenerator< * @param inputModel */ render( - args: AbstractGeneratorRenderArgs + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + options?: DeepPartial ): Promise { const optionsToUse = PythonGenerator.getPythonOptions({ ...this.options, - ...args.options + ...options }); - if (args.constrainedModel instanceof ConstrainedObjectModel) { - return this.renderClass( - args.constrainedModel, - args.inputModel, - optionsToUse - ); - } else if (args.constrainedModel instanceof ConstrainedEnumModel) { - return this.renderEnum( - args.constrainedModel, - args.inputModel, - optionsToUse - ); + if (model instanceof ConstrainedObjectModel) { + return this.renderClass(model, inputModel, optionsToUse); + } else if (model instanceof ConstrainedEnumModel) { + return this.renderEnum(model, inputModel, optionsToUse); } Logger.warn( - `Python generator, cannot generate this type of model, ${args.constrainedModel.name}` + `Python generator, cannot generate this type of model, ${model.name}` ); return Promise.resolve( RenderOutput.toRenderOutput({ @@ -172,29 +164,24 @@ export class PythonGenerator extends AbstractGenerator< * @param options used to render the full output */ async renderCompleteModel( - args: AbstractGeneratorRenderCompleteModelArgs< - PythonOptions, - PythonRenderCompleteModelOptions - > + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + completeModelOptions: Partial, + options: DeepPartial ): Promise { //const completeModelOptionsToUse = mergePartialAndDefault(PythonGenerator.defaultCompleteModelOptions, completeModelOptions) as PythonRenderCompleteModelOptions; const optionsToUse = PythonGenerator.getPythonOptions({ ...this.options, - ...args.options + ...options }); const dependencyManagerToUse = this.getDependencyManager(optionsToUse); - const outputModel = await this.render({ - ...args, - options: { - ...optionsToUse, - dependencyManager: dependencyManagerToUse - } + const outputModel = await this.render(model, inputModel, { + ...optionsToUse, + dependencyManager: dependencyManagerToUse + }); + const modelDependencies = model.getNearestDependencies().map((model) => { + return dependencyManagerToUse.renderDependency(model); }); - const modelDependencies = args.constrainedModel - .getNearestDependencies() - .map((model) => { - return dependencyManagerToUse.renderDependency(model); - }); const outputContent = `${modelDependencies.join('\n')} ${outputModel.dependencies.join('\n')} ${outputModel.result}`; diff --git a/src/generators/rust/RustGenerator.ts b/src/generators/rust/RustGenerator.ts index 758f5e2d60..c5987ce151 100644 --- a/src/generators/rust/RustGenerator.ts +++ b/src/generators/rust/RustGenerator.ts @@ -1,7 +1,5 @@ import { AbstractGenerator, - AbstractGeneratorRenderArgs, - AbstractGeneratorRenderCompleteModelArgs, CommonGeneratorOptions, defaultGeneratorOptions } from '../AbstractGenerator'; @@ -180,39 +178,25 @@ export class RustGenerator extends AbstractGenerator< } render( - args: AbstractGeneratorRenderArgs + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + options?: DeepPartial ): Promise { const optionsToUse = RustGenerator.getRustOptions({ ...this.options, - ...args.options + ...options }); - if (args.constrainedModel instanceof ConstrainedObjectModel) { - return this.renderStruct( - args.constrainedModel, - args.inputModel, - optionsToUse - ); - } else if (args.constrainedModel instanceof ConstrainedEnumModel) { - return this.renderEnum( - args.constrainedModel, - args.inputModel, - optionsToUse - ); - } else if (args.constrainedModel instanceof ConstrainedTupleModel) { - return this.renderTuple( - args.constrainedModel, - args.inputModel, - optionsToUse - ); - } else if (args.constrainedModel instanceof ConstrainedUnionModel) { - return this.renderUnion( - args.constrainedModel, - args.inputModel, - optionsToUse - ); + if (model instanceof ConstrainedObjectModel) { + return this.renderStruct(model, inputModel, optionsToUse); + } else if (model instanceof ConstrainedEnumModel) { + return this.renderEnum(model, inputModel, optionsToUse); + } else if (model instanceof ConstrainedTupleModel) { + return this.renderTuple(model, inputModel, optionsToUse); + } else if (model instanceof ConstrainedUnionModel) { + return this.renderUnion(model, inputModel, optionsToUse); } Logger.warn( - `Rust generator, cannot generate this type of model, ${args.constrainedModel.name}` + `Rust generator, cannot generate this type of model, ${model.name}` ); return Promise.resolve( RenderOutput.toRenderOutput({ @@ -231,17 +215,17 @@ export class RustGenerator extends AbstractGenerator< * @param options */ async renderCompleteModel( - args: AbstractGeneratorRenderCompleteModelArgs< - RustOptions, - RustRenderCompleteModelOptions - > + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + _completeModelOptions: Partial, + options: DeepPartial ): Promise { const optionsToUse = RustGenerator.getRustOptions({ ...this.options, - ...args.options + ...options }); Logger.debug('Generating complete models with options: ', optionsToUse); - const outputModel = await this.render({ ...args, options: optionsToUse }); + const outputModel = await this.render(model, inputModel); const outputContent = outputModel.result; return RenderOutput.toRenderOutput({ result: outputContent, diff --git a/src/generators/template/TemplateGenerator.ts b/src/generators/template/TemplateGenerator.ts index afa1f7db91..e85145bdef 100644 --- a/src/generators/template/TemplateGenerator.ts +++ b/src/generators/template/TemplateGenerator.ts @@ -1,7 +1,5 @@ import { AbstractGenerator, - AbstractGeneratorRenderArgs, - AbstractGeneratorRenderCompleteModelArgs, CommonGeneratorOptions, defaultGeneratorOptions } from '../AbstractGenerator'; @@ -126,15 +124,16 @@ export class TemplateGenerator extends AbstractGenerator< * @param inputModel */ render( - args: AbstractGeneratorRenderArgs + model: ConstrainedMetaModel, + inputModel: InputMetaModel ): Promise { - if (args.constrainedModel instanceof ConstrainedObjectModel) { - return this.renderClass(args.constrainedModel, args.inputModel); - } else if (args.constrainedModel instanceof ConstrainedEnumModel) { - return this.renderEnum(args.constrainedModel, args.inputModel); + if (model instanceof ConstrainedObjectModel) { + return this.renderClass(model, inputModel); + } else if (model instanceof ConstrainedEnumModel) { + return this.renderEnum(model, inputModel); } Logger.warn( - `Template generator, cannot generate this type of model, ${args.constrainedModel.name}` + `Template generator, cannot generate this type of model, ${model.name}` ); return Promise.resolve( RenderOutput.toRenderOutput({ @@ -155,30 +154,23 @@ export class TemplateGenerator extends AbstractGenerator< * @param options used to render the full output */ async renderCompleteModel( - args: AbstractGeneratorRenderCompleteModelArgs< - TemplateOptions, - TemplateRenderCompleteModelOptions - > + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + options: TemplateRenderCompleteModelOptions ): Promise { - const completeModelOptionsToUse = - mergePartialAndDefault( - TemplateGenerator.defaultCompleteModelOptions, - args.completeOptions - ); - - if (isReservedTemplateKeyword(completeModelOptionsToUse.packageName)) { + if (isReservedTemplateKeyword(options.packageName)) { throw new Error( - `You cannot use reserved Template keyword (${args.completeOptions.packageName}) as package name, please use another.` + `You cannot use reserved Template keyword (${options.packageName}) as package name, please use another.` ); } - const outputModel = await this.render(args); - const modelDependencies = args.constrainedModel + const outputModel = await this.render(model, inputModel); + const modelDependencies = model .getNearestDependencies() .map((dependencyModel) => { - return `import ${completeModelOptionsToUse.packageName}.${dependencyModel.name};`; + return `import ${options.packageName}.${dependencyModel.name};`; }); - const outputContent = `package ${completeModelOptionsToUse.packageName}; + const outputContent = `package ${options.packageName}; ${modelDependencies.join('\n')} ${outputModel.dependencies.join('\n')} ${outputModel.result}`; diff --git a/src/generators/typescript/TypeScriptGenerator.ts b/src/generators/typescript/TypeScriptGenerator.ts index e9058f4be8..251d6ee9e4 100644 --- a/src/generators/typescript/TypeScriptGenerator.ts +++ b/src/generators/typescript/TypeScriptGenerator.ts @@ -1,7 +1,5 @@ import { AbstractGenerator, - AbstractGeneratorRenderArgs, - AbstractGeneratorRenderCompleteModelArgs, CommonGeneratorOptions, defaultGeneratorOptions } from '../AbstractGenerator'; @@ -158,28 +156,25 @@ export class TypeScriptGenerator extends AbstractGenerator< * @param options */ async renderCompleteModel( - args: AbstractGeneratorRenderCompleteModelArgs< - TypeScriptOptions, - TypeScriptRenderCompleteModelOptions - > + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + completeModelOptions: Partial, + options: DeepPartial ): Promise { const completeModelOptionsToUse = mergePartialAndDefault( TypeScriptGenerator.defaultCompleteModelOptions, - args.completeOptions + completeModelOptions ) as TypeScriptRenderCompleteModelOptions; const optionsToUse = TypeScriptGenerator.getOptions({ ...this.options, - ...args.options + ...options }); const dependencyManagerToUse = this.getDependencyManager(optionsToUse); - const outputModel = await this.render({ - ...args, - options: { - ...optionsToUse, - dependencyManager: dependencyManagerToUse - } + const outputModel = await this.render(model, inputModel, { + ...optionsToUse, + dependencyManager: dependencyManagerToUse }); - const modelDependencies = args.constrainedModel.getNearestDependencies(); + const modelDependencies = model.getNearestDependencies(); //Create the correct model dependency imports const modelDependencyImports = modelDependencies.map((model) => { @@ -189,7 +184,7 @@ export class TypeScriptGenerator extends AbstractGenerator< ); }); const modelExport = dependencyManagerToUse.renderExport( - args.constrainedModel, + model, completeModelOptionsToUse.exportType ); @@ -212,37 +207,23 @@ ${modelCode}`; * Render any ConstrainedMetaModel to code based on the type */ render( - args: AbstractGeneratorRenderArgs + model: ConstrainedMetaModel, + inputModel: InputMetaModel, + options?: DeepPartial ): Promise { const optionsToUse = TypeScriptGenerator.getOptions({ ...this.options, - ...args.options + ...options }); - if (args.constrainedModel instanceof ConstrainedObjectModel) { + if (model instanceof ConstrainedObjectModel) { if (this.options.modelType === 'interface') { - return this.renderInterface( - args.constrainedModel, - args.inputModel, - optionsToUse - ); + return this.renderInterface(model, inputModel, optionsToUse); } - return this.renderClass( - args.constrainedModel, - args.inputModel, - optionsToUse - ); - } else if (args.constrainedModel instanceof ConstrainedEnumModel) { - return this.renderEnum( - args.constrainedModel, - args.inputModel, - optionsToUse - ); + return this.renderClass(model, inputModel, optionsToUse); + } else if (model instanceof ConstrainedEnumModel) { + return this.renderEnum(model, inputModel, optionsToUse); } - return this.renderType( - args.constrainedModel, - args.inputModel, - optionsToUse - ); + return this.renderType(model, inputModel, optionsToUse); } async renderClass(