Skip to content

Commit dd12f94

Browse files
committed
Upgrade schemars to 0.9
1 parent 23e5063 commit dd12f94

File tree

22 files changed

+2487
-2625
lines changed

22 files changed

+2487
-2625
lines changed

Cargo.lock

Lines changed: 30 additions & 10 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
@@ -60,7 +60,7 @@ syn2mas = { path = "./crates/syn2mas", version = "=0.17.0-rc.0" }
6060

6161
# OpenAPI schema generation and validation
6262
[workspace.dependencies.aide]
63-
version = "0.14.2"
63+
version = "0.15.0"
6464
features = ["axum", "axum-extra", "axum-json", "axum-query", "macros"]
6565

6666
# An `Arc` that can be atomically updated
@@ -330,7 +330,7 @@ features = ["yaml", "json"]
330330
# IP network address types
331331
[workspace.dependencies.ipnetwork]
332332
version = "0.20.0"
333-
features = ["serde", "schemars"]
333+
features = ["serde"]
334334

335335
# Iterator utilities
336336
[workspace.dependencies.itertools]
@@ -531,8 +531,8 @@ version = "0.4.5"
531531

532532
# JSON Schema generation
533533
[workspace.dependencies.schemars]
534-
version = "0.8.22"
535-
features = ["url", "chrono", "preserve_order"]
534+
version = "0.9.0"
535+
features = ["url2", "chrono04", "preserve_order"]
536536

537537
# SEC1 encoding format
538538
[workspace.dependencies.sec1]

crates/config/src/bin/schema.rs

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

7-
use schemars::r#gen::SchemaSettings;
7+
use schemars::{
8+
generate::SchemaSettings,
9+
transform::{AddNullable, RecursiveTransform},
10+
};
811

912
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();
13+
let generator = SchemaSettings::draft07()
14+
.with_transform(RecursiveTransform(AddNullable::default()))
15+
.into_generator();
1516
let schema = generator.into_root_schema_for::<mas_config::RootConfig>();
1617

1718
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
@@ -24,10 +24,6 @@ use tracing::info;
2424

2525
use super::ConfigurationSection;
2626

27-
fn example_secret() -> &'static str {
28-
"0000111122223333444455556666777788889999aaaabbbbccccddddeeeeffff"
29-
}
30-
3127
/// Password config option.
3228
///
3329
/// It either holds the password value directly or references a file where the
@@ -204,7 +200,7 @@ struct EncryptionRaw {
204200
#[schemars(
205201
with = "Option<String>",
206202
regex(pattern = r"[0-9a-fA-F]{64}"),
207-
example = "example_secret"
203+
example = &"0000111122223333444455556666777788889999aaaabbbbccccddddeeeeffff"
208204
)]
209205
#[serde_as(as = "Option<serde_with::hex::Hex>")]
210206
#[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

crates/handlers/src/admin/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use mas_router::{
2929
};
3030
use mas_storage::BoxRng;
3131
use mas_templates::{ApiDocContext, Templates};
32+
use schemars::transform::{AddNullable, RecursiveTransform};
3233
use tower_http::cors::{Any, CorsLayer};
3334

3435
mod call_context;
@@ -159,8 +160,10 @@ where
159160
aide::generate::infer_responses(false);
160161

161162
aide::generate::in_context(|ctx| {
162-
ctx.schema =
163-
schemars::r#gen::SchemaGenerator::new(schemars::r#gen::SchemaSettings::openapi3());
163+
ctx.schema = schemars::generate::SchemaGenerator::new(
164+
schemars::generate::SchemaSettings::openapi3()
165+
.with_transform(RecursiveTransform(AddNullable::default())),
166+
);
164167
});
165168

166169
let mut api = OpenApi::default();

0 commit comments

Comments
 (0)