Skip to main content

opendatasoft_explore_api/
schema.rs

1//! Schema for Opendatasoft Explore API v2
2
3use chrono::{DateTime, Utc};
4use serde_derive::Deserialize;
5use serde_derive::Serialize;
6use serde_json::Value as JsonValue;
7
8/*  -------------------------------------------------------------
9    links
10    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    */
11
12#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
13pub struct Link {
14    pub href: String,
15    pub rel: String,
16}
17
18/*  -------------------------------------------------------------
19    dataset
20    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    */
21
22#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
23pub struct Dataset {
24    pub links: Vec<Link>,
25    pub dataset: DatasetProperties,
26}
27
28#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
29pub struct DatasetProperties {
30    pub dataset_id: String,
31    pub dataset_uid: String,
32    pub attachments: Vec<AttachmentProperties>,
33    pub has_records: bool,
34    pub data_visible: bool,
35    /// A map of available features for a dataset, with the fields they apply to.
36    pub features: Vec<String>,
37    pub metas: JsonValue,
38    pub fields: Vec<DatasetField>,
39    #[serde(rename = "additionalProperties", default, skip_serializing_if = "Option::is_none")]
40    pub additional_properties: Option<JsonValue>,
41}
42
43#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
44pub struct DatasetField {
45    pub name: String,
46    pub label: String,
47    #[serde(rename = "type")]
48    pub field_type: String,
49    pub annotations: JsonValue,
50    #[serde(rename = "description", skip_serializing_if = "Option::is_none")]
51    pub description: Option<String>,
52}
53
54/*  -------------------------------------------------------------
55    results_dataset
56    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    */
57
58#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
59pub struct DatasetsCollection {
60    pub total_count: usize,
61    pub links: Vec<Link>,
62    pub datasets: Vec<Dataset>,
63}
64
65/*  -------------------------------------------------------------
66    facet_value_enumeration
67    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    */
68
69#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
70pub struct FacetValueEnumeration {
71    pub name: String,
72    pub count: usize,
73    pub value: String,
74    pub state: String,
75}
76
77/*  -------------------------------------------------------------
78    facet_enumeration
79    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    */
80
81#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
82pub struct FacetEnumeration {
83    pub name: String,
84    pub facets: Vec<FacetValueEnumeration>,
85}
86
87/*  -------------------------------------------------------------
88    aggregation
89    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    */
90
91#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
92pub struct Aggregation {
93    pub count: usize,
94    pub cou_name_en: String,
95}
96
97/*  -------------------------------------------------------------
98    record
99    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    */
100
101#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
102pub struct Record {
103    pub record: RecordProperties,
104    pub links: Vec<Link>,
105}
106
107#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
108pub struct RecordProperties {
109    pub id: String,
110    pub timestamp: DateTime<Utc>,
111    pub size: usize,
112    pub fields: JsonValue,
113}
114
115/*  -------------------------------------------------------------
116    results
117    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    */
118
119#[derive(Clone, Debug, Default, Serialize, Deserialize)]
120pub struct Results {
121    pub total_count: usize,
122    pub links: Vec<Link>,
123    pub records: Vec<ResultsRecord>,
124}
125
126#[derive(Clone, Debug, Serialize, Deserialize)]
127#[serde(untagged)]
128pub enum ResultsRecord {
129    Aggregation(Aggregation),
130    Record(Record),
131}
132
133/*  -------------------------------------------------------------
134    attachment
135    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    */
136
137#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
138pub struct Attachment {
139    pub href: String,
140    pub metas: AttachmentProperties,
141}
142
143#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
144pub struct AttachmentProperties {
145    #[serde(rename = "mime-type", default, skip_serializing_if = "Option::is_none")]
146    pub mime_type: Option<String>,
147    pub title: String,
148    pub url: String,
149    pub id: String,
150}
151
152/*  -------------------------------------------------------------
153    Response to /catalog/datasets/{dataset_id}/attachments
154    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    */
155
156#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
157pub struct AttachmentCollection {
158    pub links: Vec<Link>,
159    pub attachments: Vec<Attachment>,
160}
161
162/*  -------------------------------------------------------------
163    Response to /catalog/facets
164    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -    */
165
166#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
167pub struct FacetsCollection {
168    pub links: Vec<Link>,
169    pub facets: Vec<FacetEnumeration>,
170}