Tufin / oasdiff

OpenAPI Diff and Breaking Changes
https://www.oasdiff.com
Apache License 2.0
689 stars 59 forks source link

Compare inline schemas under AllOf/AnyOf/OneOf by title #527

Closed reuvenharrison closed 4 months ago

reuvenharrison commented 5 months ago

This PR improves comparison of subschemas under AllOf/AnyOf/OneOf with the following capabilities:

  1. Ability to compare subschemas that have the same title to each other
  2. Improved diff output format
  3. Improved messages for breaking changes and changelog (note: you may need to update exception files)

Diff Before:

anyOf:
    added:
        - Fox
        - RevisionSchema[2]:Rabbit
        - RevisionSchema[4]
    deleted:
        - BaseSchema[2]:Rabbit
        - BaseSchema[3]
    modified:
        '#/components/schemas/Dog':
            properties:
                modified:
                    breed:
                        anyOf:
                            modified:
                                '#/components/schemas/Breed2':
                                    properties:
                                        modified:
                                            name:
                                                type:
                                                    from: string
                                                    to: number

Diff After:

anyOf:
    added:
        - index: 3
          component: Fox
    modified:
        - base:
            index: 0
            component: Dog
          revision:
            index: 0
            component: Dog
          diff:
            properties:
                modified:
                    breed:
                        anyOf:
                            modified:
                                - base:
                                    index: 1
                                    component: Breed2
                                  revision:
                                    index: 0
                                    component: Breed2
                                  diff:
                                    properties:
                                        modified:
                                            name:
                                                type:
                                                    from: string
                                                    to: number
        - base:
            index: 2
            title: Rabbit
          revision:
            index: 2
            title: Rabbit
          diff:
            type:
                from: string
                to: number
        - base:
            index: 3
          revision:
            index: 4
          diff:
            type:
                from: string
                to: number

Changelog Before

3 changes: 1 error, 0 warning, 2 info
error   [response-property-type-changed] at /tmp/response_property_any_of_complex_revision.yaml
    in API GET /pets
        the '/anyOf[#/components/schemas/Dog]/breed/anyOf[#/components/schemas/Breed2]/name' response's property type/format changed from 'string'/'' to 'number'/'' for status '200'

info    [response-body-any-of-added] at /tmp/response_property_any_of_complex_revision.yaml
    in API GET /pets
        added 'Fox, RevisionSchema[2]:Rabbit, RevisionSchema[4]' to the response body 'anyOf' list for the response status '200'

info    [response-body-any-of-removed] at /tmp/response_property_any_of_complex_revision.yaml
    in API GET /pets
        removed 'BaseSchema[2]:Rabbit, BaseSchema[3]' from the response body 'anyOf' list for the response status '200'

Changelog After

4 changes: 3 error, 0 warning, 1 info
error   [response-property-type-changed] at /tmp/response_property_any_of_complex_revision.yaml
    in API GET /pets
        the '/anyOf[#/components/schemas/Dog]/breed/anyOf[#/components/schemas/Breed2]/name' response's property type/format changed from 'string'/'' to 'number'/'' for status '200'

error   [response-property-type-changed] at /tmp/response_property_any_of_complex_revision.yaml
    in API GET /pets
        the '/anyOf[subschema #3: Rabbit]/' response's property type/format changed from 'string'/'' to 'number'/'' for status '200'

error   [response-property-type-changed] at /tmp/response_property_any_of_complex_revision.yaml
    in API GET /pets
        the '/anyOf[subschema #4 -> subschema #5]/' response's property type/format changed from 'string'/'' to 'number'/'' for status '200'

info    [response-body-any-of-added] at /tmp/response_property_any_of_complex_revision.yaml
    in API GET /pets
        added '#/components/schemas/Fox' to the response body 'anyOf' list for the response status '200'
codecov[bot] commented 5 months ago

Codecov Report

Attention: Patch coverage is 84.12698% with 50 lines in your changes are missing coverage. Please review.

Project coverage is 83.86%. Comparing base (051d11e) to head (2cf2ab8). Report is 5 commits behind head on main.

Files Patch % Lines
diff/subschemas_diff.go 78.64% 27 Missing and 17 partials :warning:
diff/modified_subschemas.go 94.64% 2 Missing and 1 partial :warning:
report/report.go 25.00% 3 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #527 +/- ## ========================================== + Coverage 83.29% 83.86% +0.56% ========================================== Files 226 226 Lines 12964 13180 +216 ========================================== + Hits 10798 11053 +255 + Misses 1745 1705 -40 - Partials 421 422 +1 ``` | [Flag](https://app.codecov.io/gh/Tufin/oasdiff/pull/527/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tufin) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/Tufin/oasdiff/pull/527/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tufin) | `83.86% <84.12%> (+0.56%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tufin#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.