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

add auth and fix some generated code issue in .net #24725

Merged
merged 5 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions specification/contosowidgetmanager/Contoso.WidgetManager/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,34 @@ using TypeSpec.Rest;
using TypeSpec.Versioning;
using Azure.Core;

@useAuth(OAuth2Auth<[ContosoAuthFlow]>)
mikeharder marked this conversation as resolved.
Show resolved Hide resolved
@service({
title: "Contoso Widget Manager",
})
@versioned(Contoso.WidgetManager.Versions)

namespace Azure.Contoso.WidgetManager;

#suppress "@azure-tools/typespec-azure-core/documentation-required" "https://github.com/Azure/typespec-azure/issues/3107"
mikeharder marked this conversation as resolved.
Show resolved Hide resolved
@doc("Versions info.")
enum Versions {
@doc("The 2022-11-01-preview version.")
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
v2022_11_01_Preview: "2022-11-01-preview",
}

@doc("A faked auth model.")
model ContosoAuthFlow {
@doc("The auth flow type.")
type: OAuth2FlowType.implicit;
@doc("The auth flow authorization URL.")
authorizationUrl: "https://login.microsoftonline.com/common/oauth2/authorize";
@doc("The auth flow token URL.")
scopes: ["https://security.microsoft.com/.default"];
}

@doc("A widget.")
@resource("widgets")
model Widget {
model WidgetSuite {
@key("widgetName")
@doc("The widget name.")
@visibility("read")
Expand All @@ -38,22 +51,22 @@ model Widget {

interface Widgets {
@doc("Fetch a Widget by name.")
getWidget is ResourceRead<Widget>;
getWidget is ResourceRead<WidgetSuite>;

@doc("Gets status of a Widget operation.")
getWidgetOperationStatus is GetResourceOperationStatus<Widget>;
getWidgetOperationStatus is GetResourceOperationStatus<WidgetSuite>;

@doc("Creates or updates a Widget asynchronously.")
@pollingOperation(Widgets.getWidgetOperationStatus)
createOrUpdateWidget is LongRunningResourceCreateOrUpdate<Widget>;
createOrUpdateWidget is LongRunningResourceCreateOrUpdate<WidgetSuite>;

@doc("Delete a Widget asynchronously.")
@pollingOperation(Widgets.getWidgetOperationStatus)
deleteWidget is LongRunningResourceDelete<Widget>;
deleteWidget is LongRunningResourceDelete<WidgetSuite>;

@doc("List Widget resources")
listWidgets is ResourceList<
Widget,
WidgetSuite,
{
parameters: StandardListQueryParameters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ options:
package-mode: "dataplane"
package-name: "{package-dir}"
"@azure-tools/typespec-csharp":
package-dir: "Azure.Contoso.WidgetManager"
package-dir: "Azure.Template.Contoso"
clear-output-folder: true
model-namespace: false
namespace: "{package-dir}"
Expand All @@ -28,4 +28,4 @@ options:
name: "@azure-rest/contoso-widgetmanager-rest"
"@azure-tools/typespec-java":
package-dir: "azure-contoso-widgetmanager"
namespace: com.azure.contoso.widgetmanager
namespace: com.azure.contoso.widgetmanager
Copy link
Member

Choose a reason for hiding this comment

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

@raych1: Please do not remove trailing newlines when editing files.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@
"consumes": [
"application/json"
],
"security": [
{
"OAuth2Auth": [
"https://security.microsoft.com/.default"
]
}
],
"securityDefinitions": {
"OAuth2Auth": {
"type": "oauth2",
"flow": "implicit",
"authorizationUrl": "https://login.microsoftonline.com/common/oauth2/authorize",
"scopes": {
"https://security.microsoft.com/.default": ""
}
}
},
"tags": [],
"paths": {
"/widgets": {
Expand All @@ -38,11 +55,11 @@
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/Widget"
"$ref": "#/definitions/WidgetSuite"
},
"x-ms-identifiers": [],
"description": "The Widget items on this page",
"x-typespec-name": "Widget[]"
"description": "The WidgetSuite items on this page",
"x-typespec-name": "WidgetSuite[]"
},
"nextLink": {
"type": "string",
Expand All @@ -51,11 +68,11 @@
"x-typespec-name": "TypeSpec.Rest.ResourceLocation"
}
},
"description": "Paged collection of Widget items",
"description": "Paged collection of WidgetSuite items",
"required": [
"value"
],
"x-typespec-name": "Azure.Core.Foundations.CustomPage<Widget, Azure.Core.(anonymous model)>"
"x-typespec-name": "Azure.Core.Foundations.CustomPage<WidgetSuite, Azure.Core.(anonymous model)>"
}
},
"default": {
Expand Down Expand Up @@ -101,7 +118,7 @@
"200": {
"description": "The request has succeeded.",
"schema": {
"$ref": "#/definitions/Widget"
"$ref": "#/definitions/WidgetSuite"
}
},
"default": {
Expand Down Expand Up @@ -143,7 +160,7 @@
"required": true,
"description": "The resource instance.",
"schema": {
"$ref": "#/definitions/WidgetUpdate"
"$ref": "#/definitions/WidgetSuiteUpdate"
}
}
],
Expand All @@ -158,7 +175,7 @@
}
},
"schema": {
"$ref": "#/definitions/Widget"
"$ref": "#/definitions/WidgetSuite"
}
},
"201": {
Expand All @@ -171,7 +188,7 @@
}
},
"schema": {
"$ref": "#/definitions/Widget"
"$ref": "#/definitions/WidgetSuite"
}
},
"default": {
Expand Down Expand Up @@ -307,7 +324,7 @@
"description": "Error object that describes the error when status is \"Failed\"."
},
"result": {
"$ref": "#/definitions/Widget",
"$ref": "#/definitions/WidgetSuite",
"description": "The result of the operation."
}
},
Expand All @@ -316,7 +333,7 @@
"id",
"status"
],
"x-typespec-name": "Azure.Core.ResourceOperationStatus<Widget, Widget, Azure.Core.Foundations.Error>"
"x-typespec-name": "Azure.Core.ResourceOperationStatus<WidgetSuite, WidgetSuite, Azure.Core.Foundations.Error>"
}
},
"default": {
Expand Down Expand Up @@ -439,6 +456,40 @@
]
}
},
"ContosoAuthFlow": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"implicit"
],
"description": "The auth flow type."
},
"authorizationUrl": {
"type": "string",
"enum": [
"https://login.microsoftonline.com/common/oauth2/authorize"
],
"x-ms-enum": {
"modelAsString": false
},
"description": "The auth flow authorization URL."
},
"scopes": {
"type": "array",
"items": {},
"x-typespec-name": "[https://security.microsoft.com/.default]",
"description": "The auth flow token URL."
}
},
"description": "A faked auth model.",
"required": [
"type",
"authorizationUrl",
"scopes"
]
},
"FakedSharedModel": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -475,6 +526,7 @@
},
"Versions": {
"type": "string",
"description": "Versions info.",
"enum": [
"2022-11-01-preview"
],
Expand All @@ -484,12 +536,13 @@
"values": [
{
"name": "v2022_11_01_Preview",
"value": "2022-11-01-preview"
"value": "2022-11-01-preview",
"description": "The 2022-11-01-preview version."
}
]
}
},
"Widget": {
"WidgetSuite": {
"type": "object",
"properties": {
"name": {
Expand All @@ -512,7 +565,7 @@
"manufacturerId"
]
},
"WidgetUpdate": {
"WidgetSuiteUpdate": {
"type": "object",
"properties": {
"manufacturerId": {
Expand Down