| 
 | 1 | +use std::path::PathBuf;  | 
 | 2 | +use argh::FromArgs;  | 
 | 3 | +use clients_schema::Flavor;  | 
 | 4 | +use crate::Configuration;  | 
 | 5 | + | 
 | 6 | +/// Convert schema.json to an OpenAPI schema  | 
 | 7 | +#[derive(Debug, FromArgs)]  | 
 | 8 | +pub struct Cli {  | 
 | 9 | +    /// schema file to transform.  | 
 | 10 | +    #[argh(option)]  | 
 | 11 | +    pub schema: PathBuf,  | 
 | 12 | + | 
 | 13 | +    /// output file.  | 
 | 14 | +    #[argh(option)]  | 
 | 15 | +    pub output: PathBuf,  | 
 | 16 | + | 
 | 17 | +    //---- Fields from lib::Configuration  | 
 | 18 | + | 
 | 19 | +    /// the flavor to generate [all, stack, serverless - default = all]  | 
 | 20 | +    #[argh(option, default = "SchemaFlavor::All")]  | 
 | 21 | +    pub flavor: SchemaFlavor,  | 
 | 22 | + | 
 | 23 | +    /// add enum descriptions to property descriptions [default = true]  | 
 | 24 | +    #[argh(option, default = "true")]  | 
 | 25 | +    pub lift_enum_descriptions: bool,  | 
 | 26 | + | 
 | 27 | +    /// generate only this namespace (can be repeated)  | 
 | 28 | +    #[argh(option)]  | 
 | 29 | +    pub namespace: Vec<String>,  | 
 | 30 | +}  | 
 | 31 | + | 
 | 32 | +use derive_more::FromStr;  | 
 | 33 | + | 
 | 34 | +#[derive(Debug, Clone, PartialEq, FromStr)]  | 
 | 35 | +pub enum SchemaFlavor {  | 
 | 36 | +    /// No schema filtering  | 
 | 37 | +    All,  | 
 | 38 | +    /// Stack (stateful) flavor  | 
 | 39 | +    Stack,  | 
 | 40 | +    /// Serverless flavor  | 
 | 41 | +    Serverless,  | 
 | 42 | +}  | 
 | 43 | + | 
 | 44 | +impl From<Cli> for Configuration {  | 
 | 45 | +    fn from(val: Cli) -> Configuration {  | 
 | 46 | +        let flavor = match val.flavor {  | 
 | 47 | +            SchemaFlavor::All => None,  | 
 | 48 | +            SchemaFlavor::Serverless => Some(Flavor::Serverless),  | 
 | 49 | +            SchemaFlavor::Stack => Some(Flavor::Stack),  | 
 | 50 | +        };  | 
 | 51 | + | 
 | 52 | +        Configuration {  | 
 | 53 | +            flavor,  | 
 | 54 | +            lift_enum_descriptions: val.lift_enum_descriptions,  | 
 | 55 | +            namespaces: if val.namespace.is_empty() {  | 
 | 56 | +                None  | 
 | 57 | +            } else {  | 
 | 58 | +                Some(val.namespace)  | 
 | 59 | +            },  | 
 | 60 | +        }  | 
 | 61 | +    }  | 
 | 62 | +}  | 
0 commit comments