@@ -19,15 +19,15 @@ pub enum SchemaUriPrefix {
19
19
impl std:: fmt:: Display for SchemaUriPrefix {
20
20
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
21
21
match self {
22
- Self :: AkaDotMs => write ! ( f, "{}" , " https://aka.ms/dsc/schemas") ,
23
- Self :: Github => write ! ( f, "{}" , " https://raw.githubusercontent.com/PowerShell/DSC/main/schemas") ,
22
+ Self :: AkaDotMs => write ! ( f, "https://aka.ms/dsc/schemas" ) ,
23
+ Self :: Github => write ! ( f, "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas" ) ,
24
24
}
25
25
}
26
26
}
27
27
28
28
impl SchemaUriPrefix {
29
29
/// Returns every known URI prefix for convenient iteration.
30
- pub fn all ( ) -> Vec < SchemaUriPrefix > {
30
+ # [ must_use ] pub fn all ( ) -> Vec < SchemaUriPrefix > {
31
31
vec ! [
32
32
Self :: AkaDotMs ,
33
33
Self :: Github ,
@@ -66,11 +66,10 @@ impl SchemaForm {
66
66
/// The extension for [`Bundled`] and [`Canonical`] schemas is `.json`
67
67
///
68
68
/// The extension for [`VSCode`] schemas is `.vscode.json`
69
- pub fn to_extension ( & self ) -> String {
69
+ # [ must_use ] pub fn to_extension ( & self ) -> String {
70
70
match self {
71
- Self :: Bundled => ".json" . to_string ( ) ,
71
+ Self :: Bundled | Self :: Canonical => ".json" . to_string ( ) ,
72
72
Self :: VSCode => ".vscode.json" . to_string ( ) ,
73
- Self :: Canonical => ".json" . to_string ( ) ,
74
73
}
75
74
}
76
75
@@ -79,16 +78,15 @@ impl SchemaForm {
79
78
/// The [`Bundled`] and [`VSCode`] schemas are always published in the `bundled` folder
80
79
/// immediately beneath the version folder. The [`Canonical`] schemas use the folder path
81
80
/// as defined for that schema.
82
- pub fn to_folder_prefix ( & self ) -> String {
81
+ # [ must_use ] pub fn to_folder_prefix ( & self ) -> String {
83
82
match self {
84
- Self :: Bundled => "bundled/" . to_string ( ) ,
85
- Self :: VSCode => "bundled/" . to_string ( ) ,
86
- Self :: Canonical => "" . to_string ( ) ,
83
+ Self :: Bundled | Self :: VSCode => "bundled/" . to_string ( ) ,
84
+ Self :: Canonical => String :: new ( ) ,
87
85
}
88
86
}
89
87
90
88
/// Returns every schema form for convenient iteration.
91
- pub fn all ( ) -> Vec < SchemaForm > {
89
+ # [ must_use ] pub fn all ( ) -> Vec < SchemaForm > {
92
90
vec ! [
93
91
Self :: Bundled ,
94
92
Self :: VSCode ,
@@ -137,16 +135,16 @@ pub enum RecognizedSchemaVersion {
137
135
impl std:: fmt:: Display for RecognizedSchemaVersion {
138
136
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
139
137
match self {
140
- Self :: V3 => write ! ( f, "{}" , " v3") ,
141
- Self :: V3_0 => write ! ( f, "{}" , " v3.0") ,
142
- Self :: V3_0_0 => write ! ( f, "{}" , " v3.0.0") ,
138
+ Self :: V3 => write ! ( f, "v3" ) ,
139
+ Self :: V3_0 => write ! ( f, "v3.0" ) ,
140
+ Self :: V3_0_0 => write ! ( f, "v3.0.0" ) ,
143
141
}
144
142
}
145
143
}
146
144
147
145
impl RecognizedSchemaVersion {
148
146
/// Returns every recognized schema version for convenient iteration.
149
- pub fn all ( ) -> Vec < RecognizedSchemaVersion > {
147
+ # [ must_use ] pub fn all ( ) -> Vec < RecognizedSchemaVersion > {
150
148
vec ! [
151
149
Self :: V3 ,
152
150
Self :: V3_0 ,
@@ -155,17 +153,17 @@ impl RecognizedSchemaVersion {
155
153
}
156
154
157
155
//// Returns the latest version with major, minor, and patch segments, like `3.0.0`.
158
- pub fn latest ( ) -> RecognizedSchemaVersion {
156
+ # [ must_use ] pub fn latest ( ) -> RecognizedSchemaVersion {
159
157
Self :: V3_0_0
160
158
}
161
159
162
160
/// Returns the latest minor version for the latest major version, like `3.0`.
163
- pub fn latest_minor ( ) -> RecognizedSchemaVersion {
161
+ # [ must_use ] pub fn latest_minor ( ) -> RecognizedSchemaVersion {
164
162
Self :: V3_0
165
163
}
166
164
167
165
/// Returns the latest major version, like `3`
168
- pub fn latest_major ( ) -> RecognizedSchemaVersion {
166
+ # [ must_use ] pub fn latest_major ( ) -> RecognizedSchemaVersion {
169
167
Self :: V3
170
168
}
171
169
}
@@ -224,9 +222,10 @@ pub(crate) fn get_recognized_schema_uris(
224
222
should_bundle : bool
225
223
) -> Vec < String > {
226
224
let mut uris: Vec < String > = Vec :: new ( ) ;
227
- let schema_forms = match should_bundle {
228
- true => SchemaForm :: all ( ) ,
229
- false => vec ! [ SchemaForm :: Canonical ] ,
225
+ let schema_forms = if should_bundle {
226
+ SchemaForm :: all ( )
227
+ } else {
228
+ vec ! [ SchemaForm :: Canonical ]
230
229
} ;
231
230
for uri_prefix in SchemaUriPrefix :: all ( ) {
232
231
for schema_form in schema_forms. iter ( ) . copied ( ) {
@@ -244,15 +243,15 @@ pub(crate) fn get_recognized_schema_uris(
244
243
}
245
244
}
246
245
247
- return uris. into ( )
246
+ uris
248
247
}
249
248
250
249
/// Returns the JSON Schema to validate that a `$schema` keyword for a DSC type is one of the
251
250
/// recognized URIs.
252
251
///
253
252
/// This is a convenience function used by the [`DscRepoSchema`] trait. It's not intended for
254
- /// direct use.`
255
- pub ( crate ) fn get_recognized_uris_subschema (
253
+ /// direct use.
254
+ # [ must_use ] pub ( crate ) fn get_recognized_uris_subschema (
256
255
metadata : Metadata ,
257
256
schema_file_base_name : & str ,
258
257
schema_folder_path : & str ,
@@ -317,9 +316,10 @@ pub(crate) fn get_default_schema_uri(
317
316
/// If a schema is published in bundled form, the bundled form is the default. Otherwise, the
318
317
/// default form is canonical (non-bundled).
319
318
fn get_default_schema_form ( should_bundle : bool ) -> SchemaForm {
320
- match should_bundle {
321
- false => SchemaForm :: Canonical ,
322
- true => SchemaForm :: Bundled ,
319
+ if should_bundle {
320
+ SchemaForm :: Bundled
321
+ } else {
322
+ SchemaForm :: Canonical
323
323
}
324
324
}
325
325
@@ -352,7 +352,7 @@ pub trait DscRepoSchema : JsonSchema {
352
352
/// default when creating an instance is the latest major version of the schema with the
353
353
/// `aka.ms` prefix. If the schema is published in the bundled form, the default is for the
354
354
/// bundled schema. Otherwise, the default is for the canonical (non-bundled) schema.
355
- fn default_schema_id_uri ( ) -> String {
355
+ # [ must_use ] fn default_schema_id_uri ( ) -> String {
356
356
get_default_schema_uri (
357
357
Self :: SCHEMA_FILE_BASE_NAME ,
358
358
Self :: SCHEMA_FOLDER_PATH ,
@@ -361,7 +361,7 @@ pub trait DscRepoSchema : JsonSchema {
361
361
}
362
362
363
363
/// Returns the schema URI for a given version, form, and prefix.
364
- fn get_schema_id_uri (
364
+ # [ must_use ] fn get_schema_id_uri (
365
365
schema_version : RecognizedSchemaVersion ,
366
366
schema_form : SchemaForm ,
367
367
uri_prefix : SchemaUriPrefix
@@ -379,7 +379,7 @@ pub trait DscRepoSchema : JsonSchema {
379
379
/// version.
380
380
///
381
381
/// If the type isn't published in bundled form, this function returns `None`.
382
- fn get_enhanced_schema_id_uri ( schema_version : RecognizedSchemaVersion ) -> Option < String > {
382
+ # [ must_use ] fn get_enhanced_schema_id_uri ( schema_version : RecognizedSchemaVersion ) -> Option < String > {
383
383
if !Self :: SCHEMA_SHOULD_BUNDLE {
384
384
return None ;
385
385
}
@@ -395,7 +395,7 @@ pub trait DscRepoSchema : JsonSchema {
395
395
396
396
/// Returns the URI for the canonical (non-bundled) form of the schema with the default
397
397
/// prefix for a given version.
398
- fn get_canonical_schema_id_uri ( schema_version : RecognizedSchemaVersion ) -> String {
398
+ # [ must_use ] fn get_canonical_schema_id_uri ( schema_version : RecognizedSchemaVersion ) -> String {
399
399
get_recognized_schema_uri (
400
400
Self :: SCHEMA_FILE_BASE_NAME ,
401
401
Self :: SCHEMA_FOLDER_PATH ,
@@ -407,7 +407,7 @@ pub trait DscRepoSchema : JsonSchema {
407
407
408
408
/// Returns the URI for the bundled form of the schema with the default prefix for a given
409
409
/// version.
410
- fn get_bundled_schema_id_uri ( schema_version : RecognizedSchemaVersion ) -> Option < String > {
410
+ # [ must_use ] fn get_bundled_schema_id_uri ( schema_version : RecognizedSchemaVersion ) -> Option < String > {
411
411
if !Self :: SCHEMA_SHOULD_BUNDLE {
412
412
return None ;
413
413
}
@@ -426,7 +426,7 @@ pub trait DscRepoSchema : JsonSchema {
426
426
/// This convenience function generates a vector containing every recognized JSON Schema `$id`
427
427
/// URI for a specific schema. It handles returning the schemas for every recognized prefix,
428
428
/// version, and form.
429
- fn recognized_schema_uris ( ) -> Vec < String > {
429
+ # [ must_use ] fn recognized_schema_uris ( ) -> Vec < String > {
430
430
get_recognized_schema_uris (
431
431
Self :: SCHEMA_FILE_BASE_NAME ,
432
432
Self :: SCHEMA_FOLDER_PATH ,
@@ -441,7 +441,7 @@ pub trait DscRepoSchema : JsonSchema {
441
441
/// recognized and validated. This method generates the appropriate subschema with every
442
442
/// valid URI for the schema's `$id` without needing to regularly update an enum for each
443
443
/// schema and release.
444
- fn recognized_schema_uris_subschema ( _: & mut schemars:: gen:: SchemaGenerator ) -> Schema {
444
+ # [ must_use ] fn recognized_schema_uris_subschema ( _: & mut schemars:: gen:: SchemaGenerator ) -> Schema {
445
445
get_recognized_uris_subschema (
446
446
Self :: schema_metadata ( ) ,
447
447
Self :: SCHEMA_FILE_BASE_NAME ,
@@ -451,7 +451,7 @@ pub trait DscRepoSchema : JsonSchema {
451
451
}
452
452
453
453
/// Indicates whether a given string is a recognized shema URI.
454
- fn is_recognized_schema_uri ( uri : & String ) -> bool {
454
+ # [ must_use ] fn is_recognized_schema_uri ( uri : & String ) -> bool {
455
455
Self :: recognized_schema_uris ( ) . contains ( uri)
456
456
}
457
457
@@ -465,7 +465,12 @@ pub trait DscRepoSchema : JsonSchema {
465
465
/// types that don't define the `$schema` keyword in their serialized form.
466
466
///
467
467
/// Any DSC type that serializes with the `$schema` keyword **must** define this
468
- /// method to actually validate the instance.
468
+ /// method to actually validate the instance.
469
+ ///
470
+ /// # Errors
471
+ ///
472
+ /// If the value for the schema field isn't a recognized schema, the method should raise the
473
+ /// [`DscError::UnrecognizedSchemaUri`] error.
469
474
fn validate_schema_uri ( & self ) -> Result < ( ) , DscError > {
470
475
Ok ( ( ) )
471
476
}
0 commit comments