OpenAPITools / OpenAPITools/openapi-diff
Property `type` change on referenced component schema is silently ignored
还没有人认领这个 Issue。
- 主要语言
- Java
- 星标
- 1.1k
- 派生
- 190
- PR 合并指标
- 30 天内没有已合并 PR
描述
Library version: org.openapitools.openapidiff:openapi-diff-core:2.1.7
Java: 21
OpenAPI version of test specs: 3.1.0 (also reproduces on 3.0.x)
Summary
When the only difference between two specs is a type change on a property of a referenced component schema, OpenApiCompare.fromContents reports zero changes. Both getChangedOperations() and getChangedSchemas() are empty. Other property-level changes (required list deltas, enum value deltas) on the same referenced schema are detected normally — only type swaps are dropped.
Minimal reproduction
old.yaml:
openapi: 3.1.0
info:
title: t
version: '1'
paths:
/widgets:
get:
responses:
'200':
description: ok
content:
application/json:
schema:
$ref: '#/components/schemas/Widget'
components:
schemas:
Widget:
type: object
properties:
weight:
type: integer
new.yaml — identical except for weight.type:
openapi: 3.1.0
info:
title: t
version: '1'
paths:
/widgets:
get:
responses:
'200':
description: ok
content:
application/json:
schema:
$ref: '#/components/schemas/Widget'
components:
schemas:
Widget:
type: object
properties:
weight:
type: string
import org.openapitools.openapidiff.core.OpenApiCompare;
import org.openapitools.openapidiff.core.model.ChangedOpenApi;
import java.nio.file.*;
public class Repro {
public static void main(String[] a) throws Exception {
String prev = Files.readString(Path.of("old.yaml"));
String curr = Files.readString(Path.of("new.yaml"));
ChangedOpenApi d = OpenApiCompare.fromContents(prev, curr);
System.out.println("missingEndpoints: " + d.getMissingEndpoints().size());
System.out.println("newEndpoints: " + d.getNewEndpoints().size());
System.out.println("changedOperations:" + d.getChangedOperations().size());
System.out.println("changedSchemas: " + d.getChangedSchemas().size());
}
}
Actual output
missingEndpoints: 0
newEndpoints: 0
changedOperations:0
changedSchemas: 0
Expected output
A non-empty changedOperations (or changedSchemas) containing an INCOMPATIBLE entry for the property weight on Widget.
Other findings
- Reproduces with
OpenAPIParser+ParseOptions.setResolveFully(true)andOpenApiCompare.fromSpecifications(...). - Inverting the spec versions (3.1.0 ↔ 3.0.3) does not change the result.
- The same fixture with a
required:list change instead (e.g. addingweighttorequired) is detected correctly —changedOperationsandchangedSchemasare populated. So the parser does diff the referenced schema; only thetypefield is being skipped. - As a workaround, walking the resolved
Schematree manually aftersetResolveFully(true)and comparingSchema.getType()/Schema.getTypes()recovers the change.
Happy to put up a PR if pointers to where the schema-type comparator lives would help.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 OpenApiCompare.fromContents 和 fromSpecifications 开始,使用提供的 old.yaml/new.yaml 复现用例,并设置 ParseOptions.setResolveFully(true)。跟踪 ChangedOpenApi 如何记录被引用 schema 的变更,以及在哪里比较 Schema.getType()/getTypes()。完成的标准是:将 weight 从 integer 改为 string 后,产生非空的 changedOperations 或 changedSchemas 结果,并包含一个 INCOMPATIBLE 条目,同时仍能检测到 required 和 enum 的变更。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java
- 领域
- api, backend-api-design
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 68/100