Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

ExpandAllOf() throws "incompatible properties" if schemas are compatible but not equal

Abierto
#347 5 comentarios 0 reacciones 1 asignado Ver en GitHub

@mikeharder ya está trabajando en esto.

Desde el 3/12/2024.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

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 to PetOwner.pet of type Pet.

https://github.com/Azure/openapi-diff/blob/88502940aed70915f3ff88c551d37db43d37ba45/src/lib/util/resolveSwagger.ts#L250

@JeffreyRichter, @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 https://github.com/Azure/openapi-diff/pull/329, although in this case the types were identical with just an extra step of indirection.

@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
{
  "swagger": "2.0",
  "info": {
    "version": "1.0.0",
    "title": "title",
  },
  "paths": {
  },
  "definitions": {
    "Pet": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        } 
      }
    },
    "Dog": {
      "type": "object",
      "properties": {
        "bones": {
          "type": "integer"
        }
      },
      "allOf": [{"$ref": "#/definitions/Pet"}]
    },
    "PetOwner": {
      "type": "object",
      "properties": {
        "ssn": {
          "type": "integer"
        },
        "pet": {
          "$ref": "#/definitions/Pet"
        }
      }
    },
    "DogOwner": {
      "type": "object",
      "properties": {
        "pet": {
          "$ref": "#/definitions/Dog"
        }
      },
      "allOf": [{"$ref": "#/definitions/PetOwner"}]
    }
  }
}
Lenguaje dominante
C#
Estrellas
290
Forks
50
Merge medio
2 d 21 h
PR fusionados (30 d)
10

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Azure/openapi-diff

Todos los issues de Azure/openapi-diff

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.