Skip to content

Commit e785df6

Browse files
fixes around methods and url-encoded body
1 parent d04d92e commit e785df6

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

src/serializers/swagger/v2.0/Serializer.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ methods.isBodyParameter = (parameter) => {
693693
const isUrlEncoded = parameter.isValid(
694694
new Parameter({
695695
key: 'Content-Type',
696-
default: 'multipart/form-data'
696+
default: 'application/x-www-form-urlencoded'
697697
})
698698
)
699699

@@ -1334,7 +1334,8 @@ methods.convertRequestToOperationObject = (store, { consumes, produces }, reques
13341334
}
13351335

13361336
const value = operation
1337-
return { key: key.toLowerCase(), value }
1337+
const method = request.get('method') || key
1338+
return { key: method.toLowerCase(), value }
13381339
}
13391340
/* eslint-enable max-statements */
13401341

src/serializers/swagger/v2.0/__tests__/Serializer.spec.js

+65
Original file line numberDiff line numberDiff line change
@@ -2275,6 +2275,71 @@ describe('serializers/swagger/v2.0/Serializer.js', () => {
22752275

22762276
expect(actual).toEqual(expected)
22772277
})
2278+
2279+
it('should work if underlying methods are correct and with request method', () => {
2280+
spyOn(__internals__, 'getTagStrings').andReturn([ 'pet', 'store' ])
2281+
spyOn(__internals__, 'getKeysFromRecord').andReturn({
2282+
summary: 'update a Pet',
2283+
description: 'updates a pet with some params',
2284+
operationId: 'updatePet'
2285+
})
2286+
2287+
spyOn(__internals__, 'getConsumesEntry').andReturn([ 'application/json' ])
2288+
spyOn(__internals__, 'getProducesEntry').andReturn([ 'application/xml' ])
2289+
spyOn(__internals__, 'getParametersFromRequest').andReturn([ {
2290+
in: 'query',
2291+
name: 'petId',
2292+
type: 'string'
2293+
} ])
2294+
spyOn(__internals__, 'getSchemesFromRequestEndpointOverlay').andReturn([ 'https' ])
2295+
spyOn(__internals__, 'getSecurityRequirementsFromRequest').andReturn([
2296+
{
2297+
petstore_auth: [ 'write:self' ]
2298+
}
2299+
])
2300+
spyOn(__internals__, 'getResponsesFromRequest').andReturn({
2301+
'200': {
2302+
description: 'this method should return 200'
2303+
}
2304+
})
2305+
2306+
const store = new Store()
2307+
const globalInfo = {}
2308+
const request = new Request({ method: 'Get' })
2309+
const key = 'put'
2310+
2311+
const expectedValue = {
2312+
tags: [ 'pet', 'store' ],
2313+
summary: 'update a Pet',
2314+
description: 'updates a pet with some params',
2315+
operationId: 'updatePet',
2316+
consumes: [ 'application/json' ],
2317+
produces: [ 'application/xml' ],
2318+
parameters: [
2319+
{
2320+
in: 'query',
2321+
name: 'petId',
2322+
type: 'string'
2323+
}
2324+
],
2325+
schemes: [ 'https' ],
2326+
security: [
2327+
{
2328+
petstore_auth: [ 'write:self' ]
2329+
}
2330+
],
2331+
responses: {
2332+
'200': {
2333+
description: 'this method should return 200'
2334+
}
2335+
}
2336+
}
2337+
2338+
const expected = { key: 'get', value: expectedValue }
2339+
const actual = __internals__.convertRequestToOperationObject(store, globalInfo, request, key)
2340+
2341+
expect(actual).toEqual(expected)
2342+
})
22782343
/* eslint-enable max-statements */
22792344
})
22802345

0 commit comments

Comments
 (0)