Coverage for functions \ flipdare \ generated \ model \ search \ search_response_model.py: 100%
0 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
1#!/usr/bin/env python
2#
3# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved.
4#
5# This file is part of Flipdare's proprietary software and contains
6# confidential and copyrighted material. Unauthorised copying,
7# modification, distribution, or use of this file is strictly
8# prohibited without prior written permission from Flipdare Pty Ltd.
9#
10# This software includes third-party components licensed under MIT,
11# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details.
12#
13# NOTE: THIS FILE IS AUTO GENERATED. DO NOT EDIT.
14#
15# Generated by codegen_models.py
16#
17# Modify 'codegen_models.py'
18# and re-run the script above to update.
19#
20# pragma: no cover
21from __future__ import annotations
22from typing import Any, TypedDict, cast, Unpack
23from enum import StrEnum
24from pydantic import ConfigDict, TypeAdapter
25from flipdare.firestore.core.app_base_model import AppBaseModel
26from flipdare.generated.model.search.search_document_model import (
27 SearchDocumentModel,
28 SearchDocumentDict,
29)
30from flipdare.generated.model.search.result_hint_model import ResultHintModel, ResultHintDict
33class SearchResponseKeys(StrEnum):
34 Q = "q"
35 FOUND = "found"
36 PAGE = "page"
37 OUT_OF = "out_of"
38 COLLECTION_NAME = "collection_name"
39 RESULTS = "results"
40 HIGHLIGHTS = "highlights"
43class SearchResponseModel(AppBaseModel):
44 """A search response."""
46 model_config = ConfigDict(populate_by_name=True)
48 # Search query string.
49 q: str
50 found: int
51 page: int
52 out_of: int
53 collection_name: str
54 results: list[SearchDocumentModel]
55 highlights: list[ResultHintModel]
57 @classmethod
58 def validate_partial(cls, **data: Unpack[SearchResponseDict]) -> dict[str, Any]:
59 """
60 Uses Unpack to give you autocomplete and static warnings
61 if you pass an invalid key or type in your code.
63 Returns a dict with Firestore field names (aliases) for use with batch.update().
64 """
65 result: dict[str, Any] = {}
66 for k, v in data.items():
67 if k in cls.__pydantic_fields__:
68 field_info = cls.__pydantic_fields__[k]
69 validated_value = cast(
70 "Any",
71 TypeAdapter(field_info.annotation).validate_python(v),
72 )
73 # Use alias if defined, otherwise use field name
74 output_key = field_info.alias or k
75 result[output_key] = validated_value
76 return result
79SEARCHRESPONSE_FIELD_NAMES: list[str] = list(SearchResponseModel.model_fields.keys())
82class SearchResponseDict(TypedDict, total=False):
83 q: str
84 found: int
85 page: int
86 out_of: int
87 collection_name: str
88 results: list[SearchDocumentDict]
89 highlights: list[ResultHintDict]