Skip to content

Commit

Permalink
proposal for add any overload for accept different header values
Browse files Browse the repository at this point in the history
  • Loading branch information
qiaozha committed Jun 3, 2024
1 parent 112fbbe commit 1a59763
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { PngImageAsJson } from "../../models/models.js";
import {
ContentNegotiationContext as Client,
DifferentBodyGetAvatarAsAny200Response,
DifferentBodyGetAvatarAsJson200Response,
DifferentBodyGetAvatarAsPng200Response,
} from "../../rest/index.js";
Expand All @@ -27,8 +28,7 @@ export function _getAvatarAsPngSend(
.get({
...operationOptionsToRequestParameters(options),
headers: {
accept:
options.requestOptions?.headers?.["accept"] ?? ("image/png" as any),
accept:"image/png",
},
}) as StreamableMethod<DifferentBodyGetAvatarAsPng200Response>;
}
Expand Down Expand Up @@ -60,11 +60,10 @@ export function _getAvatarAsJsonSend(
.get({
...operationOptionsToRequestParameters(options),
headers: {
accept:
options.requestOptions?.headers?.["accept"] ??
("application/json" as any),
accept: "application/json",
},
}) as unknown as StreamableMethod<DifferentBodyGetAvatarAsJson200Response>;
}) as StreamableMethod<DifferentBodyGetAvatarAsJson200Response>;
}

export async function _getAvatarAsJsonDeserialize(
result: DifferentBodyGetAvatarAsJson200Response,
Expand All @@ -88,3 +87,35 @@ export async function getAvatarAsJson(
const result = await _getAvatarAsJsonSend(context, options);
return _getAvatarAsJsonDeserialize(result);
}

export function _getAvatarAsAnySend(
context: Client,
options: DifferentBodyGetAvatarAsJsonOptionalParams = { requestOptions: {} },
): StreamableMethod<DifferentBodyGetAvatarAsAny200Response> {
return context
.path("/content-negotiation/different-body")
.get({
...operationOptionsToRequestParameters(options),
headers: {
accept: options.requestOptions?.headers?.["accept"] as any,
},
}) as StreamableMethod<DifferentBodyGetAvatarAsAny200Response>;
}

export async function getAvatarAsAny(
context: Client,
options: DifferentBodyGetAvatarAsJsonOptionalParams = { requestOptions: {} },
): Promise<any> {
const result = await _getAvatarAsAnySend(context, options);
return _getAvatarAsAnyDeserialize(result);
}

export async function _getAvatarAsAnyDeserialize(
result: DifferentBodyGetAvatarAsAny200Response,
): Promise<any> {
if (result.status !== "200") {
throw createRestError(result);
}

return result.body;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { PngImageAsJson } from "../../models/models.js";
import {
getAvatarAsPng,
getAvatarAsJson,
getAvatarAsAny,
} from "../../api/differentBody/index.js";
import {
DifferentBodyGetAvatarAsPngOptionalParams,
DifferentBodyGetAvatarAsJsonOptionalParams,
DifferentBodyGetAvatarAsAnyOptionalParams,
} from "../../models/options.js";

export interface DifferentBodyOperations {
Expand All @@ -19,6 +21,9 @@ export interface DifferentBodyOperations {
getAvatarAsJson: (
options?: DifferentBodyGetAvatarAsJsonOptionalParams,
) => Promise<PngImageAsJson>;
getAvatarAsAny: (
options?: DifferentBodyGetAvatarAsAnyOptionalParams,
) => Promise<any>;
}

export function getDifferentBody(context: ContentNegotiationContext) {
Expand All @@ -27,6 +32,8 @@ export function getDifferentBody(context: ContentNegotiationContext) {
getAvatarAsPng(context, options),
getAvatarAsJson: (options?: DifferentBodyGetAvatarAsJsonOptionalParams) =>
getAvatarAsJson(context, options),
getAvatarAsAny: (options: DifferentBodyGetAvatarAsAnyOptionalParams) =>
getAvatarAsAny(context, options),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ export interface DifferentBodyGetAvatarAsJsonOptionalParams
extends OperationOptions {
accept?: "application/json";
}

export interface DifferentBodyGetAvatarAsAnyOptionalParams
extends OperationOptions {
accept?: any;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import {
SameBodyGetAvatarAsJpegParameters,
DifferentBodyGetAvatarAsPngParameters,
DifferentBodyGetAvatarAsJsonParameters,
DifferentBodyGetAvatarAsAnyParameters,
} from "./parameters.js";
import {
SameBodyGetAvatarAsPng200Response,
SameBodyGetAvatarAsJpeg200Response,
DifferentBodyGetAvatarAsPng200Response,
DifferentBodyGetAvatarAsJson200Response,
DifferentBodyGetAvatarAsAny200Response,
} from "./responses.js";
import { Client, StreamableMethod } from "@azure-rest/core-client";

Expand All @@ -25,12 +27,15 @@ export interface SameBodyGetAvatarAsPng {
}

export interface DifferentBodyGetAvatarAsPng {
get(
options: DifferentBodyGetAvatarAsJsonParameters,
): StreamableMethod<DifferentBodyGetAvatarAsJson200Response>;
get(
options: DifferentBodyGetAvatarAsPngParameters,
): StreamableMethod<DifferentBodyGetAvatarAsPng200Response>;
get(
options: DifferentBodyGetAvatarAsJsonParameters,
): StreamableMethod<DifferentBodyGetAvatarAsJson200Response>;
options: DifferentBodyGetAvatarAsAnyParameters,
): StreamableMethod<DifferentBodyGetAvatarAsAny200Response>;
}

export interface Routes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,14 @@ export interface DifferentBodyGetAvatarAsJsonHeaderParam {

export type DifferentBodyGetAvatarAsJsonParameters =
DifferentBodyGetAvatarAsJsonHeaderParam & RequestParameters;

export interface DifferentBodyGetAvatarAsAnyHeaders {
accept: any;
}

export interface DifferentBodyGetAvatarAsAnyHeaderParam {
headers: RawHttpHeadersInput & DifferentBodyGetAvatarAsAnyHeaders;
}

export type DifferentBodyGetAvatarAsAnyParameters =
DifferentBodyGetAvatarAsAnyHeaderParam & RequestParameters;
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ export interface DifferentBodyGetAvatarAsJson200Response extends HttpResponse {
status: "200";
body: PngImageAsJsonOutput;
}

export interface DifferentBodyGetAvatarAsAny200Response extends HttpResponse {
status: "200";
/** Value may contain any sequence of octets */
body: any;
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ describe("Payload Content Negotiation Client", () => {
pngFile.toString()
);
});

it("should get application/json for different body in content negotiation", async () => {
const result = await client.differentBody.getAvatarAsAny({
accept: "wrongType"
});
assert.strictEqual(
uint8ArrayToString(result.content, "utf-8"),
pngFile.toString()
);
});
});

0 comments on commit 1a59763

Please sign in to comment.