Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues #7: CADL Generated Code Issue in EventGrid SDK #1853

Open
sarangan12 opened this issue May 17, 2023 · 1 comment
Open

Issues #7: CADL Generated Code Issue in EventGrid SDK #1853

sarangan12 opened this issue May 17, 2023 · 1 comment
Assignees
Labels

Comments

@sarangan12
Copy link
Member

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

We have the following CADL:

@doc("The result of the Acknowledge operation.")
model AcknowledgeResult {
    @doc("Array of LockToken values for failed cloud events. Each LockToken includes the lock token value along with the related error information (namely, the error code and description).")
    failedLockTokens: FailedLockToken[];

    @doc("Array of lock tokens values for the successfully acknowledged cloud events.")
    succeededLockTokens: string[];
  }

@doc("Acknowledge Cloud Events Body")
  model AcknowledgeCloudEventsBody {
    @doc("content type")
    @header("content-type")
    contentType: "application/json; charset=utf-8";

    @doc("Topic Name.")
    @path
    topicName: string;

    @doc("Event Subscription Name.")
    @path
    eventSubscriptionName: string;

    @doc("AcknowledgeOptions.")
    @body
    lockTokens: AcknowledgeOptions;
  }

@doc("Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is successfully acknowledged. The response body will include the set of successfully acknowledged lockTokens, along with other failed lockTokens with their corresponding error information. Successfully acknowledged events will no longer be available to any consumer.")

  @route("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:acknowledge")
  @post op AcknowledgeCloudEvents is Azure.Core.RpcOperation<AcknowledgeCloudEventsBody, AcknowledgeResult>;

With the above CADL, the generated code has the following snippet:

return {
    failedLockTokens: (result.body["failedLockTokens"] ?? []).map((p) => ({
      lockToken: p["lockToken"],
      errorCode: p["errorCode"],
      errorDescription: p["errorDescription"],
    })),
    succeededLockTokens: result.body["succeededLockTokens"],
  };

Now, this causes the build error at result.body["failedLockTokens"]. Now the problem is I was able to get this error only when I use certain versions of packages to generate the SDK. I coordinated with Jose and used the following config:

"@azure-tools/rlc-common": "https://bit.ly/3Bj3aHb",
"@azure-tools/typespec-ts": "https://bit.ly/3VVKUNH",
"@typespec/compiler": "0.43.0",    
"@typespec/http": "0.43.1",
"@typespec/rest": "0.43.0",
"@typespec/openapi": "0.43.0",
"@typespec/versioning": "0.43.0",
"@azure-tools/typespec-azure-core": "0.29.0",
"@azure-tools/typespec-autorest": "0.29.0",
"@azure-tools/typespec-client-generator-core": "0.29.0",
"@typespec/openapi3": "0.43.0",
"@typespec/prettier-plugin-typespec": "0.43.0",
"prettier": "2.7.1"

With the above configuration, the error is not reported. But, If I use the latest, I can see the error happening. So, please verify the issue with the latest version and ensure that the error does not happen

@sarangan12
Copy link
Member Author

@sarangan12 sarangan12 changed the title Issues #6: CADL Generated Code Issue in EventGrid SDK Issues #7: CADL Generated Code Issue in EventGrid SDK May 18, 2023
sarangan12 added a commit to Azure/azure-sdk-for-js that referenced this issue May 22, 2023
)

### Packages impacted by this PR
@Azure/eventgrid 

### Issues associated with this PR
NA

### Describe the problem that is addressed by this PR
1. The EventGrid Service team has introduced a new Client called
`EventGridClient` with 4 apis - `publishCloudEvent`,
`publishCloudEvents`, `receiveCloudEvents`, `acknowledgeCloudEvents`,
`releaseCloudEvents` and `rejectCloudEvents`. Now, the service is
represented using the [new CADL
specification](https://github.com/Azure/azure-rest-api-specs/tree/feature/eventgrid/typespec/specification/eventgrid/Azure.Messaging.EventGrid).
This SDK, in this PR, has been generated using the new [JS SDK CADL
Generator](https://github.com/Azure/autorest.typescript/tree/main/packages/typespec-ts).

2. During the generation process, I had a few issues in the generation
process. Seperate issues have been filed for the same and many of them
have already been resolved. For the remaining issues, I have provided
manual patches in this PR, so the release schedule will not be impacted.
Jose is already working on fixing any remaining issues. A complete list
of issues can be found in the related PRs/Issues section below.

3. This is a **beta** release. So, this code is not merged to the main
branch. The code changes are merged to a private branch
**feature/eventgrid/4_13_beta_1**.

**APIView To Approve** 

https://apiview.dev/Assemblies/Review/de09872b51a24f489981db711a73c430/2e0e731c80a840faab6df4c51acb6e95?diffRevisionId=2a4fb5a9265847c09428acb9b0581b0e&doc=False&diffOnly=True

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?
No special design considerations for the generation process.

### Are there test cases added in this PR? _(If not, why?)_
This version of the eventgrid service has not been released to public
and not available through azure portal. So, the test cases are not added
to this PR for now. Locally, I have tested the code changes with private
test resources and confirmed that the apis are working fine.

### Provide a list of related PRs/Issues _(if any)_
1. Azure/autorest.typescript#1818
2. Azure/autorest.typescript#1819
3. Azure/autorest.typescript#1820
4. Azure/autorest.typescript#1821
5. Azure/autorest.typescript#1851
6. Azure/autorest.typescript#1852
7. Azure/autorest.typescript#1853

### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_
npx tsp compile main.tsp

### Checklists
- [X] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [X] Added a changelog (if necessary)

@joheredi @ellismg Please review and approve the PR. 

@xirzec FYI....
@qiaozha qiaozha assigned MaryGao and unassigned joheredi May 31, 2023
@qiaozha qiaozha added HRLC DPG/RLC v2.1 Gallium work labels May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants