@@ -4,7 +4,7 @@ use crate::error::extension::{
44} ;
55use crate :: json:: structure:: VersionReqWithJsonSchema ;
66use schemars:: JsonSchema ;
7- use serde:: { Deserialize , Deserializer } ;
7+ use serde:: { Deserialize , Deserializer , Serialize , Serializer } ;
88use serde_json:: Value ;
99use std:: path:: PathBuf ;
1010use std:: {
@@ -17,7 +17,7 @@ pub static MANIFEST_FILE_NAME: &str = "extension.json";
1717type SubcmdName = String ;
1818type ArgName = String ;
1919
20- #[ derive( Debug , Deserialize , JsonSchema ) ]
20+ #[ derive( Debug , Serialize , Deserialize , JsonSchema ) ]
2121#[ serde( deny_unknown_fields) ]
2222pub struct ExtensionManifest {
2323 pub name : String ,
@@ -33,7 +33,7 @@ pub struct ExtensionManifest {
3333 pub canister_type : Option < ExtensionCanisterType > ,
3434}
3535
36- #[ derive( Debug , Deserialize , JsonSchema ) ]
36+ #[ derive( Debug , Serialize , Deserialize , JsonSchema ) ]
3737#[ serde( untagged) ]
3838pub enum ExtensionDependency {
3939 /// A SemVer version requirement, for example ">=0.17.0".
@@ -71,7 +71,7 @@ impl ExtensionManifest {
7171 }
7272}
7373
74- #[ derive( Debug , Deserialize , JsonSchema ) ]
74+ #[ derive( Debug , Serialize , Deserialize , JsonSchema ) ]
7575pub struct ExtensionCanisterType {
7676 /// If one field depends on another and both specify a handlebars expression,
7777 /// list the fields in the order that they should be evaluated.
@@ -88,18 +88,18 @@ pub struct ExtensionCanisterType {
8888 pub defaults : BTreeMap < String , Value > ,
8989}
9090
91- #[ derive( Debug , Deserialize , Default , JsonSchema ) ]
92- pub struct ExtensionSubcommandsOpts ( BTreeMap < SubcmdName , ExtensionSubcommandOpts > ) ;
91+ #[ derive( Debug , Serialize , Deserialize , Default , JsonSchema ) ]
92+ pub struct ExtensionSubcommandsOpts ( pub BTreeMap < SubcmdName , ExtensionSubcommandOpts > ) ;
9393
94- #[ derive( Debug , Deserialize , JsonSchema ) ]
94+ #[ derive( Debug , Serialize , Deserialize , JsonSchema ) ]
9595#[ serde( deny_unknown_fields) ]
9696pub struct ExtensionSubcommandOpts {
9797 pub about : Option < String > ,
9898 pub args : Option < BTreeMap < ArgName , ExtensionSubcommandArgOpts > > ,
9999 pub subcommands : Option < ExtensionSubcommandsOpts > ,
100100}
101101
102- #[ derive( Debug , Deserialize , JsonSchema ) ]
102+ #[ derive( Debug , Serialize , Deserialize , JsonSchema ) ]
103103#[ serde( deny_unknown_fields) ]
104104pub struct ExtensionSubcommandArgOpts {
105105 pub about : Option < String > ,
@@ -167,6 +167,22 @@ impl<'de> Deserialize<'de> for ArgNumberOfValues {
167167 }
168168}
169169
170+ impl Serialize for ArgNumberOfValues {
171+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
172+ where
173+ S : Serializer ,
174+ {
175+ match self {
176+ Self :: Number ( n) => serializer. serialize_u64 ( * n as u64 ) ,
177+ Self :: Unlimited => serializer. serialize_str ( "unlimited" ) ,
178+ Self :: Range ( range) => {
179+ let s = format ! ( "{}..{}" , range. start, range. end - 1 ) ;
180+ serializer. serialize_str ( & s)
181+ }
182+ }
183+ }
184+ }
185+
170186impl ExtensionSubcommandArgOpts {
171187 pub fn into_clap_arg (
172188 self ,
0 commit comments