Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function HttpRequestParametersExpression(props: HttpRequestParametersExpr

if (propertyExpression.isNullish) {
return code`
...(${propertyExpression.fullExpression} && {${(<JsonTransform itemRef={propertyExpression.leadingExpression} type={httpProperty.property} target="transport" />)}})
...(${propertyExpression.fullExpression} != undefined && {${(<JsonTransform itemRef={propertyExpression.leadingExpression} type={httpProperty.property} target="transport" />)}})
`;
} else {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function defaultEncoding(
const path = parse("/default").expand({});
const httpRequestOptions = {
headers: {
...(options?.value && {
...(options?.value != undefined && {
value: encodeUint8Array(options.value, "base64")!,
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export async function defaultEncoding(
const path = parse("/default").expand({});
const httpRequestOptions = {
headers: {
...(options?.value && { value: dateRfc7231Serializer(options.value) }),
...(options?.value != undefined && {
value: dateRfc7231Serializer(options.value),
}),
},
};
const response = await client.pathUnchecked(path).get(httpRequestOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export async function defaultEncoding(
options?: DefaultEncodingOptions,
): Promise<void> {
const path = parse("/default{?value}").expand({
...(options?.value && { value: dateRfc3339Serializer(options.value) }),
...(options?.value != undefined && {
value: dateRfc3339Serializer(options.value),
}),
});
const httpRequestOptions = {
headers: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,55 @@ export async function read(
throw createRestError(response);
}
```

# Should preserve falsy optional HTTP parameters

This test verifies optional query and header parameters are emitted when their value is falsy but present.

## TypeSpec

```tsp
@service(#{ title: "Widget Service" })
namespace DemoService;

@route("/widgets")
@tag("Widgets")
interface Widgets {
@test
@get
read(
@query isActive?: boolean,
@query count?: int32,
@query filter?: string,
@header ifMatch?: string,
): void;
}
```

## TypeScript

### Request

```ts src/api/widgetsClient/widgetsClientOperations.ts function read
export async function read(client: WidgetsClientContext, options?: ReadOptions): Promise<void> {
const path = parse("/widgets{?isActive,count,filter}").expand({
...(options?.isActive != undefined && { isActive: options.isActive }),
...(options?.count != undefined && { count: options.count }),
...(options?.filter != undefined && { filter: options.filter }),
});
const httpRequestOptions = {
headers: {
...(options?.ifMatch != undefined && { "if-match": options.ifMatch }),
},
};
const response = await client.pathUnchecked(path).get(httpRequestOptions);

if (typeof options?.operationOptions?.onResponse === "function") {
options?.operationOptions?.onResponse(response);
}
if (+response.status === 204 && !response.body) {
return;
}
throw createRestError(response);
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function link(
async function linkSend(client: TestClientContext, filter: string, options?: Record<string, any>) {
const path = parse("/link{?filter,nextToken}").expand({
filter: filter,
...(options?.nextToken && { nextToken: options.nextToken }),
...(options?.nextToken != undefined && { nextToken: options.nextToken }),
});
const httpRequestOptions = {
headers: {},
Expand Down Expand Up @@ -174,7 +174,9 @@ export function link(
async function linkSend(client: TestClientContext, filter: string, options?: Record<string, any>) {
const path = parse("/link{?filter,maxPageSize}").expand({
filter: filter,
...(options?.maxPageSize && { maxPageSize: options.maxPageSize }),
...(options?.maxPageSize != undefined && {
maxPageSize: options.maxPageSize,
}),
});
const httpRequestOptions = {
headers: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function headModel(
const path = parse("/").expand({});
const httpRequestOptions = {
headers: {
...(input.foo && { foo: input.foo }),
...(input.foo != undefined && { foo: input.foo }),
},
body: jsonVisibilityModelToTransportTransform(input),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function create(
const path = parse("/").expand({});
const httpRequestOptions = {
headers: {
...(widget.foo && { foo: widget.foo }),
...(widget.foo != undefined && { foo: widget.foo }),
},
body: {
id: widget.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function create(
const path = parse("/").expand({});
const httpRequestOptions = {
headers: {
...(options?.foo && { foo: options.foo }),
...(options?.foo != undefined && { foo: options.foo }),
},
body: jsonWidgetToTransportTransform(widget),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function create(
const path = parse("/").expand({});
const httpRequestOptions = {
headers: {
...(widget.foo && { foo: widget.foo }),
...(widget.foo != undefined && { foo: widget.foo }),
},
body: jsonWidgetToTransportTransform(widget),
};
Expand Down