znsio / specmatic

Turn your contracts into executable specifications. Contract Driven Development - Collaboratively Design & Independently Deploy MicroServices & MicroFrontends.
https://specmatic.io
MIT License
278 stars 50 forks source link

Specmatic shows that, contracts are not backward compatible for same OpenAPI files. #1371

Closed dilanka-cacib closed 2 hours ago

dilanka-cacib commented 4 hours ago

Description When I use same OpenAPI file to compare for backward compatibility check. It gives result as 'The newer contract is not backward compatible'

Steps to reproduce

  1. Download this file: openapi_specmatic_issue_demo.zip and extract it and use latest specmatic.jar
  2. Run this command (windows): java -jar specmatic.jar compare openapi_specmatic_issue_demo.yaml openapi_specmatic_issue_demo.yaml

Expected behavior Since I am using the same OpenAPI file, it should give the result as 'The newer contract is backward compatible.'. But I receive the result as 'The newer contract is not backward compatible.'

Screenshots image

System Information:

yogeshnikam671 commented 3 hours ago

Hi @dilanka-cacib, thanks for reporting this issue. We will look into this and get back to you.

yogeshnikam671 commented 3 hours ago

Hi @dilanka-cacib,

It looks like the issue you're facing is due to conflicting constraints in the iso2Code schema:

        - name: iso2Code
          in: path
          description: iso2Code
          required: true
          style: simple
          explode: false
          schema:
            maxLength: 2
            pattern: .+
            type: string

In this case, maxLength: 2 limits the iso2Code to 2 characters, while the pattern .+ allows any length greater than 1. These conflicts are causing inconsistent behavior in Specmatic.

To resolve this, updating the schema to the following should fix the issue:

        - name: iso2Code
          in: path
          description: iso2Code
          required: true
          style: simple
          explode: false
          schema:
            maxLength: 2
            pattern: ^.{1,2}$
            type: string

This ensures the pattern and maxLength are aligned. We're also planning to address this nuance in Specmatic soon.

Let us know if you need further assistance, and feel free to reopen the issue if it's not resolved.

Best regards!

dilanka-cacib commented 1 hour ago

Hi @yogeshnikam671,

Thanks for the quick reply. I will test as you suggested.

Thanks