本文整理汇总了Python中flask_restx.fields.Nested方法的典型用法代码示例。如果您正苦于以下问题:Python fields.Nested方法的具体用法?Python fields.Nested怎么用?Python fields.Nested使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_restx.fields
的用法示例。
在下文中一共展示了fields.Nested方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unpack_nested
# 需要导入模块: from flask_restx import fields [as 别名]
# 或者: from flask_restx.fields import Nested [as 别名]
def test_unpack_nested():
app = Flask(__name__)
api = Api(app)
class IntegerSchema(Schema):
my_int: ma.Integer()
result = utils.unpack_nested(ma.Nested(IntegerSchema), api=api)
assert result
示例2: test_unpack_nested_self
# 需要导入模块: from flask_restx import fields [as 别名]
# 或者: from flask_restx.fields import Nested [as 别名]
def test_unpack_nested_self():
app = Flask(__name__)
api = Api(app)
class IntegerSchema(Schema):
my_int = ma.Integer()
children = ma.Nested("self", exclude=["children"])
schema = IntegerSchema()
result = utils.unpack_nested(schema.fields.get("children"), api=api)
assert type(result) == fr.Nested
示例3: test_unpack_nested_self_many
# 需要导入模块: from flask_restx import fields [as 别名]
# 或者: from flask_restx.fields import Nested [as 别名]
def test_unpack_nested_self_many():
app = Flask(__name__)
api = Api(app)
class IntegerSchema(Schema):
my_int = ma.Integer()
children = ma.Nested("self", exclude=["children"], many=True)
schema = IntegerSchema()
result = utils.unpack_nested(schema.fields.get("children"), api=api)
assert type(result) == fr.List
示例4: unpack_nested
# 需要导入模块: from flask_restx import fields [as 别名]
# 或者: from flask_restx.fields import Nested [as 别名]
def unpack_nested(val, api, model_name: str = None, operation: str = "dump"):
if val.nested == "self":
return unpack_nested_self(val, api, model_name, operation)
model_name = get_default_model_name(val.nested)
return fr.Nested(
map_type(val.nested, api, model_name, operation), **_ma_field_to_fr_field(val)
)
示例5: unpack_nested_self
# 需要导入模块: from flask_restx import fields [as 别名]
# 或者: from flask_restx.fields import Nested [as 别名]
def unpack_nested_self(val, api, model_name: str = None, operation: str = "dump"):
model_name = model_name or get_default_model_name(val.schema)
fields = {
k: map_type(v, api, model_name, operation)
for k, v in (vars(val.schema).get("fields").items())
if type(v) in type_map and _check_load_dump_only(v, operation)
}
if val.many:
return fr.List(
fr.Nested(
api.model(f"{model_name}-child", fields), **_ma_field_to_fr_field(val)
)
)
else:
return fr.Nested(
api.model(f"{model_name}-child", fields), **_ma_field_to_fr_field(val)
)
示例6: make_preassembly_model
# 需要导入模块: from flask_restx import fields [as 别名]
# 或者: from flask_restx.fields import Nested [as 别名]
def make_preassembly_model(func):
"""Create new Flask model with function arguments."""
args = inspect.signature(func).parameters
# We can reuse Staetments model if only stmts_in or stmts and **kwargs are
# arguments of the function
if ((len(args) == 1 and ('stmts_in' in args or 'stmts' in args)) or
(len(args) == 2 and 'kwargs' in args and
('stmts_in' in args or 'stmts' in args))):
return stmts_model
# Inherit a model if there are other arguments
model_fields = {}
for arg in args:
if arg != 'stmts_in' and arg != 'stmts' and arg != 'kwargs':
default = None
if args[arg].default is not inspect.Parameter.empty:
default = args[arg].default
# Need to use default for boolean and example for other types
if arg in boolean_args:
model_fields[arg] = fields.Boolean(default=default)
elif arg in int_args:
model_fields[arg] = fields.Integer(example=default)
elif arg in float_args:
model_fields[arg] = fields.Float(example=0.7)
elif arg in list_args:
if arg == 'curations':
model_fields[arg] = fields.List(
fields.Nested(dict_model),
example=[{'pa_hash': '1234', 'source_hash': '2345',
'tag': 'wrong_relation'}])
else:
model_fields[arg] = fields.List(
fields.String, example=default)
elif arg in dict_args:
model_fields[arg] = fields.Nested(dict_model)
else:
model_fields[arg] = fields.String(example=default)
new_model = api.inherit(
('%s_input' % func.__name__), stmts_model, model_fields)
return new_model