Skip to content

Commit ac788d7

Browse files
ya7010konstin
andauthored
Update schemars 1.0.0 (#13693)
<!-- Thank you for contributing to uv! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary Update [schemars 0.9.0](https://github.com/GREsau/schemars/releases/tag/v0.9.0) There are differences in the generated JSON Schema and I will [contact the author](GREsau/schemars#407). ## Test Plan --------- Co-authored-by: konstin <[email protected]>
1 parent 9fba7a4 commit ac788d7

File tree

21 files changed

+526
-815
lines changed

21 files changed

+526
-815
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ rust-netrc = { version = "0.1.2" }
151151
rustc-hash = { version = "2.0.0" }
152152
rustix = { version = "1.0.0", default-features = false, features = ["fs", "std"] }
153153
same-file = { version = "1.0.6" }
154-
schemars = { version = "0.8.21", features = ["url"] }
154+
schemars = { version = "1.0.0", features = ["url2"] }
155155
seahash = { version = "4.1.0" }
156156
self-replace = { version = "1.5.0" }
157157
serde = { version = "1.0.210", features = ["derive", "rc"] }

crates/uv-configuration/src/name_specifiers.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::str::FromStr;
1+
use std::{borrow::Cow, str::FromStr};
22

33
use uv_pep508::PackageName;
44

@@ -63,28 +63,16 @@ impl<'de> serde::Deserialize<'de> for PackageNameSpecifier {
6363

6464
#[cfg(feature = "schemars")]
6565
impl schemars::JsonSchema for PackageNameSpecifier {
66-
fn schema_name() -> String {
67-
"PackageNameSpecifier".to_string()
66+
fn schema_name() -> Cow<'static, str> {
67+
Cow::Borrowed("PackageNameSpecifier")
6868
}
6969

70-
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
71-
schemars::schema::SchemaObject {
72-
instance_type: Some(schemars::schema::InstanceType::String.into()),
73-
string: Some(Box::new(schemars::schema::StringValidation {
74-
// See: https://packaging.python.org/en/latest/specifications/name-normalization/#name-format
75-
pattern: Some(
76-
r"^(:none:|:all:|([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]))$"
77-
.to_string(),
78-
),
79-
..schemars::schema::StringValidation::default()
80-
})),
81-
metadata: Some(Box::new(schemars::schema::Metadata {
82-
description: Some("The name of a package, or `:all:` or `:none:` to select or omit all packages, respectively.".to_string()),
83-
..schemars::schema::Metadata::default()
84-
})),
85-
..schemars::schema::SchemaObject::default()
86-
}
87-
.into()
70+
fn json_schema(_gen: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
71+
schemars::json_schema!({
72+
"type": "string",
73+
"pattern": r"^(:none:|:all:|([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]))$",
74+
"description": "The name of a package, or `:all:` or `:none:` to select or omit all packages, respectively.",
75+
})
8876
}
8977
}
9078

crates/uv-configuration/src/required_version.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::fmt::Formatter;
21
use std::str::FromStr;
2+
use std::{borrow::Cow, fmt::Formatter};
33

44
use uv_pep440::{Version, VersionSpecifier, VersionSpecifiers, VersionSpecifiersParseError};
55

@@ -36,20 +36,15 @@ impl FromStr for RequiredVersion {
3636

3737
#[cfg(feature = "schemars")]
3838
impl schemars::JsonSchema for RequiredVersion {
39-
fn schema_name() -> String {
40-
String::from("RequiredVersion")
39+
fn schema_name() -> Cow<'static, str> {
40+
Cow::Borrowed("RequiredVersion")
4141
}
4242

43-
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
44-
schemars::schema::SchemaObject {
45-
instance_type: Some(schemars::schema::InstanceType::String.into()),
46-
metadata: Some(Box::new(schemars::schema::Metadata {
47-
description: Some("A version specifier, e.g. `>=0.5.0` or `==0.5.0`.".to_string()),
48-
..schemars::schema::Metadata::default()
49-
})),
50-
..schemars::schema::SchemaObject::default()
51-
}
52-
.into()
43+
fn json_schema(_generator: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
44+
schemars::json_schema!({
45+
"type": "string",
46+
"description": "A version specifier, e.g. `>=0.5.0` or `==0.5.0`."
47+
})
5348
}
5449
}
5550

crates/uv-configuration/src/trusted_host.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use serde::{Deserialize, Deserializer};
2-
use std::str::FromStr;
2+
use std::{borrow::Cow, str::FromStr};
33
use url::Url;
44

55
/// A host specification (wildcard, or host, with optional scheme and/or port) for which
@@ -143,20 +143,15 @@ impl std::fmt::Display for TrustedHost {
143143

144144
#[cfg(feature = "schemars")]
145145
impl schemars::JsonSchema for TrustedHost {
146-
fn schema_name() -> String {
147-
"TrustedHost".to_string()
146+
fn schema_name() -> Cow<'static, str> {
147+
Cow::Borrowed("TrustedHost")
148148
}
149149

150-
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
151-
schemars::schema::SchemaObject {
152-
instance_type: Some(schemars::schema::InstanceType::String.into()),
153-
metadata: Some(Box::new(schemars::schema::Metadata {
154-
description: Some("A host or host-port pair.".to_string()),
155-
..schemars::schema::Metadata::default()
156-
})),
157-
..schemars::schema::SchemaObject::default()
158-
}
159-
.into()
150+
fn json_schema(_generator: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
151+
schemars::json_schema!({
152+
"type": "string",
153+
"description": "A host or host-port pair."
154+
})
160155
}
161156
}
162157

crates/uv-dev/src/generate_json_schema.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::PathBuf;
33
use anstream::println;
44
use anyhow::{Result, bail};
55
use pretty_assertions::StrComparison;
6-
use schemars::{JsonSchema, schema_for};
6+
use schemars::JsonSchema;
77
use serde::Deserialize;
88

99
use uv_settings::Options as SettingsOptions;
@@ -91,7 +91,10 @@ const REPLACEMENTS: &[(&str, &str)] = &[
9191

9292
/// Generate the JSON schema for the combined options as a string.
9393
fn generate() -> String {
94-
let schema = schema_for!(CombinedOptions);
94+
let settings = schemars::generate::SchemaSettings::draft07();
95+
let generator = schemars::SchemaGenerator::new(settings);
96+
let schema = generator.into_root_schema_for::<CombinedOptions>();
97+
9598
let mut output = serde_json::to_string_pretty(&schema).unwrap();
9699

97100
for (value, replacement) in REPLACEMENTS {

crates/uv-distribution-types/src/index_url.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,15 @@ impl IndexUrl {
9292

9393
#[cfg(feature = "schemars")]
9494
impl schemars::JsonSchema for IndexUrl {
95-
fn schema_name() -> String {
96-
"IndexUrl".to_string()
97-
}
98-
99-
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
100-
schemars::schema::SchemaObject {
101-
instance_type: Some(schemars::schema::InstanceType::String.into()),
102-
metadata: Some(Box::new(schemars::schema::Metadata {
103-
description: Some("The URL of an index to use for fetching packages (e.g., `https://pypi.org/simple`), or a local path.".to_string()),
104-
..schemars::schema::Metadata::default()
105-
})),
106-
..schemars::schema::SchemaObject::default()
107-
}
108-
.into()
95+
fn schema_name() -> Cow<'static, str> {
96+
Cow::Borrowed("IndexUrl")
97+
}
98+
99+
fn json_schema(_generator: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
100+
schemars::json_schema!({
101+
"type": "string",
102+
"description": "The URL of an index to use for fetching packages (e.g., `https://pypi.org/simple`), or a local path."
103+
})
109104
}
110105
}
111106

crates/uv-distribution-types/src/pip_index.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! flags set.
44
55
use serde::{Deserialize, Deserializer, Serialize};
6-
use std::path::Path;
6+
use std::{borrow::Cow, path::Path};
77

88
use crate::{Index, IndexUrl};
99

@@ -50,14 +50,14 @@ macro_rules! impl_index {
5050

5151
#[cfg(feature = "schemars")]
5252
impl schemars::JsonSchema for $name {
53-
fn schema_name() -> String {
53+
fn schema_name() -> Cow<'static, str> {
5454
IndexUrl::schema_name()
5555
}
5656

5757
fn json_schema(
58-
r#gen: &mut schemars::r#gen::SchemaGenerator,
59-
) -> schemars::schema::Schema {
60-
IndexUrl::json_schema(r#gen)
58+
generator: &mut schemars::generate::SchemaGenerator,
59+
) -> schemars::Schema {
60+
IndexUrl::json_schema(generator)
6161
}
6262
}
6363
};

crates/uv-distribution-types/src/status_code_strategy.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::ops::Deref;
1+
use std::{borrow::Cow, ops::Deref};
22

33
use http::StatusCode;
44
use rustc_hash::FxHashSet;
@@ -136,17 +136,17 @@ impl<'de> Deserialize<'de> for SerializableStatusCode {
136136

137137
#[cfg(feature = "schemars")]
138138
impl schemars::JsonSchema for SerializableStatusCode {
139-
fn schema_name() -> String {
140-
"StatusCode".to_string()
139+
fn schema_name() -> Cow<'static, str> {
140+
Cow::Borrowed("StatusCode")
141141
}
142142

143-
fn json_schema(r#gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
144-
let mut schema = r#gen.subschema_for::<u16>().into_object();
145-
schema.metadata().description = Some("HTTP status code (100-599)".to_string());
146-
schema.number().minimum = Some(100.0);
147-
schema.number().maximum = Some(599.0);
148-
149-
schema.into()
143+
fn json_schema(_generator: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
144+
schemars::json_schema!({
145+
"type": "number",
146+
"minimum": 100,
147+
"maximum": 599,
148+
"description": "HTTP status code (100-599)"
149+
})
150150
}
151151
}
152152

crates/uv-fs/src/path.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,11 @@ pub struct PortablePathBuf(Box<Path>);
330330

331331
#[cfg(feature = "schemars")]
332332
impl schemars::JsonSchema for PortablePathBuf {
333-
fn schema_name() -> String {
334-
PathBuf::schema_name()
333+
fn schema_name() -> Cow<'static, str> {
334+
Cow::Borrowed("PortablePathBuf")
335335
}
336336

337-
fn json_schema(_gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
337+
fn json_schema(_gen: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
338338
PathBuf::json_schema(_gen)
339339
}
340340
}

0 commit comments

Comments
 (0)