Skip to content

Conversation

@steverice
Copy link
Contributor

@steverice steverice commented Dec 2, 2025

This makes a small change to the code introduced in #849 to allow for models to be used as OAuth scopes. Without this check, an object like {value: "foo", description: "bar"} gets wrapped in an additional value key. When the OpenAPI3 emitter tries to print out the securitySchemes, it sees {value: {...}} and produces a scope with value [object Object] and no description.

This also introduces a base SecurityScheme model that allows for more specific type checking on the @useAuth decorator.

We need to remove an openapi3 test that checks for an error when providing an unsupported auth type.
Now the compiler enforces that the auth type is AuthType, and openapi3 supports all of the types in AuthType, it should not be possible to trigger this condition in TSP.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 2, 2025

Open in StackBlitz

npm i https://pkg.pr.new/microsoft/typespec/@typespec/http@9126

commit: 265b0b9

@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2025

All changed packages have been documented.

  • @typespec/http
Show changes

@typespec/http - fix ✏️

Allow for OAuth2 scopes to be properly specified with descriptions

@steverice steverice force-pushed the fix/allow-scope-descriptions branch from f02ce1c to 0e02281 Compare December 2, 2025 23:34

@doc("list of scopes for the credential")
scopes?: string[];
scopes?: ScopeList;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some previous idea here was to allow an enum instead what do you think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that instead of using OAuth2Scope, you would define scopes as e.g.

enum MyScopes {
  Read: "Read public data",
  Write: "Write private data",
}

?

If so, I like it. I like that it gives you a convenient way to reference individual scopes.

Are there any other places where we employ enums this way (enum value is documentation / description)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah exactly, we do for the version enum where the value is the api version(though that also could be left to interpretation)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good; I'll make that change.

This makes a small change to the code introduced in microsoft#849 to allow for models to be used as OAuth scopes.
Without this check, an object like `{value: "foo", description: "bar"}` gets wrapped in an additional `value` key.
When the OpenAPI3 emitter tries to print out the `securitySchemes`, it sees `{value: {...}}` and produces a scope with value `[object Object]` and no description.
@steverice steverice force-pushed the fix/allow-scope-descriptions branch from 0e02281 to 265b0b9 Compare December 3, 2025 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants