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

Type changed for envelopeResult from getLroMetadata #311

Closed
tadelesh opened this issue Feb 26, 2024 · 4 comments
Closed

Type changed for envelopeResult from getLroMetadata #311

tadelesh opened this issue Feb 26, 2024 · 4 comments
Assignees
Labels
bug Something isn't working lib:azure-core Issues for @azure-tools/typespec-azure-core library

Comments

@tadelesh
Copy link
Member

tadelesh commented Feb 26, 2024

When calling getLroMetadata for createOrUpdate for the template resource, I got logicResult with right TypeSpec type Product, but envelopResult with a wrong calculated TypeSpec type ProxyResource as follow screenshot.
After some investigation, I found the type is changed after calling getEffectiveModelType here. Since the resource model has a path parameter, so it will enter the logic of finding a naming model which is same to the resource model without this path parameter (filter logic). When it has no exactly same model, it will also find a model that is same with it with the same filter logic, then the final result will fall to the original model. But after the complicated process, the type has totally changed and the naming info lost, it make the emitter hard to distinguish if it is the same resource model. Either fix the getEffectiveModelType logic for templated model or change the logic of getLroMetadata coudl resolve it. I don't know whether it should be opened as a core compiler problem or a getLroMetadata problem, If wrong place, I could move it.
image

@markcowl
Copy link
Member

markcowl commented Feb 26, 2024

@tadelesh I think this is by design, the finalEnvelopeResult (which matches the finalResult) is the value that should be used by emitters. The operations in the attached specs are a bit strange, as the interface template instantiates them without using TResource, which might be a factor in why the odd result, but the finalResult/finalEnvelopeResult/finalPath should be definitive, regardless.

@markcowl markcowl removed this from the [2024] April milestone Feb 26, 2024
@tadelesh
Copy link
Member Author

tadelesh commented Feb 27, 2024

Let me explain more clearly. The main problem here is for the following TypeSpec, when we call getEffectiveModelType, we will get the result type with same structure with Product, but another type with wrong name ProxyResource. I suppose it should return the type of Product.

model Product is ProxyResource<ProductProperties> {
  @doc("Name of product.")
  @pattern("^[\\w][\\w\\s]{1,48}[\\w]$|^\\.default$|^\\.unassigned$")
  @key("productName")
  @path
  @segment("products")
  name: string;
}

@tadelesh
Copy link
Member Author

tadelesh commented Mar 5, 2024

Let me explain more clearly. The main problem here is for the following TypeSpec, when we call getEffectiveModelType, we will get the result type with same structure with Product, but another type with wrong name ProxyResource. I suppose it should return the type of Product.

model Product is ProxyResource<ProductProperties> {
  @doc("Name of product.")
  @pattern("^[\\w][\\w\\s]{1,48}[\\w]$|^\\.default$|^\\.unassigned$")
  @key("productName")
  @path
  @segment("products")
  name: string;
}

@timotheeguerin do you think it is a bug for getEffectiveModelType?

@markcowl
Copy link
Member

This should be handled by the fix here: #1416

Closing as duplicate

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:azure-core Issues for @azure-tools/typespec-azure-core library
Projects
None yet
Development

No branches or pull requests

4 participants