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

Nested class not generated right #102

Open
trondhindenes opened this issue Jun 8, 2016 · 1 comment
Open

Nested class not generated right #102

trondhindenes opened this issue Jun 8, 2016 · 1 comment

Comments

@trondhindenes
Copy link

I'm trying to express the following:

{                                               
    "module":  "ping",                          
    "extra_args":  {                            
                       "var2":  "value2",       
                       "var":  "value1"         
                   }                            
}                                               

I've done this in python like so:

@swagger.model
class AnsibleExtraArgsModel:
    resource_fields = {
        'arg_name' : fields.String,
        'arg_value' : fields.String,
        }

@swagger.model
class AnsibleCommandModel:
    resource_fields = {
        'module': fields.String,
        'extra_args': fields.List(fields.Nested(AnsibleExtraArgsModel.resource_fields)),
    }

However, the resulting swagger spec doesn't include the nested class:

{
    "apiVersion": "0.1", 
    "apis": [
        {
            "description": null, 
            "notes": null, 
            "operations": [], 
            "path": "/api/starttask"
        }, 
        {
            "description": null, 
            "notes": null, 
            "operations": [
                {
                    "method": "post", 
                    "nickname": "nickname", 
                    "notes": "Run ad-hoc Ansible command", 
                    "parameters": [
                        {
                            "allowMultiple": false, 
                            "dataType": "AnsibleCommandModel", 
                            "description": "Inut object", 
                            "name": "body", 
                            "paramType": "body", 
                            "required": true
                        }
                    ], 
                    "responseClass": "AnsibleRequestResultModel", 
                    "responseMessages": [
                        {
                            "code": 200, 
                            "message": "Ansible command started"
                        }, 
                        {
                            "code": 400, 
                            "message": "Invalid input"
                        }
                    ], 
                    "summary": null
                }
            ], 
            "path": "/ansiblecommand"
        }, 
        {
            "description": null, 
            "notes": null, 
            "operations": [], 
            "path": "/ansibletaskstatus/{task_id}"
        }
    ], 
    "basePath": "http://localhost", 
    "description": "Auto generated API docs by flask-restful-swagger", 
    "models": {
        "AnsibleCommandModel": {
            "description": null, 
            "id": "AnsibleCommandModel", 
            "notes": null, 
            "properties": {
                "extra_args": {
                    "items": {
                        "$ref": null
                    }, 
                    "type": "array"
                }, 
                "module": {
                    "type": "string"
                }
            }
        }, 
        "AnsibleExtraArgsModel": {
            "description": null, 
            "id": "AnsibleExtraArgsModel", 
            "notes": null, 
            "properties": {
                "arg_name": {
                    "type": "string"
                }, 
                "arg_value": {
                    "type": "string"
                }
            }
        }, 
        "AnsibleRequestResultModel": {
            "description": null, 
            "id": "AnsibleRequestResultModel", 
            "notes": null, 
            "properties": {
                "task_id": {
                    "type": "string"
                }
            }, 
            "required": [
                "task_id"
            ]
        }
    }, 
    "produces": [
        "application/json"
    ], 
    "resourcePath": "/", 
    "spec_endpoint_path": "/api/spec", 
    "swaggerVersion": "1.2"
}

How can I troubleshoot this?

@robxrocks
Copy link

robxrocks commented May 26, 2020

I know this is an old issue, but it seems it still hasn't been resolved. The way I had it - partially - working was by adding @swagger.nested decorator, which in the above case would be:

@swagger.model
@swagger.nested(extra_args=AnsibleExtraArgsModel.__name__)
class AnsibleCommandModel:
    resource_fields = {
        'module': fields.String,
        'extra_args': fields.List(fields.Nested(AnsibleExtraArgsModel.resource_fields)),
    }

and the swagger doc was generated correctly.
The problem I got - and that why I mentioned it worked partially - was that the nested decorator broke @classmethod decorator and SQLAlchemy select queries were not working.

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