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

[EventGrid] Move to Core V2 Generator #16047

Merged
merged 2 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion sdk/eventgrid/eventgrid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
"scripts": {
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:autorest": "autorest ./swagger/README.md --typescript --v3",
"build:autorest": "autorest ./swagger/README.md --typescript --v3 && node ./scripts/setPathToEmpty.js",
"build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1",
"build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1",
"build:samples": "echo Obsolete",
Expand Down
12 changes: 12 additions & 0 deletions sdk/eventgrid/eventgrid/scripts/setPathToEmpty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";
const fs = require("fs");

// The "endpoint" shown in the portal and CLI for an Azure Event Grid includes the "/api/events"
// path parameter. We need to ensure that we don't add another "/api/events" suffix, but there
// is not a way to express this in swagger. So, we post process the generated client to ensure
// that the operation spec we build has the empty string for the path to append.
console.log("Updating ./scr/generate/generateClient.ts path entries");
let data = fs.readFileSync("./src/generated/generatedClient.ts", "utf8");
data = data.replace(new RegExp('path: "/api/events"', "g"), 'path: ""');
fs.writeFileSync("./src/generated/generatedClient.ts", data, "utf8");
console.log("Done Updating ./scr/generate/generateClient.ts path entries");
34 changes: 20 additions & 14 deletions sdk/eventgrid/eventgrid/src/generated/generatedClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/

import { OperationOptions, OperationSpec, createSerializer } from "@azure/core-client";
import * as coreClient from "@azure/core-client";
import * as Parameters from "./models/parameters";
import * as Mappers from "./models/mappers";
import { GeneratedClientContext } from "./generatedClientContext";
import { GeneratedClientOptionalParams, EventGridEvent, CloudEvent } from "./models";
import {
GeneratedClientOptionalParams,
EventGridEvent,
GeneratedClientPublishEventsOptionalParams,
CloudEvent,
GeneratedClientPublishCloudEventEventsOptionalParams,
GeneratedClientPublishCustomEventEventsOptionalParams
} from "./models";

/** @hidden */
/** @internal */
export class GeneratedClient extends GeneratedClientContext {
/**
* Initializes a new instance of the GeneratedClient class.
Expand All @@ -31,9 +38,9 @@ export class GeneratedClient extends GeneratedClientContext {
publishEvents(
topicHostname: string,
events: EventGridEvent[],
options?: OperationOptions
options?: GeneratedClientPublishEventsOptionalParams
): Promise<void> {
return this.sendOperationRequest<void>(
return this.sendOperationRequest(
{ topicHostname, events, options },
publishEventsOperationSpec
);
Expand All @@ -48,9 +55,9 @@ export class GeneratedClient extends GeneratedClientContext {
publishCloudEventEvents(
topicHostname: string,
events: CloudEvent[],
options?: OperationOptions
options?: GeneratedClientPublishCloudEventEventsOptionalParams
): Promise<void> {
return this.sendOperationRequest<void>(
return this.sendOperationRequest(
{ topicHostname, events, options },
publishCloudEventEventsOperationSpec
);
Expand All @@ -65,19 +72,18 @@ export class GeneratedClient extends GeneratedClientContext {
publishCustomEventEvents(
topicHostname: string,
events: any[],
options?: OperationOptions
options?: GeneratedClientPublishCustomEventEventsOptionalParams
): Promise<void> {
return this.sendOperationRequest<void>(
return this.sendOperationRequest(
{ topicHostname, events, options },
publishCustomEventEventsOperationSpec
);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);

const serializer = createSerializer(Mappers, /* isXml */ false);

const publishEventsOperationSpec: OperationSpec = {
const publishEventsOperationSpec: coreClient.OperationSpec = {
path: "",
httpMethod: "POST",
responses: { 200: {}, default: {} },
Expand All @@ -88,7 +94,7 @@ const publishEventsOperationSpec: OperationSpec = {
mediaType: "json",
serializer
};
const publishCloudEventEventsOperationSpec: OperationSpec = {
const publishCloudEventEventsOperationSpec: coreClient.OperationSpec = {
path: "",
httpMethod: "POST",
responses: { 200: {}, default: {} },
Expand All @@ -99,7 +105,7 @@ const publishCloudEventEventsOperationSpec: OperationSpec = {
mediaType: "json",
serializer
};
const publishCustomEventEventsOperationSpec: OperationSpec = {
const publishCustomEventEventsOperationSpec: coreClient.OperationSpec = {
path: "",
httpMethod: "POST",
responses: { 200: {}, default: {} },
Expand Down
22 changes: 12 additions & 10 deletions sdk/eventgrid/eventgrid/src/generated/generatedClientContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,34 @@
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/

import { ServiceClient } from "@azure/core-client";
import * as coreClient from "@azure/core-client";
import { GeneratedClientOptionalParams } from "./models";

export class GeneratedClientContext extends ServiceClient {
/** @internal */
export class GeneratedClientContext extends coreClient.ServiceClient {
apiVersion: string;

/**
* Initializes a new instance of the GeneratedClientContext class.
* @param options The parameter options
*/
constructor(options: GeneratedClientOptionalParams = {}) {
constructor(options?: GeneratedClientOptionalParams) {
// Initializing default values for options
if (!options) {
options = {};
}
const defaults: GeneratedClientOptionalParams = {
requestContentType: "application/json; charset=utf-8"
};

const { endpoint, apiVersion, ...restOptions } = options;

const optionsWithDefaults: GeneratedClientOptionalParams = {
const optionsWithDefaults = {
...defaults,
...restOptions,
baseUri: endpoint || "{topicHostname}"
...options,
baseUri: options.endpoint || "{topicHostname}"
};

super(optionsWithDefaults);

// Assigning values to Constant parameters
this.apiVersion = apiVersion || "2018-01-01";
this.apiVersion = options.apiVersion || "2018-01-01";
}
}
28 changes: 21 additions & 7 deletions sdk/eventgrid/eventgrid/src/generated/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
import { ServiceClientOptions } from "@azure/core-client";

import * as coreClient from "@azure/core-client";

export type MediaJobOutputUnion = MediaJobOutput | MediaJobOutputAsset;

Expand Down Expand Up @@ -2369,7 +2370,7 @@ export const enum KnownAppAction {
* Defines values for AppAction. \
* {@link KnownAppAction} can be used interchangeably with AppAction,
* this enum contains the known values that the service supports.
* ### Know values supported by the service
* ### Known values supported by the service
* **Restarted**: Web app was restarted. \
* **Stopped**: Web app was stopped. \
* **ChangedAppSettings**: There was an operation to change app setting on the web app. \
Expand All @@ -2393,7 +2394,7 @@ export const enum KnownStampKind {
* Defines values for StampKind. \
* {@link KnownStampKind} can be used interchangeably with StampKind,
* this enum contains the known values that the service supports.
* ### Know values supported by the service
* ### Known values supported by the service
* **Public**: App Service Plan is running on a public stamp. \
* **AseV1**: App Service Plan is running on an App Service Environment V1. \
* **AseV2**: App Service Plan is running on an App Service Environment V2.
Expand All @@ -2410,7 +2411,7 @@ export const enum KnownAppServicePlanAction {
* Defines values for AppServicePlanAction. \
* {@link KnownAppServicePlanAction} can be used interchangeably with AppServicePlanAction,
* this enum contains the known values that the service supports.
* ### Know values supported by the service
* ### Known values supported by the service
* **Updated**: App Service plan is being updated.
*/
export type AppServicePlanAction = string;
Expand All @@ -2429,7 +2430,7 @@ export const enum KnownAsyncStatus {
* Defines values for AsyncStatus. \
* {@link KnownAsyncStatus} can be used interchangeably with AsyncStatus,
* this enum contains the known values that the service supports.
* ### Know values supported by the service
* ### Known values supported by the service
* **Started**: Async operation has started. \
* **Completed**: Async operation has completed. \
* **Failed**: Async operation failed to complete.
Expand All @@ -2447,7 +2448,7 @@ export const enum KnownCommunicationCloudEnvironmentModel {
* Defines values for CommunicationCloudEnvironmentModel. \
* {@link KnownCommunicationCloudEnvironmentModel} can be used interchangeably with CommunicationCloudEnvironmentModel,
* this enum contains the known values that the service supports.
* ### Know values supported by the service
* ### Known values supported by the service
* **public** \
* **dod** \
* **gcch**
Expand Down Expand Up @@ -2484,7 +2485,20 @@ export type MediaJobErrorCategory =
export type MediaJobRetry = "DoNotRetry" | "MayRetry";

/** Optional parameters. */
export interface GeneratedClientOptionalParams extends ServiceClientOptions {
export interface GeneratedClientPublishEventsOptionalParams
extends coreClient.OperationOptions {}

/** Optional parameters. */
export interface GeneratedClientPublishCloudEventEventsOptionalParams
extends coreClient.OperationOptions {}

/** Optional parameters. */
export interface GeneratedClientPublishCustomEventEventsOptionalParams
extends coreClient.OperationOptions {}

/** Optional parameters. */
export interface GeneratedClientOptionalParams
extends coreClient.ServiceClientOptions {
/** Api Version */
apiVersion?: string;
/** Overrides client endpoint. */
Expand Down
Loading