Skip to content

Commit fc6756d

Browse files
committed
Remove optional features from the mas-policy crate
1 parent 97e83e1 commit fc6756d

File tree

4 files changed

+29
-48
lines changed

4 files changed

+29
-48
lines changed

crates/policy/Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ workspace = true
1515
anyhow.workspace = true
1616
arc-swap.workspace = true
1717
opa-wasm.workspace = true
18-
schemars = { workspace = true, optional = true }
18+
schemars.workspace = true
1919
serde_json.workspace = true
2020
serde.workspace = true
2121
thiserror.workspace = true
@@ -25,9 +25,5 @@ tracing.workspace = true
2525
mas-data-model.workspace = true
2626
oauth2-types.workspace = true
2727

28-
[features]
29-
jsonschema = ["dep:schemars"]
30-
3128
[[bin]]
3229
name = "schema"
33-
required-features = ["jsonschema"]

crates/policy/src/bin/schema.rs

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

7+
#![expect(
8+
clippy::disallowed_types,
9+
reason = "We use Path/PathBuf instead of camino here for simplicity"
10+
)]
11+
712
use std::path::{Path, PathBuf};
813

914
use mas_policy::model::{
@@ -12,17 +17,14 @@ use mas_policy::model::{
1217
use schemars::{JsonSchema, r#gen::SchemaSettings};
1318

1419
fn write_schema<T: JsonSchema>(out_dir: Option<&Path>, file: &str) {
15-
let mut writer: Box<dyn std::io::Write> = match out_dir {
16-
Some(out_dir) => {
17-
let path = out_dir.join(file);
18-
eprintln!("Writing to {path:?}");
19-
let file = std::fs::File::create(path).expect("Failed to create file");
20-
Box::new(std::io::BufWriter::new(file))
21-
}
22-
None => {
23-
eprintln!("--- {file} ---");
24-
Box::new(std::io::stdout())
25-
}
20+
let mut writer: Box<dyn std::io::Write> = if let Some(out_dir) = out_dir {
21+
let path = out_dir.join(file);
22+
eprintln!("Writing to {path:?}");
23+
let file = std::fs::File::create(path).expect("Failed to create file");
24+
Box::new(std::io::BufWriter::new(file))
25+
} else {
26+
eprintln!("--- {file} ---");
27+
Box::new(std::io::stdout())
2628
};
2729

2830
let settings = SchemaSettings::draft07().with(|s| {

crates/policy/src/model.rs

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ use std::net::IpAddr;
1313

1414
use mas_data_model::{Client, User};
1515
use oauth2_types::{registration::VerifiedClientMetadata, scope::Scope};
16+
use schemars::JsonSchema;
1617
use serde::{Deserialize, Serialize};
1718

1819
/// A well-known policy code.
19-
#[derive(Deserialize, Debug, Clone, Copy)]
20+
#[derive(Deserialize, Debug, Clone, Copy, JsonSchema)]
2021
#[serde(rename_all = "kebab-case")]
21-
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
2222
pub enum Code {
2323
/// The username is too short.
2424
UsernameTooShort,
@@ -71,8 +71,7 @@ impl Code {
7171
}
7272

7373
/// A single violation of a policy.
74-
#[derive(Deserialize, Debug)]
75-
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
74+
#[derive(Deserialize, Debug, JsonSchema)]
7675
pub struct Violation {
7776
pub msg: String,
7877
pub redirect_uri: Option<String>,
@@ -111,9 +110,8 @@ impl EvaluationResult {
111110
}
112111

113112
/// Identity of the requester
114-
#[derive(Serialize, Debug, Default)]
113+
#[derive(Serialize, Debug, Default, JsonSchema)]
115114
#[serde(rename_all = "snake_case")]
116-
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
117115
pub struct Requester {
118116
/// IP address of the entity making the request
119117
pub ip_address: Option<IpAddr>,
@@ -122,8 +120,7 @@ pub struct Requester {
122120
pub user_agent: Option<String>,
123121
}
124122

125-
#[derive(Serialize, Debug)]
126-
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
123+
#[derive(Serialize, Debug, JsonSchema)]
127124
pub enum RegistrationMethod {
128125
#[serde(rename = "password")]
129126
Password,
@@ -133,9 +130,8 @@ pub enum RegistrationMethod {
133130
}
134131

135132
/// Input for the user registration policy.
136-
#[derive(Serialize, Debug)]
133+
#[derive(Serialize, Debug, JsonSchema)]
137134
#[serde(tag = "registration_method")]
138-
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
139135
pub struct RegisterInput<'a> {
140136
pub registration_method: RegistrationMethod,
141137

@@ -148,21 +144,16 @@ pub struct RegisterInput<'a> {
148144
}
149145

150146
/// Input for the client registration policy.
151-
#[derive(Serialize, Debug)]
147+
#[derive(Serialize, Debug, JsonSchema)]
152148
#[serde(rename_all = "snake_case")]
153-
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
154149
pub struct ClientRegistrationInput<'a> {
155-
#[cfg_attr(
156-
feature = "jsonschema",
157-
schemars(with = "std::collections::HashMap<String, serde_json::Value>")
158-
)]
150+
#[schemars(with = "std::collections::HashMap<String, serde_json::Value>")]
159151
pub client_metadata: &'a VerifiedClientMetadata,
160152
pub requester: Requester,
161153
}
162154

163-
#[derive(Serialize, Debug)]
155+
#[derive(Serialize, Debug, JsonSchema)]
164156
#[serde(rename_all = "snake_case")]
165-
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
166157
pub enum GrantType {
167158
AuthorizationCode,
168159
ClientCredentials,
@@ -171,23 +162,16 @@ pub enum GrantType {
171162
}
172163

173164
/// Input for the authorization grant policy.
174-
#[derive(Serialize, Debug)]
165+
#[derive(Serialize, Debug, JsonSchema)]
175166
#[serde(rename_all = "snake_case")]
176-
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
177167
pub struct AuthorizationGrantInput<'a> {
178-
#[cfg_attr(
179-
feature = "jsonschema",
180-
schemars(with = "Option<std::collections::HashMap<String, serde_json::Value>>")
181-
)]
168+
#[schemars(with = "Option<std::collections::HashMap<String, serde_json::Value>>")]
182169
pub user: Option<&'a User>,
183170

184-
#[cfg_attr(
185-
feature = "jsonschema",
186-
schemars(with = "std::collections::HashMap<String, serde_json::Value>")
187-
)]
171+
#[schemars(with = "std::collections::HashMap<String, serde_json::Value>")]
188172
pub client: &'a Client,
189173

190-
#[cfg_attr(feature = "jsonschema", schemars(with = "String"))]
174+
#[schemars(with = "String")]
191175
pub scope: &'a Scope,
192176

193177
pub grant_type: GrantType,
@@ -196,9 +180,8 @@ pub struct AuthorizationGrantInput<'a> {
196180
}
197181

198182
/// Input for the email add policy.
199-
#[derive(Serialize, Debug)]
183+
#[derive(Serialize, Debug, JsonSchema)]
200184
#[serde(rename_all = "snake_case")]
201-
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
202185
pub struct EmailInput<'a> {
203186
pub email: &'a str,
204187

misc/update.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ cargo run -p mas-config > "${CONFIG_SCHEMA}"
1414
cargo run -p mas-handlers --bin graphql-schema > "${GRAPHQL_SCHEMA}"
1515
cargo run -p mas-handlers --bin api-schema > "${API_SCHEMA}"
1616
cargo run -p mas-i18n-scan -- --update "${BASE_DIR}/templates/" "${BASE_DIR}/translations/en.json"
17-
OUT_DIR="${POLICIES_SCHEMA}" cargo run -p mas-policy --features jsonschema
17+
OUT_DIR="${POLICIES_SCHEMA}" cargo run -p mas-policy
1818

1919
cd "${BASE_DIR}/frontend"
2020
npm run format

0 commit comments

Comments
 (0)