Skip to content

Commit 6a3fbce

Browse files
committed
Instead of an ever growing list of included operations
Specify a list of excluded operations
1 parent 5ea3c24 commit 6a3fbce

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

src/api.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl Api {
2626
paths: openapi::Paths,
2727
component_schemas: &IndexMap<String, openapi::SchemaObject>,
2828
include_mode: IncludeMode,
29-
specified_operations: BTreeSet<String>,
29+
excluded_operations: BTreeSet<String>,
3030
) -> anyhow::Result<Self> {
3131
let mut resources = BTreeMap::new();
3232

@@ -47,7 +47,7 @@ impl Api {
4747
op,
4848
component_schemas,
4949
include_mode,
50-
&specified_operations,
50+
&excluded_operations,
5151
) {
5252
let resource = get_or_insert_resource(&mut resources, res_path);
5353
resource.operations.push(op);
@@ -192,7 +192,7 @@ impl Operation {
192192
op: openapi::Operation,
193193
component_schemas: &IndexMap<String, aide::openapi::SchemaObject>,
194194
include_mode: IncludeMode,
195-
specified_operations: &BTreeSet<String>,
195+
excluded_operations: &BTreeSet<String>,
196196
) -> Option<(Vec<String>, Self)> {
197197
let Some(op_id) = op.operation_id else {
198198
// ignore operations without an operationId
@@ -206,9 +206,8 @@ impl Operation {
206206
IncludeMode::OnlyPublic => !x_hidden,
207207
IncludeMode::PublicAndHidden => true,
208208
IncludeMode::OnlyHidden => x_hidden,
209-
IncludeMode::Specified => specified_operations.contains(&op_id),
210209
};
211-
if !include_operation {
210+
if !include_operation || excluded_operations.contains(&op_id) {
212211
return None;
213212
}
214213

src/main.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,15 @@ enum Command {
3939
input_file: String,
4040

4141
/// Path to the output directory.
42-
#[clap(long)]
42+
#[clap(short, long)]
4343
output_dir: Option<Utf8PathBuf>,
4444

4545
#[clap(flatten)]
4646
flags: GenerateFlags,
4747

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>,
48+
/// The codegen will ignore any operations in this list
49+
#[clap(short, long)]
50+
excluded_operations: Vec<String>,
5351
},
5452
}
5553

@@ -78,8 +76,6 @@ enum IncludeMode {
7876
PublicAndHidden,
7977
/// Only operations marked with `x-hidden`
8078
OnlyHidden,
81-
/// Only include operations specified in `--specified-operations`
82-
Specified,
8379
}
8480

8581
fn main() -> anyhow::Result<()> {
@@ -91,17 +87,17 @@ fn main() -> anyhow::Result<()> {
9187
input_file,
9288
output_dir,
9389
flags,
94-
specified_operations,
90+
excluded_operations,
9591
} = args.command;
96-
let specified_operations = BTreeSet::from_iter(specified_operations);
92+
let excluded_operations = BTreeSet::from_iter(excluded_operations);
9793

9894
let spec = fs::read_to_string(&input_file)?;
9995

10096
let spec: OpenApi = serde_json::from_str(&spec).context("failed to parse OpenAPI spec")?;
10197

10298
match &output_dir {
10399
Some(path) => {
104-
analyze_and_generate(spec, template.into(), path, flags, specified_operations)?;
100+
analyze_and_generate(spec, template.into(), path, flags, excluded_operations)?;
105101
}
106102
None => {
107103
let output_dir_root = PathBuf::from("out");
@@ -123,7 +119,7 @@ fn main() -> anyhow::Result<()> {
123119
.path()
124120
.try_into()
125121
.context("non-UTF8 tempdir path")?;
126-
analyze_and_generate(spec, template.into(), path, flags, specified_operations)?;
122+
analyze_and_generate(spec, template.into(), path, flags, excluded_operations)?;
127123
// Persist the TempDir if everything was successful
128124
_ = output_dir.into_path();
129125
}
@@ -137,7 +133,7 @@ fn analyze_and_generate(
137133
template: String,
138134
path: &Utf8Path,
139135
flags: GenerateFlags,
140-
specified_operations: BTreeSet<String>,
136+
excluded_operations: BTreeSet<String>,
141137
) -> anyhow::Result<()> {
142138
let webhooks = get_webhooks(&spec);
143139
let mut components = spec.components.unwrap_or_default();
@@ -146,7 +142,7 @@ fn analyze_and_generate(
146142
paths,
147143
&components.schemas,
148144
flags.include_mode,
149-
specified_operations,
145+
excluded_operations,
150146
)
151147
.unwrap();
152148
let types = api.types(&mut components.schemas, webhooks);

0 commit comments

Comments
 (0)