@@ -9,6 +9,7 @@ use serde::Serialize;
9
9
use crate :: {
10
10
types:: { FieldType , Types } ,
11
11
util:: { get_schema_name, serialize_btree_map_values} ,
12
+ IncludeMode ,
12
13
} ;
13
14
14
15
/// The API we generate a client for.
@@ -24,7 +25,7 @@ impl Api {
24
25
pub ( crate ) fn new (
25
26
paths : openapi:: Paths ,
26
27
component_schemas : & IndexMap < String , openapi:: SchemaObject > ,
27
- include_hidden : bool ,
28
+ include_mode : IncludeMode ,
28
29
) -> anyhow:: Result < Self > {
29
30
let mut resources = BTreeMap :: new ( ) ;
30
31
@@ -40,7 +41,7 @@ impl Api {
40
41
41
42
for ( method, op) in path_item {
42
43
if let Some ( ( res_path, op) ) =
43
- Operation :: from_openapi ( & path, method, op, component_schemas, include_hidden )
44
+ Operation :: from_openapi ( & path, method, op, component_schemas, include_mode )
44
45
{
45
46
let resource = get_or_insert_resource ( & mut resources, res_path) ;
46
47
resource. operations . push ( op) ;
@@ -184,15 +185,22 @@ impl Operation {
184
185
method : & str ,
185
186
op : openapi:: Operation ,
186
187
component_schemas : & IndexMap < String , aide:: openapi:: SchemaObject > ,
187
- include_hidden : bool ,
188
+ include_mode : IncludeMode ,
188
189
) -> Option < ( Vec < String > , Self ) > {
189
190
let Some ( op_id) = op. operation_id else {
190
191
// ignore operations without an operationId
191
192
return None ;
192
193
} ;
193
194
tracing:: Span :: current ( ) . record ( "op_id" , & op_id) ;
194
195
195
- if !include_hidden && op. extensions . get ( "x-hidden" ) . is_some_and ( |val| val == true ) {
196
+ // verbose, but very easy to understand
197
+ let x_hidden = op. extensions . get ( "x-hidden" ) . is_some_and ( |val| val == true ) ;
198
+ let include_operation = match include_mode {
199
+ IncludeMode :: OnlyPublic => !x_hidden,
200
+ IncludeMode :: PublicAndHidden => true ,
201
+ IncludeMode :: OnlyHidden => x_hidden,
202
+ } ;
203
+ if !include_operation {
196
204
return None ;
197
205
}
198
206
0 commit comments