1
1
use std:: {
2
+ collections:: BTreeSet ,
2
3
io:: { self , BufWriter , Write as _} ,
3
4
path:: PathBuf ,
4
5
} ;
@@ -43,6 +44,12 @@ enum Command {
43
44
44
45
#[ clap( flatten) ]
45
46
flags : GenerateFlags ,
47
+
48
+ /// The specified operations for --include-mode=specified
49
+ ///
50
+ /// This expects the operation ID, for example v1.message.create
51
+ #[ clap( long) ]
52
+ specified_operations : Vec < String > ,
46
53
} ,
47
54
}
48
55
@@ -71,6 +78,8 @@ enum IncludeMode {
71
78
PublicAndHidden ,
72
79
/// Only operations marked with `x-hidden`
73
80
OnlyHidden ,
81
+ /// Only include operations specified in `--specified-operations`
82
+ Specified ,
74
83
}
75
84
76
85
fn main ( ) -> anyhow:: Result < ( ) > {
@@ -82,15 +91,17 @@ fn main() -> anyhow::Result<()> {
82
91
input_file,
83
92
output_dir,
84
93
flags,
94
+ specified_operations,
85
95
} = args. command ;
96
+ let specified_operations = BTreeSet :: from_iter ( specified_operations) ;
86
97
87
98
let spec = fs:: read_to_string ( & input_file) ?;
88
99
89
100
let spec: OpenApi = serde_json:: from_str ( & spec) . context ( "failed to parse OpenAPI spec" ) ?;
90
101
91
102
match & output_dir {
92
103
Some ( path) => {
93
- analyze_and_generate ( spec, template. into ( ) , path, flags) ?;
104
+ analyze_and_generate ( spec, template. into ( ) , path, flags, specified_operations ) ?;
94
105
}
95
106
None => {
96
107
let output_dir_root = PathBuf :: from ( "out" ) ;
@@ -112,7 +123,7 @@ fn main() -> anyhow::Result<()> {
112
123
. path ( )
113
124
. try_into ( )
114
125
. context ( "non-UTF8 tempdir path" ) ?;
115
- analyze_and_generate ( spec, template. into ( ) , path, flags) ?;
126
+ analyze_and_generate ( spec, template. into ( ) , path, flags, specified_operations ) ?;
116
127
// Persist the TempDir if everything was successful
117
128
_ = output_dir. into_path ( ) ;
118
129
}
@@ -126,11 +137,18 @@ fn analyze_and_generate(
126
137
template : String ,
127
138
path : & Utf8Path ,
128
139
flags : GenerateFlags ,
140
+ specified_operations : BTreeSet < String > ,
129
141
) -> anyhow:: Result < ( ) > {
130
142
let webhooks = get_webhooks ( & spec) ;
131
143
let mut components = spec. components . unwrap_or_default ( ) ;
132
144
if let Some ( paths) = spec. paths {
133
- let api = Api :: new ( paths, & components. schemas , flags. include_mode ) . unwrap ( ) ;
145
+ let api = Api :: new (
146
+ paths,
147
+ & components. schemas ,
148
+ flags. include_mode ,
149
+ specified_operations,
150
+ )
151
+ . unwrap ( ) ;
134
152
let types = api. types ( & mut components. schemas , webhooks) ;
135
153
136
154
if flags. debug {
0 commit comments