mirror of
https://git.proxmox.com/git/proxmox
synced 2025-05-03 13:55:06 +00:00
move ParameterSchema from router to schema
it's the place where it belongs, and unbreaks the --no-default-features build Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
a5b8f9d340
commit
43e9cf10af
@ -19,7 +19,7 @@ syn = { version = "1.0", features = [ "full", "visit-mut" ] }
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
proxmox = { path = "../proxmox", features = [ "test-harness" ] }
|
proxmox = { version = "0.9.1", path = "../proxmox", features = [ "test-harness" ] }
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
@ -677,7 +677,7 @@ fn serialize_input_schema(
|
|||||||
pub const #input_schema_name: ::proxmox::api::schema::ObjectSchema = #ts;
|
pub const #input_schema_name: ::proxmox::api::schema::ObjectSchema = #ts;
|
||||||
},
|
},
|
||||||
quote_spanned! { func_sig_span =>
|
quote_spanned! { func_sig_span =>
|
||||||
::proxmox::api::router::ParameterSchema::Object(&#input_schema_name)
|
::proxmox::api::schema::ParameterSchema::Object(&#input_schema_name)
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -750,7 +750,7 @@ fn serialize_input_schema(
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
quote_spanned! { func_sig_span =>
|
quote_spanned! { func_sig_span =>
|
||||||
::proxmox::api::router::ParameterSchema::AllOf(&#input_schema_name)
|
::proxmox::api::schema::ParameterSchema::AllOf(&#input_schema_name)
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ pub fn hello(it: IndexText, nv: NameValue) -> Result<(NameValue, IndexText), Err
|
|||||||
fn hello_schema_check() {
|
fn hello_schema_check() {
|
||||||
const TEST_METHOD: ::proxmox::api::ApiMethod = ::proxmox::api::ApiMethod::new_full(
|
const TEST_METHOD: ::proxmox::api::ApiMethod = ::proxmox::api::ApiMethod::new_full(
|
||||||
&::proxmox::api::ApiHandler::Sync(&api_function_hello),
|
&::proxmox::api::ApiHandler::Sync(&api_function_hello),
|
||||||
::proxmox::api::router::ParameterSchema::AllOf(&::proxmox::api::schema::AllOfSchema::new(
|
::proxmox::api::schema::ParameterSchema::AllOf(&::proxmox::api::schema::AllOfSchema::new(
|
||||||
"Hello method.",
|
"Hello method.",
|
||||||
&[&IndexText::API_SCHEMA, &NameValue::API_SCHEMA],
|
&[&IndexText::API_SCHEMA, &NameValue::API_SCHEMA],
|
||||||
)),
|
)),
|
||||||
@ -176,7 +176,7 @@ fn with_extra_schema_check() {
|
|||||||
|
|
||||||
const TEST_METHOD: ::proxmox::api::ApiMethod = ::proxmox::api::ApiMethod::new_full(
|
const TEST_METHOD: ::proxmox::api::ApiMethod = ::proxmox::api::ApiMethod::new_full(
|
||||||
&::proxmox::api::ApiHandler::Sync(&api_function_with_extra),
|
&::proxmox::api::ApiHandler::Sync(&api_function_with_extra),
|
||||||
::proxmox::api::router::ParameterSchema::AllOf(&::proxmox::api::schema::AllOfSchema::new(
|
::proxmox::api::schema::ParameterSchema::AllOf(&::proxmox::api::schema::AllOfSchema::new(
|
||||||
"Extra method.",
|
"Extra method.",
|
||||||
&[
|
&[
|
||||||
&INNER_SCHEMA,
|
&INNER_SCHEMA,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::api::router::ParameterSchema;
|
|
||||||
use crate::api::schema::*;
|
use crate::api::schema::*;
|
||||||
|
|
||||||
fn record_done_argument(
|
fn record_done_argument(
|
||||||
|
@ -3,7 +3,6 @@ use std::collections::HashMap;
|
|||||||
use anyhow::*;
|
use anyhow::*;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
use crate::api::router::ParameterSchema;
|
|
||||||
use crate::api::schema::*;
|
use crate::api::schema::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -43,8 +43,7 @@ pub mod router;
|
|||||||
#[cfg(feature = "router")]
|
#[cfg(feature = "router")]
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use router::{
|
pub use router::{
|
||||||
ApiFuture, ApiHandler, ApiMethod, ApiResponseFuture, ParameterSchema, Router, SubRoute,
|
ApiFuture, ApiHandler, ApiMethod, ApiResponseFuture, Router, SubRoute, SubdirMap,
|
||||||
SubdirMap,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "cli")]
|
#[cfg(feature = "cli")]
|
||||||
|
@ -10,7 +10,7 @@ use hyper::Body;
|
|||||||
use percent_encoding::percent_decode_str;
|
use percent_encoding::percent_decode_str;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
use crate::api::schema::{self, AllOfSchema, ObjectSchema, Schema};
|
use crate::api::schema::{self, ObjectSchema, ParameterSchema, Schema};
|
||||||
use crate::api::RpcEnvironment;
|
use crate::api::RpcEnvironment;
|
||||||
|
|
||||||
use super::Permission;
|
use super::Permission;
|
||||||
@ -430,59 +430,6 @@ impl ReturnType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parameters are objects, but we have two types of object schemas, the regular one and the
|
|
||||||
/// `AllOf` schema.
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
#[cfg_attr(feature = "test-harness", derive(Eq, PartialEq))]
|
|
||||||
pub enum ParameterSchema {
|
|
||||||
Object(&'static ObjectSchema),
|
|
||||||
AllOf(&'static AllOfSchema),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl schema::ObjectSchemaType for ParameterSchema {
|
|
||||||
type PropertyIter = Box<dyn Iterator<Item = &'static schema::SchemaPropertyEntry>>;
|
|
||||||
|
|
||||||
fn description(&self) -> &'static str {
|
|
||||||
match self {
|
|
||||||
ParameterSchema::Object(o) => o.description(),
|
|
||||||
ParameterSchema::AllOf(o) => o.description(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn lookup(&self, key: &str) -> Option<(bool, &Schema)> {
|
|
||||||
match self {
|
|
||||||
ParameterSchema::Object(o) => o.lookup(key),
|
|
||||||
ParameterSchema::AllOf(o) => o.lookup(key),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn properties(&self) -> Self::PropertyIter {
|
|
||||||
match self {
|
|
||||||
ParameterSchema::Object(o) => Box::new(o.properties()),
|
|
||||||
ParameterSchema::AllOf(o) => Box::new(o.properties()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn additional_properties(&self) -> bool {
|
|
||||||
match self {
|
|
||||||
ParameterSchema::Object(o) => o.additional_properties(),
|
|
||||||
ParameterSchema::AllOf(o) => o.additional_properties(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&'static ObjectSchema> for ParameterSchema {
|
|
||||||
fn from(schema: &'static ObjectSchema) -> Self {
|
|
||||||
ParameterSchema::Object(schema)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&'static AllOfSchema> for ParameterSchema {
|
|
||||||
fn from(schema: &'static AllOfSchema) -> Self {
|
|
||||||
ParameterSchema::AllOf(schema)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This struct defines a synchronous API call which returns the result as json `Value`
|
/// This struct defines a synchronous API call which returns the result as json `Value`
|
||||||
#[cfg_attr(feature = "test-harness", derive(Eq, PartialEq))]
|
#[cfg_attr(feature = "test-harness", derive(Eq, PartialEq))]
|
||||||
pub struct ApiMethod {
|
pub struct ApiMethod {
|
||||||
|
@ -10,7 +10,6 @@ use anyhow::{bail, format_err, Error};
|
|||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
use url::form_urlencoded;
|
use url::form_urlencoded;
|
||||||
|
|
||||||
use super::router::ParameterSchema;
|
|
||||||
use crate::api::const_regex::ConstRegexPattern;
|
use crate::api::const_regex::ConstRegexPattern;
|
||||||
|
|
||||||
/// Error type for schema validation
|
/// Error type for schema validation
|
||||||
@ -752,6 +751,59 @@ impl PartialEq for ApiStringFormat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parameters are objects, but we have two types of object schemas, the regular one and the
|
||||||
|
/// `AllOf` schema.
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
#[cfg_attr(feature = "test-harness", derive(Eq, PartialEq))]
|
||||||
|
pub enum ParameterSchema {
|
||||||
|
Object(&'static ObjectSchema),
|
||||||
|
AllOf(&'static AllOfSchema),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ObjectSchemaType for ParameterSchema {
|
||||||
|
type PropertyIter = Box<dyn Iterator<Item = &'static SchemaPropertyEntry>>;
|
||||||
|
|
||||||
|
fn description(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
ParameterSchema::Object(o) => o.description(),
|
||||||
|
ParameterSchema::AllOf(o) => o.description(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lookup(&self, key: &str) -> Option<(bool, &Schema)> {
|
||||||
|
match self {
|
||||||
|
ParameterSchema::Object(o) => o.lookup(key),
|
||||||
|
ParameterSchema::AllOf(o) => o.lookup(key),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn properties(&self) -> Self::PropertyIter {
|
||||||
|
match self {
|
||||||
|
ParameterSchema::Object(o) => Box::new(o.properties()),
|
||||||
|
ParameterSchema::AllOf(o) => Box::new(o.properties()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn additional_properties(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
ParameterSchema::Object(o) => o.additional_properties(),
|
||||||
|
ParameterSchema::AllOf(o) => o.additional_properties(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&'static ObjectSchema> for ParameterSchema {
|
||||||
|
fn from(schema: &'static ObjectSchema) -> Self {
|
||||||
|
ParameterSchema::Object(schema)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&'static AllOfSchema> for ParameterSchema {
|
||||||
|
fn from(schema: &'static AllOfSchema) -> Self {
|
||||||
|
ParameterSchema::AllOf(schema)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Helper function to parse boolean values
|
/// Helper function to parse boolean values
|
||||||
///
|
///
|
||||||
/// - true: `1 | on | yes | true`
|
/// - true: `1 | on | yes | true`
|
||||||
|
Loading…
Reference in New Issue
Block a user