Coverage for C: \ Users \ peaco \ OneDrive \ Documents \ GitHub \ mt_metadata \ mt_metadata \ common \ citation.py: 100%
16 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-10 00:11 -0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-10 00:11 -0800
1# =====================================================
2# Imports
3# =====================================================
4from typing import Annotated
6from pydantic import AliasChoices, Field, field_validator, HttpUrl
8from mt_metadata.base import MetadataBase
9from mt_metadata.utils.validators import validate_doi
12# =====================================================
13class Citation(MetadataBase):
14 doi: Annotated[
15 HttpUrl | str | None,
16 Field(
17 default=None,
18 description="full url of the doi number",
19 validation_alias=AliasChoices("doi", "survey_doi"),
20 json_schema_extra={
21 "units": None,
22 "required": False,
23 "examples": ["http://doi.###"],
24 },
25 ),
26 ]
28 authors: Annotated[
29 str | None,
30 Field(
31 default=None,
32 description="author names",
33 alias=None,
34 json_schema_extra={
35 "units": None,
36 "required": False,
37 "examples": ["M.Tee A. Roura"],
38 },
39 ),
40 ]
42 title: Annotated[
43 str | None,
44 Field(
45 default=None,
46 description="Full title of the citation",
47 alias=None,
48 json_schema_extra={
49 "units": None,
50 "required": False,
51 "examples": ["Paper Title"],
52 },
53 ),
54 ]
56 year: Annotated[
57 str | None,
58 Field(
59 default=None,
60 description="Year of citation",
61 alias=None,
62 pattern=r"^\d{4}(-\d{4})?$", # Allows for ranges like "2020-2021"
63 json_schema_extra={
64 "units": None,
65 "required": False,
66 "examples": ["2020"],
67 },
68 ),
69 ]
71 volume: Annotated[
72 str | None,
73 Field(
74 default=None,
75 description="Journal volume of the citation",
76 alias=None,
77 json_schema_extra={
78 "units": None,
79 "required": False,
80 "examples": ["12"],
81 },
82 ),
83 ]
85 pages: Annotated[
86 str | None,
87 Field(
88 default=None,
89 description="Page numbers of the citation",
90 alias=None,
91 json_schema_extra={
92 "units": None,
93 "required": False,
94 "examples": ["10-15"],
95 },
96 ),
97 ]
99 journal: Annotated[
100 str | None,
101 Field(
102 default=None,
103 description="Journal title of citation",
104 alias=None,
105 json_schema_extra={
106 "units": None,
107 "required": False,
108 "examples": ["Journal of Geophysical Research"],
109 },
110 ),
111 ]
113 @field_validator("doi", mode="before")
114 @classmethod
115 def validate_doi(
116 cls,
117 value: HttpUrl | str | None,
118 ) -> HttpUrl | None:
119 """
120 Validate the DOI.
122 Parameters
123 ----------
124 value : str | None
125 The DOI value to validate.
126 info : ValidationInfo
127 Additional validation information.
129 Returns
130 -------
131 str | None
132 The validated DOI or None if not provided.
133 """
134 return validate_doi(value)