Skip to main content

estat_api/
catalog.rs

1//! Response of `getDataCatalog`.
2
3use crate::de;
4use crate::response::{ApiResult, CodeName, Description, ResultInf};
5use serde::{Deserialize, Serialize};
6use serde_json::{Map, Value};
7
8/// Response of [`EstatApi::data_catalog`](crate::EstatApi::data_catalog) (`GET_DATA_CATALOG`).
9#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
11#[non_exhaustive]
12pub struct DataCatalog {
13    /// Outcome of the request.
14    pub result: ApiResult,
15    /// Parameters as e-Stat received them.
16    #[serde(default)]
17    pub parameter: Map<String, Value>,
18    /// Datasets found. Empty when [`ApiResult::status`] is `1` (no match).
19    #[serde(default, deserialize_with = "de::object_or_default")]
20    pub data_catalog_list_inf: DataCatalogListInf,
21    /// Fields this crate does not know yet, kept as received.
22    #[serde(flatten)]
23    pub extra: Map<String, Value>,
24}
25
26/// `DATA_CATALOG_LIST_INF` element.
27#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
28#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
29#[non_exhaustive]
30pub struct DataCatalogListInf {
31    /// Number of datasets matching the conditions.
32    #[serde(default, deserialize_with = "de::number")]
33    pub number: u64,
34    /// Position of the returned datasets.
35    #[serde(default, deserialize_with = "de::object_or_default")]
36    pub result_inf: ResultInf,
37    /// Datasets.
38    #[serde(default, deserialize_with = "de::one_or_many")]
39    pub data_catalog_inf: Vec<DataCatalogInf>,
40    /// Fields this crate does not know yet, kept as received.
41    #[serde(flatten)]
42    pub extra: Map<String, Value>,
43}
44
45/// `DATA_CATALOG_INF` element: a dataset and its files.
46#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
47#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
48#[non_exhaustive]
49pub struct DataCatalogInf {
50    /// Catalog ID (`@id`).
51    #[serde(rename = "@id")]
52    pub id: String,
53    /// The dataset.
54    pub dataset: Dataset,
55    /// Its files and database tables.
56    #[serde(default, deserialize_with = "de::object_or_default")]
57    pub resources: Resources,
58    /// Fields this crate does not know yet, kept as received.
59    #[serde(flatten)]
60    pub extra: Map<String, Value>,
61}
62
63/// `DATASET` element.
64#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
65#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
66#[non_exhaustive]
67pub struct Dataset {
68    /// Survey name with the government statistics code.
69    #[serde(
70        default,
71        deserialize_with = "de::object_or_empty",
72        skip_serializing_if = "Option::is_none"
73    )]
74    pub stat_name: Option<CodeName>,
75    /// Agency with its code.
76    #[serde(
77        default,
78        deserialize_with = "de::object_or_empty",
79        skip_serializing_if = "Option::is_none"
80    )]
81    pub organization: Option<CodeName>,
82    /// Names.
83    #[serde(
84        default,
85        deserialize_with = "de::object_or_empty",
86        skip_serializing_if = "Option::is_none"
87    )]
88    pub title: Option<DatasetTitle>,
89    /// Explanations. `None` when e-Stat sends an empty element.
90    #[serde(
91        default,
92        deserialize_with = "de::object_or_empty",
93        skip_serializing_if = "Option::is_none"
94    )]
95    pub description: Option<Description>,
96    /// Publishing organization (公表組織名).
97    #[serde(
98        default,
99        deserialize_with = "de::opt_text",
100        skip_serializing_if = "Option::is_none"
101    )]
102    pub publisher: Option<String>,
103    /// Contact of the agency.
104    #[serde(
105        default,
106        deserialize_with = "de::opt_text",
107        skip_serializing_if = "Option::is_none"
108    )]
109    pub contact_point: Option<String>,
110    /// Creator.
111    #[serde(
112        default,
113        deserialize_with = "de::opt_text",
114        skip_serializing_if = "Option::is_none"
115    )]
116    pub creator: Option<String>,
117    /// Release date, `yyyy-mm-dd`.
118    #[serde(
119        default,
120        deserialize_with = "de::opt_text",
121        skip_serializing_if = "Option::is_none"
122    )]
123    pub release_date: Option<String>,
124    /// Last modified date, `yyyy-mm-dd`.
125    #[serde(
126        default,
127        deserialize_with = "de::opt_text",
128        skip_serializing_if = "Option::is_none"
129    )]
130    pub last_modified_date: Option<String>,
131    /// Update frequency.
132    #[serde(
133        default,
134        deserialize_with = "de::opt_text",
135        skip_serializing_if = "Option::is_none"
136    )]
137    pub frequency_of_update: Option<String>,
138    /// Page on e-Stat. Empty for database tables.
139    #[serde(
140        default,
141        deserialize_with = "de::opt_text",
142        skip_serializing_if = "Option::is_none"
143    )]
144    pub landing_page: Option<String>,
145    /// Fields this crate does not know yet, kept as received.
146    #[serde(flatten)]
147    pub extra: Map<String, Value>,
148}
149
150/// `TITLE` element of a [`Dataset`].
151#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
152#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
153#[non_exhaustive]
154pub struct DatasetTitle {
155    /// Dataset name.
156    #[serde(
157        default,
158        deserialize_with = "de::opt_text",
159        skip_serializing_if = "Option::is_none"
160    )]
161    pub name: Option<String>,
162    /// Name of the statistics (提供統計名).
163    #[serde(
164        default,
165        deserialize_with = "de::opt_text",
166        skip_serializing_if = "Option::is_none"
167    )]
168    pub tabulation_category: Option<String>,
169    /// Classification 1 (提供分類名1).
170    #[serde(
171        default,
172        deserialize_with = "de::opt_text",
173        skip_serializing_if = "Option::is_none"
174    )]
175    pub tabulation_sub_category1: Option<String>,
176    /// Classification 2.
177    #[serde(
178        default,
179        deserialize_with = "de::opt_text",
180        skip_serializing_if = "Option::is_none"
181    )]
182    pub tabulation_sub_category2: Option<String>,
183    /// Classification 3.
184    #[serde(
185        default,
186        deserialize_with = "de::opt_text",
187        skip_serializing_if = "Option::is_none"
188    )]
189    pub tabulation_sub_category3: Option<String>,
190    /// Classification 4.
191    #[serde(
192        default,
193        deserialize_with = "de::opt_text",
194        skip_serializing_if = "Option::is_none"
195    )]
196    pub tabulation_sub_category4: Option<String>,
197    /// Classification 5.
198    #[serde(
199        default,
200        deserialize_with = "de::opt_text",
201        skip_serializing_if = "Option::is_none"
202    )]
203    pub tabulation_sub_category5: Option<String>,
204    /// Release cycle (提供周期).
205    #[serde(
206        default,
207        deserialize_with = "de::opt_text",
208        skip_serializing_if = "Option::is_none"
209    )]
210    pub cycle: Option<String>,
211    /// Survey period (調査実施時期), such as `2006` or `201210`.
212    #[serde(
213        default,
214        deserialize_with = "de::opt_text",
215        skip_serializing_if = "Option::is_none"
216    )]
217    pub survey_date: Option<String>,
218    /// Area level (集計地域区分).
219    #[serde(
220        default,
221        deserialize_with = "de::opt_text",
222        skip_serializing_if = "Option::is_none"
223    )]
224    pub collect_area: Option<String>,
225    /// Fields this crate does not know yet, kept as received.
226    #[serde(flatten)]
227    pub extra: Map<String, Value>,
228}
229
230/// `RESOURCES` element.
231#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
232#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
233#[non_exhaustive]
234pub struct Resources {
235    /// Files and database tables.
236    #[serde(default, deserialize_with = "de::one_or_many")]
237    pub resource: Vec<Resource>,
238    /// Fields this crate does not know yet, kept as received.
239    #[serde(flatten)]
240    pub extra: Map<String, Value>,
241}
242
243/// `RESOURCE` element: one file, or one table of the statistics database.
244#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
245#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
246#[non_exhaustive]
247pub struct Resource {
248    /// Resource ID (`@id`).
249    #[serde(rename = "@id")]
250    pub id: String,
251    /// Names.
252    #[serde(
253        default,
254        deserialize_with = "de::object_or_empty",
255        skip_serializing_if = "Option::is_none"
256    )]
257    pub title: Option<ResourceTitle>,
258    /// Download URL on e-Stat, or the table ID for database tables
259    /// ([`format`](Self::format) `DB`).
260    #[serde(
261        default,
262        deserialize_with = "de::opt_text",
263        skip_serializing_if = "Option::is_none"
264    )]
265    pub url: Option<String>,
266    /// Explanation.
267    #[serde(
268        default,
269        deserialize_with = "de::opt_text",
270        skip_serializing_if = "Option::is_none"
271    )]
272    pub description: Option<String>,
273    /// Format: `XLS`, `CSV`, `PDF`, `XML`, `XLS_REP` or `DB`.
274    #[serde(
275        default,
276        deserialize_with = "de::opt_text",
277        skip_serializing_if = "Option::is_none"
278    )]
279    pub format: Option<String>,
280    /// Release date, `yyyy-mm-dd`.
281    #[serde(
282        default,
283        deserialize_with = "de::opt_text",
284        skip_serializing_if = "Option::is_none"
285    )]
286    pub release_date: Option<String>,
287    /// Last modified date, `yyyy-mm-dd`.
288    #[serde(
289        default,
290        deserialize_with = "de::opt_text",
291        skip_serializing_if = "Option::is_none"
292    )]
293    pub last_modified_date: Option<String>,
294    /// License, such as `Government of Japan Standard Terms of Use`.
295    #[serde(
296        default,
297        deserialize_with = "de::opt_text",
298        skip_serializing_if = "Option::is_none"
299    )]
300    pub resource_licence_id: Option<String>,
301    /// Language, `J` or `E`.
302    #[serde(
303        default,
304        deserialize_with = "de::opt_text",
305        skip_serializing_if = "Option::is_none"
306    )]
307    pub language: Option<String>,
308    /// Fields this crate does not know yet, kept as received.
309    #[serde(flatten)]
310    pub extra: Map<String, Value>,
311}
312
313/// `TITLE` element of a [`Resource`].
314#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
315#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
316#[non_exhaustive]
317pub struct ResourceTitle {
318    /// Resource name.
319    #[serde(
320        default,
321        deserialize_with = "de::opt_text",
322        skip_serializing_if = "Option::is_none"
323    )]
324    pub name: Option<String>,
325    /// Table category (表分類名).
326    #[serde(
327        default,
328        deserialize_with = "de::opt_text",
329        skip_serializing_if = "Option::is_none"
330    )]
331    pub table_category: Option<String>,
332    /// Table number (表番号). e-Stat sends a number or a string; it is kept as text.
333    #[serde(
334        default,
335        deserialize_with = "de::opt_text",
336        skip_serializing_if = "Option::is_none"
337    )]
338    pub table_no: Option<String>,
339    /// Title (表題).
340    #[serde(
341        default,
342        deserialize_with = "de::opt_text",
343        skip_serializing_if = "Option::is_none"
344    )]
345    pub table_name: Option<String>,
346    /// Explanation of the table.
347    #[serde(
348        default,
349        deserialize_with = "de::opt_text",
350        skip_serializing_if = "Option::is_none"
351    )]
352    pub table_explanation: Option<String>,
353    /// Title division 1 (表題区分1).
354    #[serde(
355        default,
356        deserialize_with = "de::opt_text",
357        skip_serializing_if = "Option::is_none"
358    )]
359    pub table_sub_category1: Option<String>,
360    /// Title division 2.
361    #[serde(
362        default,
363        deserialize_with = "de::opt_text",
364        skip_serializing_if = "Option::is_none"
365    )]
366    pub table_sub_category2: Option<String>,
367    /// Title division 3.
368    #[serde(
369        default,
370        deserialize_with = "de::opt_text",
371        skip_serializing_if = "Option::is_none"
372    )]
373    pub table_sub_category3: Option<String>,
374    /// Fields this crate does not know yet, kept as received.
375    #[serde(flatten)]
376    pub extra: Map<String, Value>,
377}