You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ExpandAllOf() throws "incompatible properties" if schemas are compatible but not equal #347
The following spec should be valid per JSON Schema and Swagger. However, we throw error incompatible properties when trying to process it, since DogOwner.pet is type Dog, which is compatible with but not equal toPetOwner.pet of type Pet.
Jeffrey Richter (@JeffreyRichter), Mike Kistler (@mikekistler): Do you think the code should be changed to allow types that are compatible but not equal? If so, should it be conditioned on whether the swagger is handwritten or typespec-generated, under the assumption that SDKs for TypeSpec will be generated directly from TypeSpec and not the intermediate Swagger?
We recently fixed a similar issue in #329, although in this case the types were identical with just an extra step of indirection.
Mark Cowlishaw (@markcowl) and I believe this is valid swagger, but some of our SDK generators may not handle it correctly, which might be why it's not allowed in openapi-diff. However, openapi-diff should not be responsible for this. It should be tested directly by the SDK generation tests.
Repro Steps
Save spec below to file test.json, then run npx @azure/oad test.json test.json.
Error: incompatible properties : pet
definitions/DogOwner/properties/pet
at file:///home/mharder/tmp/oad/test.json#L61:8
definitions/PetOwner/properties/pet
at file:///home/mharder/tmp/oad/test.json#L53:8
It might be dangerous to compare on content rather than name, because schemas that are the same today might not be the same tomorrow. In fact, it's possible that two different schemas exist simply to allow them to evolve independently.
It might be dangerous to compare on content rather than name, because schemas that are the same today might not be the same tomorrow. In fact, it's possible that two different schemas exist simply to allow them to evolve independently.
Can you elaborate on this, or provide an example to illustrate what you mean? Why do you think it might be dangerous to allow my example spec above? If either schema changes, the BreakingChanges tool will run again on the PR.
Note this error happens when we are pre-processing the spec, before we even get to comparing two specs. The chain of events:
DogOwner has a property pet of type Dog
DogOwner is also allOfPetOwner
PetOwner has a property pet of type Pet
Our code determines the properties are "incompatible", because the types are not the exact same
However, since type Dog satisfies type Pet, both JSON Schema and Swagger would consider this a semantically valid schema
I also think this is a more general case of the problem we fixed in #329, where we decided to allow $ref to be considered equivalent to the thing being referenced. All of the properties here are compatible with each other:
"details":"incompatible properties : tags
definitions/ContainerGroup/properties/tags
at file:///home/runner/work/azure-rest-api-specs/azure-rest-api-specs/specification/containerinstance/resource-manager/Microsoft.ContainerInstance/ContainerInstance/stable/2025-09-01/containerInstance.json#L2245:8
definitions/Resource/properties/tags
at file:///home/runner/work/azure-rest-api-specs/azure-rest-api-specs/specification/containerinstance/resource-manager/Microsoft.ContainerInstance/ContainerInstance/stable/2025-09-01/containerInstance.json#L4642:8"
Activity
mikekistler commentedon Dec 3, 2024
It might be dangerous to compare on content rather than name, because schemas that are the same today might not be the same tomorrow. In fact, it's possible that two different schemas exist simply to allow them to evolve independently.
mikeharder commentedon Dec 3, 2024
Can you elaborate on this, or provide an example to illustrate what you mean? Why do you think it might be dangerous to allow my example spec above? If either schema changes, the BreakingChanges tool will run again on the PR.
Note this error happens when we are pre-processing the spec, before we even get to comparing two specs. The chain of events:
DogOwnerhas a propertypetof typeDogDogOwneris alsoallOfPetOwnerPetOwnerhas a propertypetof typePetDogsatisfies typePet, both JSON Schema and Swagger would consider this a semantically valid schemaI also think this is a more general case of the problem we fixed in #329, where we decided to allow
$refto be considered equivalent to the thing being referenced. All of the properties here are compatible with each other:openapi-diff/src/test/specs/compatible-properties.json
Lines 10 to 51 in 8850294
mikekistler commentedon Dec 3, 2024
Okay ... now I understand. Anything that is a
Dogmust also be aPetbecauseDogallOf'sPet. I suppose this is safe.mikeharder commentedon Dec 3, 2024
Sounds good, let me try to create a PR to see how hard this will be to fix.
mikeharder commentedon May 4, 2026
Example of TSP conversion with this error:
https://github.com/Azure/azure-rest-api-specs/actions/runs/23628050434