OpenAPITools / OpenAPITools/openapi-diff
[Bug] Backward compatibility check fails on reordered discriminator mappings
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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