OpenAPITools / OpenAPITools/openapi-diff

[Bug] Backward compatibility check fails on reordered discriminator mappings

Open
#886 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Breaking/Non-Breaking classification
Dominant language
Java
Stars
1.1k
Forks
190
PR merge metrics
No merged PRs in 30d

Description

Ran into a compatibility issue, which I believe is a false positive. I have one polymorphic schema, that maps to two different property names. The backwards compatibility check fails if the mappings are re-ordered.

This should not be failing, because neither discriminator names nor the mapping changed.

For example, the following 2 should be considered compatible, but are not. Assume the actual schemas are identical. Schema A is mapped to a-type and z-type which are present in both mappings, but are ordered differently.

             schema:
               oneOf:
                 - $ref: '#/components/schemas/A'
                 - $ref: '#/components/schemas/B'
               discriminator:
                 propertyName: realtype
                 mapping:
                   z-type: '#/components/schemas/A'
                   a-type: '#/components/schemas/A'
                   b-type: '#/components/schemas/B'

and

              schema:
                oneOf:
                  - $ref: '#/components/schemas/A'
                  - $ref: '#/components/schemas/B'
                discriminator:
                  propertyName: realtype
                  mapping:
                    a-type: '#/components/schemas/A'
                    z-type: '#/components/schemas/A'
                    b-type: '#/components/schemas/B'

I was able to reproduce this in this repo by adding a test to OneOfDiffTest with the above as an example (based on oneOf_discriminator-missing_1.yaml).

  @Test
  public void testOneOfDiscrimitatorDifferentOrder() {
    assertOpenApiAreEquals(OPENAPI_DOC11, OPENAPI_DOC12);
  }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the existing OneOfDiffTest and the oneOf_discriminator-missing_1.yaml example mentioned in the issue. Add or run the reordered-mapping case, then trace the comparison entry point it exercises. Done means the two shown schemas are treated as compatible when only discriminator mapping order differs.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.