|
1 |
| -use std::str::FromStr; |
| 1 | +use std::{borrow::Cow, str::FromStr}; |
2 | 2 |
|
3 | 3 | use uv_pep508::PackageName;
|
4 | 4 |
|
@@ -63,28 +63,16 @@ impl<'de> serde::Deserialize<'de> for PackageNameSpecifier {
|
63 | 63 |
|
64 | 64 | #[cfg(feature = "schemars")]
|
65 | 65 | 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") |
68 | 68 | }
|
69 | 69 |
|
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 | + }) |
88 | 76 | }
|
89 | 77 | }
|
90 | 78 |
|
|
0 commit comments