当前位置: 首页>>代码示例>>Python>>正文


Python Model.inherit方法代码示例

本文整理汇总了Python中flask_restplus.Model.inherit方法的典型用法代码示例。如果您正苦于以下问题:Python Model.inherit方法的具体用法?Python Model.inherit怎么用?Python Model.inherit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask_restplus.Model的用法示例。


在下文中一共展示了Model.inherit方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_model_deepcopy

# 需要导入模块: from flask_restplus import Model [as 别名]
# 或者: from flask_restplus.Model import inherit [as 别名]
    def test_model_deepcopy(self):
        parent = Model('Person', {
            'name': fields.String,
            'age': fields.Integer(description="foo"),
        })

        child = parent.inherit('Child', {
            'extra': fields.String,
        })

        parent_copy = copy.deepcopy(parent)

        assert parent_copy["age"].description == "foo"

        parent_copy["age"].description = "bar"

        assert parent["age"].description == "foo"
        assert parent_copy["age"].description == "bar"

        child = parent.inherit('Child', {
            'extra': fields.String,
        })

        child_copy = copy.deepcopy(child)
        assert child_copy.__parents__[0] == parent
开发者ID:bedge,项目名称:flask-restplus,代码行数:27,代码来源:test_model.py

示例2: test_polymorph_inherit_common_ancestor

# 需要导入模块: from flask_restplus import Model [as 别名]
# 或者: from flask_restplus.Model import inherit [as 别名]
    def test_polymorph_inherit_common_ancestor(self):
        class Child1:
            pass

        class Child2:
            pass

        parent = Model('Person', {
            'name': fields.String,
            'age': fields.Integer,
        })

        child1 = parent.inherit('Child1', {
            'extra1': fields.String,
        })

        child2 = parent.inherit('Child2', {
            'extra2': fields.String,
        })

        mapping = {
            Child1: child1,
            Child2: child2,
        }

        output = Model('Output', {
            'child': fields.Polymorph(mapping)
        })

        # Should use the common ancestor
        self.assertEqual(output.__schema__, {
            'properties': {
                'child': {'$ref': '#/definitions/Person'},
            }
        })
开发者ID:NyanKiyoshi,项目名称:flask-restplus,代码行数:37,代码来源:test_model.py

示例3: test_inherit_from_instance_from_multiple_parents

# 需要导入模块: from flask_restplus import Model [as 别名]
# 或者: from flask_restplus.Model import inherit [as 别名]
    def test_inherit_from_instance_from_multiple_parents(self):
        grand_parent = Model('GrandParent', {
            'grand_parent': fields.String,
        })

        parent = Model('Parent', {
            'name': fields.String,
            'age': fields.Integer,
        })

        child = grand_parent.inherit('Child', parent, {
            'extra': fields.String,
        })

        assert child.__schema__ == {
            'allOf': [
                {'$ref': '#/definitions/GrandParent'},
                {'$ref': '#/definitions/Parent'},
                {
                    'properties': {
                        'extra': {'type': 'string'}
                    },
                    'type': 'object'
                }
            ]
        }
开发者ID:bedge,项目名称:flask-restplus,代码行数:28,代码来源:test_model.py

示例4: test_inherit_from_class

# 需要导入模块: from flask_restplus import Model [as 别名]
# 或者: from flask_restplus.Model import inherit [as 别名]
    def test_inherit_from_class(self):
        parent = Model('Parent', {
            'name': fields.String,
            'age': fields.Integer,
        })

        child = Model.inherit('Child', parent, {
            'extra': fields.String,
        })

        assert parent.__schema__ == {
            'properties': {
                'name': {'type': 'string'},
                'age': {'type': 'integer'},
            },
            'type': 'object'
        }
        assert child.__schema__ == {
            'allOf': [
                {'$ref': '#/definitions/Parent'},
                {
                    'properties': {
                        'extra': {'type': 'string'}
                    },
                    'type': 'object'
                }
            ]
        }
开发者ID:bedge,项目名称:flask-restplus,代码行数:30,代码来源:test_model.py

示例5: test_inherit_from_instance

