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]: How to locate/decorate union variant in union? #5081

Open
4 tasks done
MaryGao opened this issue Nov 13, 2024 · 3 comments
Open
4 tasks done

[Bug]: How to locate/decorate union variant in union? #5081

MaryGao opened this issue Nov 13, 2024 · 3 comments
Labels
compiler:core Issues for @typespec/compiler design:needed A design request has been raised that needs a proposal triaged:core
Milestone

Comments

@MaryGao
Copy link
Member

MaryGao commented Nov 13, 2024

Describe the bug

Say we have following spec and we want to add a better name for enum item 3, but the compile reports errors. Is this a bug?

import "@typespec/http";
import "@azure-tools/typespec-client-generator-core";

using TypeSpec.Http;
using Azure.ClientGenerator.Core;

union ExtensibleNumber {
  One: 1,
  Two: 2,
  3,
  int8,
}
model Foo {
  extensibleNumber: ExtensibleNumber;
}
op post(@body body: Foo): void;

@@clientName(ExtensibleNumber.One, "ItemOne");
@@clientName(ExtensibleNumber.Two, "ItemTwo");
@@clientName(ExtensibleNumber.`3`, "ItemThree");

Image

Reproduction

playground

Checklist

@MaryGao MaryGao added the bug Something isn't working label Nov 13, 2024
@MaryGao MaryGao changed the title [Bug]: How to locate number enum member in extensible number of union? [Bug]: How to locate number enum member in union? Nov 13, 2024
@MaryGao MaryGao changed the title [Bug]: How to locate number enum member in union? [Bug]: How to locate number variant in union? Nov 13, 2024
@MaryGao MaryGao changed the title [Bug]: How to locate number variant in union? [Bug]: How to locate/decorate number variant in union? Nov 13, 2024
@markcowl markcowl removed the bug Something isn't working label Nov 13, 2024
@markcowl markcowl self-assigned this Nov 13, 2024
@markcowl
Copy link
Contributor

@markcowl look for design issue on referencing union variants

@markcowl markcowl removed their assignment Nov 13, 2024
@markcowl markcowl added design:needed A design request has been raised that needs a proposal compiler:core Issues for @typespec/compiler triaged:core and removed needs-area labels Nov 13, 2024
@markcowl markcowl added this to the Backlog milestone Nov 13, 2024
@markcowl
Copy link
Contributor

@MaryGao It is by design that union variants cannot be decorated, and so cannot be referenced in augment decorators. The workaround would be to create a scalar type with the needed decoration and use that as the union variant. You can also use enums for these scenarios, as shown here

@MaryGao MaryGao changed the title [Bug]: How to locate/decorate number variant in union? [Bug]: How to locate/decorate union variant in union? Nov 14, 2024
@MaryGao
Copy link
Member Author

MaryGao commented Nov 19, 2024

@markcowl thanks for the info. With the union as enum feature in azure, emitters would have the requirement to emit a member name and rename it if necessary. So I was wondering if we could add this ability using type metadata(::) similar to model expression.

I notice that union variant without a name is common usage for customers e.g example spec. I was also wondering if we should add a linter in azure to warn always having a variant member name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:core Issues for @typespec/compiler design:needed A design request has been raised that needs a proposal triaged:core
Projects
None yet
Development

No branches or pull requests

2 participants