Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#347 5 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@mikeharder 已经在做这个了。

开始于 2024年12月3日。

评估

这个 Issue 还没有评估数据。

描述

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"}]
    }
  }
}
主要语言
C#
星标
290
派生
50
平均合并
2 天 21 小时
30 天内合并 PR
10

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Azure/openapi-diff 的其他 Issue

查看 Azure/openapi-diff 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。