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

EventGridv2 TypeSpec Api Preview #23204

Merged
merged 38 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
68f887b
start typespec
l0lawrence Mar 17, 2023
6554c10
adding eventgrid typespec for api w/ TODOs
l0lawrence Mar 20, 2023
eb98a20
update eventgrid typespec with latest eventgrid v2 operations
Mar 22, 2023
c879030
don't require content-type if there is no body
l0lawrence Mar 23, 2023
6b989da
Update specification/eventgrid/typespec/main.tsp
lmazuel Mar 24, 2023
4a5f9cf
Update specification/eventgrid/typespec/main.tsp
lmazuel Mar 24, 2023
5511313
changing naming of cloudevent and added in data_base64
l0lawrence Mar 24, 2023
1a56614
openapi.json
l0lawrence Mar 24, 2023
c724eed
Update specification/eventgrid/typespec/main.tsp
lmazuel Mar 24, 2023
f91ee18
Update specification/eventgrid/typespec/main.tsp
lmazuel Mar 24, 2023
eb01ed4
Update specification/eventgrid/typespec/main.tsp
lmazuel Mar 24, 2023
69ccc41
lockTokens format, updated json, optional? params
l0lawrence Mar 25, 2023
0d2cb3a
changes
l0lawrence Mar 25, 2023
c2d4c68
address code review comments
ahamad-MS Mar 28, 2023
36d0e06
Merge branch 'feature/eventgrid/typespec' of https://github.com/Azure…
ahamad-MS Mar 28, 2023
15dccec
name_change
l0lawrence Apr 12, 2023
13f6949
add @internal for python
l0lawrence Apr 12, 2023
069bafb
Update specification/eventgrid/Azure.Messaging.EventGrid/main.tsp
l0lawrence Apr 12, 2023
5d21632
move @internal to client.tsp (#23538)
l0lawrence Apr 13, 2023
17fd291
rename (#23565)
l0lawrence Apr 14, 2023
663b348
[EventGrid Typespec] breaking changes with april release of typespec …
l0lawrence Apr 14, 2023
fd1fd9d
[EG Typespec] Update Release behavior (#23699)
l0lawrence Apr 24, 2023
02ea7de
Add tspconfig and remove AAD auth (#23717)
JoshLove-msft Apr 25, 2023
17d65e2
Merge branch 'main' of https://github.com/Azure/azure-rest-api-specs …
l0lawrence Apr 25, 2023
3806bc1
[EG TypeSpec] Archboard Comments (#23696)
l0lawrence Apr 26, 2023
799d10c
Address couple of stewardship team feedback. These include: 1. Rename…
ahamad-MS Apr 28, 2023
10e0e8c
Add support for missing Reject operation + adding deliveryAttemptCoun…
ahamad-MS Apr 29, 2023
09f9244
Update failedTokens/SuccessfulTokens Description to address code revi…
ahamad-MS May 1, 2023
6c2b560
Update to match service behavior (#23754)
JoshLove-msft May 1, 2023
20958fd
[EGv2] Editing unused variables (#23917)
l0lawrence May 10, 2023
16602df
Merge branch 'main' of https://github.com/Azure/azure-rest-api-specs …
l0lawrence May 11, 2023
911c47f
[EGv2] Version dependency on Azure.Core (#23936)
l0lawrence May 11, 2023
418e39a
[EventGrid] Deliveryattempt change (#23960)
l0lawrence May 12, 2023
e570388
[EventGrid] Remove internal (#23995)
l0lawrence May 16, 2023
0b24c89
remove waitWaitTime (#24078)
l0lawrence May 19, 2023
a90210c
move location of json file (#24076)
l0lawrence May 19, 2023
d1c21b5
[Egv2] Encode param (#24080)
l0lawrence May 22, 2023
4b1d4a0
[EGv2] Fix pipeline (#24098)
l0lawrence May 22, 2023
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 custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ eventhubconnections
eventhubs
eventroutes
eventstream
eventsubscriptions
eventtime
eventtypes
evpn
Expand Down
293 changes: 293 additions & 0 deletions specification/eventgrid/Azure.Messaging.EventGrid/main.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
import "@typespec/http";
import "@typespec/rest";
import "@typespec/versioning";
import "@azure-tools/typespec-azure-core";

@useAuth(
ApiKeyAuth<ApiKeyLocation.header, "SharedAccessKey">
)

@service({
title: "Azure.Messaging.EventGridClient",
})

//
// Supported operations.
//
// POST https://{namespaceName}.{region}.eventgrid.azure.net/topics/{topicName}:publish?api-version={apiVersion}
// POST https://{namespaceName}.{region}.eventgrid.azure.net/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:receive?api-Version={apiVersion}&maxWaitTime=60&maxEvents={maxEvents}
// POST https://{namespaceName}.{region}.eventgrid.azure.net/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:acknowledge?api-Version={apiVersion}
// POST https://{namespaceName}.{region}.eventgrid.azure.net/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:release?api-version={apiVersion}
// POST https://{namespaceName}.{region}.eventgrid.azure.net/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:reject?api-version={apiVersion}


@server(
"{endpoint}",
"The host name of the namespace",
{
@doc("The host name of the namespace, e.g. namespaceName1.westus-1.eventgrid.azure.net")
endpoint: url,
}
)

@doc("Azure Messaging EventGrid Client")
@versioned(ServiceApiVersions)
namespace Azure.Messaging.EventGrid {
using TypeSpec.Http;
using TypeSpec.Rest;
using TypeSpec.Versioning;
using Azure.Core;
using Azure.Core.Foundations;

enum ServiceApiVersions {
@useDependency(Azure.Core.Versions.v1_0_Preview_2)
v2023_06_01_preview: "2023-06-01-preview"
}

@doc("Properties of an event published to an Azure Messaging EventGrid Namespace topic using the CloudEvent 1.0 Schema.")
model CloudEvent {
@doc("An identifier for the event. The combination of id and source must be unique for each distinct event.")
id: string;

@doc("Identifies the context in which an event happened. The combination of id and source must be unique for each distinct event.")
source: string;

@doc("Event data specific to the event type.")
data?: unknown;

@doc("Event data specific to the event type, encoded as a base64 string.")
data_base64?: bytes;
Copy link
Member

Choose a reason for hiding this comment

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

Here, and directly below, we prefer camelCase for property names and enum values.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because this is following the outside spec of CloudEvent, it requires these parameters to be lowercase


@doc("Type of event related to the originating occurrence.")
type: string;

@doc("The time (in UTC) the event was generated, in RFC3339 format.")
time?: utcDateTime;

@doc("The version of the CloudEvents specification which the event uses.")
specversion: string;

@doc("Identifies the schema that data adheres to.")
dataschema?: string;

@doc("Content type of data value.")
datacontenttype?: string;

@doc("This describes the subject of the event in the context of the event producer (identified by source).")
subject?: string;
}

@doc("Properties of the Event Broker operation.")
model BrokerProperties {
@doc("The token used to lock the event.")
lockToken: string;

@doc("The attempt count for delivering the event.")
deliveryCount: int32;
}

@doc("Receive operation details per Cloud Event.")
model ReceiveDetails {
@doc("The Event Broker details.")
brokerProperties: BrokerProperties;

@doc("Cloud Event details.")
event: CloudEvent;
}

@doc("Details of the Receive operation response.")
model ReceiveResult {
@doc("Array of receive responses, one per cloud event.")
value: ReceiveDetails[];
}

@doc("Failed LockToken information.")
model FailedLockToken {
@doc("LockToken value")
lockToken: string;

@doc("Error code related to the token. Example of such error codes are BadToken: which indicates the Token is not formatted correctly, TokenLost: which indicates that token is not found, and InternalServerError: For any internal server errors.")
errorCode: string;

@doc("Description of the token error.")
errorDescription: string;
}

@doc("The result of the Publish operation.")
model PublishResult {}

@doc("The result of the Acknowledge operation.")
model AcknowledgeResult {
@doc("Array of LockToken values for failed cloud events. Each LockToken includes the lock token value along with the related error information (namely, the error code and description).")
failedLockTokens: FailedLockToken[];

@doc("Array of lock tokens values for the successfully acknowledged cloud events.")
succeededLockTokens: string[];
}

@doc("The result of the Release operation.")
model ReleaseResult {
@doc("Array of LockToken values for failed cloud events. Each LockToken includes the lock token value along with the related error information (namely, the error code and description).")
failedLockTokens: FailedLockToken[];
Copy link
Member Author

@l0lawrence l0lawrence May 10, 2023

Choose a reason for hiding this comment

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

Release/Reject/Acknowledge will return 200 response even if a lock token has failed.

The error code for that lock token failure is placed under this FailedLockToken array with errorCode and errorDescription.

Should this be a failure response instead when a lock token fails?

{'succeededLockTokens': [], 'failedLockTokens': [{'lockToken': 'token', 'errorCode': 'TokenLost', 'errorDescription': 'Token has expired.'}]}

Copy link
Member

@JoshLove-msft JoshLove-msft May 10, 2023

Choose a reason for hiding this comment

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

In particular, even when there are only failures we get a 200. So there are three cases:

  • all successes
  • partial success/failure
  • all failures

All three cases return 200. Is this correct from a REST-design perspective? /cc @mikekistler


@doc("Array of lock tokens values for the successfully released cloud events.")
succeededLockTokens: string[];
}

@doc("The result of the Reject operation.")
model RejectResult {
@doc("Array of LockToken values for failed cloud events. Each LockToken includes the lock token value along with the related error information (namely, the error code and description).")
failedLockTokens: FailedLockToken[];

@doc("Array of lock tokens values for the successfully rejected cloud events.")
succeededLockTokens: string[];
}

@doc("Array of lock token strings for the corresponding received Cloud Events to be released.")
model ReleaseOptions {
@doc("String array of lock tokens.")
lockTokens: string[];
}

@doc("Array of lock token strings for the corresponding received Cloud Events to be acknowledged.")
model AcknowledgeOptions {
@doc("String array of lock tokens.")
lockTokens: string[];
}

@doc("Array of lock token strings for the corresponding received Cloud Events to be rejected.")
model RejectOptions {
@doc("String array of lock tokens.")
lockTokens: string[];
Copy link
Member

Choose a reason for hiding this comment

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

Why is this string array rather than LockToken array?

Copy link
Member

Choose a reason for hiding this comment

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

I guess the LockToken type is meant for output that might evolve over time.

}

// Publish Operation:
// POST https://{namespaceName}.{region}.eventgrid.azure.net/topics/{topicName}:publish?api-version={apiVersion}}

@doc("Publish Single Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200 status code with an empty JSON object in response. Otherwise, the server can return various error codes. For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for internal server error. ")
@route("/topics/{topicName}:publish", {shared: true})
@post op PublishCloudEvent is Azure.Core.RpcOperation<{
Copy link
Member

Choose a reason for hiding this comment

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

Why not a collection action of a Topic resource?

@doc("content type")
@header("content-type")
contentType: "application/cloudevents+json; charset=utf-8";

@doc("Topic Name.")
@path
topicName: string;

@doc("Single Cloud Event being published.")
@body
event: CloudEvent;
}, PublishResult>;
Copy link
Member

Choose a reason for hiding this comment

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

Why do we return an empty object? Can we just don't return anything?

Copy link
Member

Choose a reason for hiding this comment

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

Is the service really returning {} as the body?

Copy link
Member Author

@l0lawrence l0lawrence May 17, 2023

Choose a reason for hiding this comment

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

The service does return a 200 with '{}'. Having the return as a model keeps everything consistent and if publish ever returns anything else the response type is already there



@doc("Publish Batch Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200 status code with an empty JSON object in response. Otherwise, the server can return various error codes. For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for internal server error. ")
@route("/topics/{topicName}:publish", {shared: true})
@post op PublishCloudEvents is Azure.Core.RpcOperation<{
@doc("content type")
@header("content-type")
contentType: "application/cloudevents-batch+json; charset=utf-8";

@doc("Topic Name.")
@path
topicName: string;

@doc("Array of Cloud Events being published.")
@body
events: CloudEvent[];
}, PublishResult>;

// Receive Operation:
// POST https://{namespaceName}.{region}.eventgrid.azure.net/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:receive?api-Version={apiVersion}&maxWaitTime=60&maxEvents={maxEvents}

@doc("Receive Batch of Cloud Events from the Event Subscription.")
@route("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:receive")
@post op ReceiveCloudEvents is Azure.Core.RpcOperation<{
@doc("Topic Name.")
@path
topicName: string;

@doc("Event Subscription Name.")
@path
eventSubscriptionName: string;

@doc("Max Events count to be received. Minimum value is 1, while maximum value is 100 events. If not specified, the default value is 1.")
@query
maxEvents?: int32 = 1;

@doc("Max wait time value for receive operation in Seconds. It is the time in seconds that the server approximately waits for the availability of an event and responds to the request. If an event is available, the broker responds immediately to the client. Minimum value is 10 seconds, while maximum value is 120 seconds. If not specified, the default value is 60 seconds.")
@encode("seconds", int32)
@query
maxWaitTime?: duration;
}, ReceiveResult>;

// Acknowledge Operation:
// POST https://{namespaceName}.{region}.eventgrid.azure.net/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:acknowledge&apiVersion={apiVersion}

@doc("Acknowledge batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is successfully acknowledged. The response body will include the set of successfully acknowledged lockTokens, along with other failed lockTokens with their corresponding error information. Successfully acknowledged events will no longer be available to any consumer.")

@route("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:acknowledge")
@post op AcknowledgeCloudEvents is Azure.Core.RpcOperation<{
@doc("content type")
@header("content-type")
contentType: "application/json; charset=utf-8";

@doc("Topic Name.")
@path
topicName: string;

@doc("Event Subscription Name.")
@path
eventSubscriptionName: string;

@doc("AcknowledgeOptions.")
@body
lockTokens: AcknowledgeOptions;
}, AcknowledgeResult>;

// Release Operation:
// POST https://{namespaceName}.{region}.eventgrid.azure.net/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:release?api-version={apiVersion}

@doc("Release batch of Cloud Events. The server responds with an HTTP 200 status code if at least one event is successfully released. The response body will include the set of successfully released lockTokens, along with other failed lockTokens with their corresponding error information.")
@route("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:release")
@post op ReleaseCloudEvents is Azure.Core.RpcOperation<{
@doc("content type")
@header("content-type")
contentType: "application/json; charset=utf-8";

@doc("Topic Name.")
@path
topicName: string;

@doc("Event Subscription Name.")
@path
eventSubscriptionName: string;

@doc("ReleaseOptions")
@body
lockTokens : ReleaseOptions;
}, ReleaseResult>;

// Reject Operation:
// POST https://{namespaceName}.{region}.eventgrid.azure.net/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:reject?api-version={apiVersion}

@doc("Reject batch of Cloud Events.")
@route("/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:reject")
@post op RejectCloudEvents is Azure.Core.RpcOperation<{
@doc("content type")
@header("content-type")
contentType: "application/json; charset=utf-8";

@doc("Topic Name.")
@path
topicName: string;

@doc("Event Subscription Name.")
@path
eventSubscriptionName: string;

@doc("RejectOptions")
@body
lockTokens : RejectOptions;
}, RejectResult>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
parameters:
"python-sdk-folder":
default: "{project-root}/azure-sdk-for-python/"
"service-directory-name":
default: "eventgrid"
emit: [
"@azure-tools/typespec-autorest",
]
options:
"@azure-tools/typespec-autorest":
examples-directory: ./examples
omit-unreachable-types: true
output-file: EventGrid.json
emitter-output-dir: "{project-root}/../data-plane/Microsoft.EventGrid/preview/2023-06-01-preview"
"@azure-tools/typespec-python":
"package-pprint-name": "\"Azure Event Grid\""
"package-mode": "dataplane"
"package-version": 4.12.0b1
"package-name": "azure-eventgrid"
"emitter-output-dir": "{python-sdk-folder}/sdk/{service-directory-name}/{package-name}"
# Uncomment this line and add "@azure-tools/typespec-csharp" to your package.json to generate C# code
"@azure-tools/typespec-csharp":
model-namespace: false
generate-convenience-methods: false
namespace: Azure.Messaging.EventGrid.Namespaces
Loading