diff --git a/docs/source/user_docs.rst b/docs/source/user_docs.rst index 06ec1d5..05ac0cd 100644 --- a/docs/source/user_docs.rst +++ b/docs/source/user_docs.rst @@ -234,6 +234,12 @@ for code readability. .. autofunction:: wysdom.schema +Other convenience functions +--------------------------- + +.. autofunction:: wysdom.properties + + Mixins ====== diff --git a/features/dict.feature b/features/dict.feature index 4d116e0..dccba1c 100644 --- a/features/dict.feature +++ b/features/dict.feature @@ -120,6 +120,7 @@ Feature: Test dictionary DOM objects example_dict_output == example_dict_input copy.copy(example).to_builtin() == example_dict_input copy.deepcopy(example).to_builtin() == example_dict_input + set(properties(example).keys()) == {"first_name", "last_name", "current_address", "previous_addresses", "vehicles"} """ And the list walk_elements contains the following tuples: | element | document | parent | element_key | diff --git a/features/steps/steps.py b/features/steps/steps.py index 19cba35..f608f5b 100644 --- a/features/steps/steps.py +++ b/features/steps/steps.py @@ -1,7 +1,7 @@ from behave import * import wysdom -from wysdom import document, parent, key, schema +from wysdom import document, parent, key, schema, properties import os import importlib.util diff --git a/wysdom/__init__.py b/wysdom/__init__.py index 33f92a6..ebca75e 100644 --- a/wysdom/__init__.py +++ b/wysdom/__init__.py @@ -4,6 +4,6 @@ from . import dom from .base_schema import Schema, SchemaType, SchemaNone, SchemaPrimitive, SchemaAnything, SchemaConst from .object_schema import SchemaArray, SchemaDict, SchemaAnyOf, SchemaObject -from .user_objects import UserProperty, UserObject +from .user_objects import UserProperty, UserObject, properties from .mixins import ReadsJSON, ReadsYAML, RegistersSubclasses diff --git a/wysdom/user_objects/__init__.py b/wysdom/user_objects/__init__.py index f38c7e4..701ebda 100644 --- a/wysdom/user_objects/__init__.py +++ b/wysdom/user_objects/__init__.py @@ -1,2 +1,3 @@ from .UserObject import UserObject, UserProperties from .UserProperty import UserProperty +from .functions import properties diff --git a/wysdom/user_objects/functions.py b/wysdom/user_objects/functions.py new file mode 100644 index 0000000..681f07c --- /dev/null +++ b/wysdom/user_objects/functions.py @@ -0,0 +1,15 @@ +from typing import Dict + +from ..base_schema import Schema +from .UserObject import UserObject + + +def properties(user_object: UserObject) -> Dict[str, Schema]: + """ + Retrieve the property names and their associated :class:`~wysdom.base_schema.Schema` + objects for a particular `:class:`~wysdom.user_objects.UserObject. + + :param user_object: A `:class:`~wysdom.user_objects.UserObject + :return: A dictionary mapping property names to their :class:`~wysdom.base_schema.Schema` + """ + return user_object.__json_schema_properties__.properties