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]: Property is lost in projected versions #3239

Closed
4 tasks done
archerzz opened this issue Apr 26, 2024 · 3 comments · Fixed by #3255
Closed
4 tasks done

[Bug]: Property is lost in projected versions #3239

archerzz opened this issue Apr 26, 2024 · 3 comments · Fixed by #3255
Assignees
Labels
bug Something isn't working triaged:core
Milestone

Comments

@archerzz
Copy link
Member

Describe the bug

Let assume a service with 3 versions:

enum ApiVersions {
  @useDependency(global.Azure.Core.Versions.v1_0_Preview_2)
  v2022_06_01_preview: "2022-06-01-preview",

  v2022_09_01: "2022-09-01",
  v2022_12_01_preview: "2022-12-01-preview",
}

And a model has a property Type which is added in the first version, deleted in the 2nd version, and added back in the 3rd version:

model ExportedResource {
  id: string;
  resourceUri: string;

  @removed(ApiVersions.v2022_09_01)
  name: string;

  @removed(ApiVersions.v2022_09_01)
  @added(ApiVersions.v2022_12_01_preview)
  type: string;
}

If I specify api-version: "2022-06-01-preview", then Type should be generated. But currently the compiler will return ExportedResource without Type property.

Reproduction

Check this playground: https://azure.github.io/typespec-azure/playground?c=aW1wb3J0ICJAdHlwZXNwZWMvcmVzdCI7DQrJGmF6dXJlLXRvb2xzL8gmLcYVY29yZd8sZWMtY2xpZW50LWdlbmVyYXRvcsk3DQp1c2luZyBUeXBlU3BlYy5IdHRwO9EWUmVzdNIWVmVyc2lvbmluZ8kcQcR%2BLkNvcmXTEy5Gb3VuZGF0aW9uc9QfVHJhaXTEGg0KQHNlcnZpY2Uoew0KICB0aXRsZTogIspxIiwNCn0pDQpAdsYTZWQoQXBpxyBzKQ0KbmFtZXNwYWNl9ACvLk9sZOYA0g0KZW51bSDLPCDFckB1c2VEZXBlbmRlbmN5KGdsb2JhbC7rAKzILy52MV8wX1ByZXZpZXdfMinEPXYyMDIyXzA2XzAxX3DGGjogIsQVLTA2LTAxLccV5ADFyzA5XzAxySg5LTAxxCDIHjEy004xMs9OfcRRQHJlc291cmNlKCLICnMiKQ0KbW9kZWwgUscT5wDodmlzaWJpbGl0ecQuYWTEKSAgaWQ6IHN0cuYB2sUoa2V52zDkAW7PMuQCfMsT5QCa5gCCRXjkAqtlZO4Ais1zICDoALpVcmnPWUByZW1vdu4B8S7rAUP4AJHfOMY4QGFkZNUj7QGAxSv%2FAOF0UGFyYW3oAk9xdWVy5QFBcHJvamVjdEZpbGXHYj%2FLRf8Ag%2FAAg9FXZWTEWUZvcm1hdNFY%2FwEAz1LHLlHEEOUAy99Q11D%2FAM31AM1tYXhMaW5lcz86IGludDMy7gFeTGlzdOoAlucBYS4uLlNlbGVjyxpldGVy%2FwFT%2FQCGQGRvYygiRmlsdGVyIHRoZeQCk3VsdCBsaXN0IOYEvMQWZ2l2ZW4gZXhwcmVzxFsu5gMSZsU4%2FwE0%2FwCL6QCLZXhwYW5kzE3lARBpbnRlcmbkBOToA0tPcOQF4MRWxjd0ZW5kc%2BwFY9IpPE5vUmVwZWF0YWJsZVJlcXVlc3RzICbEQMQBTm9Db25kacQrYWzVH%2BUGW8caSWQ%2BIHvnBIVvdXRlKCIv5wWh5AW0KewAs%2BoFjk9w5wMlcG9sbMUQ5wCcKPIAri5HZXTRFlN0YXR1czzIGCzxBGI%2B5QFQZcUWIGlz8wEvLkxvbmdSdW7kAJDIHkFjxBvRV%2BYCd9Nl5wHk5QIg1mXIE%2BQCw8tY7gLS5AK4c%2BUHCzzOGXM%2ByGP%2FAkfvAkdzaGFyZWRS5AGQxBBjcmVhdGX%2FAKJDxSVPclJlcGxhY2XpAK3pAIL%2FA1L%2FAIB0ZesBcP8BkusBkvwAln0%3D&e=%40azure-tools%2Ftypespec-autorest&options=%7B%7D

Checklist

@timotheeguerin
Copy link
Member

Minimal repo

The problem seems to be we don't assume anymore that there it was added in v1 if it was removed after.
I am not sure this is really a bug in the projection as much as it should maybe validate this scenario to tell you you might need to be explicit here otherwise its a bit ambigous

@markcowl markcowl added this to the [2024] June milestone Apr 29, 2024
@tjprescott tjprescott self-assigned this Apr 30, 2024
tjprescott added a commit to tjprescott/typespec that referenced this issue Apr 30, 2024
tjprescott added a commit to tjprescott/typespec that referenced this issue Apr 30, 2024
tjprescott added a commit to tjprescott/typespec that referenced this issue May 8, 2024
tjprescott added a commit to tjprescott/typespec that referenced this issue May 21, 2024
tjprescott added a commit to tjprescott/typespec that referenced this issue May 22, 2024
tjprescott added a commit to tjprescott/typespec that referenced this issue May 22, 2024
tjprescott added a commit to tjprescott/typespec that referenced this issue May 23, 2024
tjprescott added a commit to tjprescott/typespec that referenced this issue May 28, 2024
tjprescott added a commit to tjprescott/typespec that referenced this issue Jun 4, 2024
@tjprescott
Copy link
Member

Hm... this is made trickier by the fact that whether we treat the parent containing no version information as "this thing was always available" depends on a lot of assumptions:

// Here we DO NOT want to assume val was available in v1
model Foo {
  @added(Versions.v2);
  val: string;
}

// But here we are saying do assume that val was available in v1
model Bar {
  @removed(Versions.v2);
  val: string;
}

The more special case assumptions we build in, the harder it will be to maintain the code. It may be better to simply be explicit here.

@timotheeguerin
Copy link
Member

being explicit was also my idea, if you have a @removed and @added ask for user to be explicit on when was the first added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triaged:core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants