#![allow(unused_imports, unused_qualifications, unused_extern_crates)] {{>partial_header}} use serde::de::{DeserializeOwned, Deserializer}; use serde::ser::Serializer; use serde::Deserialize; use serde_json::value::Value; use std::cmp::Eq; use std::collections::HashMap; use std::default::Default; use std::fmt::{self, Display, Formatter}; use std::hash::Hash; use chrono::DateTime; use chrono::offset::FixedOffset; {{#models}}{{#model}}{{^vendorExtensions.x-rustgen-noop}} {{#description}}/// {{{description}}} {{/description}}{{#vendorExtensions.is-enum}}/// Enumeration of values. /// Since this enum's variants do not hold data, we can easily define them them as `#[repr(C)]` /// which helps with FFI. #[allow(non_camel_case_types)] #[repr(C)] {{#vendorExtensions.x-rustgen-is-untagged-enum}} #[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize, Eq, Ord)] #[serde(untagged)] pub enum {{classname}} { {{~#allowableValues}}{{#enumVars}} {{name}}({{value}}),{{/enumVars}}{{/allowableValues}} } impl Display for {{classname}} { fn fmt(&self, f: &mut Formatter) -> fmt::Result { match self { {{~#allowableValues}}{{#enumVars}} {{classname}}::{{name}}(value) => write!(f, value),{{/enumVars}}{{/allowableValues}} } } } {{/vendorExtensions.x-rustgen-is-untagged-enum}}{{^vendorExtensions.x-rustgen-is-untagged-enum}} #[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Serialize, Deserialize, Eq, Ord)] pub enum {{classname}} { {{~#allowableValues}}{{#enumVars}} #[serde(rename = {{{value}}})] {{name}},{{/enumVars}}{{/allowableValues}} } impl Display for {{classname}} { fn fmt(&self, f: &mut Formatter) -> fmt::Result { match *self { {{~#allowableValues}}{{#enumVars}} {{classname}}::{{name}} => write!(f, {{{value}}}),{{/enumVars}}{{/allowableValues}} } } } impl std::str::FromStr for {{classname}} { type Err = (); fn from_str(s: &str) -> Result { match s { {{#allowableValues}}{{#enumVars}} {{{value}}} => Ok({{classname}}::{{name}}), {{/enumVars}}{{/allowableValues}} _ => Err(()), } } } {{/vendorExtensions.x-rustgen-is-untagged-enum}}{{/vendorExtensions.is-enum}}{{^vendorExtensions.is-enum}}{{#vendorExtensions.x-rustgen-enum-one-of}} #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum {{classname}} { {{~#allowableValues}}{{#values}} {{../classname}}Variant{{@index}}({{#vendorExtensions.x-is-list-container}}Vec<{{#items}}{{{datatype}}}{{/items}}>{{/vendorExtensions.x-is-list-container}}{{#vendorExtensions.x-is-map-container}}HashMap{{/vendorExtensions.x-is-map-container}}{{^vendorExtensions.x-is-container}}{{{datatype}}}{{/vendorExtensions.x-is-container}}),{{/values}}{{/allowableValues}} } {{#allowableValues}}{{#values}} impl From<{{#vendorExtensions.x-is-list-container}}Vec<{{#items}}{{{datatype}}}{{/items}}>{{/vendorExtensions.x-is-list-container}}{{#vendorExtensions.x-is-map-container}}HashMap{{/vendorExtensions.x-is-map-container}}{{^vendorExtensions.x-is-container}}{{{datatype}}}{{/vendorExtensions.x-is-container}}> for {{../classname}} { fn from(value: {{#vendorExtensions.x-is-list-container}}Vec<{{#items}}{{{datatype}}}{{/items}}>{{/vendorExtensions.x-is-list-container}}{{#vendorExtensions.x-is-map-container}}HashMap{{/vendorExtensions.x-is-map-container}}{{^vendorExtensions.x-is-container}}{{{datatype}}}{{/vendorExtensions.x-is-container}}) -> Self { {{../classname}}::{{../classname}}Variant{{@index}}(value) } } {{/values}}{{/allowableValues}}{{#vendorExtensions.x-rustgen-is-display}} impl Display for {{classname}} { fn fmt(&self, f: &mut Formatter) -> fmt::Result { match self { {{~#allowableValues}}{{#values}} {{../classname}}::{{../classname}}Variant{{@index}}(value) => write!(f, "{}", value),{{/values}}{{/allowableValues}} } } } {{/vendorExtensions.x-rustgen-is-display}}{{/vendorExtensions.x-rustgen-enum-one-of}}{{^vendorExtensions.x-rustgen-enum-one-of}}{{#vendorExtensions.x-rustgen-is-bool}} pub type {{classname}} = bool; {{/vendorExtensions.x-rustgen-is-bool}}{{#vendorExtensions.x-rustgen-is-integer}} pub type {{classname}} = i32; {{/vendorExtensions.x-rustgen-is-integer}}{{#vendorExtensions.x-rustgen-is-string}} pub type {{classname}} = String; {{/vendorExtensions.x-rustgen-is-string}}{{#vendorExtensions.x-rustgen-is-datetime}} pub type {{classname}} = DateTime; {{/vendorExtensions.x-rustgen-is-datetime}}{{#vendorExtensions.x-rustgen-is-array}} pub type {{classname}} = Vec<{{arrayModelType}}>; {{/vendorExtensions.x-rustgen-is-array}}{{^vendorExtensions.has-vars}}{{! general struct}}#[derive(Debug, {{^vendorExtensions.x-rustgen-has-default-impl}}Default, {{/vendorExtensions.x-rustgen-has-default-impl}}Clone, PartialEq, Serialize, Deserialize)]{{#xmlName}} #[serde(rename = "{{xmlName}}")]{{/xmlName}} #[allow(clippy::derive_partial_eq_without_eq)] pub struct {{classname}} { {{#vars}}{{^vendorExtensions.x-rustgen-skip-prop}}{{#description}} /// {{{.}}} {{/description}}{{^vendorExtensions.x-rustgen-serde-no-rename}} #[serde(rename = "{{baseName}}")] {{/vendorExtensions.x-rustgen-serde-no-rename}} {{#vendorExtensions.x-rustgen-is-required ~}} {{~#vendorExtensions.x-rustgen-has-default-impl}}{{^vendorExtensions.is-enum}} #[serde(default = "{{classname}}::{{name}}_default")] {{/vendorExtensions.is-enum}}{{/vendorExtensions.x-rustgen-has-default-impl}}{{^vendorExtensions.x-rustgen-has-default-impl}}{{#vendorExtensions.x-rustgen-is-string}} #[serde(skip_serializing_if = "String::is_empty")] {{/vendorExtensions.x-rustgen-is-string}}{{/vendorExtensions.x-rustgen-has-default-impl}} pub {{name}}: {{#vendorExtensions.is-enum}}{{classname}}{{enumName}}{{/vendorExtensions.is-enum}}{{^vendorExtensions.is-enum}}{{#vendorExtensions.x-is-list-container}}Vec<{{#items}}{{{datatype}}}{{/items}}>{{/vendorExtensions.x-is-list-container}}{{#vendorExtensions.x-is-map-container}}HashMap{{/vendorExtensions.x-is-map-container}}{{^vendorExtensions.x-is-container}}{{{datatype}}}{{/vendorExtensions.x-is-container}}{{/vendorExtensions.is-enum}}, {{/vendorExtensions.x-rustgen-is-required}} {{^vendorExtensions.x-rustgen-is-required}}{{^vendorExtensions.x-rustgen-no-skip-none}} #[serde(skip_serializing_if = "Option::is_none")] {{/vendorExtensions.x-rustgen-no-skip-none}} pub {{name}}: Option<{{#vendorExtensions.is-enum}}{{classname}}{{enumName}}{{/vendorExtensions.is-enum}}{{^vendorExtensions.is-enum}}{{#vendorExtensions.x-is-list-container}}Vec<{{#items}}{{{datatype}}}{{/items}}>{{/vendorExtensions.x-is-list-container}}{{#vendorExtensions.x-is-map-container}}HashMap{{/vendorExtensions.x-is-map-container}}{{^vendorExtensions.x-is-container}}{{{datatype}}}{{/vendorExtensions.x-is-container}}{{/vendorExtensions.is-enum}}>, {{/vendorExtensions.x-rustgen-is-required}} {{/vendorExtensions.x-rustgen-skip-prop}}{{/vars}} } {{#vendorExtensions.x-rustgen-has-default-impl}} #[allow(clippy::derivable_impls)] impl Default for {{classname}} { fn default() -> Self { Self { {{#vars}} {{#vendorExtensions.x-rustgen-has-default-impl}}{{^vendorExtensions.is-enum}} {{name}}: String::from("{{vendorExtensions.x-rustgen-default-impl}}"), {{/vendorExtensions.is-enum}}{{#vendorExtensions.is-enum}} {{name}}: Default::default(), {{/vendorExtensions.is-enum}}{{/vendorExtensions.x-rustgen-has-default-impl}} {{^vendorExtensions.x-rustgen-has-default-impl}} {{name}}: Default::default(), {{/vendorExtensions.x-rustgen-has-default-impl}} {{/vars}} } } } impl {{classname}} { {{#vendorExtensions.x-rustgen-default-impl}} #[allow(dead_code)] fn {{key}}_default() -> String { String::from("{{value}}") } {{/vendorExtensions.x-rustgen-default-impl}} } {{/vendorExtensions.x-rustgen-has-default-impl}}{{#vars}}{{#vendorExtensions.is-enum}} #[allow(non_camel_case_types)] {{#vendorExtensions.x-rustgen-is-untagged-enum}} #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum {{classname}}{{enumName}} { {{~#allowableValues}}{{#untaggedVars}} {{name}}({{value}}),{{/untaggedVars}}{{#complexVars}} {{#value}}{{classname}} { {{#vars}}{{name}}: {{datatype}}, {{/vars}} },{{/value}}{{/complexVars}}{{/allowableValues}} } impl Display for {{classname}}{{enumName}} { fn fmt(&self, f: &mut Formatter) -> fmt::Result { match self { {{~#allowableValues}}{{#untaggedVars}} {{classname}}{{enumName}}::{{name}}(value) => write!(f, "{:?}", value),{{/untaggedVars}}{{/allowableValues}} } } } impl std::default::Default for {{classname}}{{enumName}} { fn default() -> Self { {{#allowableValues}}{{#untaggedVars.[0]}} {{classname}}{{enumName}}::{{name}}({{value}}::default()) {{/untaggedVars.[0]}}{{/allowableValues}} } } {{/vendorExtensions.x-rustgen-is-untagged-enum}}{{^vendorExtensions.x-rustgen-is-untagged-enum}} #[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize, Eq, Ord)] pub enum {{classname}}{{enumName}} { {{~#allowableValues}}{{#enumVars}} #[serde(rename = {{{value}}})] {{name}},{{/enumVars}}{{/allowableValues}}{{#vendorExtensions}}{{#x-rustgen-additional-enum-values}} #[serde(rename = {{{value}}})] {{name}},{{/x-rustgen-additional-enum-values}}{{/vendorExtensions}} #[serde(other)] UNKNOWN, } impl ::std::fmt::Display for {{classname}}{{enumName}} { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { match *self { {{~#allowableValues}}{{#enumVars}} {{classname}}{{enumName}}::{{name}} => write!(f, {{{value}}}),{{/enumVars}}{{/allowableValues}}{{#vendorExtensions}}{{#x-rustgen-additional-enum-values}} {{classname}}{{enumName}}::{{name}} => write!(f, {{{value}}}),{{/x-rustgen-additional-enum-values}}{{/vendorExtensions}} {{classname}}{{enumName}}::UNKNOWN => write!(f, "unknown"), } } } impl ::std::str::FromStr for {{classname}}{{enumName}} { type Err = String; fn from_str(s: &str) -> Result { match s { {{#allowableValues}}{{#enumVars}} {{{value}}} => Ok({{classname}}{{enumName}}::{{name}}), {{/enumVars}}{{/allowableValues}}{{#vendorExtensions}}{{#x-rustgen-additional-enum-values}} {{{value}}} => Ok({{classname}}{{enumName}}::{{name}}), {{/x-rustgen-additional-enum-values}}{{/vendorExtensions}} x => Err(format!("Invalid enum type: {}", x)), } } } impl ::std::convert::AsRef for {{classname}}{{enumName}} { fn as_ref(&self) -> &str { match self { {{~#allowableValues}}{{#enumVars}} {{classname}}{{enumName}}::{{name}} => {{{value}}},{{/enumVars}}{{/allowableValues}}{{#vendorExtensions}}{{#x-rustgen-additional-enum-values}} {{classname}}{{enumName}}::{{name}} => {{{value}}},{{/x-rustgen-additional-enum-values}}{{/vendorExtensions}} {{classname}}{{enumName}}::UNKNOWN => "unknown", } } } // Pick the first enum var as default. Please report this as a bug if it's not correct. impl std::default::Default for {{classname}}{{enumName}} { fn default() -> Self { {{#allowableValues}}{{#enumVars.[0]}} {{classname}}{{enumName}}::{{name}} {{/enumVars.[0]}}{{/allowableValues}} } } {{/vendorExtensions.x-rustgen-is-untagged-enum}}{{/vendorExtensions.is-enum}} {{#vendorExtensions.x-is-container}}{{#items}}{{#vendorExtensions.is-enum}} #[allow(non_camel_case_types, clippy::derive_partial_eq_without_eq)] {{#vendorExtensions.x-rustgen-is-untagged-enum}} #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum {{classname}}{{enumName}} { {{~#allowableValues}}{{#untaggedVars}} {{name}}({{value}}),{{/untaggedVars}}{{#complexVars}} {{enumName}}{{@index}}{{#value}} { {{#vars}}{{name}}: {{datatype}}{{#hasMore}}, {{/hasMore}}{{/vars}} },{{/value}}{{/complexVars}}{{/allowableValues}} } impl Display for {{classname}}{{enumName}} { fn fmt(&self, f: &mut Formatter) -> fmt::Result { match self { {{~#allowableValues}}{{#untaggedVars}} {{classname}}{{enumName}}::{{name}}(value) => write!(f, "{:?}", value),{{/untaggedVars}}{{#complexVars}} {{classname}}{{enumName}}::{{enumName}}{{@index}}{{#value}} { {{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}} }{{/value}} => write!(f, "{{enumName}}{{@index}}{{#value}}{ {{~noop}}{ {{#vars}}{:?}{{#hasMore}}, {{/hasMore}}{{/vars}} }{{noop~}} }{{/value}}", {{#value.vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/value.vars}}),{{/complexVars}}{{/allowableValues}} } } } impl std::default::Default for {{classname}}{{enumName}} { fn default() -> Self { {{#allowableValues}}{{#untaggedVars.[0]}} {{classname}}{{enumName}}::{{name}}({{value}}::default()) {{/untaggedVars.[0]}}{{#complexVars.[0]}} {{classname}}{{enumName}}::{{enumName}}0{{#value}} { {{#vars}}{{name}}: {{datatype}}::default(){{#hasMore}}, {{/hasMore}}{{/vars}} }{{/value}} {{/complexVars.[0]}}{{/allowableValues}} } } {{/vendorExtensions.x-rustgen-is-untagged-enum}}{{/vendorExtensions.is-enum}}{{/items}}{{/vendorExtensions.x-is-container}} {{#vendorExtensions.x-rustgen-additional-model}} #[derive(Debug, {{^vendorExtensions.x-rustgen-has-default-impl}}Default, {{/vendorExtensions.x-rustgen-has-default-impl}}Clone, PartialEq, Serialize, Deserialize)] #[allow(clippy::derive_partial_eq_without_eq)] pub struct {{../classname}}{{classname}} { {{#vars}}{{^vendorExtensions.x-rustgen-skip-prop}}{{#description}} /// {{{.}}} {{/description}}{{^vendorExtensions.x-rustgen-serde-no-rename}} #[serde(rename = "{{baseName}}")] {{/vendorExtensions.x-rustgen-serde-no-rename}} {{#vendorExtensions.x-rustgen-is-required ~}} {{~#vendorExtensions.x-rustgen-has-default-impl}}{{^vendorExtensions.is-enum}} #[serde(default = "{{classname}}::{{name}}_default")] {{/vendorExtensions.is-enum}}{{/vendorExtensions.x-rustgen-has-default-impl}}{{^vendorExtensions.x-rustgen-has-default-impl}}{{#vendorExtensions.x-rustgen-is-string}} #[serde(skip_serializing_if = "String::is_empty")] {{/vendorExtensions.x-rustgen-is-string}}{{/vendorExtensions.x-rustgen-has-default-impl}} pub {{name}}: {{#vendorExtensions.is-enum}}{{classname}}{{enumName}}{{/vendorExtensions.is-enum}}{{^vendorExtensions.is-enum}}{{#vendorExtensions.x-is-list-container}}Vec<{{#items}}{{{datatype}}}{{/items}}>{{/vendorExtensions.x-is-list-container}}{{#vendorExtensions.x-is-map-container}}HashMap{{/vendorExtensions.x-is-map-container}}{{^vendorExtensions.x-is-container}}{{{datatype}}}{{/vendorExtensions.x-is-container}}{{/vendorExtensions.is-enum}}, {{/vendorExtensions.x-rustgen-is-required}} {{^vendorExtensions.x-rustgen-is-required}}{{^vendorExtensions.x-rustgen-no-skip-none}} #[serde(skip_serializing_if = "Option::is_none")] {{/vendorExtensions.x-rustgen-no-skip-none}} pub {{name}}: Option<{{#vendorExtensions.is-enum}}{{classname}}{{enumName}}{{/vendorExtensions.is-enum}}{{^vendorExtensions.is-enum}}{{#vendorExtensions.x-is-list-container}}Vec<{{#items}}{{{datatype}}}{{/items}}>{{/vendorExtensions.x-is-list-container}}{{#vendorExtensions.x-is-map-container}}HashMap{{/vendorExtensions.x-is-map-container}}{{^vendorExtensions.x-is-container}}{{{datatype}}}{{/vendorExtensions.x-is-container}}{{/vendorExtensions.is-enum}}>, {{/vendorExtensions.x-rustgen-is-required}} {{/vendorExtensions.x-rustgen-skip-prop}}{{/vars}} } {{/vendorExtensions.x-rustgen-additional-model}} {{/vars}}{{/vendorExtensions.has-vars}}{{/vendorExtensions.x-rustgen-enum-one-of}}{{/vendorExtensions.is-enum}}{{/vendorExtensions.x-rustgen-noop}}{{/model}}{{/models}}