swagger-combine icon indicating copy to clipboard operation
swagger-combine copied to clipboard

recursive model definitions causes crash

Open sev-g opened this issue 6 years ago • 5 comments

version 0.18.1 If you have a model with a recursive property like:

"Person": {
  "required": ["id", "persons"],
  "type": "object",
  "properties": {
    "id": {
      "format": "int64",
      "minimum": 0,
      "exclusiveMinimum": true,
      "minLength": 1,
      "type": "integer",
      "readOnly": true
    },
    "persons": {
      "uniqueItems": false,
      "type": "array",
      "items": {
        "$ref": "#/definitions/Person"
      },
      "readOnly": true
    }
  }
}

then the code generation will crash with:

 Failed to find schema example for Person
RangeError: Maximum call stack size exceeded
    at String.replace (<anonymous>)
    at Function.Pointer.join (/app-run/node_modules/json-schema-ref-parser/lib/pointer.js:198:44)
    at /app-run/node_modules/json-schema-ref-parser/lib/resolve-external.js:63:31
    at Array.forEach (<anonymous>)
    at crawl (/app-run/node_modules/json-schema-ref-parser/lib/resolve-external.js:62:24)
    at /app-run/node_modules/json-schema-ref-parser/lib/resolve-external.js:70:38
    at Array.forEach (<anonymous>)
    at crawl (/app-run/node_modules/json-schema-ref-parser/lib/resolve-external.js:62:24)
    at /app-run/node_modules/json-schema-ref-parser/lib/resolve-external.js:70:38
    at Array.forEach (<anonymous>) 

sev-g avatar Jan 29 '19 15:01 sev-g

@SevastianGioanca I'm getting the same failure.

{ RangeError: Maximum call stack size exceeded
    at Array.forEach (native)
    at crawl (~/.nvm/versions/node/v8.1.4/lib/node_modules/swagger-combine/node_modules/json-schema-ref-parser/lib/resolve-external.js:61:24)
    at ~/.nvm/versions/node/v8.1.4/lib/node_modules/swagger-combine/node_modules/json-schema-ref-parser/lib/resolve-external.js:69:38
    at Array.forEach (native)
    at crawl (~/.nvm/versions/node/v8.1.4/lib/node_modules/swagger-combine/node_modules/json-schema-ref-parser/lib/resolve-external.js:61:24)
    at ~/.nvm/versions/node/v8.1.4/lib/node_modules/swagger-combine/node_modules/json-schema-ref-parser/lib/resolve-external.js:69:38
    at Array.forEach (native)
    at crawl (~/.nvm/versions/node/v8.1.4/lib/node_modules/swagger-combine/node_modules/json-schema-ref-parser/lib/resolve-external.js:61:24)
    at ~/.nvm/versions/node/v8.1.4/lib/node_modules/swagger-combine/node_modules/json-schema-ref-parser/lib/resolve-external.js:69:38
    at Array.forEach (native)
  api: 'https://some.domain/swagger.yaml' }

tmack8001 avatar Feb 28 '19 04:02 tmack8001

likely to be caused by https://github.com/APIDevTools/json-schema-ref-parser/issues/36 or https://github.com/APIDevTools/json-schema-ref-parser/issues/40

tmack8001 avatar Feb 28 '19 20:02 tmack8001

In my scenario I wasn't purposefully making an infinite nesting behavior... so I've now split the swagger data types to prevent an indefinite nesting and instead just a 2 layer nesting

tmack8001 avatar Feb 28 '19 20:02 tmack8001

got the same, with four huge swagger definition files

glebmachine avatar Mar 30 '20 13:03 glebmachine

The exception should be avoided now with #110 . Please see the description in the PR for how to set up to ignore circular references.

ELymar avatar Aug 18 '20 20:08 ELymar