Skip to content

Commit 52eec4c

Browse files
authored
Upgrade schemars to 0.9 (#4682)
2 parents 8d85f89 + db2288b commit 52eec4c

File tree

24 files changed

+3405
-3022
lines changed

24 files changed

+3405
-3022
lines changed

Cargo.lock

Lines changed: 20 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ syn2mas = { path = "./crates/syn2mas", version = "=1.6.0-rc.0" }
6666

6767
# OpenAPI schema generation and validation
6868
[workspace.dependencies.aide]
69-
version = "0.14.2"
69+
version = "0.15.1"
7070
features = ["axum", "axum-extra", "axum-extra-query", "axum-json", "macros"]
7171

7272
# An `Arc` that can be atomically updated
@@ -336,7 +336,7 @@ features = ["yaml", "json"]
336336
# IP network address types
337337
[workspace.dependencies.ipnetwork]
338338
version = "0.20.0"
339-
features = ["serde", "schemars"]
339+
features = ["serde"]
340340

341341
# Iterator utilities
342342
[workspace.dependencies.itertools]
@@ -541,8 +541,8 @@ version = "0.4.5"
541541

542542
# JSON Schema generation
543543
[workspace.dependencies.schemars]
544-
version = "0.8.22"
545-
features = ["url", "chrono", "preserve_order"]
544+
version = "0.9.0"
545+
features = ["url2", "chrono04", "preserve_order"]
546546

547547
# SEC1 encoding format
548548
[workspace.dependencies.sec1]

crates/config/src/bin/schema.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
55
// Please see LICENSE files in the repository root for full details.
66

7-
use schemars::r#gen::SchemaSettings;
7+
use schemars::generate::SchemaSettings;
88

99
fn main() {
10-
let settings = SchemaSettings::draft07().with(|s| {
11-
s.option_nullable = false;
12-
s.option_add_null_type = false;
13-
});
14-
let generator = settings.into_generator();
10+
let generator = SchemaSettings::draft07().into_generator();
1511
let schema = generator.into_root_schema_for::<mas_config::RootConfig>();
1612

1713
serde_json::to_writer_pretty(std::io::stdout(), &schema).expect("Failed to serialize schema");

crates/config/src/schema.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,22 @@
66

77
//! Useful JSON Schema definitions
88
9-
use schemars::{
10-
JsonSchema,
11-
r#gen::SchemaGenerator,
12-
schema::{InstanceType, Schema, SchemaObject},
13-
};
9+
use std::borrow::Cow;
10+
11+
use schemars::{JsonSchema, Schema, SchemaGenerator, json_schema};
1412

1513
/// A network hostname
1614
pub struct Hostname;
1715

1816
impl JsonSchema for Hostname {
19-
fn schema_name() -> String {
20-
"Hostname".to_string()
17+
fn schema_name() -> Cow<'static, str> {
18+
Cow::Borrowed("Hostname")
2119
}
2220

23-
fn json_schema(generator: &mut SchemaGenerator) -> Schema {
24-
hostname(generator)
21+
fn json_schema(_generator: &mut SchemaGenerator) -> Schema {
22+
json_schema!({
23+
"type": "string",
24+
"format": "hostname",
25+
})
2526
}
2627
}
27-
28-
fn hostname(_gen: &mut SchemaGenerator) -> Schema {
29-
Schema::Object(SchemaObject {
30-
instance_type: Some(InstanceType::String.into()),
31-
format: Some("hostname".to_owned()),
32-
..SchemaObject::default()
33-
})
34-
}

crates/config/src/sections/http.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ fn default_public_base() -> Url {
2323
"http://[::]:8080".parse().unwrap()
2424
}
2525

26-
fn http_address_example_1() -> &'static str {
27-
"[::1]:8080"
28-
}
29-
fn http_address_example_2() -> &'static str {
30-
"[::]:8080"
31-
}
32-
fn http_address_example_3() -> &'static str {
33-
"127.0.0.1:8080"
34-
}
35-
fn http_address_example_4() -> &'static str {
36-
"0.0.0.0:8080"
37-
}
38-
3926
#[cfg(not(any(feature = "docker", feature = "dist")))]
4027
fn http_listener_assets_path_default() -> Utf8PathBuf {
4128
"./frontend/dist/".into()
@@ -111,10 +98,10 @@ pub enum BindConfig {
11198
Address {
11299
/// Host and port on which to listen
113100
#[schemars(
114-
example = "http_address_example_1",
115-
example = "http_address_example_2",
116-
example = "http_address_example_3",
117-
example = "http_address_example_4"
101+
example = &"[::1]:8080",
102+
example = &"[::]:8080",
103+
example = &"127.0.0.1:8080",
104+
example = &"0.0.0.0:8080",
118105
)]
119106
address: String,
120107
},
@@ -354,6 +341,7 @@ pub struct HttpConfig {
354341
/// List of trusted reverse proxies that can set the `X-Forwarded-For`
355342
/// header
356343
#[serde(default = "default_trusted_proxies")]
344+
#[schemars(with = "Vec<String>", inner(ip))]
357345
pub trusted_proxies: Vec<IpNetwork>,
358346

359347
/// Public URL base from where the authentication service is reachable

crates/config/src/sections/secrets.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ use tracing::info;
2020

2121
use super::ConfigurationSection;
2222

23-
fn example_secret() -> &'static str {
24-
"0000111122223333444455556666777788889999aaaabbbbccccddddeeeeffff"
25-
}
26-
2723
/// Password config option.
2824
///
2925
/// It either holds the password value directly or references a file where the
@@ -209,7 +205,7 @@ struct EncryptionRaw {
209205
#[schemars(
210206
with = "Option<String>",
211207
regex(pattern = r"[0-9a-fA-F]{64}"),
212-
example = "example_secret"
208+
example = &"0000111122223333444455556666777788889999aaaabbbbccccddddeeeeffff"
213209
)]
214210
#[serde_as(as = "Option<serde_with::hex::Hex>")]
215211
#[serde(skip_serializing_if = "Option::is_none")]

