From 14f7f858f1908daf4ff66bf65f981a4ad35ca65f Mon Sep 17 00:00:00 2001 From: Daniyar Yeralin Date: Tue, 20 Aug 2019 11:27:04 -0400 Subject: [PATCH 1/2] Introduce ability to modify json schema property name --- marshmallow_jsonschema/base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/marshmallow_jsonschema/base.py b/marshmallow_jsonschema/base.py index ec0cb57..71fc371 100644 --- a/marshmallow_jsonschema/base.py +++ b/marshmallow_jsonschema/base.py @@ -108,7 +108,7 @@ def get_properties(self, obj): for field_name, field in sorted(obj.fields.items()): schema = self._get_schema_for_field(obj, field) - properties[field.name] = schema + properties[field.metadata.get('name') or field.name] = schema return properties @@ -140,7 +140,7 @@ def _from_python_type(self, obj, field, pytype): metadata.update(field.metadata) for md_key, md_val in metadata.items(): - if md_key == "metadata": + if md_key in ("metadata", "name"): continue json_schema[md_key] = md_val @@ -219,7 +219,7 @@ def _from_nested_schema(self, obj, field): metadata.update(field.metadata) for md_key, md_val in metadata.items(): - if md_key == "metadata": + if md_key in ("metadata", "name"): continue schema[md_key] = md_val From 5912cdad53bedd0004b5e1572dc82fc47f6eaa18 Mon Sep 17 00:00:00 2001 From: Daniyar Yeralin Date: Tue, 20 Aug 2019 11:51:31 -0400 Subject: [PATCH 2/2] pre-commit hooks --- marshmallow_jsonschema/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/marshmallow_jsonschema/base.py b/marshmallow_jsonschema/base.py index 71fc371..49184b6 100644 --- a/marshmallow_jsonschema/base.py +++ b/marshmallow_jsonschema/base.py @@ -108,7 +108,7 @@ def get_properties(self, obj): for field_name, field in sorted(obj.fields.items()): schema = self._get_schema_for_field(obj, field) - properties[field.metadata.get('name') or field.name] = schema + properties[field.metadata.get("name") or field.name] = schema return properties @@ -140,7 +140,7 @@ def _from_python_type(self, obj, field, pytype): metadata.update(field.metadata) for md_key, md_val in metadata.items(): - if md_key in ("metadata", "name"): + if md_key in ("metadata", "name"): continue json_schema[md_key] = md_val