Azure / autorest.typescript

Extension for AutoRest (https://github.com/Azure/autorest) that generates TypeScript code. The transpiled javascript code is isomorphic. It can be run in browser and in node.js environment.
MIT License
178 stars 75 forks source link

Issues #6: CADL Generated Code Issue in EventGrid SDK #1852

Open sarangan12 opened 1 year ago

sarangan12 commented 1 year ago

While working on the EventGrid SDK, generated from the CADL files, I have noticed the following.

In CADL, we have the following PublishCloudEvent api.

@doc("Publish Single Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200 status code with an empty JSON object in response. Otherwise, the server can return various error codes. For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for internal server error. ")
@route("/topics/{topicName}:publish", {shared: true})
@post op PublishCloudEvent is Azure.Core.RpcOperation<PublishCloudEventBody, PublishResult>;

@doc("The result of the Publish operation.")
model PublishResult {}

Look at the return type. It is PublishResult and is an empty object. Look at the generated output:

publishCloudEvent(
    event: CloudEvent,
    topicName: string,
    options: PublishCloudEventOptions = { requestOptions: {} }
): Promise<Record<string, any>> {
    return publishCloudEvent(this._client, event, topicName, options);
}

Now, the generated output has no reference to PublishResult object. We want the output to be:

export interface PublishResult {}

publishCloudEvent(
    event: CloudEvent,
    topicName: string,
    options: PublishCloudEventOptions = { requestOptions: {} }
): Promise<PublishResult> {
    return publishCloudEvent(this._client, event, topicName, options);
}

We need a code change to fix this issue

sarangan12 commented 1 year ago

Input file that can be used for testing: https://github.com/Azure/azure-rest-api-specs/blob/feature/eventgrid/typespec/specification/eventgrid/Azure.Messaging.EventGrid/main.tsp