Search code examples
pythonflask-restplus

Flask-RESTPlus - Nested Fields not getting registered into SwaggerUI


I'm trying to create a Nested field to a response model. I don't unserstand why the generated swagger.json is aware of the nested field but do not register it under $/definitions.

This is my Model

HypervisorResponse = ns.model('HypervisorResponse', {
    'name': fields.String(required=True, example='hypervisor01.xx.com'),
    'ip_addr': fields.String(required=True, example='192.168.0.0'),
    'provider': fields.String(required=True),
    'runtime': fields.Nested(
        ns.model('RuntimeResponse', {
            'uptime': fields.Integer(attribute='uptime'),
            'last_boot': fields.String(attribute='last_boot'),
            'memory_total': fields.Integer(attribute='memory_total'),
            'memory_used': fields.Integer(attribute='memory_used')
        })
    )
})

The outputted swagger.json is

        "HypervisorResponse": {
            "required": [
                "ip_addr",
                "name",
                "provider"
            ],
            "properties": {
                "name": {
                    "type": "string",
                    "example": "hypervisor01.xx.com"
                },
                "ip_addr": {
                    "type": "string",
                    "example": "192.168.0.0"
                },
                "provider": {
                    "type": "string"
                },
                "runtime": {
                    "$ref": "#/definitions/RuntimeResponse"
                }
            },
            "type": "object"
        }

Solution

  • After a while i figured out that the NAMESPACE ordered property were the cause of it. Setting it to False solved the issue.