diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e29a223..5a145dce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog 1.0.0]. +## Unreleased + +### BREAKING CHANGE + +- Document can now no longer be initialised with a string as the `uri`, it must be a `DocumentURIString`. + ## v27.4.0 (2024-11-07) ### Change of behaviour diff --git a/src/caselawclient/factories.py b/src/caselawclient/factories.py index 356e8e6b..efa38825 100644 --- a/src/caselawclient/factories.py +++ b/src/caselawclient/factories.py @@ -5,7 +5,7 @@ from typing_extensions import TypeAlias from caselawclient.Client import MarklogicApiClient -from caselawclient.models.documents import Document +from caselawclient.models.documents import Document, DocumentURIString from caselawclient.models.documents.body import DocumentBody from caselawclient.models.judgments import Judgment from caselawclient.models.press_summaries import PressSummary @@ -54,7 +54,7 @@ class DocumentFactory: @classmethod def build( cls, - uri: str = "test/2023/123", + uri: DocumentURIString = DocumentURIString("test/2023/123"), html: str = "
This is a judgment.
", api_client: Optional[MarklogicApiClient] = None, **kwargs: Any, diff --git a/src/caselawclient/models/documents/__init__.py b/src/caselawclient/models/documents/__init__.py index d4ec4e2d..7c3d5171 100644 --- a/src/caselawclient/models/documents/__init__.py +++ b/src/caselawclient/models/documents/__init__.py @@ -105,13 +105,15 @@ class Document: Individual document classes should extend this list where necessary to validate document type-specific attributes. """ - def __init__(self, uri: str, api_client: "MarklogicApiClient", search_query: Optional[str] = None): + def __init__(self, uri: DocumentURIString, api_client: "MarklogicApiClient", search_query: Optional[str] = None): """ - :param uri: For historical reasons this accepts a pseudo-URI which may include leading or trailing slashes. + :param uri: The URI of the document to retrieve from MarkLogic. + :param api_client: An instance of the API client object to handle communication with the MarkLogic server. + :param search_query: Optionally, a search string which should be highlighted if it appears in the document body. :raises DocumentNotFoundError: The document does not exist within MarkLogic """ - self.uri: DocumentURIString = DocumentURIString(uri.strip("/")) + self.uri: DocumentURIString = uri self.api_client: MarklogicApiClient = api_client if not self.document_exists(): raise DocumentNotFoundError(f"Document {self.uri} does not exist") @@ -123,7 +125,7 @@ def __init__(self, uri: str, api_client: "MarklogicApiClient", search_query: Opt search_query=search_query, ), ) - """ `Document.body` represents the XML of the document itself, without any information such as version tracking or properties. """ + """ `Document.body` represents the body of the document itself, without any information such as version tracking or properties. """ def __repr__(self) -> str: name = self.body.name or "un-named"