Thomas
04/06/2023, 1:50 PMResponse body is incompatible with the response body schema in the spec file: should be objectI think there is something missing in the error message? What
should be object
?Thomas
04/06/2023, 1:53 PMStatus:200
Headers:
{
"Content-Type": "application/json"
}
Body:
{"foo":true}
API:
{
"foo": true
}
Thomas
04/06/2023, 2:00 PM{
"consumer": {
"name": "gem"
},
"provider": {
"name": "service"
},
"interactions": [
{
"description": "A request to fetch the user's example",
"providerState": "the required headers are passed to the request",
"request": {
"method": "get",
"path": "/v1/user/925888/example.json",
"headers": {
"Accept": "application/json"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "{\"foo\":true}"
}
},
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}
Timothy Jones
04/07/2023, 1:35 AMThomas
04/07/2023, 5:25 AMpact (1.63.0)
for ruby on the consumer side. The above pact is a bit simplified.Thomas
04/07/2023, 5:25 AMThomas
04/07/2023, 7:48 AMopenapi: 3.0.0
x-stoplight:
id: zri1hpqxajhkj
info:
title: internal.v1
version: '1.0'
description: Simply dummy `application/json` API.
servers:
- url: '<http://localhost:3000>'
paths:
'/v1/users/{userId}':
parameters:
- schema:
type: integer
name: userId
in: path
required: true
description: Id of an existing user.
get:
summary: Get User Info by User ID
tags: []
responses:
'200':
description: User Found
content:
application/json:
schema:
$ref: '#/components/schemas/User'
examples:
Example:
value:
id: 4711
first_name: Bob
email: <mailto:bob.doe@example.com|bob.doe@example.com>
email_verified: true
create_date: '2023-04-07'
operationId: get-users-userId
description: Retrieve the information of the user with the matching user ID.
x-internal: true
components:
schemas:
User:
title: User
type: object
x-examples:
Example:
id: 4711
first_name: Bob
email: <mailto:bob.doe@example.com|bob.doe@example.com>
email_verified: true
create_date: '2023-04-07'
x-internal: true
properties:
id:
type: integer
description: Unique identifier for the given user.
example: 4711
first_name:
type: string
example: Bob
email:
type: string
format: email
example: <mailto:bob.doe@example.com|bob.doe@example.com>
email_verified:
type: boolean
description: Set to true if the user's email has been verified.
default: true
create_date:
type: string
format: date
description: The date that the user was created.
example: '2023-04-07'
required:
- id
- first_name
- email
- email_verified
x-internal: true
Pact:
{
"consumer": {
"name": "sandbox-gem"
},
"provider": {
"name": "sandbox-service"
},
"interactions": [
{
"description": "A request to fetch a dummy user",
"providerState": "and the service returns successful response",
"request": {
"method": "get",
"path": "/v1/users/925888",
"headers": {
"Accept": "application/json"
}
},
"response": {
"status": 200,
"headers": {},
"body": "{\"id\":4711,\"first_name\":\"Bob\",\"email\":\"<mailto:bob.doe@example.com|bob.doe@example.com>\",\"email_verified\":true,\"create_date\":\"2023-04-07\"}"
}
}
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}
Pactflow validation result
response body is incompatible
Response body is incompatible with the response body schema in the spec file: should be object
Mismatched at:
[root].interactions[0].response.body
Thomas
04/07/2023, 7:49 AMThomas
04/07/2023, 8:01 AMThomas
04/07/2023, 9:03 AMapplication/vnd.api+json
) doesn't lead to the above error!
OAS:
openapi: 3.0.0
x-stoplight:
id: zri1hpqxajhkj
info:
title: internal.v1
version: '1.0'
description: 'Simply dummy `application/vnd.api+json` API. <https://jsonapi.org/>'
servers:
- url: '<http://localhost:3000>'
paths:
'/v1/users/{userId}':
parameters:
- schema:
type: integer
name: userId
in: path
required: true
description: Id of an existing user.
get:
summary: Get User Info by User ID
tags: []
responses:
'200':
description: User Found
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/User'
examples:
Example:
value:
data:
id: 4711
type: user
attributes:
email: <mailto:bob.doe@example.com|bob.doe@example.com>
email_verified: true
create_date: '2023-04-07'
operationId: get-users-userId
description: Retrieve the information of the user with the matching user ID.
x-internal: true
components:
schemas:
User:
title: User
type: object
x-examples:
Example:
data:
id: 4711
type: user
attributes:
email: <mailto:bob.doe@example.com|bob.doe@example.com>
email_verified: true
create_date: '2023-04-07'
x-internal: true
properties:
data:
type: object
required:
- id
- type
- attributes
properties:
id:
type: integer
example: 4711
type:
type: string
enum:
- user
example: user
attributes:
type: object
required:
- email
- email_verified
properties:
email:
type: string
format: email
example: <mailto:bob.doe@example.com|bob.doe@example.com>
email_verified:
type: boolean
default: true
create_date:
type: string
format: date
example: '2023-04-07'
required:
- data
x-internal: true
Pact:
{
"consumer": {
"name": "sandbox-gem"
},
"provider": {
"name": "sandbox-service"
},
"interactions": [
{
"description": "A request to fetch a dummy user",
"providerState": "and the service returns successful response",
"request": {
"method": "get",
"path": "/v1/users/925888",
"headers": {
"Accept": "application/vnd.api+json"
}
},
"response": {
"status": 200,
"headers": {},
"body": "{\"data\":{\"id\":4711,\"type\":\"user\",\"attributes\":{\"email\":\"<mailto:bob.doe@example.com|bob.doe@example.com>\",\"email_verified\":true,\"create_date\":\"2023-04-07\"}}}"
}
}
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}
Thomas
04/07/2023, 9:17 AMapplication/hal+json
also works, but I haven't investigated that in depth.Matt (pactflow.io / pact-js / pact-go)
response.body
property is escaped JSON, but it shouldn’t be if it is supposed to be a type of JSONMatt (pactflow.io / pact-js / pact-go)
Thomas
04/11/2023, 6:11 AMTheThank you for the hint. It wasn't clear for me, that this could be the issue. I'll try to generate a non-escaped version.property is escaped JSON, but it shouldn’t be if it is supposed to be a type of JSONresponse.body
Matt (pactflow.io / pact-js / pact-go)
Thomas
04/11/2023, 6:22 AMThomas
04/11/2023, 6:24 AMHow are you generated that?We use pact-ruby for testing the consumer contract. There I used a ruby hash for the response body and called
.json
on it. This resulted in the escaped JSON string in the pact.
I would expect a warning from pact-ruby
in this case.Matt (pactflow.io / pact-js / pact-go)
Thomas
04/11/2023, 6:33 AMThomas
04/11/2023, 7:21 AMResponse body is incompatible with the response body schema in the spec file: should be objectFor me "Response body is incompatible with the response body schema in the spec file: The response body should be a JSON object, but is as (JSON) string" would be more clear and helpful.
Timothy Jones
04/11/2023, 7:21 AMMatt (pactflow.io / pact-js / pact-go)