Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive Model Definition is not correctly handled #35

Closed
laucia opened this issue Jul 22, 2015 · 2 comments
Closed

Recursive Model Definition is not correctly handled #35

laucia opened this issue Jul 22, 2015 · 2 comments
Assignees

Comments

@laucia
Copy link

laucia commented Jul 22, 2015

A simple recursive model definition like this

{
    "swagger": "2.0",
    "info": {
        "version": "1.0.0",
        "title": ""
    },
    "paths": {
        "/recursion": {
            "get": {
                "responses": {
                    "200": {
                        "description": "Recurse",
                        "schema": {
                            "$ref": "#/definitions/Recursion"
                        }
                    }
                },
                "parameters": []
            }
        }
    },
    "host": "localhost",
    "basePath": "/",
    "definitions": {
        "Recursion": {
            "properties": {
                "title": {
                    "description": "user facing localized display string",
                    "type": "string"
                },
                "parent": {
                    "description": "parent recursion",
                    "$ref": "#/definitions/Recursion"
                }
            },
            "required": [
                "title"
            ]
        }
    }
}

Leads to this exception

  File "/usr/local/lib/python2.7/site-packages/bravado_core/spec.py", line 203, in descend
    if is_dict_like(fragment):
  File "/usr/local/lib/python2.7/site-packages/bravado_core/schema.py", line 49, in is_dict_like
    if type(spec) == dict:
RuntimeError: maximum recursion depth exceeded while calling a Python object

As nothing in the swagger spec advise against recursive model definitions and the canonical swagger-codegen handles it, this should also work in bravado.

@analogue
Copy link
Contributor

This is not going to be a simple fix. Just some notes:

  • swagger_spec_validator and bravado_core both need this functionality
  • jsonschema doesn't support validation of json documents with external refs (local refs are ok) which is a necessary feature
  • usage of jsonref will have to be removed entirely since it doesn't support cyclic refs
  • all call sites that may encounter a ref need to resolve the ref transparently at runtime
  • do some research on how this is handled best in existing libs outside the python ecosystem

@analogue
Copy link
Contributor

Fixed in 4.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants