Skip to content

Commit

Permalink
Dpg code gen fix docs (#1861)
Browse files Browse the repository at this point in the history
* Add return types

* Version update

* Upgrade the cadl-ranch version to v15 (#1863)

* Upgrade the cadl-ranch version

* Add test cases for encode

* Typo fix

* Change to workspace

* Remove duplicate generation

* make subscirption id optional if there're tenant level operations (#1869)

* try fix subscriptionId in tenant level

* use overload to fix subscription optional

* refine and fix smoke test

* fix test and resolve comments

* fix sample transform

* Re-generate

* Add return types

* Version update

* Remove duplicate generation

* Re-generate

* Update

* re generate tests

* use workspace

* fix unit test

* fix integration test

---------

Co-authored-by: Mary Gao <yanmeigao1210@gmail.com>
Co-authored-by: Qiaoqiao Zhang <55688292+qiaozha@users.noreply.github.com>
Co-authored-by: qiaozha <qiaozha@microsoft.com>
  • Loading branch information
4 people authored May 29, 2023
1 parent ed9a308 commit df35b83
Show file tree
Hide file tree
Showing 60 changed files with 507 additions and 1,091 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function createClient(
options = {
...options,
credentials: {
scopes: ["user_impersonation"]
scopes: options.credentials?.scopes ?? ["user_impersonation"]
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export default function createClient(
options = {
...options,
credentials: {
scopes: ["https://security.microsoft.com/.default"]
scopes: options.credentials?.scopes ?? [
"https://security.microsoft.com/.default"
]
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function createClient(
options = {
...options,
credentials: {
apiKeyHeaderName: "security-key"
apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "security-key"
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function createClient(
options = {
...options,
credentials: {
apiKeyHeaderName: "Authorization"
apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "Authorization"
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export default function createClient(
options = {
...options,
credentials: {
apiKeyHeaderName: "Ocp-Apim-Subscription-Key"
apiKeyHeaderName:
options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key"
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export default function createClient(
options = {
...options,
credentials: {
apiKeyHeaderName: "Ocp-Apim-Subscription-Key"
apiKeyHeaderName:
options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key"
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export function createClient(
options = {
...options,
credentials: {
scopes: ["https://purview.azure.net/.default"]
scopes: options.credentials?.scopes ?? [
"https://purview.azure.net/.default"
]
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function createClient(
options = {
...options,
credentials: {
apiKeyHeaderName: "CustomAuth"
apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "CustomAuth"
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export default function createClient(
options = {
...options,
credentials: {
scopes: ["https://dev.azuresynapse.net/.default"]
scopes: options.credentials?.scopes ?? [
"https://dev.azuresynapse.net/.default"
]
}
};

Expand Down
6 changes: 4 additions & 2 deletions packages/rlc-common/src/buildClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,12 @@ function getClientFactoryBody(
credentialScopes && credentialScopes.length
? credentialScopes.map((cs) => `"${cs}"`).join(", ")
: "";
const scopes = scopesString ? `scopes: [${scopesString}],` : "";
const scopes = scopesString
? `scopes: options.credentials?.scopes ?? [${scopesString}],`
: "";

const apiKeyHeaderName = credentialKeyHeaderName
? `apiKeyHeaderName: "${credentialKeyHeaderName}",`
? `apiKeyHeaderName: options.credentials?.apiKeyHeaderName ?? "${credentialKeyHeaderName}",`
: "";

const credentials =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default function createClient(
options = {
...options,
credentials: {
apiKeyHeaderName: "Ocp-Apim-Subscription-Key",
apiKeyHeaderName:
options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key",
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export default function createClient(
options = {
...options,
credentials: {
apiKeyHeaderName: "Ocp-Apim-Subscription-Key",
apiKeyHeaderName:
options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key",
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export default function createClient(
options = {
...options,
credentials: {
scopes: ["https://confidential-ledger.azure.com/.default"],
scopes: options.credentials?.scopes ?? [
"https://confidential-ledger.azure.com/.default",
],
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export default function createClient(
options = {
...options,
credentials: {
apiKeyHeaderName: "Ocp-Apim-Subscription-Key",
apiKeyHeaderName:
options.credentials?.apiKeyHeaderName ?? "Ocp-Apim-Subscription-Key",
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
```ts

import { ClientOptions as ClientOptions_2 } from '@azure-rest/core-client';
import { HttpResponse } from '@azure-rest/core-client';
import { ClientOptions } from '@azure-rest/core-client';
import { KeyCredential } from '@azure/core-auth';
import { RawHttpHeadersInput } from '@azure/core-rest-pipeline';

Expand All @@ -14,33 +13,18 @@ export interface AcknowledgeCloudEventsOptions extends RequestOptions {
contentType?: string;
}

// @public
export interface AcknowledgeOptions {
lockTokens: string[];
}

// @public
export interface AcknowledgeResult {
failedLockTokens: FailedLockToken[];
succeededLockTokens: string[];
}

// @public (undocumented)
export interface AcknowledgeResult {
failedLockTokens: FailedLockToken[];
succeededLockTokens: string[];
}

// @public
export interface BrokerProperties {
deliveryCount: number;
lockToken: string;
}

// @public (undocumented)
export interface ClientOptions extends ClientOptions_2 {
}

// @public
export interface CloudEvent {
data?: any;
Expand All @@ -57,21 +41,19 @@ export interface CloudEvent {

// @public (undocumented)
export class EventGridClient {
constructor(endpoint: string, credential: KeyCredential, options?: ClientOptions);
// (undocumented)
constructor(endpoint: string, credential: KeyCredential, options?: EventGridClientOptions);
acknowledgeCloudEvents(lockTokens: string[], topicName: string, eventSubscriptionName: string, options?: AcknowledgeCloudEventsOptions): Promise<AcknowledgeResult>;
// (undocumented)
publishCloudEvent(event: CloudEvent, topicName: string, options?: PublishCloudEventOptions): Promise<Record<string, any>>;
// (undocumented)
publishCloudEvents(events: CloudEvent[], topicName: string, options?: PublishCloudEventsOptions): Promise<Record<string, any>>;
// (undocumented)
receiveCloudEvents(topicName: string, eventSubscriptionName: string, options?: ReceiveCloudEventsOptions): Promise<ReceiveResult>;
// (undocumented)
rejectCloudEvents(lockTokens: string[], topicName: string, eventSubscriptionName: string, options?: RejectCloudEventsOptions): Promise<RejectResult>;
// (undocumented)
releaseCloudEvents(lockTokens: string[], topicName: string, eventSubscriptionName: string, options?: ReleaseCloudEventsOptions): Promise<ReleaseResult>;
}

// @public (undocumented)
export interface EventGridClientOptions extends ClientOptions {
}

// @public
export interface FailedLockToken {
errorCode: string;
Expand All @@ -84,12 +66,6 @@ export interface PublishCloudEventOptions extends RequestOptions {
contentType?: string;
}

// @public (undocumented)
export interface PublishCloudEventRequest {
// (undocumented)
event: CloudEvent;
}

// @public (undocumented)
export interface PublishCloudEventsOptions extends RequestOptions {
contentType?: string;
Expand All @@ -112,28 +88,12 @@ export interface ReceiveResult {
value: ReceiveDetails[];
}

// @public (undocumented)
export interface ReceiveResult {
value: ReceiveDetails[];
}

// @public (undocumented)
export interface RejectCloudEventsOptions extends RequestOptions {
contentType?: string;
}

// @public
export interface RejectOptions {
lockTokens: string[];
}

// @public
export interface RejectResult {
failedLockTokens: FailedLockToken[];
succeededLockTokens: string[];
}

// @public (undocumented)
export interface RejectResult {
failedLockTokens: FailedLockToken[];
succeededLockTokens: string[];
Expand All @@ -144,31 +104,18 @@ export interface ReleaseCloudEventsOptions extends RequestOptions {
contentType?: string;
}

// @public
export interface ReleaseOptions {
lockTokens: string[];
}

// @public
export interface ReleaseResult {
failedLockTokens: FailedLockToken[];
succeededLockTokens: string[];
}

// @public (undocumented)
export interface ReleaseResult {
failedLockTokens: FailedLockToken[];
succeededLockTokens: string[];
}

// @public (undocumented)
// @public
export interface RequestOptions {
// (undocumented)
requestOptions?: {
headers?: RawHttpHeadersInput;
allowInsecureConnection?: boolean;
skipUrlEncoding?: boolean;
onResponse?: (response: HttpResponse) => void;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Licensed under the MIT license.

import { KeyCredential } from "@azure/core-auth";
import { ClientOptions } from "./common/interfaces.js";
import {
createEventGrid,
EventGridContext,
EventGridClientOptions,
CloudEvent,
ReceiveResult,
AcknowledgeResult,
Expand All @@ -25,18 +25,21 @@ import {
RejectCloudEventsOptions,
} from "./api/index.js";

export { EventGridClientOptions } from "./api/EventGridContext.js";

export class EventGridClient {
private _client: EventGridContext;

/** Azure Messaging EventGrid Client */
constructor(
endpoint: string,
credential: KeyCredential,
options: ClientOptions = {}
options: EventGridClientOptions = {}
) {
this._client = createEventGrid(endpoint, credential, options);
}

/** 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. */
publishCloudEvent(
event: CloudEvent,
topicName: string,
Expand All @@ -45,6 +48,7 @@ export class EventGridClient {
return publishCloudEvent(this._client, event, topicName, options);
}

/** 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. */
publishCloudEvents(
events: CloudEvent[],
topicName: string,
Expand All @@ -53,6 +57,7 @@ export class EventGridClient {
return publishCloudEvents(this._client, events, topicName, options);
}

/** Receive Batch of Cloud Events from the Event Subscription. */
receiveCloudEvents(
topicName: string,
eventSubscriptionName: string,
Expand All @@ -66,6 +71,7 @@ export class EventGridClient {
);
}

/** 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. */
acknowledgeCloudEvents(
lockTokens: string[],
topicName: string,
Expand All @@ -81,6 +87,7 @@ export class EventGridClient {
);
}

/** 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. */
releaseCloudEvents(
lockTokens: string[],
topicName: string,
Expand All @@ -96,6 +103,7 @@ export class EventGridClient {
);
}

/** Reject batch of Cloud Events. */
rejectCloudEvents(
lockTokens: string[],
topicName: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
// Licensed under the MIT license.

import { EventGridContext } from "../rest/index.js";
import { ClientOptions } from "@azure-rest/core-client";
import { KeyCredential } from "@azure/core-auth";
import getClient from "../rest/index.js";
import { ClientOptions } from "../common/interfaces.js";

export { EventGridContext } from "../rest/index.js";

export interface EventGridClientOptions extends ClientOptions {}

/** Azure Messaging EventGrid Client */
export function createEventGrid(
endpoint: string,
credential: KeyCredential,
options: ClientOptions = {}
options: EventGridClientOptions = {}
): EventGridContext {
const baseUrl = endpoint;
options.credentials = {
Expand Down
Loading

0 comments on commit df35b83

Please sign in to comment.