Skip to content

Commit 5c8a2d8

Browse files
Add security scheme descriptions to Azure Core data-plane playground sample (#4547)
The Azure Core Data Plane playground sample emitted auth schemes without `description`, so generated REST docs did not show guidance text for API key/OAuth2 authentication. This PR updates the sample to model and emit explicit security scheme descriptions. - **Problem summary** - Playground users had no example of how to attach descriptions to security schemes in TypeSpec Azure data-plane services. - Generated OpenAPI `securityDefinitions`/`securitySchemes` for the sample lacked descriptive auth text. - **Sample update (source)** - Updated `packages/samples/specs/data-plane/widget-manager/main.tsp`. - Replaced inline auth types with named auth models and attached doc comments (`/** ... */`) to each. - Updated `@useAuth(...)` to reference those named models so auth docs propagate into emitted OpenAPI. - **Snapshot/output update** - Regenerated widget-manager sample outputs: - `@azure-tools/typespec-autorest/.../openapi.json` - `@typespec/openapi3/openapi.2022-08-31.yaml` - Both now include auth scheme `description` fields for API key and OAuth2 entries. - **Example** ```tsp /** Authenticate requests with an API key in the X-Key header. */ model WidgetManagerApiKeyAuth is ApiKeyAuth<ApiKeyLocation.header, "X-Key">; /** Authenticate requests with OAuth2 using the widget service scope. */ model WidgetManagerOauth2Auth is OAuth2Auth<[ { type: OAuth2FlowType.implicit, authorizationUrl: "https://login.contoso.com/common/oauth2/v2.0/authorize", scopes: ["https://widget.contoso.com/.default"], } ]>; @useAuth(WidgetManagerApiKeyAuth | WidgetManagerOauth2Auth) namespace Contoso.WidgetManager; ``` --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com> Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
1 parent 364b924 commit 5c8a2d8

3 files changed

Lines changed: 44 additions & 5 deletions

File tree

packages/samples/specs/data-plane/widget-manager/main.tsp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,22 @@ using Azure.Core.Traits;
1111

1212
@service(#{ title: "Contoso Widget Manager" })
1313
@versioned(Contoso.WidgetManager.Versions)
14-
@useAuth(ApiKeyAuth<ApiKeyLocation.header, "X-Key">)
14+
@useAuth(WidgetManagerApiKeyAuth | WidgetManagerOauth2Auth)
1515
namespace Contoso.WidgetManager;
1616

17+
/** Authenticate requests with an API key in the X-Key header. */
18+
model WidgetManagerApiKeyAuth is ApiKeyAuth<ApiKeyLocation.header, "X-Key">;
19+
20+
/** Authenticate requests with OAuth2 using the widget service scope. */
21+
model WidgetManagerOauth2Auth
22+
is OAuth2Auth<[
23+
{
24+
type: OAuth2FlowType.implicit;
25+
authorizationUrl: "https://login.contoso.com/common/oauth2/v2.0/authorize";
26+
scopes: ["https://widget.contoso.com/.default"];
27+
}
28+
]>;
29+
1730
@doc("The Contoso Widget Manager service version.")
1831
enum Versions {
1932
@doc("Version 2022-08-31")

packages/samples/test/output/azure/core/data-plane/widget-manager/@azure-tools/typespec-autorest/2022-08-31/openapi.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,29 @@
2020
],
2121
"security": [
2222
{
23-
"ApiKeyAuth": []
23+
"WidgetManagerApiKeyAuth": []
24+
},
25+
{
26+
"WidgetManagerOauth2Auth": [
27+
"https://widget.contoso.com/.default"
28+
]
2429
}
2530
],
2631
"securityDefinitions": {
27-
"ApiKeyAuth": {
32+
"WidgetManagerApiKeyAuth": {
2833
"type": "apiKey",
34+
"description": "Authenticate requests with an API key in the X-Key header.",
2935
"name": "X-Key",
3036
"in": "header"
37+
},
38+
"WidgetManagerOauth2Auth": {
39+
"type": "oauth2",
40+
"description": "Authenticate requests with OAuth2 using the widget service scope.",
41+
"flow": "implicit",
42+
"authorizationUrl": "https://login.contoso.com/common/oauth2/v2.0/authorize",
43+
"scopes": {
44+
"https://widget.contoso.com/.default": ""
45+
}
3146
}
3247
},
3348
"tags": [],

packages/samples/test/output/azure/core/data-plane/widget-manager/@typespec/openapi3/openapi.2022-08-31.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,9 @@ paths:
12711271
schema:
12721272
$ref: '#/components/schemas/WidgetRepairRequest'
12731273
security:
1274-
- ApiKeyAuth: []
1274+
- WidgetManagerApiKeyAuth: []
1275+
- WidgetManagerOauth2Auth:
1276+
- https://widget.contoso.com/.default
12751277
components:
12761278
parameters:
12771279
Azure.Core.ClientRequestIdHeader:
@@ -1684,7 +1686,16 @@ components:
16841686
- SentToManufacturer
16851687
description: The repair state of a widget.
16861688
securitySchemes:
1687-
ApiKeyAuth:
1689+
WidgetManagerApiKeyAuth:
16881690
type: apiKey
16891691
in: header
16901692
name: X-Key
1693+
description: Authenticate requests with an API key in the X-Key header.
1694+
WidgetManagerOauth2Auth:
1695+
type: oauth2
1696+
flows:
1697+
implicit:
1698+
authorizationUrl: https://login.contoso.com/common/oauth2/v2.0/authorize
1699+
scopes:
1700+
https://widget.contoso.com/.default: ''
1701+
description: Authenticate requests with OAuth2 using the widget service scope.

0 commit comments

Comments
 (0)