Hello, I am using Pactflow and specifically Bi-dir...
# pactflow
n
Hello, I am using Pactflow and specifically Bi-directional testing and I am running into an interesting error during contract comparison. The error I am running into is:
Copy code
Validator Error
can't resolve reference #components/schemas/class from id #
Here is the api spec:
Copy code
openapi: 3.0.0
info:
  title: "API"
  version: "1.0.0"
components:
  schemas:
    class: 
      type: object
      properties:
        attempted:
          type: boolean
paths:
  /api/v1/instructor/me:
    get:
      tags:
        - Instructor
      description: This will fetch a users classes.
      responses:
        200:
          description: You have successfully found all classes and their status for the current user
          content:
            application/json:
              schema:
                type: object
                properties:
                  Classes:
                    type: array
                    items:
                      $ref: '#components/schemas/class'  
                  Elem:
                    type: array
                    items:
                      $ref: '#components/schemas/class'
                  Trainings:
                    type: array
                    items:
                      $ref: '#components/schemas/class'
                  Sela:
                    type: array
                    items:
                      $ref: '#components/schemas/class'
                  SelaFT:
                    type: array
                    items:
                      $ref: '#components/schemas/class'
        401:
          description: Unauthorized
And here is the consumer contract:
Copy code
{
  "consumer": {
    "name": "Consumer"
  },
  "provider": {
    "name": "Provider"
  },
  "interactions": [
    {
      "description": "A request for a single user classes",
      "providerState": "User exists with no classes",
      "request": {
        "method": "GET",
        "path": "/api/v1/instructor/me",
        "headers": {
          "Authorization": "Bearer undefined",
          "Accept": "application/json, text/plain, */*",
          "Cache-Control": "no-cache"
        }
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json; charset=utf-8 "
        },
        "body": {
          "Classes": [],
          "Elementary": [],
          "Sela": [],
          "SelaFT": [],
          "Trainings": []
        }
      }
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "2.0.0"
    }
  }
}
Hoping to get some guidance as to why I might be receiving this error. I have validated the Spec. One thing I was curious about is I am using the the pact specification of
2.0.0
on the consumer side. Should I be using
3.0.0
? Thank you!!!
y
Hey @Nigel Finley Top marks for providing your spec + pact! Your OAS is incorrect, just popped it into https://editor.swagger.io/ Your refs should be
$ref: '#/components/schemas/class'
The pact will return an error, as it specifies the field
Elementary
but your spec states
Elem
Best of luck in your bi-directional journey buddy
reference docs on ref usage 🙂 https://swagger.io/docs/specification/using-ref/
n
Thank you so much for the speedy reply!!! Amazing!!! 🙏
🙌 1
Its always the smallest errors that create the biggest thorns 🙂
1000000 1
y
I wrote a blog post about not trusting an OpenAPI spec until you've ran it through it an validator, the online swagger editor is a nice quick go to 🙂 glad you are sorted for now
👍 1