cli icon indicating copy to clipboard operation
cli copied to clipboard

The generated code is making weird Type errors

Open ALagoni97 opened this issue 2 years ago • 2 comments

Following channel:

"runs.command.start.{type}.{run_uid}": {
	"description": "This starts a run",
	"parameters": {
		"run_uid": {
			"schema": {
				"type": "string"
			}
		},
		"type": {
			"schema": {
				"type": "string",
				"enum": ["openapi", "asyncapi"]
			}
		}
	},
	"subscribe": {
		"summary": "Start a run",
		"operationId": "startRun",
		"message": {
			"$ref": "#/components/messages/startRun"
		}
	},
	"bindings": {
		"$ref": "./bindings.json#/components/channelBindings/StartRun"
	}
},

I would think this is sufficient:

await nats.jetStreamPublishToRunsCommandStartTypeRunUid(
	startRun,
	{
		runUid: data.run.id,
		type: 'asyncapi',
	},
	data.type === GeneratorTypes.OPENAPI ? 'openapi' : 'asyncapi'
)

But I get type errors: image

The generated RunsCommandStartTypeRunUidParameters type:

import {Type} from './Type';
class RunsCommandStartTypeRunUidParameters {
  private _runUid: string;
  private _type: Type;

  constructor(input: {
    runUid: string,
    type: Type,
  }) {
    this._runUid = input.runUid;
    this._type = input.type;
  }

  get runUid(): string { return this._runUid; }
  set runUid(runUid: string) { this._runUid = runUid; }

  get type(): Type { return this._type; }
  set type(type: Type) { this._type = type; }


  /**
   * Realize the channel/topic with the parameters added to this class.
   */
  public getChannelWithParameters(channel: string) {
    channel = channel.replace(/\{run_uid\}/g, this.runUid)
  channel = channel.replace(/\{type\}/g, this.type);
    return channel;
  }
}
export { RunsCommandStartTypeRunUidParameters };

ALagoni97 avatar Sep 28 '24 09:09 ALagoni97

This error is not only happening in this instance, but every channel/protocol generated.

ALagoni97 avatar Sep 28 '24 09:09 ALagoni97

Nevermind it is me who doesn't understand the code generated properly. The params are a class and need to obviously be instantiated first.

new RunsStatusRunUidStoppedParameters({
    runUid: run.id,
})

😅

ALagoni97 avatar Sep 28 '24 09:09 ALagoni97