mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-03 01:05:39 +00:00
api-macro: reference consistency
API_RETURN_* and API_PARAMETER_* schemas are no references anymore to allow using them as external schemas via the `"schema"` key inside object schemas inside the `#[api]` macro. Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
59467a11d6
commit
0ce4c9eeb8
@ -318,7 +318,7 @@ impl SchemaItem {
|
||||
let mut items = TokenStream::new();
|
||||
array.to_schema(&mut items)?;
|
||||
ts.extend(quote! {
|
||||
::proxmox::api::schema::ArraySchema::new(#description, #items)
|
||||
::proxmox::api::schema::ArraySchema::new(#description, &#items)
|
||||
});
|
||||
}
|
||||
SchemaItem::ExternType(path) => {
|
||||
@ -332,7 +332,7 @@ impl SchemaItem {
|
||||
if !properties.is_empty() {
|
||||
bail!(&properties[0].0 => "additional properties not allowed on schema ref");
|
||||
}
|
||||
ts.extend(quote_spanned! { path.span() => &#path });
|
||||
ts.extend(quote_spanned! { path.span() => #path });
|
||||
return Ok(true);
|
||||
}
|
||||
SchemaItem::Inferred(span) => {
|
||||
@ -367,7 +367,7 @@ impl SchemaItem {
|
||||
if self.to_inner_schema(&mut inner_ts, description, span, properties)? {
|
||||
ts.extend(inner_ts);
|
||||
} else {
|
||||
ts.extend(quote! { & #inner_ts .schema() });
|
||||
ts.extend(quote! { #inner_ts .schema() });
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -432,7 +432,7 @@ impl SchemaObject {
|
||||
let optional = element.1;
|
||||
let mut schema = TokenStream::new();
|
||||
element.2.to_schema(&mut schema)?;
|
||||
ts.extend(quote! { (#key, #optional, #schema), });
|
||||
ts.extend(quote! { (#key, #optional, &#schema), });
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -76,8 +76,8 @@ pub fn handle_enum(
|
||||
Ok(quote_spanned! { name.span() =>
|
||||
#enum_ty
|
||||
impl #name {
|
||||
pub const API_SCHEMA: &'static ::proxmox::api::schema::Schema =
|
||||
& #schema
|
||||
pub const API_SCHEMA: ::proxmox::api::schema::Schema =
|
||||
#schema
|
||||
.format(&::proxmox::api::schema::ApiStringFormat::Enum(&[#variants]))
|
||||
.schema();
|
||||
}
|
||||
|
@ -127,9 +127,9 @@ pub fn handle_method(mut attribs: JSONObject, mut func: syn::ItemFn) -> Result<T
|
||||
let mut inner = TokenStream::new();
|
||||
schema.to_schema(&mut inner)?;
|
||||
returns_schema_definition = quote_spanned! { func.sig.span() =>
|
||||
pub const #return_schema_name: &'static ::proxmox::api::schema::Schema = #inner;
|
||||
pub const #return_schema_name: ::proxmox::api::schema::Schema = #inner;
|
||||
};
|
||||
returns_schema_setter = quote! { .returns(#return_schema_name) };
|
||||
returns_schema_setter = quote! { .returns(&#return_schema_name) };
|
||||
}
|
||||
|
||||
let api_handler = if is_async {
|
||||
@ -141,13 +141,13 @@ pub fn handle_method(mut attribs: JSONObject, mut func: syn::ItemFn) -> Result<T
|
||||
Ok(quote_spanned! { func.sig.span() =>
|
||||
#returns_schema_definition
|
||||
|
||||
pub const #input_schema_name: &'static ::proxmox::api::schema::ObjectSchema =
|
||||
&#input_schema;
|
||||
pub const #input_schema_name: ::proxmox::api::schema::ObjectSchema =
|
||||
#input_schema;
|
||||
|
||||
#vis const #api_method_name: ::proxmox::api::ApiMethod =
|
||||
::proxmox::api::ApiMethod::new(
|
||||
&#api_handler,
|
||||
#input_schema_name,
|
||||
&#input_schema_name,
|
||||
)
|
||||
#returns_schema_setter
|
||||
#access_setter
|
||||
|
@ -78,7 +78,7 @@ fn finish_schema(
|
||||
Ok(quote_spanned! { name.span() =>
|
||||
#stru
|
||||
impl #name {
|
||||
pub const API_SCHEMA: &'static ::proxmox::api::schema::Schema = #schema;
|
||||
pub const API_SCHEMA: ::proxmox::api::schema::Schema = #schema;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ pub struct AnI16(i16);
|
||||
|
||||
#[test]
|
||||
fn test_an_i16_schema() {
|
||||
const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema =
|
||||
&::proxmox::api::schema::IntegerSchema::new("An i16: -32768 to 32767.")
|
||||
const TEST_SCHEMA: ::proxmox::api::schema::Schema =
|
||||
::proxmox::api::schema::IntegerSchema::new("An i16: -32768 to 32767.")
|
||||
.minimum(-32768)
|
||||
.maximum(32767)
|
||||
.schema();
|
||||
@ -23,8 +23,8 @@ pub struct I16G50(i16);
|
||||
|
||||
#[test]
|
||||
fn test_i16g50_schema() {
|
||||
const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema =
|
||||
&::proxmox::api::schema::IntegerSchema::new("Already limited on one side.")
|
||||
const TEST_SCHEMA: ::proxmox::api::schema::Schema =
|
||||
::proxmox::api::schema::IntegerSchema::new("Already limited on one side.")
|
||||
.minimum(-50)
|
||||
.maximum(32767)
|
||||
.schema();
|
||||
@ -38,8 +38,8 @@ pub struct AnI32(i32);
|
||||
|
||||
#[test]
|
||||
fn test_an_i32_schema() {
|
||||
const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema =
|
||||
&::proxmox::api::schema::IntegerSchema::new("An i32: -0x8000_0000 to 0x7fff_ffff.")
|
||||
const TEST_SCHEMA: ::proxmox::api::schema::Schema =
|
||||
::proxmox::api::schema::IntegerSchema::new("An i32: -0x8000_0000 to 0x7fff_ffff.")
|
||||
.minimum(-0x8000_0000)
|
||||
.maximum(0x7fff_ffff)
|
||||
.schema();
|
||||
@ -53,8 +53,8 @@ pub struct AnU32(u32);
|
||||
|
||||
#[test]
|
||||
fn test_an_u32_schema() {
|
||||
const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema =
|
||||
&::proxmox::api::schema::IntegerSchema::new("Unsigned implies a minimum of zero.")
|
||||
const TEST_SCHEMA: ::proxmox::api::schema::Schema =
|
||||
::proxmox::api::schema::IntegerSchema::new("Unsigned implies a minimum of zero.")
|
||||
.minimum(0)
|
||||
.maximum(0xffff_ffff)
|
||||
.schema();
|
||||
@ -68,8 +68,8 @@ pub struct AnI64(i64);
|
||||
|
||||
#[test]
|
||||
fn test_an_i64_schema() {
|
||||
const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema =
|
||||
&::proxmox::api::schema::IntegerSchema::new("An i64: this is left unlimited.")
|
||||
const TEST_SCHEMA: ::proxmox::api::schema::Schema =
|
||||
::proxmox::api::schema::IntegerSchema::new("An i64: this is left unlimited.")
|
||||
.schema();
|
||||
|
||||
assert_eq!(TEST_SCHEMA, AnI64::API_SCHEMA);
|
||||
@ -81,8 +81,8 @@ pub struct AnU64(u64);
|
||||
|
||||
#[test]
|
||||
fn test_an_u64_schema() {
|
||||
const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema =
|
||||
&::proxmox::api::schema::IntegerSchema::new("Unsigned implies a minimum of zero.")
|
||||
const TEST_SCHEMA: ::proxmox::api::schema::Schema =
|
||||
::proxmox::api::schema::IntegerSchema::new("Unsigned implies a minimum of zero.")
|
||||
.minimum(0)
|
||||
.schema();
|
||||
|
||||
|
@ -23,8 +23,8 @@ pub struct OkString(String);
|
||||
|
||||
#[test]
|
||||
fn ok_string() {
|
||||
const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema =
|
||||
&::proxmox::api::schema::StringSchema::new("A string")
|
||||
const TEST_SCHEMA: ::proxmox::api::schema::Schema =
|
||||
::proxmox::api::schema::StringSchema::new("A string")
|
||||
.format(&schema::ApiStringFormat::Enum(&[
|
||||
EnumEntry::new("ok", "Ok"),
|
||||
EnumEntry::new("not-ok", "Not OK"),
|
||||
@ -45,8 +45,8 @@ pub struct TestStruct {
|
||||
|
||||
#[test]
|
||||
fn test_struct() {
|
||||
pub const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema =
|
||||
&::proxmox::api::schema::ObjectSchema::new(
|
||||
pub const TEST_SCHEMA: ::proxmox::api::schema::Schema =
|
||||
::proxmox::api::schema::ObjectSchema::new(
|
||||
"An example of a simple struct type.",
|
||||
&[
|
||||
(
|
||||
@ -84,8 +84,8 @@ pub struct RenamedStruct {
|
||||
|
||||
#[test]
|
||||
fn renamed_struct() {
|
||||
const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema =
|
||||
&::proxmox::api::schema::ObjectSchema::new(
|
||||
const TEST_SCHEMA: ::proxmox::api::schema::Schema =
|
||||
::proxmox::api::schema::ObjectSchema::new(
|
||||
"An example of a struct with renamed fields.",
|
||||
&[
|
||||
(
|
||||
@ -124,8 +124,8 @@ pub enum Selection {
|
||||
|
||||
#[test]
|
||||
fn selection_test() {
|
||||
const TEST_SCHEMA: &'static ::proxmox::api::schema::Schema =
|
||||
&::proxmox::api::schema::StringSchema::new(
|
||||
const TEST_SCHEMA: ::proxmox::api::schema::Schema =
|
||||
::proxmox::api::schema::StringSchema::new(
|
||||
"A selection of either \'onekind\', \'another-kind\' or \'selection-number-three\'.",
|
||||
)
|
||||
.format(&::proxmox::api::schema::ApiStringFormat::Enum(&[
|
||||
@ -164,8 +164,8 @@ fn string_check_schema_test() {
|
||||
&::proxmox::api::schema::ObjectSchema::new(
|
||||
"Check a string.",
|
||||
&[
|
||||
("arg", false, OkString::API_SCHEMA),
|
||||
("selection", false, Selection::API_SCHEMA),
|
||||
("arg", false, &OkString::API_SCHEMA),
|
||||
("selection", false, &Selection::API_SCHEMA),
|
||||
],
|
||||
),
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user