-
Notifications
You must be signed in to change notification settings - Fork 760
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(oas3-encoding): encode form-urlencoded array values as comma-sepa…
…rated values by default
- Loading branch information
Showing
2 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// https://github.com/swagger-api/swagger-ui/issues/4071 | ||
|
||
import expect, {createSpy, spyOn} from 'expect' | ||
import {execute, buildRequest, baseUrl, self as stubs} from '../../src/execute' | ||
|
||
const spec = { | ||
openapi: '3.0.0', | ||
servers: [ | ||
{ | ||
url: 'https://workbcjobs.api.gov.bc.ca/v1' | ||
} | ||
], | ||
paths: { | ||
'/jobs': { | ||
post: { | ||
operationId: 'postJobs', | ||
description: 'The job feed endpoint returns an array of job records that satisfy the supplied criteria.', | ||
responses: { | ||
default: { | ||
description: 'Unexpected error' | ||
} | ||
}, | ||
requestBody: { | ||
content: { | ||
'application/x-www-form-urlencoded': { | ||
schema: { | ||
type: 'object', | ||
properties: { | ||
industries: { | ||
type: 'array', | ||
items: { | ||
type: 'integer' | ||
} | ||
} | ||
} | ||
}, | ||
encoding: { | ||
industries: { | ||
style: 'form' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
it('should generate a request with application/x-www-form-urlencoded', function () { | ||
const req = buildRequest({ | ||
spec, | ||
requestContentType: 'application/x-www-form-urlencoded', | ||
operationId: 'postJobs', | ||
requestBody: { | ||
industries: [ | ||
1, | ||
16 | ||
] | ||
} | ||
}) | ||
|
||
expect(req).toEqual({ | ||
url: 'https://workbcjobs.api.gov.bc.ca/v1/jobs', | ||
method: 'POST', | ||
credentials: 'same-origin', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
body: 'industries=1%2C16' | ||
}) | ||
}) |