maxdome / swagger-combine

Combines multiple Swagger schemas into one dereferenced schema.
MIT License
132 stars 36 forks source link

recursive model definitions causes crash #63

Open sev-g opened 5 years ago

sev-g commented 5 years ago

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>) 
tmack8001 commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

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

glebmachine commented 4 years ago

got the same, with four huge swagger definition files

ELymar commented 4 years ago

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