forked from proxmox-mirrors/proxmox
api-macro: rename elements to properties
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
a646146f75
commit
5a2fe67cd8
@ -208,7 +208,7 @@ impl Parse for JSONMapEntry {
|
|||||||
/// type: Object,
|
/// type: Object,
|
||||||
/// description: "text",
|
/// description: "text",
|
||||||
/// foo: bar, // "unknown", will be added as a builder-pattern method
|
/// foo: bar, // "unknown", will be added as a builder-pattern method
|
||||||
/// elements: { ... }
|
/// properties: { ... }
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
@ -343,21 +343,21 @@ impl SchemaItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Contains a sorted list of elements:
|
/// Contains a sorted list of properties:
|
||||||
struct SchemaObject {
|
struct SchemaObject {
|
||||||
elements: Vec<(String, bool, Schema)>,
|
properties: Vec<(String, bool, Schema)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SchemaObject {
|
impl SchemaObject {
|
||||||
fn try_extract_from(obj: &mut JSONObject) -> Result<Self, syn::Error> {
|
fn try_extract_from(obj: &mut JSONObject) -> Result<Self, syn::Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
elements: obj
|
properties: obj
|
||||||
.remove_required_element("elements")?
|
.remove_required_element("properties")?
|
||||||
.into_object("object field definition")?
|
.into_object("object field definition")?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.try_fold(
|
.try_fold(
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
|mut elements, (key, value)| -> Result<_, syn::Error> {
|
|mut properties, (key, value)| -> Result<_, syn::Error> {
|
||||||
let mut schema: JSONObject =
|
let mut schema: JSONObject =
|
||||||
value.into_object("schema definition for field")?;
|
value.into_object("schema definition for field")?;
|
||||||
let optional: bool = schema
|
let optional: bool = schema
|
||||||
@ -368,20 +368,20 @@ impl SchemaObject {
|
|||||||
})
|
})
|
||||||
.transpose()?
|
.transpose()?
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
elements.push((key.to_string(), optional, schema.try_into()?));
|
properties.push((key.to_string(), optional, schema.try_into()?));
|
||||||
Ok(elements)
|
Ok(properties)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
// This must be kept sorted!
|
// This must be kept sorted!
|
||||||
.map(|mut elements| {
|
.map(|mut properties| {
|
||||||
elements.sort_by(|a, b| (a.0).cmp(&b.0));
|
properties.sort_by(|a, b| (a.0).cmp(&b.0));
|
||||||
elements
|
properties
|
||||||
})?,
|
})?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_schema_inner(&self, ts: &mut TokenStream) -> Result<(), Error> {
|
fn to_schema_inner(&self, ts: &mut TokenStream) -> Result<(), Error> {
|
||||||
for element in self.elements.iter() {
|
for element in self.properties.iter() {
|
||||||
let key = &element.0;
|
let key = &element.0;
|
||||||
let optional = element.1;
|
let optional = element.1;
|
||||||
let mut schema = TokenStream::new();
|
let mut schema = TokenStream::new();
|
||||||
|
@ -73,7 +73,7 @@ fn router_do(item: TokenStream) -> Result<TokenStream, Error> {
|
|||||||
#[api]
|
#[api]
|
||||||
#[input({
|
#[input({
|
||||||
type: Object,
|
type: Object,
|
||||||
elements: {
|
properties: {
|
||||||
username: {
|
username: {
|
||||||
type: String,
|
type: String,
|
||||||
description: "User name",
|
description: "User name",
|
||||||
@ -88,7 +88,7 @@ fn router_do(item: TokenStream) -> Result<TokenStream, Error> {
|
|||||||
#[returns({
|
#[returns({
|
||||||
type: Object,
|
type: Object,
|
||||||
description: "Returns a ticket",
|
description: "Returns a ticket",
|
||||||
elements: {
|
properties: {
|
||||||
"username": {
|
"username": {
|
||||||
type: String,
|
type: String,
|
||||||
description: "User name.",
|
description: "User name.",
|
||||||
|
@ -9,7 +9,7 @@ use serde_json::Value;
|
|||||||
#[api]
|
#[api]
|
||||||
#[input({
|
#[input({
|
||||||
type: Object,
|
type: Object,
|
||||||
elements: {
|
properties: {
|
||||||
username: {
|
username: {
|
||||||
type: String,
|
type: String,
|
||||||
description: "User name",
|
description: "User name",
|
||||||
@ -24,7 +24,7 @@ use serde_json::Value;
|
|||||||
#[returns({
|
#[returns({
|
||||||
type: Object,
|
type: Object,
|
||||||
description: "Returns a ticket",
|
description: "Returns a ticket",
|
||||||
elements: {
|
properties: {
|
||||||
"username": {
|
"username": {
|
||||||
type: String,
|
type: String,
|
||||||
description: "User name.",
|
description: "User name.",
|
||||||
|
Loading…
Reference in New Issue
Block a user