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

[Bug][TCGC] Multiple instances of OperationStatus model definition #346

Closed
archerzz opened this issue Mar 1, 2024 · 3 comments
Closed
Assignees
Labels
bug Something isn't working lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Comments

@archerzz
Copy link
Member

archerzz commented Mar 1, 2024

Describe the bug
This is a successor of #204 After fixing it, OperationStatus appears in the context.modelsMap. However, it seems that the OperationStatus instance in context.modelsMap is NOT the same as the one returned in getLroMetadata. So codes like below won't work:

 function getInputModelForModel(m: Model): InputModelType | undefined {
    if (context.modelsMap!.has(m)) { // won't work because `m` is a different instance then the one in `modelsMap`.
       ...
 }

To Reproduce

Expected behavior
OperationStatus instance should be globally unique.

Additional context
image

Not sure if it's related to how OperationStatus is fetched inside getLroMetadata. I tried to debug, and it's from getResourceLocationType:

return getResourceLocationType(program, resolvedScalar);
which is: https://github.com/microsoft/typespec/blob/8c7c76bf8e17e9ab2ad5a8bab6c3a8ba2d125de3/packages/rest/src/rest.ts#L562

@archerzz archerzz added bug Something isn't working lib:tcgc Issues for @azure-tools/typespec-client-generator-core library Blocking labels Mar 1, 2024
@archerzz
Copy link
Member Author

archerzz commented Mar 5, 2024

After debugging, I think the problem is not because of there are multiple instance of the same OperationStatus. It's because of the metadata parsed by getLroMetadata() is different from what TCGC parsed.

image
The above is the OperationStaus parsed by getLroMetadata(). As you can see, it's name is OperationStatus.

image
This is what the corresponding metadata in TCGC. Its name is ResourceOperationStatus, and its sourceModel property is the same as the one parsed by getLroMetadata.

ResourceOperationStatus is a OperationStatus:

@resource("operations")
@parentResource(Resource)
model ResourceOperationStatus<
Resource extends TypeSpec.Reflection.Model,
StatusResult = Resource,
StatusError = Foundations.Error
> is Azure.Core.Foundations.OperationStatus<StatusResult, StatusError>;

Now the problem is how we get the two different sybmols.

@tadelesh
Copy link
Member

tadelesh commented Mar 5, 2024

The root cause should be #311 (comment)

@iscai-msft
Copy link
Contributor

Switching to envelopeResult should've fixed the issue, @archerzz I'm going to close this issue, if it's still an issue, can you reopen? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lib:tcgc Issues for @azure-tools/typespec-client-generator-core library
Projects
None yet
Development

No branches or pull requests

6 participants