You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug: The helper function (GetCircularReferenceResult) returns nil for this self-referential case (schema below), and the subsequent unguarded call to .GenerateJourneyPath() on nil leads to a panic (invalid memory address dereference).
openapi: "3.0.3"
info:
title: "Circular Reference Panic Example"
version: "1.0.0"
paths:
/test:
get:
summary: "Returns an object with an array of actions"
responses:
"200":
description: "Successful response with actions"
content:
application/json:
schema:
$ref: "#/components/schemas/ActionList"
components:
schemas:
# ActionList is a valid object schema that contains an array property.
# Each element in the array should conform to the ActionComponent schema.
ActionList:
type: object
properties:
actions:
type: array
items:
$ref: "#/components/schemas/ActionComponent"
# ActionComponent is defined as a self-referencing schema.
# This intentional circular reference is used to reproduce the bug.
ActionComponent:
$ref: "#/components/schemas/ActionComponent"
The text was updated successfully, but these errors were encountered:
Can you give me a snippet of the code you are using to create this because I built the following lower level test and it works just fine. I can see you're creating a model - to save me digging around trying to discover which schema you're building, a snippet of how you're calling Schema() would be very helpful
funcTestSpecIndex_CheckCircularRefIssue380(t*testing.T) {
d:=`openapi: "3.0.3"info: title: "Circular Reference Panic Example" version: "1.0.0"paths: /test: get: summary: "Returns an object with an array of actions" responses: "200": description: "Successful response with actions" content: application/json: schema: $ref: "#/components/schemas/ActionList"components: schemas: # ActionList is a valid object schema that contains an array property. # Each element in the array should conform to the ActionComponent schema. ActionList: type: object properties: actions: type: array items: $ref: "#/components/schemas/ActionComponent" # ActionComponent is defined as a self-referencing schema. # This intentional circular reference is used to reproduce the bug. ActionComponent: $ref: "#/components/schemas/ActionComponent"`varrootNode yaml.Node_=yaml.Unmarshal([]byte(d), &rootNode)
config:=CreateClosedAPIIndexConfig()
idx:=NewSpecIndexWithConfig(&rootNode, config)
resolver:=NewResolver(idx)
assert.NotNil(t, resolver)
circ:=resolver.Resolve()
assert.Len(t, circ, 1)
assert.True(t, circ[0].CircularReference.IsInfiniteLoop)
assert.Equal(t, "infinite circular reference detected: #/components/schemas/ActionComponent", circ[0].ErrorRef.Error())
assert.Equal(t, "ActionList -> ActionComponent -> ActionComponent", circ[0].CircularReference.GenerateJourneyPath())
}
Bug: The helper function (GetCircularReferenceResult) returns nil for this self-referential case (schema below), and the subsequent unguarded call to .GenerateJourneyPath() on nil leads to a panic (invalid memory address dereference).
Reproducible schema
The text was updated successfully, but these errors were encountered: