diff --git a/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager.Shared/main.cadl b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager.Shared/main.cadl new file mode 100644 index 000000000000..ce9d59382a69 --- /dev/null +++ b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager.Shared/main.cadl @@ -0,0 +1,8 @@ +@doc("Faked shared model") +model FakedSharedModel { + @doc("The tag.") + tag: string; + + @doc("The created date.") + createdDate: zonedDateTime; +} \ No newline at end of file diff --git a/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/cadl-project.yaml b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/cadl-project.yaml new file mode 100644 index 000000000000..b67f345cb4de --- /dev/null +++ b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/cadl-project.yaml @@ -0,0 +1,38 @@ +parameters: + "python-sdk-folder": + default: "{cwd}/azure-sdk-for-python/" + "java-sdk-folder": + default: "{cwd}/azure-sdk-for-java/" + "js-sdk-folder": + default: "{cwd}/azure-sdk-for-js/" + "csharp-sdk-folder": + default: "{cwd}/azure-sdk-for-csharp/" + "service-directory-name": + default: "contosowidgetmanager" +emit: + - "@azure-tools/cadl-autorest" +options: + "@azure-tools/cadl-autorest": + output-file: widgets.json + azure-resource-provider-folder: ../../../../data-plane + examples-directory: ./examples + "@azure-tools/cadl-python": + "package-name": "azure-contosowidgetmanager" + "emitter-output-dir": "{python-sdk-folder}/sdk/{service-directory-name}/{package-name}" + "package-mode": "dataplane" + "@azure-tools/cadl-csharp": + namespace: Azure.Contoso.Widgetmanager + clear-output-folder: true + model-namespace: false + "emitter-output-dir": "{csharp-sdk-folder}/sdk/{service-directory-name}/{namespace}/src" + "@azure-tools/cadl-typescript": + "emitter-output-dir": "{js-sdk-folder}/sdk/{service-directory-name}/contosowidgetmanager-rest" + generateMetadata: true + generateTest: true + azureSdkForJs: true + packageDetails: + name: "@azure-rest/contosowidgetmanager-rest" + description: "Contoso WidgetManager Service" + "@azure-tools/cadl-java": + "emitter-output-dir": "{java-sdk-folder}/sdk/{service-directory-name}/azure-contoso-widgetmanager" + namespace: com.azure.contoso.widgetmanager diff --git a/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/examples/2022-11-01-preview/Widgets_CreateOrUpdateWidgetSample.json b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/examples/2022-11-01-preview/Widgets_CreateOrUpdateWidgetSample.json new file mode 100644 index 000000000000..9adc3398bcad --- /dev/null +++ b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/examples/2022-11-01-preview/Widgets_CreateOrUpdateWidgetSample.json @@ -0,0 +1,37 @@ +{ + "title": "Widgets_CreateOrUpdateWidget", + "operationId": "Widgets_CreateOrUpdateWidget", + "parameters": { + "widgetName": "name1", + "api-version": "2022-11-01-preview", + "body": { + "manufacturerId": "manufacturer id1", + "sharedModel": { + "tag": "tag1", + "createdDate": "2023-01-09T02:12:25.689Z" + } + } + }, + "responses": { + "200": { + "body": { + "name": "name1", + "manufacturerId": "manufacturer id1", + "sharedModel": { + "tag": "tag1", + "createdDate": "2023-01-09T02:12:25.689Z" + } + } + }, + "201": { + "body": { + "name": "name1", + "manufacturerId": "manufacturer id1", + "sharedModel": { + "tag": "tag1", + "createdDate": "2023-01-09T02:12:25.689Z" + } + } + } + } +} diff --git a/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/examples/2022-11-01-preview/Widgets_DeleteWidgetSample.json b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/examples/2022-11-01-preview/Widgets_DeleteWidgetSample.json new file mode 100644 index 000000000000..8a6b117b5cde --- /dev/null +++ b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/examples/2022-11-01-preview/Widgets_DeleteWidgetSample.json @@ -0,0 +1,29 @@ +{ + "operationId": "Widgets_DeleteWidget", + "title": "Delete widget by widget name using long-running operation.", + "parameters": { + "api-version": "2022-11-01-preview", + "widgetName": "searchbox" + }, + "responses": { + "202": { + "headers": { + "location": "https://contosowidgetmanager.azure.com/operations/00000000-0000-0000-0000-000000000123/result?api-version=2022-11-01-preview", + "operation-location": "https://contosowidgetmanager.azure.com/operations/00000000-0000-0000-0000-000000000123?api-version=2022-11-01-preview" + }, + "body": { + "id": "id1", + "status": "deleted" + } + }, + "default": { + "body": { + "error": { + "code": "Error code", + "message": "Error message", + "details": [] + } + } + } + } +} diff --git a/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/examples/2022-11-01-preview/Widgets_GetWidgetOperationStatusSample.json b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/examples/2022-11-01-preview/Widgets_GetWidgetOperationStatusSample.json new file mode 100644 index 000000000000..c88b6155b003 --- /dev/null +++ b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/examples/2022-11-01-preview/Widgets_GetWidgetOperationStatusSample.json @@ -0,0 +1,45 @@ +{ + "title": "Widgets_GetWidgetOperationStatus", + "operationId": "Widgets_GetWidgetOperationStatus", + "parameters": { + "widgetName": "name1", + "operationId": "opreation id1", + "api-version": "2022-11-01-preview" + }, + "responses": { + "200": { + "body": { + "id": "opreation id1", + "status": "InProgress", + "error": { + "code": "Error code", + "message": "Error message", + "target": "op1", + "details": [ + { + "code": "code1", + "message": "message1", + "target": "op1", + "details": [], + "innererror": { + "code": "code1" + } + } + ], + "innererror": { + "code": "code1" + } + }, + "result": { + "name": "bingsearch", + "manufacturerId": "manufacturer Id1", + "sharedModel": { + "tag": "tag1", + "createdDate": "2023-01-09T02:12:25.689Z" + } + }, + "widgetName": "rfazvwnfwwomiwrh" + } + } + } +} diff --git a/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/examples/2022-11-01-preview/Widgets_GetWidgetSample.json b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/examples/2022-11-01-preview/Widgets_GetWidgetSample.json new file mode 100644 index 000000000000..9c07ed974352 --- /dev/null +++ b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/examples/2022-11-01-preview/Widgets_GetWidgetSample.json @@ -0,0 +1,25 @@ +{ + "operationId": "Widgets_GetWidget", + "title": "Get widget by widget name.", + "parameters": { + "api-version": "2022-11-01-preview", + "widgetName": "searchbox" + }, + "responses": { + "200": { + "body": { + "name": "bingsearch", + "manufacturerId": "a-22-01" + } + }, + "default": { + "body": { + "error": { + "code": "Error code", + "message": "Error message", + "details": [] + } + } + } + } +} diff --git a/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/examples/2022-11-01-preview/Widgets_ListWidgetsSample.json b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/examples/2022-11-01-preview/Widgets_ListWidgetsSample.json new file mode 100644 index 000000000000..e60878b8300a --- /dev/null +++ b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/examples/2022-11-01-preview/Widgets_ListWidgetsSample.json @@ -0,0 +1,30 @@ +{ + "title": "Widgets_ListWidgets", + "operationId": "Widgets_ListWidgets", + "parameters": { + "top": 8, + "skip": 15, + "maxpagesize": 27, + "select": [ + "type1" + ], + "api-version": "2022-11-01-preview" + }, + "responses": { + "200": { + "body": { + "value": [ + { + "name": "bingsearch", + "manufacturerId": "manufacturer Id1", + "sharedModel": { + "tag": "tag1", + "createdDate": "2023-01-09T02:12:25.689Z" + } + } + ], + "nextLink": "https://microsoft.com/a" + } + } + } +} diff --git a/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/main.cadl b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/main.cadl new file mode 100644 index 000000000000..d7521d635d85 --- /dev/null +++ b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/main.cadl @@ -0,0 +1,59 @@ +import "@cadl-lang/rest"; +import "@cadl-lang/versioning"; +import "@azure-tools/cadl-azure-core"; +import "../Contoso.WidgetManager.Shared"; + +using Cadl.Http; +using Cadl.Rest; +using Cadl.Versioning; +using Azure.Core; + +@service({ + title: "Contoso Widget Manager", + }) +@versioned(Contoso.WidgetManager.Versions) +@versionedDependency([[Contoso.WidgetManager.Versions.v2022_11_01_Preview, Azure.Core.Versions.v1_0_Preview_1]]) +namespace Azure.Contoso.WidgetManager; + +enum Versions { + v2022_11_01_Preview: "2022-11-01-preview", +} + +@doc("A widget.") +@resource("widgets") +model Widget { + @key("widgetName") + @doc("The widget name.") + @visibility("read") + name: string; + + @doc("The ID of the widget's manufacturer.") + manufacturerId: string; + + @doc("The faked shared model.") + sharedModel?: FakedSharedModel; +} + +interface Widgets { + @doc("Fetch a Widget by name.") + getWidget is ResourceRead; + + @doc("Gets status of a Widget operation.") + getWidgetOperationStatus is GetResourceOperationStatus; + + @doc("Creates or updates a Widget asynchronously.") + @pollingOperation(Widgets.getWidgetOperationStatus) + createOrUpdateWidget is LongRunningResourceCreateOrUpdate; + + @doc("Delete a Widget asynchronously.") + @pollingOperation(Widgets.getWidgetOperationStatus) + deleteWidget is LongRunningResourceDelete; + + @doc("List Widget resources") + listWidgets is ResourceList< + Widget, + { + parameters: StandardListQueryParameters & SelectQueryParameter; + } + >; +} \ No newline at end of file diff --git a/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/package.json b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/package.json new file mode 100644 index 000000000000..4d8fd4a967a1 --- /dev/null +++ b/documentation/cadl-sample-project/specification/contosowidgetmanager/Contoso.WidgetManager/package.json @@ -0,0 +1,7 @@ +{ + "name": "contoso-widget-manager", + "dependencies": { + "@azure-tools/cadl-autorest": "latest" + }, + "private": true +} diff --git a/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/examples/Widgets_CreateOrUpdateWidgetSample.json b/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/examples/Widgets_CreateOrUpdateWidgetSample.json new file mode 100644 index 000000000000..9adc3398bcad --- /dev/null +++ b/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/examples/Widgets_CreateOrUpdateWidgetSample.json @@ -0,0 +1,37 @@ +{ + "title": "Widgets_CreateOrUpdateWidget", + "operationId": "Widgets_CreateOrUpdateWidget", + "parameters": { + "widgetName": "name1", + "api-version": "2022-11-01-preview", + "body": { + "manufacturerId": "manufacturer id1", + "sharedModel": { + "tag": "tag1", + "createdDate": "2023-01-09T02:12:25.689Z" + } + } + }, + "responses": { + "200": { + "body": { + "name": "name1", + "manufacturerId": "manufacturer id1", + "sharedModel": { + "tag": "tag1", + "createdDate": "2023-01-09T02:12:25.689Z" + } + } + }, + "201": { + "body": { + "name": "name1", + "manufacturerId": "manufacturer id1", + "sharedModel": { + "tag": "tag1", + "createdDate": "2023-01-09T02:12:25.689Z" + } + } + } + } +} diff --git a/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/examples/Widgets_DeleteWidgetSample.json b/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/examples/Widgets_DeleteWidgetSample.json new file mode 100644 index 000000000000..8a6b117b5cde --- /dev/null +++ b/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/examples/Widgets_DeleteWidgetSample.json @@ -0,0 +1,29 @@ +{ + "operationId": "Widgets_DeleteWidget", + "title": "Delete widget by widget name using long-running operation.", + "parameters": { + "api-version": "2022-11-01-preview", + "widgetName": "searchbox" + }, + "responses": { + "202": { + "headers": { + "location": "https://contosowidgetmanager.azure.com/operations/00000000-0000-0000-0000-000000000123/result?api-version=2022-11-01-preview", + "operation-location": "https://contosowidgetmanager.azure.com/operations/00000000-0000-0000-0000-000000000123?api-version=2022-11-01-preview" + }, + "body": { + "id": "id1", + "status": "deleted" + } + }, + "default": { + "body": { + "error": { + "code": "Error code", + "message": "Error message", + "details": [] + } + } + } + } +} diff --git a/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/examples/Widgets_GetWidgetOperationStatusSample.json b/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/examples/Widgets_GetWidgetOperationStatusSample.json new file mode 100644 index 000000000000..c88b6155b003 --- /dev/null +++ b/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/examples/Widgets_GetWidgetOperationStatusSample.json @@ -0,0 +1,45 @@ +{ + "title": "Widgets_GetWidgetOperationStatus", + "operationId": "Widgets_GetWidgetOperationStatus", + "parameters": { + "widgetName": "name1", + "operationId": "opreation id1", + "api-version": "2022-11-01-preview" + }, + "responses": { + "200": { + "body": { + "id": "opreation id1", + "status": "InProgress", + "error": { + "code": "Error code", + "message": "Error message", + "target": "op1", + "details": [ + { + "code": "code1", + "message": "message1", + "target": "op1", + "details": [], + "innererror": { + "code": "code1" + } + } + ], + "innererror": { + "code": "code1" + } + }, + "result": { + "name": "bingsearch", + "manufacturerId": "manufacturer Id1", + "sharedModel": { + "tag": "tag1", + "createdDate": "2023-01-09T02:12:25.689Z" + } + }, + "widgetName": "rfazvwnfwwomiwrh" + } + } + } +} diff --git a/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/examples/Widgets_GetWidgetSample.json b/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/examples/Widgets_GetWidgetSample.json new file mode 100644 index 000000000000..9c07ed974352 --- /dev/null +++ b/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/examples/Widgets_GetWidgetSample.json @@ -0,0 +1,25 @@ +{ + "operationId": "Widgets_GetWidget", + "title": "Get widget by widget name.", + "parameters": { + "api-version": "2022-11-01-preview", + "widgetName": "searchbox" + }, + "responses": { + "200": { + "body": { + "name": "bingsearch", + "manufacturerId": "a-22-01" + } + }, + "default": { + "body": { + "error": { + "code": "Error code", + "message": "Error message", + "details": [] + } + } + } + } +} diff --git a/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/examples/Widgets_ListWidgetsSample.json b/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/examples/Widgets_ListWidgetsSample.json new file mode 100644 index 000000000000..e60878b8300a --- /dev/null +++ b/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/examples/Widgets_ListWidgetsSample.json @@ -0,0 +1,30 @@ +{ + "title": "Widgets_ListWidgets", + "operationId": "Widgets_ListWidgets", + "parameters": { + "top": 8, + "skip": 15, + "maxpagesize": 27, + "select": [ + "type1" + ], + "api-version": "2022-11-01-preview" + }, + "responses": { + "200": { + "body": { + "value": [ + { + "name": "bingsearch", + "manufacturerId": "manufacturer Id1", + "sharedModel": { + "tag": "tag1", + "createdDate": "2023-01-09T02:12:25.689Z" + } + } + ], + "nextLink": "https://microsoft.com/a" + } + } + } +} diff --git a/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/widgets.json b/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/widgets.json new file mode 100644 index 000000000000..3f79510f911e --- /dev/null +++ b/documentation/cadl-sample-project/specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/preview/2022-11-01-preview/widgets.json @@ -0,0 +1,568 @@ +{ + "swagger": "2.0", + "info": { + "title": "Contoso Widget Manager", + "version": "2022-11-01-preview", + "x-cadl-generated": [ + { + "emitter": "@azure-tools/cadl-autorest" + } + ] + }, + "schemes": [ + "https" + ], + "produces": [ + "application/json" + ], + "consumes": [ + "application/json" + ], + "tags": [], + "paths": { + "/widgets": { + "get": { + "operationId": "Widgets_ListWidgets", + "description": "List Widget resources", + "parameters": [ + { + "$ref": "#/parameters/Azure.Core.TopQueryParameter" + }, + { + "$ref": "#/parameters/Azure.Core.SkipQueryParameter" + }, + { + "$ref": "#/parameters/Azure.Core.MaxPageSizeQueryParameter" + }, + { + "$ref": "#/parameters/Azure.Core.SelectQueryParameter" + }, + { + "$ref": "#/parameters/Azure.Core.Foundations.ApiVersionParameter" + } + ], + "responses": { + "200": { + "description": "The request has succeeded.", + "schema": { + "type": "object", + "properties": { + "value": { + "type": "array", + "items": { + "$ref": "#/definitions/Widget" + }, + "x-ms-identifiers": [], + "x-cadl-name": "Widget[]", + "description": "The Widget items on this page" + }, + "nextLink": { + "type": "string", + "format": "uri", + "description": "The link to the next page of items", + "x-cadl-name": "Rest.ResourceLocation" + } + }, + "description": "Paged collection of Widget items", + "required": [ + "value" + ], + "x-cadl-name": "Azure.Core.Foundations.CustomPage" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/Azure.Core.Foundations.ErrorResponse" + } + } + }, + "x-ms-pageable": { + "nextLinkName": "nextLink" + }, + "x-ms-examples": { + "Widgets_ListWidgets": { + "$ref": "./examples/Widgets_ListWidgetsSample.json" + } + } + } + }, + "/widgets/{widgetName}": { + "get": { + "operationId": "Widgets_GetWidget", + "description": "Fetch a Widget by name.", + "parameters": [ + { + "name": "widgetName", + "in": "path", + "required": true, + "description": "The widget name.", + "type": "string" + }, + { + "$ref": "#/parameters/Azure.Core.Foundations.ApiVersionParameter" + } + ], + "responses": { + "200": { + "description": "The request has succeeded.", + "schema": { + "$ref": "#/definitions/Widget" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/Azure.Core.Foundations.ErrorResponse" + } + } + }, + "x-ms-examples": { + "Get widget by widget name.": { + "$ref": "./examples/Widgets_GetWidgetSample.json" + } + } + }, + "patch": { + "operationId": "Widgets_CreateOrUpdateWidget", + "description": "Creates or updates a Widget asynchronously.", + "parameters": [ + { + "name": "widgetName", + "in": "path", + "required": true, + "description": "The widget name.", + "type": "string" + }, + { + "$ref": "#/parameters/Azure.Core.Foundations.ApiVersionParameter" + }, + { + "name": "body", + "in": "body", + "schema": { + "type": "object", + "properties": { + "manufacturerId": { + "type": "string", + "description": "The ID of the widget's manufacturer." + }, + "sharedModel": { + "$ref": "#/definitions/FakedSharedModel", + "description": "The faked shared model." + } + }, + "description": "The template for adding optional properties.", + "x-cadl-name": "Azure.Core.Foundations.ResourceCreateOrUpdateModel" + } + } + ], + "responses": { + "200": { + "description": "The request has succeeded.", + "headers": { + "Operation-Location": { + "description": "The location of an instance of OperationStatus", + "type": "string", + "format": "uri" + } + }, + "schema": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The widget name.", + "readOnly": true + }, + "manufacturerId": { + "type": "string", + "description": "The ID of the widget's manufacturer." + }, + "sharedModel": { + "$ref": "#/definitions/FakedSharedModel", + "description": "The faked shared model." + } + }, + "required": [ + "name", + "manufacturerId" + ], + "x-cadl-name": "Azure.Core.Foundations.ResourceOkResponse" + } + }, + "201": { + "description": "The request has succeeded and a new resource has been created as a result.", + "headers": { + "Operation-Location": { + "description": "The location of an instance of OperationStatus", + "type": "string", + "format": "uri" + } + }, + "schema": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The widget name.", + "readOnly": true + }, + "manufacturerId": { + "type": "string", + "description": "The ID of the widget's manufacturer." + }, + "sharedModel": { + "$ref": "#/definitions/FakedSharedModel", + "description": "The faked shared model." + } + }, + "description": "A resource was successfully created.", + "required": [ + "name", + "manufacturerId" + ], + "x-cadl-name": "Azure.Core.Foundations.ResourceCreatedResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/Azure.Core.Foundations.ErrorResponse" + } + } + }, + "consumes": [ + "application/merge-patch+json" + ], + "x-ms-examples": { + "Widgets_CreateOrUpdateWidget": { + "$ref": "./examples/Widgets_CreateOrUpdateWidgetSample.json" + } + } + }, + "delete": { + "operationId": "Widgets_DeleteWidget", + "description": "Delete a Widget asynchronously.", + "parameters": [ + { + "name": "widgetName", + "in": "path", + "required": true, + "description": "The widget name.", + "type": "string" + }, + { + "$ref": "#/parameters/Azure.Core.Foundations.ApiVersionParameter" + } + ], + "responses": { + "202": { + "description": "The request has been accepted for processing, but processing has not yet completed.", + "headers": { + "Operation-Location": { + "description": "The location of an instance of OperationStatus", + "type": "string", + "format": "uri" + } + }, + "schema": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "The unique ID of the operation." + }, + "status": { + "$ref": "#/definitions/Azure.Core.Foundations.OperationState", + "description": "The status of the operation" + }, + "error": { + "$ref": "#/definitions/Azure.Core.Foundations.Error", + "description": "Error object that describes the error when status is \"Failed\"." + } + }, + "required": [ + "id", + "status" + ], + "x-cadl-name": "Azure.Core.Foundations.AcceptedResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/Azure.Core.Foundations.ErrorResponse" + } + } + }, + "x-ms-examples": { + "Delete widget by widget name using long-running operation.": { + "$ref": "./examples/Widgets_DeleteWidgetSample.json" + } + } + } + }, + "/widgets/{widgetName}/operations/{operationId}": { + "get": { + "operationId": "Widgets_GetWidgetOperationStatus", + "description": "Gets status of a Widget operation.", + "parameters": [ + { + "name": "widgetName", + "in": "path", + "required": true, + "description": "The widget name.", + "type": "string" + }, + { + "name": "operationId", + "in": "path", + "required": true, + "description": "The unique ID of the operation.", + "type": "string" + }, + { + "$ref": "#/parameters/Azure.Core.Foundations.ApiVersionParameter" + } + ], + "responses": { + "200": { + "description": "The request has succeeded.", + "schema": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "The unique ID of the operation." + }, + "status": { + "$ref": "#/definitions/Azure.Core.Foundations.OperationState", + "description": "The status of the operation" + }, + "error": { + "$ref": "#/definitions/Azure.Core.Foundations.Error", + "description": "Error object that describes the error when status is \"Failed\"." + }, + "result": { + "$ref": "#/definitions/Widget", + "description": "The result of the operation." + }, + "widgetName": { + "type": "string", + "description": "The widget name." + } + }, + "required": [ + "id", + "status", + "widgetName" + ], + "x-cadl-name": "(anonymous model)" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/Azure.Core.Foundations.ErrorResponse" + } + } + }, + "x-ms-examples": { + "Widgets_GetWidgetOperationStatus": { + "$ref": "./examples/Widgets_GetWidgetOperationStatusSample.json" + } + } + } + } + }, + "definitions": { + "Azure.Core.Foundations.Error": { + "type": "object", + "properties": { + "code": { + "type": "string", + "description": "One of a server-defined set of error codes." + }, + "message": { + "type": "string", + "description": "A human-readable representation of the error." + }, + "target": { + "type": "string", + "description": "The target of the error." + }, + "details": { + "type": "array", + "items": { + "$ref": "#/definitions/Azure.Core.Foundations.Error" + }, + "x-ms-identifiers": [], + "x-cadl-name": "Azure.Core.Foundations.Error[]", + "description": "An array of details about specific errors that led to this reported error." + }, + "innererror": { + "$ref": "#/definitions/Azure.Core.Foundations.InnerError", + "description": "An object containing more specific information than the current object about the error." + } + }, + "description": "The error object.", + "required": [ + "code", + "message", + "details" + ] + }, + "Azure.Core.Foundations.ErrorResponse": { + "type": "object", + "properties": { + "error": { + "$ref": "#/definitions/Azure.Core.Foundations.Error", + "description": "The error object." + } + }, + "description": "A response containing error details.", + "required": [ + "error" + ] + }, + "Azure.Core.Foundations.InnerError": { + "type": "object", + "properties": { + "code": { + "type": "string", + "description": "One of a server-defined set of error codes." + }, + "innererror": { + "$ref": "#/definitions/Azure.Core.Foundations.InnerError", + "description": "Inner error." + } + }, + "description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.", + "required": [ + "code" + ] + }, + "Azure.Core.Foundations.OperationState": { + "type": "string", + "enum": [ + "InProgress", + "Succeeded", + "Failed", + "Canceled" + ], + "x-ms-enum": { + "name": "OperationState", + "modelAsString": true + } + }, + "FakedSharedModel": { + "type": "object", + "properties": { + "tag": { + "type": "string", + "description": "The tag." + }, + "createdDate": { + "type": "string", + "format": "date-time", + "description": "The created date." + } + }, + "description": "Faked shared model", + "required": [ + "tag", + "createdDate" + ] + }, + "Versions": { + "type": "string", + "enum": [ + "2022-11-01-preview" + ], + "x-ms-enum": { + "name": "Versions", + "modelAsString": true, + "values": [ + { + "name": "v2022_11_01_Preview", + "value": "2022-11-01-preview" + } + ] + } + }, + "Widget": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "The widget name.", + "readOnly": true + }, + "manufacturerId": { + "type": "string", + "description": "The ID of the widget's manufacturer." + }, + "sharedModel": { + "$ref": "#/definitions/FakedSharedModel", + "description": "The faked shared model." + } + }, + "description": "A widget.", + "required": [ + "name", + "manufacturerId" + ] + } + }, + "parameters": { + "Azure.Core.Foundations.ApiVersionParameter": { + "name": "api-version", + "in": "query", + "required": true, + "description": "The API version to use for this operation.", + "x-ms-client-name": "apiVersion", + "minLength": 1, + "type": "string", + "x-ms-parameter-location": "method" + }, + "Azure.Core.MaxPageSizeQueryParameter": { + "name": "maxpagesize", + "in": "query", + "required": false, + "description": "The maximum number of result items per page.", + "type": "integer", + "format": "int32", + "x-ms-parameter-location": "method" + }, + "Azure.Core.SelectQueryParameter": { + "name": "select", + "in": "query", + "required": false, + "description": "Select the specified fields to be included in the response.", + "type": "array", + "items": { + "type": "string" + }, + "x-ms-parameter-location": "method" + }, + "Azure.Core.SkipQueryParameter": { + "name": "skip", + "in": "query", + "required": false, + "description": "The number of result items to skip.", + "type": "integer", + "format": "int32", + "x-ms-parameter-location": "method" + }, + "Azure.Core.TopQueryParameter": { + "name": "top", + "in": "query", + "required": false, + "description": "The number of result items to return.", + "type": "integer", + "format": "int32", + "x-ms-parameter-location": "method" + } + } +} diff --git a/documentation/cadl-structure-guidelines.md b/documentation/cadl-structure-guidelines.md index e768ecdaa99b..f93c0ba343c9 100644 --- a/documentation/cadl-structure-guidelines.md +++ b/documentation/cadl-structure-guidelines.md @@ -1,17 +1,34 @@ -# Repository Guidelines for Cadl Specs - -## Purpose + +* 1. [Purpose](#Purpose) +* 2. [Repository](#Repository) +* 3. [Structure Overview](#StructureOverview) +* 4. [Service Folders](#ServiceFolders) + * 4.1. [Packages](#Packages) + * 4.2. [Structure](#Structure) +* 5. [Service Family Libraries](#ServiceFamilyLibraries) + * 5.1. [Service Folder](#ServiceFolder) + * 5.2. [Working in Feature Branches](#WorkinginFeatureBranches) + * 5.3. [Publishing Specs](#PublishingSpecs) +* 6. [Sample Project](#SampleProject) + + +# Repository Guidelines for Cadl Specs + +## 1. Purpose We need to formulate a strategy for checking in actual Cadl service specs for Azure. Service teams need to know where and how to check these in and tooling needs to know how to find and consume them. While OpenAPI specs traditionally have been just spec documents, Cadl "specs" could include service-specific functions, decorators and so forth that elevate them to the level of a library, and to maximize the benefits of Cadl, this approach needs to be supported as a first-class citizen. -## Repository +## 2. Repository Cadl can co-exist with Swagger within the existing `azure-rest-api-specs` repository. This approach will make it easier to generate Swagger artifacts without needing to sync between repos at the downside of having to live with any baggage associated with the repo as it ages. There are currently over 1,000 issues and 500 open PRs in this repo. -## Structure Overview +## 3. Structure Overview This proposal strives to align with [Azure SDK Repo Structure Guidelines](https://azure.github.io/azure-sdk/policies_repostructure.html). @@ -52,7 +69,7 @@ Examples below: -> resource-manager (swagger) ``` -## Service Folders +## 4. Service Folders The service folder contains the entire Cadl library specification for a service, which could include custom linter rules, methods, etc. @@ -61,13 +78,13 @@ The folder name should correspond to the RP-name, but dropping the leading "Azur - `Management` at the end of the service RP-name indicates a management (resource manager) libarary. - `Shared` at the end of the name indicates a shared library. If a management library has a shared component (unlikely), `Shared` should follow `Management`. -### Packages +### 4.1. Packages All services and service family libraries are modeled as Cadl packages, since you must install supporting librarie for proper tooling support. Per this proposal, all packages defined in the repo would be **unpublished**. Only packages in `cadl-azure` would be published. We will annotate the packages with `"private": true` in the `package.json` file to prevent publishing these to npm. All packages defined in this repo would use the `@cadl-api-spec` scope and use a lowercased, dashed form of the service namespace (ex: `@cadl-api-spec/azure-storage-blob`). -### Structure +### 4.2. Structure Each package should have the following minimum structure: @@ -87,7 +104,7 @@ To distinguish between folders which define a service, an SDK, or both, one can - SDKs _may_ have a sidecar file to customize how the SDK is shaped. Folders that describe service definitions only will not have a sidecar file. _Note: the absence of a sidecar does not mean that a folder does not describe an SDK, but the presence of one means it is an SDK._ - Services will take a dependency on `@azure-tools/autorest` and configure the emitter in `cadl-project.yaml`. -## Service Family Libraries +## 5. Service Family Libraries The service family library concept allows a family of services to share common models, linter rules, templates, etc. @@ -130,18 +147,22 @@ Here's an example of how Cognitive Services might use multiple shared libraries: Cadl has a versioning library which allows a single spec to represent multiple versions through projections. Service teams have GA service versions as well as public and private Preview service versions. The versioning library is currently optimized for the kinds of changes allowed between GA service releases: long-lived, stable, backward compatible changes. Preview versions are shorter-lived and often have wildly breaking changes from one version to the next, for which the versioning library is not optimized. -### Service Folder +### 5.1. Service Folder The service folder contains the Cadl files for the service package. Services transitioning to Cadl may simply begin by modeling their versioned Cadl from their latest stable Swagger. Existing services DO NOT need to model past service versions unless a business rationale exists. Future versions should be added to the spec using the necessary versioning decorators. The inital version in the spec need not feature version annotations since it is considered the baseline (i.e. it makes no implications about prior versions since it does not know about them). -### Working in Feature Branches +### 5.2. Working in Feature Branches Feature branches enable diffing the proposed change directly against the main branch. Feature branches should be used for either GA or preview API version development. On the feature branch, the service team should directly modify the cadl within the service folder as this works well with GitHub's diffing strategy. -### Publishing Specs +### 5.3. Publishing Specs The purest approach to publish a spec is to merge the PR that modifies the Cadl spec in the service folder. This is the simplest experience for projecting the Cadl and generating artifacts, including server-side codegen. In the event that a major break makes it infeasible to continue using a spec with version annotations, the spec could be reset to some base version (likely the breaking one) and continue versioning from there. The commit hash or tag that represented the spec prior to the reset would need to be tracked in order to regenerate older versions of the spec. At this point, if an update was needed to an older version of the spec no longer represented on the latest commit on `main`, we would need a servicing branch and update the hash pointers to the commit on that servicing branch. -This option is only suitable for _public_ previews. Private previews should live solely in a branch (in either the public or private repo) until/unless they become a public preview. \ No newline at end of file +This option is only suitable for _public_ previews. Private previews should live solely in a branch (in either the public or private repo) until/unless they become a public preview. + +## 6. Sample Project + +Here's a [cadl-sample-project](./cadl-sample-project) to demonstrate the files and folders supposed to be included when check in to this `azure-rest-api-specs` repository. \ No newline at end of file