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

Cadl Crud operations API description using Rest/Resources library #393

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,4 @@ __files/

dist/
coverage/
cadl/.vscode/settings.json
95 changes: 95 additions & 0 deletions cadl/http/op-crud/cadl-output/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"swagger": "2.0",
"info": {
"title": "Crud Operations Service",
"version": "2022-06-20",
"x-cadl-generated": [
{
"emitter": "@azure-tools/cadl-autorest"
}
]
},
"schemes": [
"https"
],
"x-ms-parameterized-host": {
"hostTemplate": "{Endpoint}",
"useSchemePrefix": false,
"parameters": [
{
"name": "Endpoint",
"in": "path",
"required": true,
"type": "string"
}
]
},
"produces": [
"application/json"
],
"consumes": [
"application/json"
],
"tags": [],
"paths": {
"/products/{id}": {
"get": {
"operationId": "Products_get",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "The request has succeeded.",
"schema": {
"$ref": "#/definitions/Product"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
}
},
"definitions": {
"Error": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
},
"required": [
"code",
"message"
]
},
"Product": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int32"
}
},
"required": [
"id"
]
}
},
"parameters": {}
}
2 changes: 2 additions & 0 deletions cadl/http/op-crud/cadl-project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
emitters:
'@azure-tools/cadl-autorest': true
25 changes: 25 additions & 0 deletions cadl/http/op-crud/op-crud.cadl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import "@cadl-lang/rest";
import "@azure-tools/cadl-azure-core";
import "@azure-tools/cadl-autorest";

@serviceTitle("Crud Operations Service")
@serviceVersion("2022-06-20")
@server("{Endpoint}", "Crud Service", {Endpoint: string}) // Use `Uri` when available: https://github.com/microsoft/cadl/issues/654
namespace CrudOps;

using Cadl.Http;

model Product {
id: int32;
}

@error
model Error {
code: int32;
message: string;
}

@route("/products")
namespace Products {
op get(@path id: int32): OkResponse<Product> | Error;
}
11 changes: 11 additions & 0 deletions cadl/http/op-crud/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "op-crud",
"dependencies": {
"@cadl-lang/compiler": "latest",
"@cadl-lang/rest": "latest",
"@cadl-lang/openapi3": "latest",
"@azure-tools/cadl-azure-core": "latest",
"@azure-tools/cadl-autorest": "latest"
},
"private": true
}
213 changes: 213 additions & 0 deletions cadl/http/webpubsub/cadl-output/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
{
"swagger": "2.0",
"info": {
"title": "WebPubSub Service",
"version": "2021-10-01",
"x-cadl-generated": [
{
"emitter": "@azure-tools/cadl-autorest"
}
]
},
"schemes": [
"https"
],
"x-ms-parameterized-host": {
"hostTemplate": "{Endpoint}",
"useSchemePrefix": false,
"parameters": [
{
"name": "Endpoint",
"in": "path",
"required": true,
"type": "string"
}
]
},
"produces": [
"application/json"
],
"consumes": [
"application/json"
],
"tags": [],
"paths": {
"/api/hubs/groups/{group}/connections/{connectionId}": {
"put": {
"operationId": "WebPubSubService_addConnectionToGroup",
"parameters": [
{
"name": "group",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "connectionId",
"in": "path",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "Ok"
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/ErrorDetail"
}
}
}
},
"delete": {
"operationId": "WebPubSubService_removeConnectionFromGroup",
"parameters": [
{
"name": "group",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "connectionId",
"in": "path",
"required": true,
"type": "string"
}
],
"responses": {
"204": {
"description": "No Content"
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/ErrorDetail"
}
}
}
}
},
"/api/hubs/permissions/{permission}/connections/{connectionId}": {
"head": {
"operationId": "WebPubSubService_checkPermission",
"parameters": [
{
"name": "permission",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "connectionId",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "targetName",
"in": "query",
"required": false,
"type": "string"
}
],
"responses": {
"200": {
"description": "Ok"
},
"404": {
"description": "Not Found"
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/ErrorDetail"
}
}
}
}
},
"/api/hubs/users/{userId}/groups/{group}": {
"put": {
"operationId": "WebPubSubService_addUserToGroup",
"parameters": [
{
"name": "group",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "userId",
"in": "path",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "Ok"
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/ErrorDetail"
}
}
}
},
"delete": {
"operationId": "WebPubSubService_removeUserFromGroup",
"parameters": [
{
"name": "group",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "userId",
"in": "path",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "Ok"
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/ErrorDetail"
}
}
}
}
}
},
"definitions": {
"ErrorDetail": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"message": {
"type": "string"
},
"target": {
"type": "string"
}
},
"required": [
"code",
"message",
"target"
]
}
},
"parameters": {}
}
2 changes: 2 additions & 0 deletions cadl/http/webpubsub/cadl-project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
emitters:
'@azure-tools/cadl-autorest': true
Loading