Skip to content

Response header should be string in RLC #3110

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion packages/typespec-ts/src/transform/transformResponses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ function transformHeaders(
usage: [SchemaContext.Output],
relevantProperty: value
}) as Schema;
const type = getTypeName(typeSchema, [SchemaContext.Output]);
let type = getTypeName(typeSchema, [SchemaContext.Output]);
if (type !== "string") {
type = "string";
}
getImportedModelName(typeSchema, [SchemaContext.Output])?.forEach(
importedModels.add,
importedModels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,12 @@ describe("EncodeDatetimeClient Rest Client", () => {
assert.strictEqual(result.headers.value, "Fri, 26 Aug 2022 14:38:00 GMT");
});

//TODO revert this skipped case after merging https://github.com/microsoft/typespec/pull/6423
it.skip(`should get unix-timestamp header`, async () => {
it(`should get unix-timestamp header`, async () => {
const result = await client
.path(`/encode/datetime/responseheader/unix-timestamp`)
.get();
assert.strictEqual(result.status, "204");
assert.strictEqual(result.headers.value, 1686566864);
assert.strictEqual(result.headers.value, "1686566864");
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export declare interface ResponseHeaderUnixTimestamp {
}

export declare interface ResponseHeaderUnixTimestamp204Headers {
value: number;
value: string;
}

export declare interface ResponseHeaderUnixTimestamp204Response extends HttpResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,12 @@ describe("EncodeDatetimeClient Rest Client", () => {
assert.strictEqual(result.headers.value, "Fri, 26 Aug 2022 14:38:00 GMT");
});

//TODO revert this skipped case after merging https://github.com/microsoft/typespec/pull/6423
it.skip(`should get unix-timestamp header`, async () => {
it(`should get unix-timestamp header`, async () => {
const result = await client
.path(`/encode/datetime/responseheader/unix-timestamp`)
.get();
assert.strictEqual(result.status, "204");
assert.strictEqual(result.headers.value, 1686566864);
assert.strictEqual(result.headers.value, "1686566864");
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export declare interface ResponseHeaderUnixTimestamp {
}

export declare interface ResponseHeaderUnixTimestamp204Headers {
value: number;
value: string;
}

export declare interface ResponseHeaderUnixTimestamp204Response extends HttpResponse {
Expand Down
10 changes: 8 additions & 2 deletions packages/typespec-ts/test/unit/responsesGenerator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ describe("Responses.ts", () => {
);
});

it("should handle int/decimal/decimal128/int8 with encode `string` in response headers", async () => {
it.only("should handle int/decimal/decimal128/int8 with encode `string` in response headers", async () => {
const responses = await emitResponsesFromTypeSpec(
`
alias SimpleModel = {
Expand All @@ -257,6 +257,10 @@ describe("Responses.ts", () => {
@header
@encode(DurationKnownEncoding.seconds, float)
z: duration;
@header
number: int64;
@header
float: float;
};
@route("/decimal/prop/encode")
@get
Expand All @@ -278,7 +282,9 @@ describe("Responses.ts", () => {
"y": string;
"value": string;
"input": string;
"z": number;
"z": string;
"number": string;
"float": string;
}

/** The request has succeeded. */
Expand Down
Loading