OpenAPITools / OpenAPITools/openapi-diff

Stackoverflow error with cyclic references involving allOf

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

还没有人认领这个 Issue。

主要语言
Java
星标
1.1k
派生
190
PR 合并指标
30 天内没有已合并 PR

描述

Given this schema definition

openapi: 3.0.1
info:
  title: recursive test
  version: '1.0'
servers:
  - url: 'http://localhost:8000/'
paths:
  /ping:
    get:
      operationId: ping
      responses:
        '200':
          description: OK
          content:
            text/plain:
              schema:
                $ref: '#/components/schemas/B'
components:
  schemas:
    B:
      type: object
      properties:
        message:
          type: string
        message2:
          type: string
        details:
          type: array
          items:
            allOf:
              - $ref: '#/components/schemas/B'

and running openapi-diff spec.yaml spec.yaml I get stack overflow error

Exception in thread "main" java.lang.StackOverflowError
        at java.base/java.util.Arrays.spliterator(Arrays.java:5482)
        at java.base/java.util.Arrays.stream(Arrays.java:5633)
        at java.base/java.util.Arrays.stream(Arrays.java:5614)
        at java.base/java.util.stream.Stream.of(Stream.java:1188)
        at com.qdesrame.openapi.diff.model.ChangedExtensions.getChangedElements(ChangedExtensions.java:37)
        at com.qdesrame.openapi.diff.model.ComposedChanged.isChanged(ComposedChanged.java:19)
        at com.qdesrame.openapi.diff.model.Changed.isUnchanged(Changed.java:21)
        at com.qdesrame.openapi.diff.utils.ChangedUtils.isUnchanged(ChangedUtils.java:9)
        at com.qdesrame.openapi.diff.utils.ChangedUtils.isChanged(ChangedUtils.java:17)
        at com.qdesrame.openapi.diff.compare.ExtensionsDiff.diff(ExtensionsDiff.java:79)
        at com.qdesrame.openapi.diff.compare.schemadiffresult.SchemaDiffResult.diff(SchemaDiffResult.java:61)
        at com.qdesrame.openapi.diff.compare.SchemaDiff.computeDiff(SchemaDiff.java:316)
        at com.qdesrame.openapi.diff.compare.SchemaDiff.computeDiff(SchemaDiff.java:27)
        at com.qdesrame.openapi.diff.compare.ReferenceDiffCache.cachedDiff(ReferenceDiffCache.java:51)
        at com.qdesrame.openapi.diff.compare.SchemaDiff.diff(SchemaDiff.java:282)
        at com.qdesrame.openapi.diff.compare.schemadiffresult.SchemaDiffResult.diff(SchemaDiffResult.java:75)
        at com.qdesrame.openapi.diff.compare.schemadiffresult.ComposedSchemaDiffResult.diff(ComposedSchemaDiffResult.java:85)
        at com.qdesrame.openapi.diff.compare.SchemaDiff.computeDiff(SchemaDiff.java:316)
        at com.qdesrame.openapi.diff.compare.SchemaDiff.computeDiff(SchemaDiff.java:27)
        at com.qdesrame.openapi.diff.compare.ReferenceDiffCache.cachedDiff(ReferenceDiffCache.java:51)
        at com.qdesrame.openapi.diff.compare.SchemaDiff.diff(SchemaDiff.java:282)
        at com.qdesrame.openapi.diff.compare.schemadiffresult.ArraySchemaDiffResult.diff(ArraySchemaDiffResult.java:31)

The problem occurs only with allOf. Replacing it with oneOf fixes the problem.

贡献指南

打开贡献指南

从这里开始

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

调研方向

使用提供的 schema 和 openapi-diff spec.yaml spec.yaml 重现该失败。以堆栈跟踪为入口,跟踪经过 SchemaDiffReferenceDiffCacheComposedSchemaDiffResultArraySchemaDiffResult 的递归调用。当递归的 allOf schema 比较能够在没有 StackOverflowError 的情况下完成时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
java, openapi
领域
api
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

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