Skip to content

Commit

Permalink
Try not flatten payload (Azure#2020)
Browse files Browse the repository at this point in the history
* try-not-flatten-payload

* fix tests

* should not generate duplicate models and should not generate body schema properties in options

* fix model property as path parameter

* format

* fix ci

* add ut for alias flattening

* add ut for not flatten if spread models

* add deserialize for flattened body

* enable cadl ranch test for spread in modular
  • Loading branch information
qiaozha authored and jeremymeng committed Sep 27, 2023
1 parent e2cd180 commit c3e495a
Show file tree
Hide file tree
Showing 88 changed files with 2,216 additions and 1,258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import { KeyCredential } from '@azure/core-auth';
import { OperationOptions } from '@azure-rest/core-client';
import { TokenCredential } from '@azure/core-auth';

// @public
export interface AddOrUpdateBlockItemsOptions {
blockItems: TextBlockItemInfo[];
}

// @public (undocumented)
export interface AddOrUpdateBlockItemsRequestOptions extends OperationOptions {
}
Expand All @@ -18,13 +23,18 @@ export interface AddOrUpdateBlockItemsResult {
value?: TextBlockItem[];
}

// @public
export interface AnalyzeImageOptions {
categories?: ImageCategory[];
image: ImageData_2;
outputType?: AnalyzeImageOutputType;
}

// @public
export type AnalyzeImageOutputType = string;

// @public (undocumented)
export interface AnalyzeImageRequestOptions extends OperationOptions {
categories?: ImageCategory[];
outputType?: AnalyzeImageOutputType;
}

// @public
Expand All @@ -33,14 +43,19 @@ export interface AnalyzeImageResult {
}

// @public
export type AnalyzeTextOutputType = string;

// @public (undocumented)
export interface AnalyzeTextRequestOptions extends OperationOptions {
export interface AnalyzeTextOptions {
blocklistNames?: string[];
breakByBlocklists?: boolean;
categories?: TextCategory[];
outputType?: AnalyzeTextOutputType;
text: string;
}

// @public
export type AnalyzeTextOutputType = string;

// @public (undocumented)
export interface AnalyzeTextRequestOptions extends OperationOptions {
}

// @public
Expand All @@ -52,16 +67,16 @@ export interface AnalyzeTextResult {
// @public (undocumented)
export class ContentSafetyClient {
constructor(endpoint: string, credential: KeyCredential | TokenCredential, options?: ContentSafetyClientOptions);
addOrUpdateBlockItems(blockItems: TextBlockItemInfo[], blocklistName: string, options?: AddOrUpdateBlockItemsRequestOptions): Promise<AddOrUpdateBlockItemsResult>;
analyzeImage(image: ImageData_2, options?: AnalyzeImageRequestOptions): Promise<AnalyzeImageResult>;
analyzeText(text: string, options?: AnalyzeTextRequestOptions): Promise<AnalyzeTextResult>;
createOrUpdateTextBlocklist(blocklistName: string, options?: CreateOrUpdateTextBlocklistOptions): Promise<TextBlocklist>;
addOrUpdateBlockItems(blocklistName: string, body: AddOrUpdateBlockItemsOptions, options?: AddOrUpdateBlockItemsRequestOptions): Promise<AddOrUpdateBlockItemsResult>;
analyzeImage(body: AnalyzeImageOptions, options?: AnalyzeImageRequestOptions): Promise<AnalyzeImageResult>;
analyzeText(body: AnalyzeTextOptions, options?: AnalyzeTextRequestOptions): Promise<AnalyzeTextResult>;
createOrUpdateTextBlocklist(blocklistName: string, resource: TextBlocklist, options?: CreateOrUpdateTextBlocklistOptions): Promise<TextBlocklist>;
deleteTextBlocklist(blocklistName: string, options?: DeleteTextBlocklistOptions): Promise<void>;
getTextBlocklist(blocklistName: string, options?: GetTextBlocklistOptions): Promise<TextBlocklist>;
getTextBlocklistItem(blocklistName: string, blockItemId: string, options?: GetTextBlocklistItemOptions): Promise<TextBlockItem>;
listTextBlocklistItems(blocklistName: string, options?: ListTextBlocklistItemsOptions): Promise<PagedTextBlockItem>;
listTextBlocklists(options?: ListTextBlocklistsOptions): Promise<PagedTextBlocklist>;
removeBlockItems(blockItemIds: string[], blocklistName: string, options?: RemoveBlockItemsRequestOptions): Promise<void>;
removeBlockItems(blocklistName: string, body: RemoveBlockItemsOptions, options?: RemoveBlockItemsRequestOptions): Promise<void>;
}

// @public (undocumented)
Expand All @@ -71,7 +86,6 @@ export interface ContentSafetyClientOptions extends ClientOptions {
// @public (undocumented)
export interface CreateOrUpdateTextBlocklistOptions extends OperationOptions {
contentType?: string;
description?: string;
}

// @public (undocumented)
Expand Down Expand Up @@ -125,6 +139,11 @@ export interface PagedTextBlocklist {
value: TextBlocklist[];
}

// @public
export interface RemoveBlockItemsOptions {
blockItemIds: string[];
}

// @public (undocumented)
export interface RemoveBlockItemsRequestOptions extends OperationOptions {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

import { TokenCredential, KeyCredential } from "@azure/core-auth";
import {
AnalyzeTextOptions,
AnalyzeTextResult,
ImageData,
AnalyzeImageOptions,
AnalyzeImageResult,
TextBlocklist,
TextBlockItemInfo,
AddOrUpdateBlockItemsOptions,
AddOrUpdateBlockItemsResult,
TextBlockItem,
RemoveBlockItemsOptions,
PagedTextBlocklist,
PagedTextBlockItem,
} from "./models/models.js";
Expand Down Expand Up @@ -57,18 +59,18 @@ export class ContentSafetyClient {

/** A sync API for harmful content analysis for text. Currently, we support four categories: Hate, SelfHarm, Sexual, Violence. */
analyzeText(
text: string,
body: AnalyzeTextOptions,
options: AnalyzeTextRequestOptions = { requestOptions: {} }
): Promise<AnalyzeTextResult> {
return analyzeText(this._client, text, options);
return analyzeText(this._client, body, options);
}

/** A sync API for harmful content analysis for image. Currently, we support four categories: Hate, SelfHarm, Sexual, Violence. */
analyzeImage(
image: ImageData,
body: AnalyzeImageOptions,
options: AnalyzeImageRequestOptions = { requestOptions: {} }
): Promise<AnalyzeImageResult> {
return analyzeImage(this._client, image, options);
return analyzeImage(this._client, body, options);
}

/** Returns text blocklist details. */
Expand All @@ -82,9 +84,15 @@ export class ContentSafetyClient {
/** Updates a text blocklist, if blocklistName does not exist, create a new blocklist. */
createOrUpdateTextBlocklist(
blocklistName: string,
resource: TextBlocklist,
options: CreateOrUpdateTextBlocklistOptions = { requestOptions: {} }
): Promise<TextBlocklist> {
return createOrUpdateTextBlocklist(this._client, blocklistName, options);
return createOrUpdateTextBlocklist(
this._client,
blocklistName,
resource,
options
);
}

/** Deletes a text blocklist. */
Expand All @@ -104,25 +112,20 @@ export class ContentSafetyClient {

/** Add or update blockItems to a text blocklist. You can add or update at most 100 BlockItems in one request. */
addOrUpdateBlockItems(
blockItems: TextBlockItemInfo[],
blocklistName: string,
body: AddOrUpdateBlockItemsOptions,
options: AddOrUpdateBlockItemsRequestOptions = { requestOptions: {} }
): Promise<AddOrUpdateBlockItemsResult> {
return addOrUpdateBlockItems(
this._client,
blockItems,
blocklistName,
options
);
return addOrUpdateBlockItems(this._client, blocklistName, body, options);
}

/** Remove blockItems from a text blocklist. You can remove at most 100 BlockItems in one request. */
removeBlockItems(
blockItemIds: string[],
blocklistName: string,
body: RemoveBlockItemsOptions,
options: RemoveBlockItemsRequestOptions = { requestOptions: {} }
): Promise<void> {
return removeBlockItems(this._client, blockItemIds, blocklistName, options);
return removeBlockItems(this._client, blocklistName, body, options);
}

/** Get blockItem By blockItemId from a text blocklist. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// Licensed under the MIT license.

import {
AnalyzeTextOptions,
AnalyzeTextResult,
ImageData,
AnalyzeImageOptions,
AnalyzeImageResult,
TextBlocklist,
TextBlockItemInfo,
AddOrUpdateBlockItemsOptions,
AddOrUpdateBlockItemsResult,
TextBlockItem,
RemoveBlockItemsOptions,
PagedTextBlocklist,
PagedTextBlockItem,
} from "../models/models.js";
Expand Down Expand Up @@ -57,19 +59,19 @@ import {

export function _analyzeTextSend(
context: Client,
text: string,
body: AnalyzeTextOptions,
options: AnalyzeTextRequestOptions = { requestOptions: {} }
): StreamableMethod<AnalyzeText200Response | AnalyzeTextDefaultResponse> {
return context
.path("/text:analyze")
.post({
...operationOptionsToRequestParameters(options),
body: {
text: text,
categories: options?.categories,
blocklistNames: options?.blocklistNames,
breakByBlocklists: options?.breakByBlocklists,
outputType: options?.outputType,
text: body["text"],
categories: body["categories"],
blocklistNames: body["blocklistNames"],
breakByBlocklists: body["breakByBlocklists"],
outputType: body["outputType"],
},
});
}
Expand Down Expand Up @@ -99,16 +101,16 @@ export async function _analyzeTextDeserialize(
/** A sync API for harmful content analysis for text. Currently, we support four categories: Hate, SelfHarm, Sexual, Violence. */
export async function analyzeText(
context: Client,
text: string,
body: AnalyzeTextOptions,
options: AnalyzeTextRequestOptions = { requestOptions: {} }
): Promise<AnalyzeTextResult> {
const result = await _analyzeTextSend(context, text, options);
const result = await _analyzeTextSend(context, body, options);
return _analyzeTextDeserialize(result);
}

export function _analyzeImageSend(
context: Client,
image: ImageData,
body: AnalyzeImageOptions,
options: AnalyzeImageRequestOptions = { requestOptions: {} }
): StreamableMethod<AnalyzeImage200Response | AnalyzeImageDefaultResponse> {
return context
Expand All @@ -118,13 +120,13 @@ export function _analyzeImageSend(
body: {
image: {
content:
image["content"] !== undefined
? uint8ArrayToString(image["content"], "base64")
body.image["content"] !== undefined
? uint8ArrayToString(body.image["content"], "base64")
: undefined,
blobUrl: image["blobUrl"],
blobUrl: body.image["blobUrl"],
},
categories: options?.categories,
outputType: options?.outputType,
categories: body["categories"],
outputType: body["outputType"],
},
});
}
Expand All @@ -147,10 +149,10 @@ export async function _analyzeImageDeserialize(
/** A sync API for harmful content analysis for image. Currently, we support four categories: Hate, SelfHarm, Sexual, Violence. */
export async function analyzeImage(
context: Client,
image: ImageData,
body: AnalyzeImageOptions,
options: AnalyzeImageRequestOptions = { requestOptions: {} }
): Promise<AnalyzeImageResult> {
const result = await _analyzeImageSend(context, image, options);
const result = await _analyzeImageSend(context, body, options);
return _analyzeImageDeserialize(result);
}

Expand Down Expand Up @@ -192,6 +194,7 @@ export async function getTextBlocklist(
export function _createOrUpdateTextBlocklistSend(
context: Client,
blocklistName: string,
resource: TextBlocklist,
options: CreateOrUpdateTextBlocklistOptions = { requestOptions: {} }
): StreamableMethod<
| CreateOrUpdateTextBlocklist200Response
Expand All @@ -204,7 +207,7 @@ export function _createOrUpdateTextBlocklistSend(
...operationOptionsToRequestParameters(options),
contentType:
(options.contentType as any) ?? "application/merge-patch+json",
body: { description: options?.description },
body: { description: resource["description"] },
});
}

Expand All @@ -228,11 +231,13 @@ export async function _createOrUpdateTextBlocklistDeserialize(
export async function createOrUpdateTextBlocklist(
context: Client,
blocklistName: string,
resource: TextBlocklist,
options: CreateOrUpdateTextBlocklistOptions = { requestOptions: {} }
): Promise<TextBlocklist> {
const result = await _createOrUpdateTextBlocklistSend(
context,
blocklistName,
resource,
options
);
return _createOrUpdateTextBlocklistDeserialize(result);
Expand Down Expand Up @@ -312,8 +317,8 @@ export async function listTextBlocklists(

export function _addOrUpdateBlockItemsSend(
context: Client,
blockItems: TextBlockItemInfo[],
blocklistName: string,
body: AddOrUpdateBlockItemsOptions,
options: AddOrUpdateBlockItemsRequestOptions = { requestOptions: {} }
): StreamableMethod<
AddOrUpdateBlockItems200Response | AddOrUpdateBlockItemsDefaultResponse
Expand All @@ -326,7 +331,7 @@ export function _addOrUpdateBlockItemsSend(
.post({
...operationOptionsToRequestParameters(options),
body: {
blockItems: (blockItems ?? []).map((p) => ({
blockItems: (body["blockItems"] ?? []).map((p) => ({
description: p["description"],
text: p["text"],
})),
Expand Down Expand Up @@ -355,23 +360,23 @@ export async function _addOrUpdateBlockItemsDeserialize(
/** Add or update blockItems to a text blocklist. You can add or update at most 100 BlockItems in one request. */
export async function addOrUpdateBlockItems(
context: Client,
blockItems: TextBlockItemInfo[],
blocklistName: string,
body: AddOrUpdateBlockItemsOptions,
options: AddOrUpdateBlockItemsRequestOptions = { requestOptions: {} }
): Promise<AddOrUpdateBlockItemsResult> {
const result = await _addOrUpdateBlockItemsSend(
context,
blockItems,
blocklistName,
body,
options
);
return _addOrUpdateBlockItemsDeserialize(result);
}

export function _removeBlockItemsSend(
context: Client,
blockItemIds: string[],
blocklistName: string,
body: RemoveBlockItemsOptions,
options: RemoveBlockItemsRequestOptions = { requestOptions: {} }
): StreamableMethod<
RemoveBlockItems204Response | RemoveBlockItemsDefaultResponse
Expand All @@ -380,7 +385,7 @@ export function _removeBlockItemsSend(
.path("/text/blocklists/{blocklistName}:removeBlockItems", blocklistName)
.post({
...operationOptionsToRequestParameters(options),
body: { blockItemIds: blockItemIds },
body: { blockItemIds: body["blockItemIds"] },
});
}

Expand All @@ -397,14 +402,14 @@ export async function _removeBlockItemsDeserialize(
/** Remove blockItems from a text blocklist. You can remove at most 100 BlockItems in one request. */
export async function removeBlockItems(
context: Client,
blockItemIds: string[],
blocklistName: string,
body: RemoveBlockItemsOptions,
options: RemoveBlockItemsRequestOptions = { requestOptions: {} }
): Promise<void> {
const result = await _removeBlockItemsSend(
context,
blockItemIds,
blocklistName,
body,
options
);
return _removeBlockItemsDeserialize(result);
Expand Down
Loading

0 comments on commit c3e495a

Please sign in to comment.