33
44use chrono:: { DateTime , Local } ;
55use rust_i18n:: t;
6- use schemars:: { JsonSchema , json_schema } ;
6+ use schemars:: JsonSchema ;
77use serde:: { Deserialize , Deserializer , Serialize } ;
88use serde_json:: { Map , Value } ;
99use std:: { collections:: HashMap , fmt:: Display } ;
1010
1111use crate :: schemas:: {
12- dsc_repo:: { DscRepoSchema , UnrecognizedSchemaUri } ,
12+ dsc_repo:: DscRepoSchema ,
1313 transforms:: { idiomaticize_externally_tagged_enum, idiomaticize_string_enum}
1414} ;
1515
16- #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema ) ]
16+ #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema , DscRepoSchema ) ]
1717#[ serde( rename_all = "camelCase" ) ]
1818#[ schemars( transform = idiomaticize_string_enum) ]
19+ #[ dsc_repo_schema( base_name = "securityContext" , folder_path = "metadata/Microsoft.DSC" ) ]
1920pub enum SecurityContextKind {
2021 Current ,
2122 Elevated ,
2223 Restricted ,
2324}
2425
25- #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema ) ]
26+ #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema , DscRepoSchema ) ]
2627#[ serde( rename_all = "camelCase" ) ]
2728#[ schemars( transform = idiomaticize_string_enum) ]
29+ #[ dsc_repo_schema( base_name = "operation" , folder_path = "metadata/Microsoft.DSC" ) ]
2830pub enum Operation {
2931 Get ,
3032 Set ,
3133 Test ,
3234 Export ,
3335}
3436
35- #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema ) ]
37+ #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema , DscRepoSchema ) ]
3638#[ serde( rename_all = "camelCase" ) ]
3739#[ schemars( transform = idiomaticize_string_enum) ]
40+ #[ dsc_repo_schema( base_name = "executionType" , folder_path = "metadata/Microsoft.DSC" ) ]
3841pub enum ExecutionKind {
3942 Actual ,
4043 WhatIf ,
@@ -47,9 +50,10 @@ pub struct Process {
4750 pub id : u32 ,
4851}
4952
50- #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema ) ]
53+ #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema , DscRepoSchema ) ]
5154#[ serde( rename_all = "camelCase" ) ]
5255#[ schemars( transform = idiomaticize_externally_tagged_enum) ]
56+ #[ dsc_repo_schema( base_name = "restartRequired" , folder_path = "metadata/Microsoft.DSC" ) ]
5357pub enum RestartRequired {
5458 System ( String ) ,
5559 Service ( String ) ,
@@ -104,33 +108,38 @@ impl MicrosoftDscMetadata {
104108 }
105109}
106110
107- #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema ) ]
111+ #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema , DscRepoSchema ) ]
112+ #[ dsc_repo_schema( base_name = "document.metadata" , folder_path = "config" ) ]
108113pub struct Metadata {
109114 #[ serde( rename = "Microsoft.DSC" , skip_serializing_if = "Option::is_none" ) ]
110115 pub microsoft : Option < MicrosoftDscMetadata > ,
111116 #[ serde( flatten) ]
112117 pub other : Map < String , Value > ,
113118}
114119
115- #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema ) ]
120+ #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema , DscRepoSchema ) ]
121+ #[ dsc_repo_schema( base_name = "document.function" , folder_path = "config" ) ]
116122pub struct UserFunction {
117123 pub namespace : String ,
118124 pub members : HashMap < String , UserFunctionDefinition > ,
119125}
120126
121- #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema ) ]
127+ #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema , DscRepoSchema ) ]
128+ #[ dsc_repo_schema( base_name = "definition" , folder_path = "definitions/functions/user" ) ]
122129pub struct UserFunctionDefinition {
123130 pub parameters : Option < Vec < UserFunctionParameter > > ,
124131 pub output : UserFunctionOutput ,
125132}
126133
127- #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema ) ]
134+ #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema , DscRepoSchema ) ]
135+ #[ dsc_repo_schema( base_name = "parameter" , folder_path = "definitions/functions/user" ) ]
128136pub struct UserFunctionParameter {
129137 pub name : String ,
130138 pub r#type : DataType ,
131139}
132140
133- #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema ) ]
141+ #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema , DscRepoSchema ) ]
142+ #[ dsc_repo_schema( base_name = "output" , folder_path = "definitions/functions/user" ) ]
134143pub struct UserFunctionOutput {
135144 pub r#type : DataType ,
136145 pub value : String ,
@@ -143,17 +152,28 @@ pub enum ValueOrCopy {
143152 Copy ( Copy ) ,
144153}
145154
146- #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema ) ]
155+ #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema , DscRepoSchema ) ]
147156#[ serde( deny_unknown_fields) ]
157+ #[ dsc_repo_schema( base_name = "document.output" , folder_path = "config" ) ]
148158pub struct Output {
149159 pub condition : Option < String > ,
150160 pub r#type : DataType ,
151161 #[ serde( flatten) ]
152162 pub value_or_copy : ValueOrCopy ,
153163}
154164
155- #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema ) ]
165+ #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema , DscRepoSchema ) ]
156166#[ serde( deny_unknown_fields) ]
167+ #[ dsc_repo_schema(
168+ base_name = "document" ,
169+ folder_path = "config" ,
170+ should_bundle = true ,
171+ schema_field(
172+ name = schema,
173+ title = t!( "configure.config_doc.configurationDocumentSchemaTitle" ) ,
174+ description = t!( "configure.config_doc.configurationDocumentSchemaDescription" ) ,
175+ )
176+ ) ]
157177pub struct Configuration {
158178 #[ serde( rename = "$schema" ) ]
159179 #[ schemars( schema_with = "Configuration::recognized_schema_uris_subschema" ) ]
@@ -222,8 +242,9 @@ where
222242 }
223243}
224244
225- #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema ) ]
245+ #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema , DscRepoSchema ) ]
226246#[ serde( deny_unknown_fields) ]
247+ #[ dsc_repo_schema( base_name = "document.parameter" , folder_path = "config" ) ]
227248pub struct Parameter {
228249 #[ serde( rename = "type" ) ]
229250 pub parameter_type : DataType ,
@@ -245,8 +266,9 @@ pub struct Parameter {
245266 pub metadata : Option < Map < String , Value > > ,
246267}
247268
248- #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema ) ]
269+ #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema , DscRepoSchema ) ]
249270#[ schemars( transform = idiomaticize_string_enum) ]
271+ #[ dsc_repo_schema( base_name = "dataTypes" , folder_path = "definitions/parameters" ) ]
250272pub enum DataType {
251273 #[ serde( rename = "string" ) ]
252274 String ,
@@ -353,8 +375,9 @@ pub struct Sku {
353375 pub capacity : Option < i32 > ,
354376}
355377
356- #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema ) ]
378+ #[ derive( Debug , Clone , PartialEq , Deserialize , Serialize , JsonSchema , DscRepoSchema ) ]
357379#[ serde( deny_unknown_fields) ]
380+ #[ dsc_repo_schema( base_name = "document.resource" , folder_path = "config" ) ]
358381pub struct Resource {
359382 #[ serde( skip_serializing_if = "Option::is_none" ) ]
360383 pub condition : Option < String > ,
@@ -406,30 +429,6 @@ impl Default for Configuration {
406429 }
407430}
408431
409- impl DscRepoSchema for Configuration {
410- const SCHEMA_FILE_BASE_NAME : & ' static str = "document" ;
411- const SCHEMA_FOLDER_PATH : & ' static str = "config" ;
412- const SCHEMA_SHOULD_BUNDLE : bool = true ;
413-
414- fn schema_property_metadata ( ) -> schemars:: Schema {
415- json_schema ! ( {
416- "title" : t!( "configure.config_doc.configurationDocumentSchemaTitle" ) . to_string( ) ,
417- "description" : t!( "configure.config_doc.configurationDocumentSchemaDescription" ) . to_string( ) ,
418- } )
419- }
420-
421- fn validate_schema_uri ( & self ) -> Result < ( ) , UnrecognizedSchemaUri > {
422- if Self :: is_recognized_schema_uri ( & self . schema ) {
423- Ok ( ( ) )
424- } else {
425- Err ( UnrecognizedSchemaUri (
426- self . schema . clone ( ) ,
427- Self :: recognized_schema_uris ( ) ,
428- ) )
429- }
430- }
431- }
432-
433432impl Configuration {
434433 #[ must_use]
435434 pub fn new ( ) -> Self {
0 commit comments