# 需要导入模块: from flask_restplus import Model [as 别名]
# 或者: from flask_restplus.Model import inherit [as 别名]
    def test_inherit_from_instance(self):
        parent = Model('Parent', {
            'name': fields.String,
            'age': fields.Integer,
        })

        child = parent.inherit('Child', {
            'extra': fields.String,
        })

        self.assertEqual(parent.__schema__, {
            'properties': {
                'name': {'type': 'string'},
                'age': {'type': 'integer'},
            },
            'type': 'object'
        })
        self.assertEqual(child.__schema__, {
            'allOf': [
                {'$ref': '#/definitions/Parent'},
                {
                    'properties': {
                        'extra': {'type': 'string'}
                    },
                    'type': 'object'
                }
            ]
        })
开发者ID:fixedd,项目名称:flask-restplus,代码行数:30,代码来源:test_model.py

示例6: test_inherit_from_class_from_multiple_parents

# 需要导入模块: from flask_restplus import Model [as 别名]
# 或者: from flask_restplus.Model import inherit [as 别名]
    def test_inherit_from_class_from_multiple_parents(self):
        grand_parent = Model('GrandParent', {
            'grand_parent': fields.String,
        })

        parent = Model('Parent', {
            'name': fields.String,
            'age': fields.Integer,
        })

        child = Model.inherit('Child', grand_parent, parent, {
            'extra': fields.String,
        })

        self.assertEqual(child.__schema__, {
            'allOf': [
                {'$ref': '#/definitions/GrandParent'},
                {'$ref': '#/definitions/Parent'},
                {
                    'properties': {
                        'extra': {'type': 'string'}
                    }
                }
            ]
        })
开发者ID:NyanKiyoshi,项目名称:flask-restplus,代码行数:27,代码来源:test_model.py

示例7: Model

# 需要导入模块: from flask_restplus import Model [as 别名]
# 或者: from flask_restplus.Model import inherit [as 别名]
funct_uid = Model("VNF", {
    'id': fields.String(required=True, description='The VNF UID'),
    'name': fields.String(required=True, description='The VNF Name'),
    'vendor': fields.String(required=True, description='The VNF Vendor'),
    'version': fields.String(required=True, description='The VNF Version')

})

uid = Model("VNF_UID", {
    'id': fields.String(required=True, description='The VNF UID')
})

funct_response = funct.inherit("FunctionResponse", funct, {
    "descriptor": fields.Nested(model=funct, description="The Complete VNF Descriptor"),
    "id": fields.Integer(description='The Project ID'),
    "project_id": fields.Integer(description='The parent project id'),
})

message_response = proj_namespace.model("Message", {
    'message': fields.String(required=True, description="The result message")
})

proj_namespace.add_model(funct.name, funct)
proj_namespace.add_model(funct_response.name, funct_response)


@proj_namespace.route('/')
@cata_namespace.route('/')
@plat_namespace.route('/')
@proj_namespace.param('ws_id', 'The Workspace identifier')
开发者ID:Jmanuel4SandMan,项目名称:upb-son-editor-backend,代码行数:32,代码来源:functionsapi.py

示例8: Model

# 需要导入模块: from flask_restplus import Model [as 别名]
# 或者: from flask_restplus.Model import inherit [as 别名]
    'version': fields.String(required=True, description='The Service Version')

})

serv_update = Model("Service Update", {
    "descriptor": fields.Nested(model=serv, description="The Complete Service Descriptor")

})

serv_id = Model("Service ID", {
    'id': fields.Integer(required=True, description='The son-editor id of the service being published')
})

serv_response = serv.inherit("ServiceResponse", serv, {
    "descriptor": fields.Nested(model=serv, description="The Complete Service Descriptor"),
    "id": fields.Integer(description='The Project ID'),
    "project_id": fields.Integer(description='The parent workspace id'),
})

message_response = proj_namespace.model("Message", {
    'message': fields.String(required=True, description="The result message")
})

proj_namespace.add_model(serv_update.name, serv_update)
proj_namespace.add_model(serv.name, serv)
proj_namespace.add_model(serv_response.name, serv_response)


@proj_namespace.route('/')
@cata_namespace.route('/')
@plat_namespace.route('/')
开发者ID:Jmanuel4SandMan,项目名称:upb-son-editor-backend,代码行数:33,代码来源:servicesapi.py


注:本文中的flask_restplus.Model.inherit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。