CLI: improve required settings for paginated operations (#469)
This commit is contained in:
parent
fb7a2d4c7e
commit
66c890807f
|
@ -286,28 +286,42 @@ impl Generator {
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let fn_name = format_ident!("cli_{}", &method.operation_id);
|
let fn_name = format_ident!("cli_{}", &method.operation_id);
|
||||||
|
|
||||||
|
let first_page_required_set = method
|
||||||
|
.dropshot_paginated
|
||||||
|
.as_ref()
|
||||||
|
.map(|d| &d.first_page_params);
|
||||||
|
|
||||||
let args = method
|
let args = method
|
||||||
.params
|
.params
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|param| {
|
.filter(|param| {
|
||||||
!matches!(¶m.kind, OperationParameterKind::Body(_))
|
!matches!(¶m.kind, OperationParameterKind::Body(_))
|
||||||
&& (method.dropshot_paginated.is_none()
|
&& (method.dropshot_paginated.is_none()
|
||||||
|| (param.name.as_str() != "page_token"))
|
|| param.name.as_str() != "page_token")
|
||||||
})
|
})
|
||||||
.map(|param| {
|
.map(|param| {
|
||||||
let arg_name = param.name.to_kebab_case();
|
let arg_name = param.name.to_kebab_case();
|
||||||
|
|
||||||
let required = match ¶m.kind {
|
let first_page_required = first_page_required_set
|
||||||
OperationParameterKind::Path => Volitionality::Required,
|
.map_or(false, |required| {
|
||||||
OperationParameterKind::Query(true)
|
required.contains(¶m.api_name)
|
||||||
| OperationParameterKind::Header(true) => {
|
});
|
||||||
Volitionality::Required
|
|
||||||
|
let required = if first_page_required {
|
||||||
|
Volitionality::Required
|
||||||
|
} else {
|
||||||
|
match ¶m.kind {
|
||||||
|
OperationParameterKind::Path => Volitionality::Required,
|
||||||
|
OperationParameterKind::Query(true)
|
||||||
|
| OperationParameterKind::Header(true) => {
|
||||||
|
Volitionality::Required
|
||||||
|
}
|
||||||
|
OperationParameterKind::Query(false)
|
||||||
|
| OperationParameterKind::Header(false) => {
|
||||||
|
Volitionality::Optional
|
||||||
|
}
|
||||||
|
OperationParameterKind::Body(_) => unreachable!(),
|
||||||
}
|
}
|
||||||
OperationParameterKind::Query(false)
|
|
||||||
| OperationParameterKind::Header(false) => {
|
|
||||||
Volitionality::Optional
|
|
||||||
}
|
|
||||||
OperationParameterKind::Body(_) => unreachable!(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let OperationParameterType::Type(arg_type_id) = ¶m.typ
|
let OperationParameterType::Type(arg_type_id) = ¶m.typ
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2022 Oxide Computer Company
|
// Copyright 2023 Oxide Computer Company
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
|
@ -88,18 +88,15 @@ struct BuilderImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DropshotPagination {
|
pub struct DropshotPagination {
|
||||||
item: TypeId,
|
pub item: TypeId,
|
||||||
// TODO this is going to be used by the SDK and CLI generation to validate
|
pub first_page_params: Vec<String>,
|
||||||
// inputs.
|
|
||||||
#[allow(unused)]
|
|
||||||
first_page_params: Vec<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct OperationParameter {
|
pub struct OperationParameter {
|
||||||
/// Sanitized parameter name.
|
/// Sanitized parameter name.
|
||||||
pub name: String,
|
pub name: String,
|
||||||
/// Original parameter name provided by the API.
|
/// Original parameter name provided by the API.
|
||||||
api_name: String,
|
pub api_name: String,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub typ: OperationParameterType,
|
pub typ: OperationParameterType,
|
||||||
pub kind: OperationParameterKind,
|
pub kind: OperationParameterKind,
|
||||||
|
|
|
@ -1066,7 +1066,7 @@ impl Cli {
|
||||||
clap::Arg::new("end-time")
|
clap::Arg::new("end-time")
|
||||||
.long("end-time")
|
.long("end-time")
|
||||||
.value_parser(clap::value_parser!(chrono::DateTime<chrono::offset::Utc>))
|
.value_parser(clap::value_parser!(chrono::DateTime<chrono::offset::Utc>))
|
||||||
.required(false)
|
.required(true)
|
||||||
.help("An exclusive end time of metrics."),
|
.help("An exclusive end time of metrics."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -1080,7 +1080,7 @@ impl Cli {
|
||||||
clap::Arg::new("start-time")
|
clap::Arg::new("start-time")
|
||||||
.long("start-time")
|
.long("start-time")
|
||||||
.value_parser(clap::value_parser!(chrono::DateTime<chrono::offset::Utc>))
|
.value_parser(clap::value_parser!(chrono::DateTime<chrono::offset::Utc>))
|
||||||
.required(false)
|
.required(true)
|
||||||
.help("An inclusive start time of metrics."),
|
.help("An inclusive start time of metrics."),
|
||||||
)
|
)
|
||||||
.about("Fetch disk metrics")
|
.about("Fetch disk metrics")
|
||||||
|
|
|
@ -1683,7 +1683,12 @@
|
||||||
"$ref": "#/components/responses/Error"
|
"$ref": "#/components/responses/Error"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"x-dropshot-pagination": true
|
"x-dropshot-pagination": {
|
||||||
|
"required": [
|
||||||
|
"end_time",
|
||||||
|
"start_time"
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/organizations/{organization_name}/projects/{project_name}/images": {
|
"/organizations/{organization_name}/projects/{project_name}/images": {
|
||||||
|
|
Loading…
Reference in New Issue