Skip to content
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

fix responding with application/json #604

Merged
merged 5 commits into from
Sep 17, 2019
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

# Unreleased

## Added

## Fixed

- Prism is now giving precedence to `application/json` instead of using it as a "fallback" serializer, fixing some conditions where it wouldn't get triggered correctly. #604

# 3.1.0 (2019-09-03)

## Added
Expand Down
2 changes: 1 addition & 1 deletion packages/http-server/src/__tests__/server.oas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ describe.each([['petstore.no-auth.oas2.yaml', 'petstore.no-auth.oas3.yaml']])('s
});

expect(response.statusCode).toBe(200);
expect(response.headers).toHaveProperty('content-type', 'application/json; charset=utf-8');
expect(response.headers).toHaveProperty('content-type', 'application/json');
});

it('respects the priority when multiple avaiable choices match', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/http-server/src/serializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const xmlSerializer = new j2xParser({});
export default [
{
regex: {
test: (value: string) => !!typeIs.is(value, ['application/*+json']),
test: (value: string) => !!typeIs.is(value, ['application/*+json', 'application/json']),
toString: () => 'application/*+json',
},
serializer: JSON.stringify,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mock -p 4010
curl -i -X GET http://localhost:4010/todos -H "accept: application/json"
====expect====
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
content-type: application/json
content-length: 7
Connection: keep-alive

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mock -p 4010
curl -i -X GET http://localhost:4010/todos -H "accept: application/json"
====expect====
HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
content-type: application/json
content-length: 7
Connection: keep-alive

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
====test====
Sending multiple values in Accept header selects the first one matched.
====spec====
swagger: "2.0"
paths:
/check-email:
get:
produces:
- application/json
- text/plain
responses:
200:
description: OK, the email is available
schema:
type: string
====server====
mock -p 4010
====command====
curl -i http://localhost:4010/check-email -H "Accept: application/json, text/plain, */*"
====expect====
HTTP/1.1 200 OK
content-type: application/json

"string"
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
====test====
Sending multiple values in Accept header selects the first one matched.
====spec====
openapi: 3.0.2
paths:
/check-email:
get:
responses:
200:
description: OK, the email is available
content:
application/json:
schema:
type: string
====server====
mock -p 4010
====command====
curl -i http://localhost:4010/check-email -H "Accept: application/json, text/plain, */*"
====expect====
HTTP/1.1 200 OK
content-type: application/json

"string"