Upgrade schemars to 0.9

This commit is contained in:
Quentin Gliech
2025-06-12 15:43:55 +02:00
parent 451cb4939d
commit e54664ad6f
22 changed files with 2412 additions and 2550 deletions

40
Cargo.lock generated
View File

@@ -85,9 +85,9 @@ dependencies = [
[[package]]
name = "aide"
version = "0.14.2"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2477554ebf38aea815a9c4729100cfc32f766876c45b9c9c38ef221b9d1a703"
checksum = "4d34f0f6ce85b460bf2f9e7eea6612f217ba700ae14e9e476805d2413480f64b"
dependencies = [
"aide-macros",
"axum",
@@ -108,11 +108,12 @@ dependencies = [
[[package]]
name = "aide-macros"
version = "0.8.0"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be8e0d4af7cc08353807aaf80722125a229bf2d67be7fe0b89163c648db3d223"
checksum = "9f2a08f14808f3c46f3e3004b727bace64af44c3c5996d0480a14d3852b1b25a"
dependencies = [
"darling",
"proc-macro2",
"quote",
"syn",
]
@@ -2812,7 +2813,6 @@ version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf466541e9d546596ee94f9f69590f89473455f88372423e0008fc1a7daf100e"
dependencies = [
"schemars",
"serde",
]
@@ -4970,6 +4970,26 @@ dependencies = [
"bitflags",
]
[[package]]
name = "ref-cast"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a0ae411dbe946a674d89546582cea4ba2bb8defac896622d6496f14c23ba5cf"
dependencies = [
"ref-cast-impl",
]
[[package]]
name = "ref-cast-impl"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1165225c21bff1f3bbce98f5a1f889949bc902d3575308cc7b0de30b4f6d27c7"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "regalloc2"
version = "0.11.2"
@@ -5344,14 +5364,14 @@ dependencies = [
[[package]]
name = "schemars"
version = "0.8.22"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fbf2ae1b8bc8e02df939598064d22402220cd5bbcca1c76f7d6a310974d5615"
checksum = "4cd191f9397d57d581cddd31014772520aa448f65ef991055d7f61582c65165f"
dependencies = [
"chrono",
"dyn-clone",
"indexmap 1.9.3",
"indexmap 2.9.0",
"ref-cast",
"schemars_derive",
"serde",
"serde_json",
@@ -5360,9 +5380,9 @@ dependencies = [
[[package]]
name = "schemars_derive"
version = "0.8.22"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32e265784ad618884abaea0600a9adf15393368d840e0222d101a072f3f7534d"
checksum = "5016d94c77c6d32f0b8e08b781f7dc8a90c2007d4e77472cc2807bc10a8438fe"
dependencies = [
"proc-macro2",
"quote",

View File

@@ -60,7 +60,7 @@ syn2mas = { path = "./crates/syn2mas", version = "=0.17.0-rc.0" }
# OpenAPI schema generation and validation
[workspace.dependencies.aide]
version = "0.14.2"
version = "0.15.0"
features = ["axum", "axum-extra", "axum-json", "axum-query", "macros"]
# An `Arc` that can be atomically updated
@@ -330,7 +330,7 @@ features = ["yaml", "json"]
# IP network address types
[workspace.dependencies.ipnetwork]
version = "0.20.0"
features = ["serde", "schemars"]
features = ["serde"]
# Iterator utilities
[workspace.dependencies.itertools]
@@ -531,8 +531,8 @@ version = "0.4.5"
# JSON Schema generation
[workspace.dependencies.schemars]
version = "0.8.22"
features = ["url", "chrono", "preserve_order"]
version = "0.9.0"
features = ["url2", "chrono04", "preserve_order"]
# SEC1 encoding format
[workspace.dependencies.sec1]

View File

@@ -4,14 +4,15 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Please see LICENSE in the repository root for full details.
use schemars::r#gen::SchemaSettings;
use schemars::{
generate::SchemaSettings,
transform::{AddNullable, RecursiveTransform},
};
fn main() {
let settings = SchemaSettings::draft07().with(|s| {
s.option_nullable = false;
s.option_add_null_type = false;
});
let generator = settings.into_generator();
let generator = SchemaSettings::draft07()
.with_transform(RecursiveTransform(AddNullable::default()))
.into_generator();
let schema = generator.into_root_schema_for::<mas_config::RootConfig>();
serde_json::to_writer_pretty(std::io::stdout(), &schema).expect("Failed to serialize schema");

View File

@@ -6,29 +6,22 @@
//! Useful JSON Schema definitions
use schemars::{
JsonSchema,
r#gen::SchemaGenerator,
schema::{InstanceType, Schema, SchemaObject},
};
use std::borrow::Cow;
use schemars::{JsonSchema, Schema, SchemaGenerator, json_schema};
/// A network hostname
pub struct Hostname;
impl JsonSchema for Hostname {
fn schema_name() -> String {
"Hostname".to_string()
fn schema_name() -> Cow<'static, str> {
Cow::Borrowed("Hostname")
}
fn json_schema(generator: &mut SchemaGenerator) -> Schema {
hostname(generator)
fn json_schema(_generator: &mut SchemaGenerator) -> Schema {
json_schema!({
"type": "string",
"format": "hostname",
})
}
}
fn hostname(_gen: &mut SchemaGenerator) -> Schema {
Schema::Object(SchemaObject {
instance_type: Some(InstanceType::String.into()),
format: Some("hostname".to_owned()),
..SchemaObject::default()
})
}

View File

@@ -23,19 +23,6 @@ fn default_public_base() -> Url {
"http://[::]:8080".parse().unwrap()
}
fn http_address_example_1() -> &'static str {
"[::1]:8080"
}
fn http_address_example_2() -> &'static str {
"[::]:8080"
}
fn http_address_example_3() -> &'static str {
"127.0.0.1:8080"
}
fn http_address_example_4() -> &'static str {
"0.0.0.0:8080"
}
#[cfg(not(any(feature = "docker", feature = "dist")))]
fn http_listener_assets_path_default() -> Utf8PathBuf {
"./frontend/dist/".into()
@@ -111,10 +98,10 @@ pub enum BindConfig {
Address {
/// Host and port on which to listen
#[schemars(
example = "http_address_example_1",
example = "http_address_example_2",
example = "http_address_example_3",
example = "http_address_example_4"
example = &"[::1]:8080",
example = &"[::]:8080",
example = &"127.0.0.1:8080",
example = &"0.0.0.0:8080",
)]
address: String,
},
@@ -354,6 +341,7 @@ pub struct HttpConfig {
/// List of trusted reverse proxies that can set the `X-Forwarded-For`
/// header
#[serde(default = "default_trusted_proxies")]
#[schemars(with = "Vec<String>", inner(ip))]
pub trusted_proxies: Vec<IpNetwork>,
/// Public URL base from where the authentication service is reachable

View File

@@ -24,10 +24,6 @@ use tracing::info;
use super::ConfigurationSection;
fn example_secret() -> &'static str {
"0000111122223333444455556666777788889999aaaabbbbccccddddeeeeffff"
}
/// Password config option.
///
/// It either holds the password value directly or references a file where the
@@ -204,7 +200,7 @@ struct EncryptionRaw {
#[schemars(
with = "Option<String>",
regex(pattern = r"[0-9a-fA-F]{64}"),
example = "example_secret"
example = &"0000111122223333444455556666777788889999aaaabbbbccccddddeeeeffff"
)]
#[serde_as(as = "Option<serde_with::hex::Hex>")]
#[serde(skip_serializing_if = "Option::is_none")]

View File

@@ -11,10 +11,6 @@ use url::Url;
use super::ConfigurationSection;
fn sample_rate_example() -> f64 {
0.5
}
/// Propagation format for incoming and outgoing requests
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "lowercase")]
@@ -70,7 +66,7 @@ pub struct TracingConfig {
///
/// Defaults to `1.0` if not set.
#[serde(skip_serializing_if = "Option::is_none")]
#[schemars(example = "sample_rate_example", range(min = 0.0, max = 1.0))]
#[schemars(example = 0.5, range(min = 0.0, max = 1.0))]
pub sample_rate: Option<f64>,
}
@@ -123,26 +119,18 @@ impl MetricsConfig {
}
}
fn sentry_dsn_example() -> &'static str {
"https://public@host:port/1"
}
fn sentry_environment_example() -> &'static str {
"production"
}
/// Configuration related to the Sentry integration
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
pub struct SentryConfig {
/// Sentry DSN
#[schemars(url, example = "sentry_dsn_example")]
#[schemars(url, example = &"https://public@host:port/1")]
#[serde(skip_serializing_if = "Option::is_none")]
pub dsn: Option<String>,
/// Environment to use when sending events to Sentry
///
/// Defaults to `production` if not set.
#[schemars(example = "sentry_environment_example")]
#[schemars(example = &"production")]
#[serde(skip_serializing_if = "Option::is_none")]
pub environment: Option<String>,
@@ -150,14 +138,14 @@ pub struct SentryConfig {
///
/// Defaults to `1.0` if not set.
#[serde(skip_serializing_if = "Option::is_none")]
#[schemars(example = "sample_rate_example", range(min = 0.0, max = 1.0))]
#[schemars(example = 0.5, range(min = 0.0, max = 1.0))]
pub sample_rate: Option<f32>,
/// Sample rate for tracing transactions
///
/// Defaults to `0.0` if not set.
#[serde(skip_serializing_if = "Option::is_none")]
#[schemars(example = "sample_rate_example", range(min = 0.0, max = 1.0))]
#[schemars(example = 0.5, range(min = 0.0, max = 1.0))]
pub traces_sample_rate: Option<f32>,
}

View File

@@ -29,6 +29,7 @@ use mas_router::{
};
use mas_storage::BoxRng;
use mas_templates::{ApiDocContext, Templates};
use schemars::transform::{AddNullable, RecursiveTransform};
use tower_http::cors::{Any, CorsLayer};
mod call_context;
@@ -159,8 +160,10 @@ where
aide::generate::infer_responses(false);
aide::generate::in_context(|ctx| {
ctx.schema =
schemars::r#gen::SchemaGenerator::new(schemars::r#gen::SchemaSettings::openapi3());
ctx.schema = schemars::generate::SchemaGenerator::new(
schemars::generate::SchemaSettings::openapi3()
.with_transform(RecursiveTransform(AddNullable::default())),
);
});
let mut api = OpenApi::default();

View File

@@ -6,11 +6,9 @@
//! Common schema definitions
use schemars::{
JsonSchema,
r#gen::SchemaGenerator,
schema::{InstanceType, Metadata, Schema, SchemaObject, StringValidation},
};
use std::borrow::Cow;
use schemars::{JsonSchema, Schema, SchemaGenerator, json_schema};
/// A type to use for schema definitions of ULIDs
///
@@ -18,32 +16,21 @@ use schemars::{
pub struct Ulid;
impl JsonSchema for Ulid {
fn schema_name() -> String {
"ULID".to_owned()
fn schema_name() -> Cow<'static, str> {
Cow::Borrowed("ULID")
}
fn json_schema(_gen: &mut SchemaGenerator) -> Schema {
SchemaObject {
instance_type: Some(InstanceType::String.into()),
metadata: Some(Box::new(Metadata {
title: Some("ULID".into()),
description: Some("A ULID as per https://github.com/ulid/spec".into()),
examples: vec![
"01ARZ3NDEKTSV4RRFFQ69G5FAV".into(),
"01J41912SC8VGAQDD50F6APK91".into(),
],
..Metadata::default()
})),
string: Some(Box::new(StringValidation {
pattern: Some(r"^[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$".into()),
..StringValidation::default()
})),
..SchemaObject::default()
}
.into()
json_schema!({
"type": "string",
"title": "ULID",
"description": "A ULID as per https://github.com/ulid/spec",
"examples": [
"01ARZ3NDEKTSV4RRFFQ69G5FAV",
"01J41912SC8VGAQDD50F6APK91",
],
"pattern": "^[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$",
})
}
}
@@ -53,27 +40,20 @@ impl JsonSchema for Ulid {
pub struct Device;
impl JsonSchema for Device {
fn schema_name() -> String {
"DeviceID".to_owned()
fn schema_name() -> Cow<'static, str> {
Cow::Borrowed("DeviceID")
}
fn json_schema(_gen: &mut SchemaGenerator) -> Schema {
SchemaObject {
instance_type: Some(InstanceType::String.into()),
metadata: Some(Box::new(Metadata {
title: Some("Device ID".into()),
examples: vec!["AABBCCDDEE".into(), "FFGGHHIIJJ".into()],
..Metadata::default()
})),
string: Some(Box::new(StringValidation {
pattern: Some(r"^[A-Za-z0-9._~!$&'()*+,;=:&/-]+$".into()),
..StringValidation::default()
})),
..SchemaObject::default()
}
.into()
json_schema!({
"type": "string",
"title": "Device ID",
"description": "A device ID as per https://matrix.org/docs/spec/client_server/r0.6.0#device-ids",
"examples": [
"AABBCCDDEE",
"FFGGHHIIJJ",
],
"pattern": "^[A-Za-z0-9._~!$&'()*+,;=:&/-]+$",
})
}
}

View File

@@ -58,7 +58,7 @@ fn data_example() -> serde_json::Value {
#[derive(Deserialize, JsonSchema)]
#[serde(rename = "SetPolicyDataRequest")]
pub struct SetPolicyDataRequest {
#[schemars(example = "data_example")]
#[schemars(example = data_example())]
pub data: serde_json::Value,
}

View File

@@ -55,16 +55,12 @@ impl IntoResponse for RouteError {
}
}
fn password_example() -> String {
"hunter2".to_owned()
}
/// # JSON payload for the `POST /api/admin/v1/users/:id/set-password` endpoint
#[derive(Deserialize, JsonSchema)]
#[schemars(rename = "SetUserPasswordRequest")]
pub struct Request {
/// The password to set for the user
#[schemars(example = "password_example")]
#[schemars(example = &"hunter2")]
password: String,
/// Skip the password complexity check

View File

@@ -165,12 +165,12 @@ pub fn json_schema_impl(
write!(
f,
r#"impl schemars::JsonSchema for {} {{
fn schema_name() -> String {{
"{}".to_owned()
fn schema_name() -> std::borrow::Cow<'static, str> {{
std::borrow::Cow::Borrowed("{}")
}}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {{
fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {{
let enums = vec!["#,
section.key, section.key,
)?;
@@ -180,20 +180,14 @@ pub fn json_schema_impl(
f,
r"
// ---
schemars::schema::SchemaObject {{",
schemars::json_schema!({{",
)?;
if let Some(description) = &member.description {
write!(
f,
r"
metadata: Some(Box::new(schemars::schema::Metadata {{
description: Some(
// ---
{}.to_owned(),
),
..Default::default()
}})),",
r#"
"description": {},"#,
raw_string(description),
)?;
}
@@ -201,34 +195,24 @@ pub fn json_schema_impl(
write!(
f,
r#"
const_value: Some("{}".into()),
..Default::default()
}}
.into(),"#,
"const": "{}",
}}),"#,
member.value
)?;
}
writeln!(
f,
r"
r#"
];
let description = {};
schemars::schema::SchemaObject {{
metadata: Some(Box::new(schemars::schema::Metadata {{
description: Some(description.to_owned()),
..Default::default()
}})),
subschemas: Some(Box::new(schemars::schema::SubschemaValidation {{
any_of: Some(enums),
..Default::default()
}})),
..Default::default()
}}
.into()
schemars::json_schema!({{
"description": description,
"anyOf": enums,
}})
}}
}}",
}}"#,
raw_string(section.doc),
)
}

File diff suppressed because it is too large Load Diff

View File

@@ -79,52 +79,36 @@ impl serde::Serialize for OAuthAccessTokenType {
}
impl schemars::JsonSchema for OAuthAccessTokenType {
fn schema_name() -> String {
"OAuthAccessTokenType".to_owned()
fn schema_name() -> std::borrow::Cow<'static, str> {
std::borrow::Cow::Borrowed("OAuthAccessTokenType")
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
let enums = vec![
// ---
schemars::schema::SchemaObject {
const_value: Some("Bearer".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "Bearer",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("N_A".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "N_A",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("PoP".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "PoP",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("DPoP".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "DPoP",
}),
];
let description = r"OAuth Access Token Type";
schemars::schema::SchemaObject {
metadata: Some(Box::new(schemars::schema::Metadata {
description: Some(description.to_owned()),
..Default::default()
})),
subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
any_of: Some(enums),
..Default::default()
})),
..Default::default()
}
.into()
schemars::json_schema!({
"description": description,
"anyOf": enums,
})
}
}
@@ -211,76 +195,52 @@ impl serde::Serialize for OAuthAuthorizationEndpointResponseType {
}
impl schemars::JsonSchema for OAuthAuthorizationEndpointResponseType {
fn schema_name() -> String {
"OAuthAuthorizationEndpointResponseType".to_owned()
fn schema_name() -> std::borrow::Cow<'static, str> {
std::borrow::Cow::Borrowed("OAuthAuthorizationEndpointResponseType")
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
let enums = vec![
// ---
schemars::schema::SchemaObject {
const_value: Some("code".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "code",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("code id_token".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "code id_token",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("code id_token token".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "code id_token token",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("code token".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "code token",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("id_token".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "id_token",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("id_token token".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "id_token token",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("none".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "none",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("token".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "token",
}),
];
let description = r"OAuth Authorization Endpoint Response Type";
schemars::schema::SchemaObject {
metadata: Some(Box::new(schemars::schema::Metadata {
description: Some(description.to_owned()),
..Default::default()
})),
subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
any_of: Some(enums),
..Default::default()
})),
..Default::default()
}
.into()
schemars::json_schema!({
"description": description,
"anyOf": enums,
})
}
}
@@ -347,46 +307,32 @@ impl serde::Serialize for OAuthTokenTypeHint {
}
impl schemars::JsonSchema for OAuthTokenTypeHint {
fn schema_name() -> String {
"OAuthTokenTypeHint".to_owned()
fn schema_name() -> std::borrow::Cow<'static, str> {
std::borrow::Cow::Borrowed("OAuthTokenTypeHint")
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
let enums = vec![
// ---
schemars::schema::SchemaObject {
const_value: Some("access_token".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "access_token",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("refresh_token".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "refresh_token",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("pct".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "pct",
}),
];
let description = r"OAuth Token Type Hint";
schemars::schema::SchemaObject {
metadata: Some(Box::new(schemars::schema::Metadata {
description: Some(description.to_owned()),
..Default::default()
})),
subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
any_of: Some(enums),
..Default::default()
})),
..Default::default()
}
.into()
schemars::json_schema!({
"description": description,
"anyOf": enums,
})
}
}
@@ -473,70 +419,48 @@ impl serde::Serialize for OAuthClientAuthenticationMethod {
}
impl schemars::JsonSchema for OAuthClientAuthenticationMethod {
fn schema_name() -> String {
"OAuthClientAuthenticationMethod".to_owned()
fn schema_name() -> std::borrow::Cow<'static, str> {
std::borrow::Cow::Borrowed("OAuthClientAuthenticationMethod")
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
let enums = vec![
// ---
schemars::schema::SchemaObject {
const_value: Some("none".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "none",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("client_secret_post".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "client_secret_post",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("client_secret_basic".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "client_secret_basic",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("client_secret_jwt".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "client_secret_jwt",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("private_key_jwt".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "private_key_jwt",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("tls_client_auth".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "tls_client_auth",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("self_signed_tls_client_auth".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "self_signed_tls_client_auth",
}),
];
let description = r"OAuth Token Endpoint Authentication Method";
schemars::schema::SchemaObject {
metadata: Some(Box::new(schemars::schema::Metadata {
description: Some(description.to_owned()),
..Default::default()
})),
subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
any_of: Some(enums),
..Default::default()
})),
..Default::default()
}
.into()
schemars::json_schema!({
"description": description,
"anyOf": enums,
})
}
}
@@ -598,39 +522,27 @@ impl serde::Serialize for PkceCodeChallengeMethod {
}
impl schemars::JsonSchema for PkceCodeChallengeMethod {
fn schema_name() -> String {
"PkceCodeChallengeMethod".to_owned()
fn schema_name() -> std::borrow::Cow<'static, str> {
std::borrow::Cow::Borrowed("PkceCodeChallengeMethod")
}
#[allow(clippy::too_many_lines)]
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
let enums = vec![
// ---
schemars::schema::SchemaObject {
const_value: Some("plain".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "plain",
}),
// ---
schemars::schema::SchemaObject {
const_value: Some("S256".into()),
..Default::default()
}
.into(),
schemars::json_schema!({
"const": "S256",
}),
];
let description = r"PKCE Code Challenge Method";
schemars::schema::SchemaObject {
metadata: Some(Box::new(schemars::schema::Metadata {
description: Some(description.to_owned()),
..Default::default()
})),
subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
any_of: Some(enums),
..Default::default()
})),
..Default::default()
}
.into()
schemars::json_schema!({
"description": description,
"anyOf": enums,
})
}
}

View File

@@ -14,7 +14,11 @@ use std::path::{Path, PathBuf};
use mas_policy::model::{
AuthorizationGrantInput, ClientRegistrationInput, EmailInput, RegisterInput,
};
use schemars::{JsonSchema, r#gen::SchemaSettings};
use schemars::{
JsonSchema,
generate::SchemaSettings,
transform::{AddNullable, RecursiveTransform},
};
fn write_schema<T: JsonSchema>(out_dir: Option<&Path>, file: &str) {
let mut writer: Box<dyn std::io::Write> = if let Some(out_dir) = out_dir {
@@ -27,11 +31,9 @@ fn write_schema<T: JsonSchema>(out_dir: Option<&Path>, file: &str) {
Box::new(std::io::stdout())
};
let settings = SchemaSettings::draft07().with(|s| {
s.option_nullable = false;
s.option_add_null_type = false;
});
let generator = settings.into_generator();
let generator = SchemaSettings::draft07()
.with_transform(RecursiveTransform(AddNullable::default()))
.into_generator();
let schema = generator.into_root_schema_for::<T>();
serde_json::to_writer_pretty(&mut writer, &schema).expect("Failed to serialize schema");
writer.flush().expect("Failed to flush writer");

View File

@@ -60,8 +60,6 @@ skip = [
{ name = "regex-syntax", version = "0.6.29" }, # tracing-subscriber[env-filter] -> matchers depends on the old version
{ name = "regex-automata", version = "0.1.10" }, # ^
{ name = "itertools", version = "0.13.0" }, # zxcvbn depends on this old version
{ name = "indexmap", version = "1.9.3" }, # schemars depends on this old version
{ name = "hashbrown", version = "0.12.3" }, # schemars -> indexmap depends on this old version
{ name = "hashbrown", version = "0.14.5" }, # a few crates depend on this old version
# a few dependencies depend on the 1.x version of thiserror
{ name = "thiserror", version = "1.0.69" },

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -3,16 +3,11 @@
"title": "AuthorizationGrantInput",
"description": "Input for the authorization grant policy.",
"type": "object",
"required": [
"client",
"grant_type",
"requester",
"scope"
],
"properties": {
"user": {
"type": "object",
"additionalProperties": true
"additionalProperties": true,
"nullable": true
},
"client": {
"type": "object",
@@ -28,6 +23,12 @@
"$ref": "#/definitions/Requester"
}
},
"required": [
"client",
"scope",
"grant_type",
"requester"
],
"definitions": {
"GrantType": {
"type": "string",
@@ -44,11 +45,13 @@
"ip_address": {
"description": "IP address of the entity making the request",
"type": "string",
"format": "ip"
"format": "ip",
"nullable": true
},
"user_agent": {
"description": "User agent of the entity making the request",
"type": "string"
"type": "string",
"nullable": true
}
}
}

View File

@@ -3,10 +3,6 @@
"title": "ClientRegistrationInput",
"description": "Input for the client registration policy.",
"type": "object",
"required": [
"client_metadata",
"requester"
],
"properties": {
"client_metadata": {
"type": "object",
@@ -16,6 +12,10 @@
"$ref": "#/definitions/Requester"
}
},
"required": [
"client_metadata",
"requester"
],
"definitions": {
"Requester": {
"description": "Identity of the requester",
@@ -24,11 +24,13 @@
"ip_address": {
"description": "IP address of the entity making the request",
"type": "string",
"format": "ip"
"format": "ip",
"nullable": true
},
"user_agent": {
"description": "User agent of the entity making the request",
"type": "string"
"type": "string",
"nullable": true
}
}
}

View File

@@ -3,10 +3,6 @@
"title": "EmailInput",
"description": "Input for the email add policy.",
"type": "object",
"required": [
"email",
"requester"
],
"properties": {
"email": {
"type": "string"
@@ -15,6 +11,10 @@
"$ref": "#/definitions/Requester"
}
},
"required": [
"email",
"requester"
],
"definitions": {
"Requester": {
"description": "Identity of the requester",
@@ -23,11 +23,13 @@
"ip_address": {
"description": "IP address of the entity making the request",
"type": "string",
"format": "ip"
"format": "ip",
"nullable": true
},
"user_agent": {
"description": "User agent of the entity making the request",
"type": "string"
"type": "string",
"nullable": true
}
}
}

View File

@@ -3,11 +3,6 @@
"title": "RegisterInput",
"description": "Input for the user registration policy.",
"type": "object",
"required": [
"registration_method",
"requester",
"username"
],
"properties": {
"registration_method": {
"$ref": "#/definitions/RegistrationMethod"
@@ -16,12 +11,18 @@
"type": "string"
},
"email": {
"type": "string"
"type": "string",
"nullable": true
},
"requester": {
"$ref": "#/definitions/Requester"
}
},
"required": [
"registration_method",
"username",
"requester"
],
"definitions": {
"RegistrationMethod": {
"type": "string",
@@ -37,11 +38,13 @@
"ip_address": {
"description": "IP address of the entity making the request",
"type": "string",
"format": "ip"
"format": "ip",
"nullable": true
},
"user_agent": {
"description": "User agent of the entity making the request",
"type": "string"
"type": "string",
"nullable": true
}
}
}