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

[Experiment] Cadl file for simple client using ResourceOperations #391

Draft
wants to merge 2 commits into
base: cadl
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
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
76 changes: 76 additions & 0 deletions cadl/http/webpubsub/main.cadl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import "@cadl-lang/rest";
import "@azure-tools/cadl-azure-core";
import "@azure-tools/cadl-autorest";

@serviceTitle("WebPubSub Service")
@serviceVersion("2021-10-01")
@server("{Endpoint}", "WebPubSub Service", {Endpoint: string}) // Use `Uri` when available: https://github.com/microsoft/cadl/issues/654
namespace WebPubSubService;

using Cadl.Http;

@error
model ErrorDetail {
code: string;
message: string;
target: string;
// TODO: details
// TODO: inner

}

// TODO: could we specify {hub} at this level?
@route("/api/hubs")
namespace WebPubSubService {

@route("/groups/{group}/connections/{connectionId}")
// TODO: How to take hub here? with regexp pattern
// TODO: How to take api-version as query parameter? SDK should handle this
// TODO: How to say this produces:
// "text/plain",
// "application/json",
// "text/json"
// TODO: group common parameters and restrictions on them
// TODO: As x-ms-error-response and x-ms-error-code header
@put
op addConnectionToGroup(@path group: string, @path connectionId: string): {
@statusCode statusCode: 200; // TODO: use Untemplated OkResponse
} | ErrorDetail;

@route("/groups/{group}/connections/{connectionId}") // TODO: is there a way to not duplicate these?
@delete
op removeConnectionFromGroup(@path group: string,@path connectionId: string): {
@statusCode statusCode: 204; // TODO: Use DeleteResponse
} | ErrorDetail;


@route("/users/{userId}/groups/{group}")
// TODO: How to take hub here? with regexp pattern
// TODO: How to take api-version as query parameter? SDK should handle this
// TODO: How to say this produces:
// "text/plain",
// "application/json",
// "text/json"
@put
op addUserToGroup(@path group: string, @path userId: string): {
@statusCode statusCode: 200;
} | ErrorDetail;

@route("/users/{userId}/groups/{group}")
@delete
op removeUserFromGroup(@path group: string, @path userId: string): {
@statusCode statusCode: 200;
} | ErrorDetail;

@route("/permissions/{permission}/connections/{connectionId}")
// TODO: How to do an enum (and have it be a string in DPG client)
// TODO: Unclear why not generating as Response<bool> from DPG generator
@head
op checkPermission(@path permission: string, @path connectionId: string, @query targetName?: string): {
@statusCode statusCode: 200;
} |
{
@statusCode statusCode: 404;
} |
ErrorDetail;
}
11 changes: 11 additions & 0 deletions cadl/http/webpubsub/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
}
2 changes: 2 additions & 0 deletions cadl/rest/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
26 changes: 26 additions & 0 deletions cadl/rest/op-crud/op-crud.cadl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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;
using Cadl.Rest;
using Cadl.Rest.Resource;

model Product {
@key
id: int32;
}

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

interface Products extends ResourceOperations<Product, Error> {
}
11 changes: 11 additions & 0 deletions cadl/rest/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
}
Loading