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