InversifyJS icon indicating copy to clipboard operation
InversifyJS copied to clipboard

[inversify-express-utils] JsonContent incorrectly serialised as string

Open egmacke opened this issue 3 years ago • 0 comments

Reposting issue from invserify-express-utils here.

https://github.com/inversify/inversify-express-utils/issues/378

Expected Behavior

When using the BaseHttpController helper method BaseHttpController.json(...) the resulting express call coerces the json object to a string.

This causes problems when using express middleware that validates JSON responses (in this case using openapi-validator-middleware) as the data is no-longer a JSON object.

Current Behavior

Json content is sent as a string, which causes downstream middleware that expects Json content to fail.

Possible Solution

https://github.com/inversify/inversify-express-utils/pull/379

Context

Trying to use the openapi-validator-middleware library with the inversify express server and BaseHttpController.json().

The validator library expects content as JSON data, but the BaseHttpController.json function results in data being sent as a plain string. This causes the validator to skip checks on the result - rendering it useless.

egmacke avatar May 12 '22 09:05 egmacke