For BDCT, we're having some trouble figuring out t...
# pactflow
w
For BDCT, we're having some trouble figuring out this error.
Copy code
Response body is incompatible with the response body schema in the spec file: should NOT have additional properties - id
Mismatched Pact Path:
[root].interactions[0].response.body.paymentMethods[0]
Mismatched Provider Path:
[root].paths./userprofile/v1/paymentmethods.get.responses.200.content.application/json.schema.properties.paymentMethods.items.additionalProperties
In our provider contract, if we follow the provider path, items can be
anyOf
, as seen below
Copy code
responses:
        '200':
          description: Successful response
          content:
            application/json: 
              schema:
                type: object
                properties:
                  paymentMethods:
                    type: array
                    items:
                      anyOf:
                        - $ref: '#/components/schemas/creditCard'
                        - $ref: '#/components/schemas/bankAccount'

 schemas:
    creditCard:
      type: object
      properties:
        id:
          type: integer
        userId:
          type: integer
        externalId:
          type: string
        type:
          type: string
        lastFour:
          type: string
        isPrimary:
          type: boolean
        issuer:
          type: string
        verificationStatus:
          type: string
        expiration:
          type: object
          properties:
            year:
              type: integer
            month:
              type: integer
We're wondering why the contract comparison can't find the schema definition?
paymentMethods[0]
is matching the credit card schema currently in our consumer contract As an aside, should BDCT questions be in #C5F4KFKR8 or #CLS16AVEE (since it's currently just a pactflow feature)?
y
Hey, some pointers here in the docs https://docs.pactflow.io/docs/bi-directional-contract-testing/contracts/oas#allof-support-and-other-logical-keywords Have you got the ref snippet for bankaccount? If it differs, your provider could only ever provide one response, and your consumer could require both, or one. BDC questions are best asked in here but appreciate it can be confusing, and some OSS users prefer not to see Pactflow messaging in general. I never minded personally prior to joining the team, but can appreciate and understand. Do you think a bi directional slack channel would be useful, especially given it is a big feature, and new so there is lots of overlap and interesting conversation that would be nice to group
w
Thanks for the response @Yousaf Nabi (pactflow.io). Yes, the bank account object is different
Copy code
bankAccount:
      type: object
      properties:
        id:
          type: integer
        userId:
          type: integer
        externalId:
          type: string
        type:
          type: string
        lastFour:
          type: string
        isPrimary:
          type: boolean
        issuer:
          type: string
        verificationStatus:
          type: string
Since Pact does not support those key words then, I assume we just don't want to contract test those use cases then? Or is there another route we should go? I think a separate BDCT channel would be super helpful since it is a big feature and the documentation is still limited
Full context: the end point is /getAllPaymentMethods and it can return a credit card, bank account object or both, or multiples of any of the above
y
Are you able to use CDCT with the traditional pact verifier flow on this endpoint or are you looking at BDCT only? With Pact CDCT, you can control the behaviour of the your provider, with provider states which would give you finer grained control of the provider response. You can run the bi directional validator locally, where you can control the flags to perform different validation behaviours. Pactflow is opinionated about its choice of flags, to prevent breaking changes that were not caught by the default behaviour of the original Atlassian tool. https://www.npmjs.com/package/@pactflow/swagger-mock-validator Not sure on the best advice at the moment but will noodle with the team and get back to you.
m
We really should be able to support the
anyOf
and
oneOf
operators. Unlike the
allOf
which I think is more problematic (albeit we could modify the behaviour to suit the standard use case), I think the validation behaviour is clearer
As Yousaf said, let’s bring this back to the team for review and come back to you (reminder set)
👍 1
w
Is there any update on the direction for this?
m
It's been added to our backlog for review. Officially we'd like to be able to support it
❤️ 1
c
We’re running into the same thing now - a large swagger def. of 16k lines with 150 uses of
allOf
in, is there any update or sense of timescale for this being reviewed? Thanks 🙂
m
It’s currently on the prioritised backlog if issues to solve around the new launch. I can’t give timeframes at this stage.
We are considering a few approaches, one of them is to look at pre-parsing through something like https://www.npmjs.com/package/json-schema-merge-allof
So you could potentially look at a similar solution - merge the
allOf
and published the tweaked OAS
c
Thanks for your replies, we’re going to look at the
json-schema-merge-allof
solution I think, and accept that the OAS file we push to the broker isn’t quite the original
👍 1
m
Thanks - feedback on that would be great
One problem I can foresee is that debugging problems could be challenging, because you won’t be comparing the uploaded OAS with the (mutated) one that was validated. But my assumption is that most errors should still look the same
c
yea, depends how agressive / opinionated the lib is in how it generates it’s output - gotta try it to see i guess!
🙌 1
We had better luck combining https://www.npmjs.com/package/json-schema-resolve-allof and https://github.com/APIDevTools/json-schema-ref-parser to turn our Openapi spec into something that now passes ❤️
🙌 1
only downside is with no
$ref
the spec file jumped from a 506K yaml, to a 695K JSON, to a 2.8MB de-$ref’ed / de-allOf’ed monster
😱 2
I don’t think you can remove the `allOf`s without also removing the `$ref`s
🤔 1