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


Python Schema.json_schema方法代码示例

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


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

示例1: test_json_schema_object_or_array_of_object

# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import json_schema [as 别名]
def test_json_schema_object_or_array_of_object():
    # Complex test where "test" accepts either an object or an array of that object
    o = {"param1": "test1", Optional("param2"): "test2"}
    s = Schema({"test": Or(o, [o])})
    assert s.json_schema("my-id") == {
        "$schema": "http://json-schema.org/draft-07/schema#",
        "id": "my-id",
        "properties": {
            "test": {
                "anyOf": [
                    {
                        "additionalProperties": False,
                        "properties": {"param1": {}, "param2": {}},
                        "required": ["param1"],
                        "type": "object",
                    },
                    {
                        "type": "array",
                        "items": {
                            "additionalProperties": False,
                            "properties": {"param1": {}, "param2": {}},
                            "required": ["param1"],
                            "type": "object",
                        },
                    },
                ]
            }
        },
        "required": ["test"],
        "additionalProperties": False,
        "type": "object",
    }
开发者ID:BillWang139967,项目名称:MyPythonLib,代码行数:34,代码来源:test_schema.py

示例2: test_json_schema_forbidden_key_ignored

# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import json_schema [as 别名]
def test_json_schema_forbidden_key_ignored():
    s = Schema({Forbidden("forbidden"): str, "test": str})
    assert s.json_schema("my-id") == {
        "$schema": "http://json-schema.org/draft-07/schema#",
        "id": "my-id",
        "properties": {"test": {"type": "string"}},
        "required": ["test"],
        "additionalProperties": False,
        "type": "object",
    }
开发者ID:BillWang139967,项目名称:MyPythonLib,代码行数:12,代码来源:test_schema.py

示例3: test_json_schema_or_types

# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import json_schema [as 别名]
def test_json_schema_or_types():
    s = Schema({"test": Or(str, int)})
    assert s.json_schema("my-id") == {
        "$schema": "http://json-schema.org/draft-07/schema#",
        "id": "my-id",
        "properties": {"test": {"anyOf": [{"type": "string"}, {"type": "integer"}]}},
        "required": ["test"],
        "additionalProperties": False,
        "type": "object",
    }
开发者ID:BillWang139967,项目名称:MyPythonLib,代码行数:12,代码来源:test_schema.py

示例4: test_json_schema_or_key

# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import json_schema [as 别名]
def test_json_schema_or_key():
    s = Schema({Or("test1", "test2"): str})
    assert s.json_schema("my-id") == {
        "$schema": "http://json-schema.org/draft-07/schema#",
        "id": "my-id",
        "properties": {"test1": {"type": "string"}, "test2": {"type": "string"}},
        "required": [],
        "additionalProperties": False,
        "type": "object",
    }
开发者ID:BillWang139967,项目名称:MyPythonLib,代码行数:12,代码来源:test_schema.py

示例5: test_json_schema_and_types

# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import json_schema [as 别名]
def test_json_schema_and_types():
    # Can't determine the type, it will not be checked
    s = Schema({"test": And(str, lambda x: len(x) < 5)})
    assert s.json_schema("my-id") == {
        "$schema": "http://json-schema.org/draft-07/schema#",
        "id": "my-id",
        "properties": {"test": {}},
        "required": ["test"],
        "additionalProperties": False,
        "type": "object",
    }
开发者ID:BillWang139967,项目名称:MyPythonLib,代码行数:13,代码来源:test_schema.py

示例6: test_json_schema_optional_key_nested

# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import json_schema [as 别名]
def test_json_schema_optional_key_nested():
    s = Schema({"test": {Optional("other"): str}})
    assert s.json_schema("my-id") == {
        "$schema": "http://json-schema.org/draft-07/schema#",
        "id": "my-id",
        "properties": {
            "test": {
                "type": "object",
                "properties": {"other": {"type": "string"}},
                "additionalProperties": False,
                "required": [],
            }
        },
        "required": ["test"],
        "additionalProperties": False,
        "type": "object",
    }
开发者ID:BillWang139967,项目名称:MyPythonLib,代码行数:19,代码来源:test_schema.py

示例7: test_json_schema_nested_schema

# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import json_schema [as 别名]
def test_json_schema_nested_schema():
    s = Schema({"test": Schema({"other": str}, ignore_extra_keys=True)})
    assert s.json_schema("my-id") == {
        "$schema": "http://json-schema.org/draft-07/schema#",
        "id": "my-id",
        "properties": {
            "test": {
                "type": "object",
                "properties": {"other": {"type": "string"}},
                "additionalProperties": True,
                "required": ["other"],
            }
        },
        "required": ["test"],
        "additionalProperties": False,
        "type": "object",
    }
开发者ID:BillWang139967,项目名称:MyPythonLib,代码行数:19,代码来源:test_schema.py

示例8: test_json_schema_types

# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import json_schema [as 别名]
def test_json_schema_types():
    s = Schema(
        {
            Optional("test_str"): str,
            Optional("test_int"): int,
            Optional("test_float"): float,
            Optional("test_bool"): bool,
        }
    )
    assert s.json_schema("my-id") == {
        "$schema": "http://json-schema.org/draft-07/schema#",
        "id": "my-id",
        "properties": {
            "test_str": {"type": "string"},
            "test_int": {"type": "integer"},
            "test_float": {"type": "number"},
            "test_bool": {"type": "boolean"},
        },
        "required": [],
        "additionalProperties": False,
        "type": "object",
    }
开发者ID:BillWang139967,项目名称:MyPythonLib,代码行数:24,代码来源:test_schema.py

示例9: test_json_schema_not_a_dict

# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import json_schema [as 别名]
def test_json_schema_not_a_dict():
    s = Schema(int)
    with raises(ValueError):
        s.json_schema()
开发者ID:BillWang139967,项目名称:MyPythonLib,代码行数:6,代码来源:test_schema.py

示例10: test_json_schema_no_id

# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import json_schema [as 别名]
def test_json_schema_no_id():
    s = Schema({"test": int})
    with raises(ValueError):
        s.json_schema()
开发者ID:BillWang139967,项目名称:MyPythonLib,代码行数:6,代码来源:test_schema.py


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