Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] support of breaking changes for "anyOf" #212

Open
TenOs opened this issue Feb 3, 2021 · 3 comments · Fixed by #318
Open

[bug] support of breaking changes for "anyOf" #212

TenOs opened this issue Feb 3, 2021 · 3 comments · Fixed by #318
Assignees
Milestone

Comments

@TenOs
Copy link

TenOs commented Feb 3, 2021

So I've been tested openapi-diff to see if we can use it in our CI/CD pipeline to prevent any breaking changes from happening.
After running a few tests I've noticed that it doesn't seem to support anyOf correctly.

See the two openapi files attached. Basically the endpoint returns a response which either ResponseA or ResponseB. New file removes a required property from ResponseA and openapi-diff doesn't catch the breaking change.
old.yaml

openapi: 3.0.2
info:
  title: test API
  version: 0.1.0
paths:
  /test:
    get:
      summary: Test
      operationId: test_test_get
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                title: Response Test Test Get
                anyOf:
                  - $ref: '#/components/schemas/ResponseA'
                  - $ref: '#/components/schemas/ResponseB'
components:
  schemas:
    ResponseA:
      title: ResponseA
      required:
        - attr_a_1
        - attr_a_2
      type: object
      properties:
        attr_a_1:
          title: Attr A 1
          type: string
        attr_a_2:
          title: Attr A 2
          type: string
    ResponseB:
      title: ResponseB
      required:
        - attr_b
      type: object
      properties:
        attr_b:
          title: Attr B
          type: string

new.yaml

openapi: 3.0.2
info:
  title: test API
  version: 0.1.0
paths:
  /test:
    get:
      summary: Test
      operationId: test_test_get
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                title: Response Test Test Get
                anyOf:
                  - $ref: '#/components/schemas/ResponseA'
                  - $ref: '#/components/schemas/ResponseB'
components:
  schemas:
    ResponseA:
      title: ResponseA
      required:
        - attr_a_1
      type: object
      properties:
        attr_a_1:
          title: Attr A 1
          type: string
    ResponseB:
      title: ResponseB
      required:
        - attr_b
      type: object
      properties:
        attr_b:
          title: Attr B
          type: string

Result

No differences. Specifications are equivalents

This is a very simple test scenario, but I've tested the same one with a change like this in:

  • request
  • response
  • nested property on request
  • nested property on response

for all of them it wasn't detecting any breaking changes....

I've tested these using docker openapitools/openapi-diff:latest.

@joschi joschi added the bug label Feb 28, 2021
@joschi
Copy link
Contributor

joschi commented Feb 28, 2021

Diff:

--- core/src/test/resources/issue-212-1.yaml	2021-02-28 17:52:14.000000000 +0100
+++ core/src/test/resources/issue-212-2.yaml	2021-02-28 17:52:34.000000000 +0100
@@ -23,15 +23,11 @@
       title: ResponseA
       required:
         - attr_a_1
-        - attr_a_2
       type: object
       properties:
         attr_a_1:
           title: Attr A 1
           type: string
-        attr_a_2:
-          title: Attr A 2
-          type: string
     ResponseB:
       title: ResponseB
       required:

@nc-nsre
Copy link

nc-nsre commented Feb 16, 2022

Found that the error is within the SchemaDiff class in the method Schema<?> resolveComposedSchema(Components, Schema<?>) which only considers ((ComposedSchema) schema).getAllOf() but not ((ComposedSchema) schema).getAnyOf()

@joschi joschi added this to the 2.1.0 milestone Mar 3, 2022
@joschi joschi linked a pull request Mar 15, 2022 that will close this issue
@willosborne
Copy link

Can this be closed now after that that PR was merged?

@DrSatyr DrSatyr self-assigned this Jan 31, 2025
@DrSatyr DrSatyr added help wanted and removed bug labels Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment