猿问

Flask 嵌套的 rest api 招摇不工作

address = api.schema_model('Address', {

    'properties': {

        'road': {

            'type': 'string'

        },

    },

    'type': 'object' })


person = address = api.schema_model('Person', {

    'required': ['address'],

    'properties': {

        'name': {

            'type': 'string'

        },

        'age': {

            'type': 'integer'

        },

        'birthdate': {

            'type': 'string',

            'format': 'date-time'

        },

        'address': {

            '$ref': '#/definitions/Address',

        }

    },

    'type': 'object' })

错误在定义中隐藏解析器错误。Person.properties.address.$ref 无法解析引用,因为:无法解析指针:/NestedModel 在文档中不存在


哔哔one
浏览 183回答 1
1回答

浮云间

最后我可以用下面的代码解决问题nested_fields = api.schema_model('NestedModel', {'name': fields.String})person = address = api.schema_model('Person', {    'required': ['address'],    'properties': {        'name': {            'type': 'string'        },        'age': {            'type': 'integer'        },        'birthdate': {            'type': 'string',            'format': 'date-time'        },        'address': {            'properties': {                'arguments': {                    'type': 'array',                    'items': {                    }                }            },            'type': 'object'        }    },    'type': 'object'})
随时随地看视频慕课网APP

相关分类

Python
我要回答