RFC: schema: make enums static
I don't see a reason to allow these to be dynamically modifiable. Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
aa1b2e04fe
commit
cc84a830c5
|
@ -33,7 +33,7 @@ pub fn api_method_upgrade_backup() -> ApiAsyncMethod {
|
|||
ObjectSchema::new("Upgraded to backup protocol.")
|
||||
.required("store", StringSchema::new("Datastore name."))
|
||||
.required("backup-type", StringSchema::new("Backup type.")
|
||||
.format(Arc::new(ApiStringFormat::Enum(vec!["vm".into(), "ct".into(), "host".into()]))))
|
||||
.format(Arc::new(ApiStringFormat::Enum(&["vm", "ct", "host"]))))
|
||||
.required("backup-id", StringSchema::new("Backup ID."))
|
||||
)
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ pub fn api_method_upload_pxar() -> ApiAsyncMethod {
|
|||
.required("store", StringSchema::new("Datastore name."))
|
||||
.required("archive-name", StringSchema::new("Backup archive name."))
|
||||
.required("backup-type", StringSchema::new("Backup type.")
|
||||
.format(Arc::new(ApiStringFormat::Enum(vec!["ct".into(), "host".into()]))))
|
||||
.format(Arc::new(ApiStringFormat::Enum(&["ct", "host"]))))
|
||||
.required("backup-id", StringSchema::new("Backup ID."))
|
||||
.required("backup-time", IntegerSchema::new("Backup time (Unix epoch.)")
|
||||
.minimum(1547797308))
|
||||
|
@ -194,7 +194,7 @@ pub fn api_method_download_pxar() -> ApiAsyncMethod {
|
|||
.required("store", StringSchema::new("Datastore name."))
|
||||
.required("archive-name", StringSchema::new("Backup archive name."))
|
||||
.required("backup-type", StringSchema::new("Backup type.")
|
||||
.format(Arc::new(ApiStringFormat::Enum(vec!["ct".into(), "host".into()]))))
|
||||
.format(Arc::new(ApiStringFormat::Enum(&["ct", "host"]))))
|
||||
.required("backup-id", StringSchema::new("Backup ID."))
|
||||
.required("backup-time", IntegerSchema::new("Backup time (Unix epoch.)")
|
||||
.minimum(1547797308))
|
||||
|
|
|
@ -372,7 +372,7 @@ impl From<ArraySchema> for Arc<Schema> {
|
|||
}
|
||||
|
||||
pub enum ApiStringFormat {
|
||||
Enum(Vec<String>),
|
||||
Enum(&'static [&'static str]),
|
||||
Pattern(&'static Regex),
|
||||
Complex(Arc<Schema>),
|
||||
VerifyFn(fn(&str) -> Result<(), Error>),
|
||||
|
@ -744,7 +744,7 @@ fn test_query_string() {
|
|||
let schema = ObjectSchema::new("Parameters.")
|
||||
.required(
|
||||
"name", StringSchema::new("Name.")
|
||||
.format(Arc::new(ApiStringFormat::Enum(vec!["ev1".into(), "ev2".into()])))
|
||||
.format(Arc::new(ApiStringFormat::Enum(&["ev1", "ev2"])))
|
||||
);
|
||||
|
||||
let res = parse_query_string("name=noenum", &schema, true);
|
||||
|
@ -873,7 +873,7 @@ fn test_verify_function() {
|
|||
fn test_verify_complex_object() {
|
||||
|
||||
let nic_models = Arc::new(ApiStringFormat::Enum(
|
||||
vec!["e1000".into(), "virtio".into()]));
|
||||
&["e1000", "virtio"]));
|
||||
|
||||
let param_schema: Arc<Schema> = ObjectSchema::new("Properties.")
|
||||
.default_key("model")
|
||||
|
|
|
@ -409,7 +409,7 @@ fn print_property_completion(
|
|||
}
|
||||
|
||||
if let Schema::String(StringSchema { format: Some(format), ..} ) = schema {
|
||||
if let ApiStringFormat::Enum(list) = format.as_ref() {
|
||||
if let ApiStringFormat::Enum(list) = *format.as_ref() {
|
||||
for value in list {
|
||||
if value.starts_with(arg) {
|
||||
println!("{}", value);
|
||||
|
|
Loading…
Reference in New Issue