Skip to content

Commit

Permalink
feat: change namespaced mapping from model to field namespacing
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-pl committed Feb 14, 2025
1 parent e951701 commit 4f856cb
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions rdfproxy/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,19 @@ class NamespacedFieldBindingsMap(FieldsBindingsMap):
def _get_field_binding_mapping(model: type[_TModelInstance]) -> dict[str, str]:
"""Resolve model fields against rdfproxy.SPARQLBindings."""

def _construct_bindings(model, top_level=True):
def _construct_bindings(model, _namespace: str = ""):
bindings_map = FieldsBindingsMap(model)

for k, v in model.model_fields.items():
# if _is_list_basemodel_type(nested_model := v.annotation):
# yield from _construct_bindings(
# get_args(nested_model)[0], top_level=False
# )

if isinstance(v.annotation, type(BaseModel)):
yield from _construct_bindings(v.annotation, top_level=False)
_namespace += f"{k}."
yield from _construct_bindings(v.annotation, _namespace=_namespace)

if _is_scalar_type(v.annotation):
yield (k if top_level else f"{model.__name__}.{k}", bindings_map[k])
yield (
k if not _namespace else f"{_namespace}{k}",
bindings_map[k],
)

return dict(_construct_bindings(model))

Expand Down

0 comments on commit 4f856cb

Please sign in to comment.