microsoft / typespec

https://typespec.io/
MIT License
4.46k stars 209 forks source link

Versioning library should support adding an auth type in a new version #2033

Open mikekistler opened 1 year ago

mikekistler commented 1 year ago

I could not find a way to specify that a service added a new authentication type in a new version. I tried:

@versioned(Versions)
@useAuth(
  ApiKeyAuth<ApiKeyLocation.header, "api-key"> |
  @added(Versions.v2) OAuth2Auth<[
    {
      type: OAuth2FlowType.implicit,
      authorizationUrl: "https://login.contoso.com/common/oauth2/v2.0/authorize",
      scopes: ["https://widget.contoso.com/.default"],
    }
  ]>
)
@service({
  title: "Widget Service",
})
namespace DemoService;

enum Versions {
  v1,
  v2,
}

but this gives the error:

error invalid-decorator-location Cannot decorate expression.
timotheeguerin commented 1 year ago

Think this comes down to the versioning of decorators

markcowl commented 1 year ago

pri: 2

tjprescott commented 11 months ago

This playground shows how you can add the decorator using the is workaround. However, it throws a weird error that seems like a bug.

@markcowl consider flagging this a bug and re-evaluating when that is fixed.