Milda
12/16/2024, 3:07 PMapplication/x-www-form-urlencoded request, it was defined as per the OAS3 spec (type: object, then key-value pairs as properties) and sent as key-value pairs, string format, by the consumer; i.e. "key=value&key2=value2".
Issue arose when adding a 2nd request body option for an application/json. Now, all of a sudden, the contract interaction that worked previously (for x-www-form-urlencoded) is failing, saying the request body must be an object. A new interaction for the application/json works (with a json request body), but the old one (form) does not.
Both application/json and application/x-www-form-urlencoded are expected to work, as long as one of them is provided for the POST request.
Any ideas on whether this is an error on our end or a bug in the swagger validator?
Relevant bits of code:
Consumer contract relevant part (looks the same when passing and when failing w/ application/json):
"request": {
"method": "post",
"path": "/transfers/create",
"headers": {
"X-Request-Id": "96c21705-fbea-4be0-8e3f-6b9543cad0d7",
"Content-Type": "application/x-www-form-urlencoded"
},
"body": "source_account_id=a66ca63f-e668-47af-8bb9-74363240d781&destination_account_id=22ed17b5-b90c-424e-aa78-d24928b1778e¤cy=USD&amount=150.00&reason=reason&unique_request_id=58e78791-e0e5-012c-2dee-001e52f3c730&request_id=96c21705-fbea-4be0-8e3f-6b9543cad0d7"
},
OAS schema old (worked)
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
request_id:
type: string
description: The request ID used for tracing requests set in the request body
principal_identifier:
$ref: "#/components/schemas/PrincipalIdentifier"
source_account_id:
description: Account UUID of the paying account.
type: string
format: uuid
destination_account_id:
description: Account UUID of the receiving account.
type: string
format: uuid
currency:
description: Three-letter ISO currency code.
type: string
pattern: '^[A-Z]{3}$'
amount:
description: Amount
type: string
format: decimal
pattern: '^(\d+(\.\d{1,3})?)$'
reason:
description: User-generated reason for transfer, freeform text.
type: string
maxLength: 255
unique_request_id:
description: User-generated idempotency key. The value must be 100 characters or fewer.
type: string
maxLength: 100
required:
- source_account_id
- destination_account_id
- currency
- amount
New schema reuses the same schema, just adding an extra content type, i.e.
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
$ref: "#/components/schemas/<schema>"
application/json:
schema:
$ref: "#/components/schemas/<schema>"
error:
Request body is incompatible with the request body schema in the spec file: must be object
Ta!Matt (pactflow.io / pact-js / pact-go)
x-www-form-urlencoded bodies, at least not according to our docs:Matt (pactflow.io / pact-js / pact-go)
Milda
12/17/2024, 11:45 AMMatt (pactflow.io / pact-js / pact-go)
Milda
12/17/2024, 11:47 AMMatt (pactflow.io / pact-js / pact-go)
Milda
12/17/2024, 11:50 AMMatt (pactflow.io / pact-js / pact-go)
Milda
12/17/2024, 11:58 AMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Milda
12/17/2024, 11:58 AMMatt (pactflow.io / pact-js / pact-go)
Milda
12/17/2024, 12:00 PMMilda
12/17/2024, 12:00 PMMilda
12/17/2024, 12:00 PMMilda
12/17/2024, 12:00 PMMilda
12/17/2024, 12:04 PMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Milda
01/13/2025, 9:26 AMMilda
01/16/2025, 1:43 PMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Milda
01/16/2025, 1:54 PMMilda
01/16/2025, 2:00 PMMilda
01/16/2025, 2:00 PMmust be object in pactflow and must match pattern for localMilda
01/16/2025, 2:00 PMRequest body is incompatible with the request body schema in the spec file: must be object
^ still seeing this in pactflowMatt (pactflow.io / pact-js / pact-go)
Milda
01/17/2025, 9:17 AMMilda
01/17/2025, 11:26 AMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Milda
01/20/2025, 9:07 AM