No schema found for response body

Issue #96 new
Former user created an issue

pact.json

{
  "provider": {
    "name": "product-service"
  },
  "consumer": {
    "name": "customer-service"
  },
  "interactions": [
    {
      "description": "Test for productById",
      "request": {
        "method": "GET",
        "path": "/product/23",
        "matchingRules": {
          "path": {
            "matchers": [
              {
                "match": "regex",
                "regex": "/product/[0-9]+"
              }
            ],
            "combine": "AND"
          }
        }
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json; charset=UTF-8"
        },
        "body": {
          "price": "21.03",
          "name": "nexus",
          "type": "smartphone"
        },
        "matchingRules": {
          "body": {
            "$.name": {
              "matchers": [
                {
                  "match": "type"
                }
              ],
              "combine": "AND"
            },
            "$.type": {
              "matchers": [
                {
                  "match": "type"
                }
              ],
              "combine": "AND"
            },
            "$.price": {
              "matchers": [
                {
                  "match": "type"
                }
              ],
              "combine": "AND"
            }
          },
          "header": {
            "Content-Type": {
              "matchers": [
                {
                  "match": "regex",
                  "regex": "application/json(;\\s?charset=[\\w\\-]+)?"
                }
              ],
              "combine": "AND"
            }
          }
        }
      },
      "providerStates": [
        {
          "name": "Product with Id: 123"
        }
      ]
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "3.0.0"
    },
    "pact-jvm": {
      "version": "4.0.10"
    }
  }
}

open-api.json

{
    "openapi": "3.0.1",
    "info": {
        "title": "OpenAPI definition",
        "version": "v0"
    },
    "servers": [
        {
            "url": "http://localhost:8080/",
            "description": "Generated server url"
        }
    ],
    "paths": {
        "/product/{id}": {
            "get": {
                "tags": [
                    "product-controller"
                ],
                "operationId": "getProductById",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer",
                            "format": "int32"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "*/*": {
                                "schema": {
                                    "$ref": "#/components/schemas/ProductDto"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "ProductDto": {
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "type": {
                        "type": "string"
                    },
                    "price": {
                        "type": "string"
                    }
                }
            }
        }
    }
}

Error:

Mock file ".\customer-service-product-service.json" is not compatible with spec file "http://localhost:8080/v3/api-docs/"
1 error(s)
        response.body.unknown: 1
0 warning(s)
{
  warnings: [],
  errors: [
    {
      code: 'response.body.unknown',
      message: 'No schema found for response body',
      mockDetails: {
        interactionDescription: 'Test for productById',
        interactionState: '[none]',
        location: '[root].interactions[0].response.body',
        mockFile: '.\\customer-service-product-service.json',
        value: { price: '21.03', name: 'nexus', type: 'smartphone' }
      },
      source: 'spec-mock-validation',
      specDetails: {
        location: '[root].paths./product/{id}.get.responses.200',
        pathMethod: 'get',
        pathName: '/product/{id}',
        specFile: 'http://localhost:8080/v3/api-docs/',
        value: { description: 'OK', content: [Object] }
      },
      type: 'error'
    }
  ]
}

Error: Mock file ".\customer-service-product-service.json" is not compatible with spec file "http://localhost:8080/v3/api-docs/"
    at C:\Users\crisc\Desktop\contract test\swagger-mock-validator\dist\cli.js:85:36
    at Generator.next (<anonymous>)
    at fulfilled (C:\Users\crisc\Desktop\contract test\swagger-mock-validator\dist\cli.js:6:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Why can't you find the schema?

Comments (0)

  1. Log in to comment