Stackoverflow error with cyclic references involving allOf

Open
#124 1 comment 6 reactions 0 assignees View on GitHub

Maintainers usually reply within 5 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java, openapi
Domain
api

Research direction

Reproduce the failure with the supplied schema and openapi-diff spec.yaml spec.yaml. Trace the recursive calls through SchemaDiff, ReferenceDiffCache, ComposedSchemaDiffResult, and ArraySchemaDiffResult, using the stack trace as the entry point. Done means the recursive allOf schema comparison completes without a StackOverflowError.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Java
Stars
1.1k
Forks
191
Avg merge
4d 23h
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OpenAPITools/openapi-diff

All issues in OpenAPITools/openapi-diff

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.