crates/config/src/sections/telemetry.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ use url::Url;
1111

1212
use super::ConfigurationSection;
1313

14-
fn sample_rate_example() -> f64 {
15-
0.5
16-
}
17-
1814
/// Propagation format for incoming and outgoing requests
1915
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
2016
#[serde(rename_all = "lowercase")]
@@ -70,7 +66,7 @@ pub struct TracingConfig {
7066
///
7167
/// Defaults to `1.0` if not set.
7268
#[serde(skip_serializing_if = "Option::is_none")]
73-
#[schemars(example = "sample_rate_example", range(min = 0.0, max = 1.0))]
69+
#[schemars(example = 0.5, range(min = 0.0, max = 1.0))]
7470
pub sample_rate: Option<f64>,
7571
}
7672

@@ -123,41 +119,33 @@ impl MetricsConfig {
123119
}
124120
}
125121

126-
fn sentry_dsn_example() -> &'static str {
127-
"https://public@host:port/1"
128-
}
129-
130-
fn sentry_environment_example() -> &'static str {
131-
"production"
132-
}
133-
134122
/// Configuration related to the Sentry integration
135123
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
136124
pub struct SentryConfig {
137125
/// Sentry DSN
138-
#[schemars(url, example = "sentry_dsn_example")]
126+
#[schemars(url, example = &"https://public@host:port/1")]
139127
#[serde(skip_serializing_if = "Option::is_none")]
140128
pub dsn: Option<String>,
141129

142130
/// Environment to use when sending events to Sentry
143131
///
144132
/// Defaults to `production` if not set.
145-
#[schemars(example = "sentry_environment_example")]
133+
#[schemars(example = &"production")]
146134
#[serde(skip_serializing_if = "Option::is_none")]
147135
pub environment: Option<String>,
148136

149137
/// Sample rate for event submissions
150138
///
151139
/// Defaults to `1.0` if not set.
152140
#[serde(skip_serializing_if = "Option::is_none")]
153-
#[schemars(example = "sample_rate_example", range(min = 0.0, max = 1.0))]
141+
#[schemars(example = 0.5, range(min = 0.0, max = 1.0))]
154142
pub sample_rate: Option<f32>,
155143

156144
/// Sample rate for tracing transactions
157145
///
158146
/// Defaults to `0.0` if not set.
159147
#[serde(skip_serializing_if = "Option::is_none")]
160-
#[schemars(example = "sample_rate_example", range(min = 0.0, max = 1.0))]
148+
#[schemars(example = 0.5, range(min = 0.0, max = 1.0))]
161149
pub traces_sample_rate: Option<f32>,
162150
}
163151

0 commit comments

Comments
 (0)