@@ -19,15 +19,15 @@ pub enum SchemaUriPrefix {
1919impl std:: fmt:: Display for SchemaUriPrefix {
2020 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
2121 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" ) ,
2424 }
2525 }
2626}
2727
2828impl SchemaUriPrefix {
2929 /// Returns every known URI prefix for convenient iteration.
30- pub fn all ( ) -> Vec < SchemaUriPrefix > {
30+ # [ must_use ] pub fn all ( ) -> Vec < SchemaUriPrefix > {
3131 vec ! [
3232 Self :: AkaDotMs ,
3333 Self :: Github ,
@@ -66,11 +66,10 @@ impl SchemaForm {
6666 /// The extension for [`Bundled`] and [`Canonical`] schemas is `.json`
6767 ///
6868 /// The extension for [`VSCode`] schemas is `.vscode.json`
69- pub fn to_extension ( & self ) -> String {
69+ # [ must_use ] pub fn to_extension ( & self ) -> String {
7070 match self {
71- Self :: Bundled => ".json" . to_string ( ) ,
71+ Self :: Bundled | Self :: Canonical => ".json" . to_string ( ) ,
7272 Self :: VSCode => ".vscode.json" . to_string ( ) ,
73- Self :: Canonical => ".json" . to_string ( ) ,
7473 }
7574 }
7675
@@ -79,16 +78,15 @@ impl SchemaForm {
7978 /// The [`Bundled`] and [`VSCode`] schemas are always published in the `bundled` folder
8079 /// immediately beneath the version folder. The [`Canonical`] schemas use the folder path
8180 /// as defined for that schema.
82- pub fn to_folder_prefix ( & self ) -> String {
81+ # [ must_use ] pub fn to_folder_prefix ( & self ) -> String {
8382 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 ( ) ,
8785 }
8886 }
8987
9088 /// Returns every schema form for convenient iteration.
91- pub fn all ( ) -> Vec < SchemaForm > {
89+ # [ must_use ] pub fn all ( ) -> Vec < SchemaForm > {
9290 vec ! [
9391 Self :: Bundled ,
9492 Self :: VSCode ,
@@ -137,16 +135,16 @@ pub enum RecognizedSchemaVersion {
137135impl std:: fmt:: Display for RecognizedSchemaVersion {
138136 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
139137 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" ) ,
143141 }
144142 }
145143}
146144
147145impl RecognizedSchemaVersion {
148146 /// Returns every recognized schema version for convenient iteration.
149- pub fn all ( ) -> Vec < RecognizedSchemaVersion > {
147+ # [ must_use ] pub fn all ( ) -> Vec < RecognizedSchemaVersion > {
150148 vec ! [
151149 Self :: V3 ,
152150 Self :: V3_0 ,
@@ -155,17 +153,17 @@ impl RecognizedSchemaVersion {
155153 }
156154
157155 //// 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 {
159157 Self :: V3_0_0
160158 }
161159
162160 /// 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 {
164162 Self :: V3_0
165163 }
166164
167165 /// Returns the latest major version, like `3`
168- pub fn latest_major ( ) -> RecognizedSchemaVersion {
166+ # [ must_use ] pub fn latest_major ( ) -> RecognizedSchemaVersion {
169167 Self :: V3
170168 }
171169}
@@ -224,9 +222,10 @@ pub(crate) fn get_recognized_schema_uris(
224222 should_bundle : bool
225223) -> Vec < String > {
226224 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 ]
230229 } ;
231230 for uri_prefix in SchemaUriPrefix :: all ( ) {
232231 for schema_form in schema_forms. iter ( ) . copied ( ) {
@@ -244,15 +243,15 @@ pub(crate) fn get_recognized_schema_uris(
244243 }
245244 }
246245
247- return uris. into ( )
246+ uris
248247}
249248
250249/// Returns the JSON Schema to validate that a `$schema` keyword for a DSC type is one of the
251250/// recognized URIs.
252251///
253252/// 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 (
256255 metadata : Metadata ,
257256 schema_file_base_name : & str ,
258257 schema_folder_path : & str ,
@@ -317,9 +316,10 @@ pub(crate) fn get_default_schema_uri(
317316/// If a schema is published in bundled form, the bundled form is the default. Otherwise, the
318317/// default form is canonical (non-bundled).
319318fn 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
323323 }
324324}
325325
@@ -352,7 +352,7 @@ pub trait DscRepoSchema : JsonSchema {
352352 /// default when creating an instance is the latest major version of the schema with the
353353 /// `aka.ms` prefix. If the schema is published in the bundled form, the default is for the
354354 /// 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 {
356356 get_default_schema_uri (
357357 Self :: SCHEMA_FILE_BASE_NAME ,
358358 Self :: SCHEMA_FOLDER_PATH ,
@@ -361,7 +361,7 @@ pub trait DscRepoSchema : JsonSchema {
361361 }
362362
363363 /// 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 (
365365 schema_version : RecognizedSchemaVersion ,
366366 schema_form : SchemaForm ,
367367 uri_prefix : SchemaUriPrefix
@@ -379,7 +379,7 @@ pub trait DscRepoSchema : JsonSchema {
379379 /// version.
380380 ///
381381 /// 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 > {
383383 if !Self :: SCHEMA_SHOULD_BUNDLE {
384384 return None ;
385385 }
@@ -395,7 +395,7 @@ pub trait DscRepoSchema : JsonSchema {
395395
396396 /// Returns the URI for the canonical (non-bundled) form of the schema with the default
397397 /// 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 {
399399 get_recognized_schema_uri (
400400 Self :: SCHEMA_FILE_BASE_NAME ,
401401 Self :: SCHEMA_FOLDER_PATH ,
@@ -407,7 +407,7 @@ pub trait DscRepoSchema : JsonSchema {
407407
408408 /// Returns the URI for the bundled form of the schema with the default prefix for a given
409409 /// 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 > {
411411 if !Self :: SCHEMA_SHOULD_BUNDLE {
412412 return None ;
413413 }
@@ -426,7 +426,7 @@ pub trait DscRepoSchema : JsonSchema {
426426 /// This convenience function generates a vector containing every recognized JSON Schema `$id`
427427 /// URI for a specific schema. It handles returning the schemas for every recognized prefix,
428428 /// version, and form.
429- fn recognized_schema_uris ( ) -> Vec < String > {
429+ # [ must_use ] fn recognized_schema_uris ( ) -> Vec < String > {
430430 get_recognized_schema_uris (
431431 Self :: SCHEMA_FILE_BASE_NAME ,
432432 Self :: SCHEMA_FOLDER_PATH ,
@@ -441,7 +441,7 @@ pub trait DscRepoSchema : JsonSchema {
441441 /// recognized and validated. This method generates the appropriate subschema with every
442442 /// valid URI for the schema's `$id` without needing to regularly update an enum for each
443443 /// 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 {
445445 get_recognized_uris_subschema (
446446 Self :: schema_metadata ( ) ,
447447 Self :: SCHEMA_FILE_BASE_NAME ,
@@ -451,7 +451,7 @@ pub trait DscRepoSchema : JsonSchema {
451451 }
452452
453453 /// 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 {
455455 Self :: recognized_schema_uris ( ) . contains ( uri)
456456 }
457457
@@ -465,7 +465,12 @@ pub trait DscRepoSchema : JsonSchema {
465465 /// types that don't define the `$schema` keyword in their serialized form.
466466 ///
467467 /// 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.
469474 fn validate_schema_uri ( & self ) -> Result < ( ) , DscError > {
470475 Ok ( ( ) )
471476 }
0 commit comments