{{>partial_header}} {{#models}} {{#model}} {{#description}} /// {{{description}}} {{/description}} {{!-- for enum schemas --}} {{#isEnum}} /// {{{description}}} #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] pub enum {{classname}} { {{#allowableValues}} {{#enumVars}} #[serde(rename = "{{{value}}}")] {{name}}, {{/enumVars}}{{/allowableValues}} } impl std::fmt::Display for {{classname}} { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { {{#allowableValues}} {{#enumVars}} {{classname}}::{{name}} => write!(f, "{{{value}}}"), {{/enumVars}}{{/allowableValues}} } } } {{/isEnum}} {{!-- for schemas that have a discriminator --}} {{#discriminator}} #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(tag = "{{{vendorExtensions.x-tag-name}}}")] pub enum {{classname}} { {{#vendorExtensions}} {{#x-mapped-models}} #[serde(rename="{{mappingName}}")] {{modelName}} { {{#vars}} {{#description}} /// {{{description}}} {{/description}} #[serde(rename = "{{{baseName}}}"{{^required}}, skip_serializing_if = "Option::is_none"{{/required}})] {{{name}}}: {{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{^required}}Option<{{/required}}{{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^required}}>{{/required}}, {{/vars}} }, {{/x-mapped-models}} {{/vendorExtensions}} } {{/discriminator}} {{!-- for non-enum schemas --}} {{^isEnum}} {{^discriminator}} #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct {{{classname}}} { {{#vars}} {{#description}} /// {{{description}}} {{/description}} #[serde(rename = "{{{baseName}}}"{{^required}}, skip_serializing_if = "Option::is_none"{{/required}})] pub {{{name}}}: {{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{^required}}Option<{{/required}}{{#isEnum}}{{#isArray}}{{#uniqueItems}}std::collections::HashSet<{{/uniqueItems}}{{^uniqueItems}}Vec<{{/uniqueItems}}{{/isArray}}{{{enumName}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^required}}>{{/required}}, {{/vars}} } impl {{{classname}}} { {{#description}} /// {{{description}}} {{/description}} pub fn new({{#requiredVars}}{{{name}}}: {{#isNullable}}Option<{{/isNullable}}{{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}}>{{/isNullable}}{{^-last}}, {{/-last}}{{/requiredVars}}) -> {{{classname}}} { {{{classname}}} { {{#vars}} {{{name}}}{{^required}}{{#isArray}}: None{{/isArray}}{{#isMap}}: None{{/isMap}}{{^isContainer}}: None{{/isContainer}}{{/required}}, {{/vars}} } } } {{/discriminator}} {{/isEnum}} {{!-- for properties that are of enum type --}} {{#vars}} {{#isEnum}} /// {{{description}}} #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)] pub enum {{enumName}} { {{#allowableValues}} {{#enumVars}} #[serde(rename = "{{{value}}}")] {{name}}, {{/enumVars}} {{/allowableValues}} } impl std::fmt::Display for {{enumName}} { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { {{#allowableValues}} {{#enumVars}} {{enumName}}::{{name}} => write!(f, "{{{value}}}"), {{/enumVars}}{{/allowableValues}} } } } {{/isEnum}} {{/vars}} {{/model}} {{/models}}