diff --git a/re.json b/re.json new file mode 100644 index 0000000..61280b4 --- /dev/null +++ b/re.json @@ -0,0 +1,33 @@ +{ + "description": "测试description.", + "properties": { + "gender": { + "enum": [ + "male", + "female", + "other", + "not_given" + ], + "type": "string" + }, + "gender_list": { + "description": "this is the value of snap", + "items": { + "enum": [ + "male", + "female", + "other", + "not_given" + ], + "type": "string" + }, + "title": "l", + "type": "array" + } + }, + "required": [ + "gender_list" + ], + "title": "GenderTest", + "type": "object" +} \ No newline at end of file diff --git a/schema_entry/utils.py b/schema_entry/utils.py index c627769..6127671 100644 --- a/schema_entry/utils.py +++ b/schema_entry/utils.py @@ -253,7 +253,7 @@ def remove_defs_interference(d: Dict[str, Any]) -> Dict[str, Any]: def replace_refs(d: Dict[str, Any]) -> Dict[str, Any]: - info = jsonref.replace_refs(d, lazy_load=False) + info = jsonref.replace_refs(d, merge_props=True, lazy_load=False) if info.get("$defs"): del info["$defs"] return info diff --git a/tests/test_entrypoint_with_schema.py b/tests/test_entrypoint_with_schema.py index ac3a167..25a4548 100644 --- a/tests/test_entrypoint_with_schema.py +++ b/tests/test_entrypoint_with_schema.py @@ -93,6 +93,7 @@ class GenderTest(BaseModel): assert root.name == "gendertest" assert root.__doc__ == "测试description." + print(root.schema) root(["-l", "male", "-l", "other"]) self.assertDictEqual(root.config, { "gender": "male", diff --git a/tests/test_utils.py b/tests/test_utils.py index 7f945fa..e51b367 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -232,14 +232,6 @@ def test_pydantic_schema_to_protocol(self) -> None: 'type': 'object'} get_schema = pydantic_schema_to_protocol(pdschema) - target = {'properties': {'gender': {'enum': ['male', 'female', 'other', 'not_given'], - 'type': 'string'}, - 'gender_list': {'description': 'this is the value of snap', - 'items': {'enum': ['male', 'female', 'other', 'not_given'], - 'type': 'string'}, - 'title': 'l', - 'type': 'array'}}, - 'required': ['gender', 'gender_list'], - 'title': 'D', - 'type': 'object'} + target = {'properties': {'gender': {'enum': ['male', 'female', 'other', 'not_given'], 'type': 'string', 'description': 'this is the value of snap', 'title': 'g'}, 'gender_list': { + 'description': 'this is the value of snap', 'items': {'enum': ['male', 'female', 'other', 'not_given'], 'type': 'string'}, 'title': 'l', 'type': 'array'}}, 'required': ['gender', 'gender_list'], 'title': 'D', 'type': 'object'} self.assertDictEqual(target, get_schema)