Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions scripts/naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ def class_name(operation_id: str) -> str:
def python_name(wire: str) -> str:
"""A query parameter's wire name as a keyword argument.

A leading `_` is dropped, `-` and `:` become `_`, and camelCase becomes snake_case:
A leading `_` is dropped, `-`, `:` and `.` become `_`, and camelCase becomes snake_case:
`_count` is `count`, `name:contains` is `name_contains`, `address-city` is `address_city`,
`serviceTypeCode` is `service_type_code`.
`serviceTypeCode` is `service_type_code`, and a FHIR chained search such as
`location.address-state` is `location_address_state`.
"""
name = wire[1:] if wire.startswith("_") else wire
name = re.sub(r"[-:]", "_", name)
name = re.sub(r"[-:.]", "_", name)
name = _CAMEL.sub("_", name).lower()
if not name.isidentifier() or keyword.iskeyword(name):
raise ValueError(f"the query parameter {wire!r} has no Python name: {name!r}")
Expand Down
5 changes: 4 additions & 1 deletion tests/test_encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def test_a_url_on_another_host_is_refused() -> None:
("displayLanguage", "display_language"),
("isVirtual", "is_virtual"),
("new-patient-from-network", "new_patient_from_network"),
# FHIR's chained search parameters, sent under their own names.
("location.address-state", "location_address_state"),
("organization.identifier", "organization_identifier"),
],
)
def test_wire_names_map_to_python_names(wire: str, python: str) -> None:
Expand All @@ -108,7 +111,7 @@ def test_a_name_python_cannot_take_is_refused() -> None:
with pytest.raises(ValueError, match="no Python name"):
naming.python_name("class")
with pytest.raises(ValueError, match="no Python name"):
naming.python_name("a.b")
naming.python_name("a/b")


def test_operation_ids_and_docs_slugs() -> None:
Expand Down
Loading