From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 2/3] move ParameterSchema from router to schema
Date: Thu, 14 Jan 2021 14:39:54 +0100 [thread overview]
Message-ID: <20210114133955.166852-3-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20210114133955.166852-1-f.gruenbichler@proxmox.com>
it's the place where it belongs, and unbreaks the --no-default-features
build
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
Notes:
breaking change, requires corresponding patch in proxmox-backup
proxmox-api-macro/Cargo.toml | 2 +-
proxmox-api-macro/src/api/method.rs | 4 +--
proxmox-api-macro/tests/allof.rs | 4 +--
proxmox/src/api/cli/completion.rs | 1 -
proxmox/src/api/cli/getopts.rs | 1 -
proxmox/src/api/mod.rs | 3 +-
proxmox/src/api/router.rs | 55 +----------------------------
proxmox/src/api/schema.rs | 54 +++++++++++++++++++++++++++-
8 files changed, 60 insertions(+), 64 deletions(-)
diff --git a/proxmox-api-macro/Cargo.toml b/proxmox-api-macro/Cargo.toml
index ab6c590..fb2e842 100644
--- a/proxmox-api-macro/Cargo.toml
+++ b/proxmox-api-macro/Cargo.toml
@@ -19,7 +19,7 @@ syn = { version = "1.0", features = [ "full", "visit-mut" ] }
[dev-dependencies]
futures = "0.3"
-proxmox = { path = "../proxmox", features = [ "test-harness" ] }
+proxmox = { version = "0.9.1", path = "../proxmox", features = [ "test-harness" ] }
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
diff --git a/proxmox-api-macro/src/api/method.rs b/proxmox-api-macro/src/api/method.rs
index 23501bc..a03e654 100644
--- a/proxmox-api-macro/src/api/method.rs
+++ b/proxmox-api-macro/src/api/method.rs
@@ -677,7 +677,7 @@ fn serialize_input_schema(
pub const #input_schema_name: ::proxmox::api::schema::ObjectSchema = #ts;
},
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 =>
- ::proxmox::api::router::ParameterSchema::AllOf(&#input_schema_name)
+ ::proxmox::api::schema::ParameterSchema::AllOf(&#input_schema_name)
},
))
}
diff --git a/proxmox-api-macro/tests/allof.rs b/proxmox-api-macro/tests/allof.rs
index 1c1b9a9..9fcf979 100644
--- a/proxmox-api-macro/tests/allof.rs
+++ b/proxmox-api-macro/tests/allof.rs
@@ -136,7 +136,7 @@ pub fn hello(it: IndexText, nv: NameValue) -> Result<(NameValue, IndexText), Err
fn hello_schema_check() {
const TEST_METHOD: ::proxmox::api::ApiMethod = ::proxmox::api::ApiMethod::new_full(
&::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.",
&[&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(
&::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.",
&[
&INNER_SCHEMA,
diff --git a/proxmox/src/api/cli/completion.rs b/proxmox/src/api/cli/completion.rs
index 42b3915..a660473 100644
--- a/proxmox/src/api/cli/completion.rs
+++ b/proxmox/src/api/cli/completion.rs
@@ -1,6 +1,5 @@
use super::*;
-use crate::api::router::ParameterSchema;
use crate::api::schema::*;
fn record_done_argument(
diff --git a/proxmox/src/api/cli/getopts.rs b/proxmox/src/api/cli/getopts.rs
index adf0658..6248fe5 100644
--- a/proxmox/src/api/cli/getopts.rs
+++ b/proxmox/src/api/cli/getopts.rs
@@ -3,7 +3,6 @@ use std::collections::HashMap;
use anyhow::*;
use serde_json::Value;
-use crate::api::router::ParameterSchema;
use crate::api::schema::*;
#[derive(Debug)]
diff --git a/proxmox/src/api/mod.rs b/proxmox/src/api/mod.rs
index 5319cc1..8c6f597 100644
--- a/proxmox/src/api/mod.rs
+++ b/proxmox/src/api/mod.rs
@@ -43,8 +43,7 @@ pub mod router;
#[cfg(feature = "router")]
#[doc(inline)]
pub use router::{
- ApiFuture, ApiHandler, ApiMethod, ApiResponseFuture, ParameterSchema, Router, SubRoute,
- SubdirMap,
+ ApiFuture, ApiHandler, ApiMethod, ApiResponseFuture, Router, SubRoute, SubdirMap,
};
#[cfg(feature = "cli")]
diff --git a/proxmox/src/api/router.rs b/proxmox/src/api/router.rs
index 2f4b6c4..609a89e 100644
--- a/proxmox/src/api/router.rs
+++ b/proxmox/src/api/router.rs
@@ -10,7 +10,7 @@ use hyper::Body;
use percent_encoding::percent_decode_str;
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 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`
#[cfg_attr(feature = "test-harness", derive(Eq, PartialEq))]
pub struct ApiMethod {
diff --git a/proxmox/src/api/schema.rs b/proxmox/src/api/schema.rs
index 1378d78..c2cc61e 100644
--- a/proxmox/src/api/schema.rs
+++ b/proxmox/src/api/schema.rs
@@ -10,7 +10,6 @@ use anyhow::{bail, format_err, Error};
use serde_json::{json, Value};
use url::form_urlencoded;
-use super::router::ParameterSchema;
use crate::api::const_regex::ConstRegexPattern;
/// 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
///
/// - true: `1 | on | yes | true`
--
2.20.1
next prev parent reply other threads:[~2021-01-14 13:41 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-12 13:58 [pbs-devel] [PATCH-SERIES 0/20] update to tokio 1.0 and friends Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox 1/4] Cargo.toml: update to tokio 1.0 Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox 2/4] update to rustyline 7 Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox 3/4] update to tokio 1.0 Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox 4/4] tokio 1.0: drop TimeoutFutureExt Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 01/12] update to tokio 1.0 Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 02/12] tokio 1.0: delay -> sleep Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 03/12] proxmox XXX: use tokio::time::timeout directly Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 04/12] tokio 1.0: AsyncRead/Seek with ReadBuf Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 05/12] tokio: adapt to 1.0 runtime changes Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 06/12] tokio: adapt to 1.0 process:Child changes Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 07/12] tokio 1.0: use ReceiverStream from tokio-stream Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 08/12] tokio 1.0: update to new tokio-openssl interface Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 09/12] tokio 1.0: update to new Signal interface Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 10/12] hyper: use new hyper::upgrade Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 11/12] examples: unify h2 examples Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-backup 12/12] cleanup: remove unnecessary 'mut' and '.clone()' Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH proxmox-fuse] update to tokio 1.0 Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [PATCH pxar 1/3] " Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [RFC pxar 2/3] clippy: use matches! instead of match Fabian Grünbichler
2021-01-12 13:58 ` [pbs-devel] [RFC pxar 3/3] remove futures-io feature Fabian Grünbichler
2021-01-12 14:42 ` Wolfgang Bumiller
2021-01-12 14:52 ` [pbs-devel] [PATCH-SERIES 0/20] update to tokio 1.0 and friends Wolfgang Bumiller
2021-01-14 13:39 ` [pbs-devel] [PATCH proxmox 1/3] fix u2f example Fabian Grünbichler
2021-01-14 13:39 ` [pbs-devel] [PATCH proxmox-backup] proxmox XXX: adapt to moved ParameterSchema Fabian Grünbichler
2021-01-14 13:39 ` Fabian Grünbichler [this message]
2021-01-14 13:39 ` [pbs-devel] [PATCH proxmox 3/3] build: add autopkgtest target Fabian Grünbichler
2021-01-14 13:41 ` [pbs-devel] [PATCH pxar 1/2] fix example Fabian Grünbichler
2021-01-14 13:41 ` [pbs-devel] [PATCH pxar 2/2] build: fix --no-default-features Fabian Grünbichler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210114133955.166852-3-f.gruenbichler@proxmox.com \
--to=f.gruenbichler@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox