Skip to content

Fix null jsonBody serialization in HttpResponse #356

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 4 commits into
base: v4.x
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
3 changes: 1 addition & 2 deletions src/http/HttpResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { HttpResponseInit } from '@azure/functions';
import { Blob } from 'buffer';
import { ReadableStream } from 'stream/web';
import { FormData, Headers, Response as uResponse, ResponseInit as uResponseInit } from 'undici';
import { isDefined } from '../utils/nonNull';

interface InternalHttpResponseInit extends HttpResponseInit {
undiciResponse?: uResponse;
Expand All @@ -27,7 +26,7 @@ export class HttpResponse implements types.HttpResponse {
this.#uRes = init.undiciResponse;
} else {
const uResInit: uResponseInit = { status: init.status, headers: init.headers };
if (isDefined(init.jsonBody)) {
if (init.jsonBody !== undefined) {
this.#uRes = uResponse.json(init.jsonBody, uResInit);
} else {
this.#uRes = new uResponse(init.body, uResInit);
Expand Down
15 changes: 15 additions & 0 deletions test/converters/toRpcHttp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ describe('toRpcHttp', () => {
);
});

it('response class json null', async () => {
const result = await toRpcHttp('invocId', new HttpResponse({ jsonBody: null }));
expect(result).to.deep.equal(getExpectedRpcHttp('null', jsonHeaders));
});

it('response class json boolean false', async () => {
const result = await toRpcHttp('invocId', new HttpResponse({ jsonBody: false }));
expect(result).to.deep.equal(getExpectedRpcHttp('false', jsonHeaders));
});

it('response class json number zero', async () => {
const result = await toRpcHttp('invocId', new HttpResponse({ jsonBody: 0 }));
expect(result).to.deep.equal(getExpectedRpcHttp('0', jsonHeaders));
});

it('undefined', async () => {
const result = await toRpcHttp('invocId', {});
expect(result).to.deep.equal(getExpectedRpcHttp('', {}));
Expand Down
4 changes: 2 additions & 2 deletions types/InvocationContext.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export interface InvocationContextExtraInputs {
* @input the configuration object for this SQL input
*/
get(input: SqlInput): unknown;

/**
* Get a secondary MySql items input for this invocation
* @input the configuration object for this MySql input
Expand Down Expand Up @@ -223,7 +223,7 @@ export interface InvocationContextExtraOutputs {
* @message the output event(s) value
*/
set(output: EventGridOutput, events: EventGridPartialEvent | EventGridPartialEvent[]): void;

/**
* Set a secondary MySql items output for this invocation
* @output the configuration object for this MySql output
Expand Down
2 changes: 1 addition & 1 deletion types/input.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import { CosmosDBInput, CosmosDBInputOptions } from './cosmosDB';
import { GenericInputOptions } from './generic';
import { FunctionInput } from './index';
import { MySqlInput, MySqlInputOptions } from './mySql';
import { SqlInput, SqlInputOptions } from './sql';
import { StorageBlobInput, StorageBlobInputOptions } from './storage';
import { TableInput, TableInputOptions } from './table';
import { MySqlInput, MySqlInputOptions } from './mySql';
import {
WebPubSubConnectionInput,
WebPubSubConnectionInputOptions,
Expand Down
2 changes: 1 addition & 1 deletion types/output.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { EventHubOutput, EventHubOutputOptions } from './eventHub';
import { GenericOutputOptions } from './generic';
import { HttpOutput, HttpOutputOptions } from './http';
import { FunctionOutput } from './index';
import { MySqlOutput, MySqlOutputOptions } from './mySql';
import {
ServiceBusQueueOutput,
ServiceBusQueueOutputOptions,
Expand All @@ -16,7 +17,6 @@ import {
import { SqlOutput, SqlOutputOptions } from './sql';
import { StorageBlobOutput, StorageBlobOutputOptions, StorageQueueOutput, StorageQueueOutputOptions } from './storage';
import { TableOutput, TableOutputOptions } from './table';
import { MySqlOutput, MySqlOutputOptions } from './mySql';
import { WebPubSubOutput, WebPubSubOutputOptions } from './webpubsub';

/**
Expand Down