From a3cd54c034e84cd2abc06d9ac397a9f642a4a380 Mon Sep 17 00:00:00 2001 From: Christoph Zwerschke Date: Tue, 6 Aug 2024 08:42:31 +0000 Subject: [PATCH] Replace underscores in auto generated field names --- src/mass/adapters/outbound/utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/mass/adapters/outbound/utils.py b/src/mass/adapters/outbound/utils.py index a3f220c..3f86d26 100644 --- a/src/mass/adapters/outbound/utils.py +++ b/src/mass/adapters/outbound/utils.py @@ -30,6 +30,11 @@ } +def name_from_key(key: str) -> str: + """Auto generate a suitable name from a key""" + return key.title().replace("_", " ") + + def pipeline_match_text_search(*, query: str) -> JsonObject: """Build text search segment of aggregation pipeline""" text_search = {"$text": {"$search": query}} @@ -95,7 +100,7 @@ def pipeline_facet_sort_and_paginate( ) name = facet.name if not name: - name = facet.key.capitalize() + name = name_from_key(facet.key) segment[name] = [ { "$unwind": { @@ -144,7 +149,9 @@ def pipeline_project(*, facet_fields: list[models.FieldLabel]) -> JsonObject: # add a segment for each facet to summarize the options for facet in facet_fields: key = facet.key - name = facet.name or key.capitalize() + name = facet.name + if not name: + name = name_from_key(key) segment["facets"].append( { "key": key,