Skip to content

Commit

Permalink
[azeventgrid] Updating to the latest swagger. Changes doc'd in the CH…
Browse files Browse the repository at this point in the history
…ANGELOG (Azure#21998)

- Flattening out the faux-Options type that was getting generated so that lockTokens is just a parameter now.
- Fixing the error type so it looks more like we expect for Error type.
  • Loading branch information
richardpark-msft authored Nov 28, 2023
1 parent 74a6034 commit 61137f4
Show file tree
Hide file tree
Showing 19 changed files with 981 additions and 324 deletions.
14 changes: 10 additions & 4 deletions sdk/messaging/azeventgrid/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# Release History

## 0.3.1 (Unreleased)
## 0.4.0 (2023-11-27)

### Features Added

### Breaking Changes
- New functionality for Event Grid namespaces:
- Client.PublishCloudEvent can be used to publish a single `messaging.CloudEvent`.
- Client.RenewCloudEventLocks can extend the lock time for a set of events.
- Client.ReleaseCloudEvents (via ReleaseCloudEventsOptions.ReleaseDelayInSeconds) can release an event with a
server-side delay, allowing the message to remain unavailable for a configured period of time.

### Bugs Fixed
### Breaking Changes

### Other Changes
- FailedLockToken, included in the response for settlement functions, has an `Error` field, which contains the data previously
in `ErrorDescription` and `ErrorCode`.
- Settlement functions (AcknowledgeCloudEvents, ReleaseCloudEvents, RejectCloudEvents) take lock tokens as a parameter.

## 0.3.0 (2023-10-17)

Expand Down
2 changes: 1 addition & 1 deletion sdk/messaging/azeventgrid/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "go",
"TagPrefix": "go/messaging/azeventgrid",
"Tag": "go/messaging/azeventgrid_b8c3771d17"
"Tag": "go/messaging/azeventgrid_1a76fcf573"
}
204 changes: 166 additions & 38 deletions sdk/messaging/azeventgrid/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ generated-metadata: false
clear-output-folder: false
go: true
input-file:
# This was the commit that everyone used to generate their first official betas.
- https://raw.githubusercontent.com/Azure/azure-rest-api-specs/c07d9898ed901330e5ac4996b1bc641adac2e6fd/specification/eventgrid/data-plane/Microsoft.EventGrid/preview/2023-06-01-preview/EventGrid.json
# - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/947c9ce9b20900c6cbc8e95bc083e723d09a9c2c/specification/eventgrid/data-plane/Microsoft.EventGrid/preview/2023-06-01-preview/EventGrid.json
- https://raw.githubusercontent.com/Azure/azure-rest-api-specs/2264262e0c7575a794cc395609d2342c7e598149/specification/eventgrid/data-plane/Microsoft.EventGrid/preview/2023-10-01-preview/EventGrid.json
license-header: MICROSOFT_MIT_NO_VERSION
module: github.com/Azure/azure-sdk-for-go/sdk/messaging/azeventgrid
openapi-type: "data-plane"
Expand All @@ -20,34 +18,111 @@ use: "@autorest/[email protected]"
version: "^3.0.0"
slice-elements-byval: true
remove-non-reference-schema: true
```
Make sure the content type is setup properly for publishing single and multiple events.
```yaml
directive:
# we have to write a little wrapper code for this so we'll hide the public function
# for now.
- from: client.go
- from:
- client.go
where: $
transform: return $.replace(/PublishCloudEvents\(/g, "internalPublishCloudEvents(");
- from: swagger-document
where: $.definitions.CloudEvent.properties.specversion
transform: $["x-ms-client-name"] = "SpecVersion"
transform: |
return $.replace(
/(func \(client \*Client\) publishCloudEventsCreateRequest.+?)return req, nil/s,
'$1\nreq.Raw().Header.Set("Content-type", "application/cloudevents-batch+json; charset=utf-8")\nreturn req, nil');
- from:
- client.go
where: $
transform: |
return $.replace(
/(func \(client \*Client\) publishCloudEventCreateRequest.+?)return req, nil/s,
'$1\nreq.Raw().Header.Set("Content-type", "application/cloudevents+json; charset=utf-8")\nreturn req, nil');
```
Fix the error type so it's a bit more presentable, and looks like an error for this package.
```yaml
directive:
- from: swagger-document
where: $.definitions.CloudEvent.properties.datacontenttype
transform: $["x-ms-client-name"] = "DataContentType"
where: $.definitions["Azure.Core.Foundations.Error"]
debug: true
transform: |
$.properties = {
code: $.properties["code"],
message: {
...$.properties["message"],
"x-ms-client-name": "InternalErrorMessageRename"
},
};
$["x-ms-client-name"] = "Error";
- from: swagger-document
where: $.definitions.CloudEvent.properties.dataschema
transform: $["x-ms-client-name"] = "DataSchema"
# mark models as external so they're just omitted
where: $.definitions
transform: delete $["Azure.Core.Foundations.InnerError"];

- from:
- models.go
- models_serde.go
where: $
transform: return $.replace(/InternalErrorMessageRename/g, "message");

- from:
- models.go
- models_serde.go
where: $
transform: |
return $
.replace(/\/\/ AzureCoreFoundationsErrorResponse.+?\n}/gs, "")
.replace(/\/\/ MarshalJSON implements the json\.Marshaller interface for type AzureCoreFoundationsErrorResponse\..+?\n}/gs, "")
.replace(/\/\/ UnmarshalJSON implements the json\.Unmarshaller interface for type AzureCoreFoundationsErrorResponse\..+?\n}/gs, "");
```
Trim out the 'Interface any' for types that are empty.
```yaml
directive:
- from: response_types.go
where: $
transform: $.replace(/\s+\/\/ Anything\s+Interface any/sg, "$1");
```
For functions that have empty responses (ie, PublishCloudEvent
and PublishCloudEvents) we can remove the schema attribute, which cleans
up the PublishCloudEventResponse/PublishCloudEventsResponse
so they don't have a vestigial `Interface any` field.

```yaml
directive:
# remove the 'Interface any' that's generated for an empty response object.
- from:
- swagger-document
where: $["x-ms-paths"]["/topics/{topicName}:publish?_overload=publishCloudEvents"].post.responses["200"]
transform: delete $["schema"];
- from:
- swagger-document
where: $["paths"]["/topics/{topicName}:publish"].post.responses["200"]
transform: delete $["schema"];
```

Use azcore's CloudEvent type instead of a locally generated version.

```yaml
directive:
# replace references to the "generated" CloudEvent to the actual version in azcore/messaging
- from:
- client.go
- models.go
- response_types.go
- options.go
where: $
transform: |
return $.replace(/\[\]CloudEvent/g, "[]messaging.CloudEvent")
.replace(/\*CloudEvent/g, "messaging.CloudEvent")
.replace(/event CloudEvent/g, "event messaging.CloudEvent")
- from: swagger-document
where: $.definitions.CloudEvent
transform: $["x-ms-external"] = true
- from: swagger-document
where: $.definitions.["Azure.Core.Foundations.Error"]
transform: $["x-ms-external"] = true
- from: swagger-document
where: $.definitions.["Azure.Core.Foundations.ErrorResponse"]
transform: $["x-ms-external"] = true
- from: swagger-document
where: $.definitions.["Azure.Core.Foundations.InnerError"]
transform: $["x-ms-external"] = true
# make the endpoint a parameter of the client constructor
- from: swagger-document
where: $["x-ms-parameterized-host"]
Expand All @@ -60,20 +135,73 @@ directive:
- options.go
where: $
transform: return $.replace(/Client(\w+)((?:Options|Response))/g, "$1$2");
# replace references to the "generated" CloudEvent to the actual version in azcore/messaging
- from:
- client.go
- models.go
- response_types.go
- options.go
```

Fix incorrect string formatting for the "release with delay"

```yaml
directive:
- from: swagger-document
where: $.paths["/topics/{topicName}/eventsubscriptions/{eventSubscriptionName}:release"].post.parameters[3]
transform: $.type = "integer";
- from: client.go
where: $
transform: |
return $.replace(/\[\]CloudEvent/g, "[]messaging.CloudEvent")
.replace(/\*CloudEvent/g, "messaging.CloudEvent");
transform: return $.replace(/string\(\*options.ReleaseDelayInSeconds\)/g, "fmt.Sprintf(\"%d\", *options.ReleaseDelayInSeconds)")
```

# remove the 'Interface any' that's generated for an empty response object.
- from:
- swagger-document
where: $["x-ms-paths"]["/topics/{topicName}:publish?api-version={apiVersion}"].post.responses["200"]
transform: delete $["schema"];
Add doc for ReleaseDelay enum

```yaml
directive:
- from: constants.go
where: $
transform: return $.replace(/type ReleaseDelay int32/, "// ReleaseDelay indicates how long the service should delay before releasing an event.\ntype ReleaseDelay int32")
```

We want to flatten out the settlement arg functions so we'll internalize
them and do the flattening in custom code.

```yaml
directive:
# Rename the functions so they're internal
- from: client.go
where: $
transform: return $.replace(/func \(client \*Client\) RejectCloudEvents\(/, "func \(client \*Client\) internalRejectCloudEvents(")
- from: client.go
where: $
transform: return $.replace(/func \(client \*Client\) AcknowledgeCloudEvents\(/, "func \(client \*Client\) internalAcknowledgeCloudEvents(")
- from: client.go
where: $
transform: return $.replace(/func \(client \*Client\) ReleaseCloudEvents\(/, "func \(client \*Client\) internalReleaseCloudEvents(")
- from: client.go
where: $
transform: return $.replace(/func \(client \*Client\) RenewCloudEventLocks\(/, "func \(client \*Client\) internalRenewCloudEventLocks(")
# Rename the old param bags to be internal as well
- from:
- client.go
- models.go
- models_serde.go
where: $
transform: return $.replace(/\bReleaseOptions\b/g, "releaseOptions")
- from:
- client.go
- models.go
- models_serde.go
where: $
transform: return $.replace(/\bRejectOptions\b/g, "rejectOptions")
- from:
- client.go
- models.go
- models_serde.go
where: $
transform: return $.replace(/\bAcknowledgeOptions\b/g, "acknowledgeOptions")
- from:
- client.go
- models.go
- models_serde.go
where: $
transform: return $.replace(/\RenewLockOptions\b/g, "renewLockOptions")
```
Loading

0 comments on commit 61137f4

Please sign in to comment.