rust-axum.models.mustache Maven / Gradle / Ivy
#![allow(unused_qualifications)]
use http::HeaderValue;
use validator::Validate;
#[cfg(feature = "server")]
use crate::header;
use crate::{models, types::*};
{{! Don't "use" structs here - they can conflict with the names of models, and mean that the code won't compile }}
{{#apiInfo}}
{{#apis}}
{{#operations}}
{{#operation}}
{{#vendorExtensions}}
{{#headerParams.size}}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct {{{operationIdCamelCase}}}HeaderParams {
{{#headerParams}}
{{#hasValidation}}
#[validate(
{{#maxLength}}
{{#minLength}}
length(min = {{minLength}}, max = {{maxLength}}),
{{/minLength}}
{{^minLength}}
length(max = {{maxLength}}),
{{/minLength}}
{{/maxLength}}
{{^maxLength}}
{{#minLength}}
length(min = {{minLength}}),
{{/minLength}}
{{/maxLength}}
{{#pattern}}
{{^isByteArray}}
regex(path = *RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}HeaderParams_{{{paramName}}}{{/lambda.uppercase}}),
{{/isByteArray}}
{{#isByteArray}}
custom(function = "validate_byte_{{#lambda.lowercase}}{{{operationIdCamelCase}}}HeaderParams_{{{paramName}}}{{/lambda.lowercase}}"),
{{/isByteArray}}
{{/pattern}}
{{#maximum}}
{{#minimum}}
range(min = {{minimum}}, max = {{maximum}}),
{{/minimum}}
{{^minimum}}
range(max = {{maximum}}),
{{/minimum}}
{{/maximum}}
{{#minimum}}
{{^maximum}}
range(min = {{minimum}}),
{{/maximum}}
{{/minimum}}
{{#maxItems}}
{{#minItems}}
length(min = {{minItems}}, max = {{maxItems}}),
{{/minItems}}
{{^minItems}}
length(max = {{maxItems}}),
{{/minItems}}
{{/maxItems}}
{{^maxItems}}
{{#minItems}}
length(min = {{minItems}}),
{{/minItems}}
{{/maxItems}}
)]
{{/hasValidation}}
pub {{{paramName}}}: {{^required}}Option<{{/required}}{{{dataType}}}{{^required}}>{{/required}},
{{/headerParams}}
}
{{#headerParams}}
{{#hasValidation}}
{{#pattern}}
{{^isByteArray}}
lazy_static::lazy_static! {
static ref RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}HeaderParams_{{{paramName}}}{{/lambda.uppercase}}: regex::Regex = regex::Regex::new(r"{{ pattern }}").unwrap();
}
{{/isByteArray}}
{{#isByteArray}}
lazy_static::lazy_static! {
static ref RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}HeaderParams_{{{paramName}}}{{/lambda.uppercase}}: regex::bytes::Regex = regex::bytes::Regex::new(r"{{ pattern }}").unwrap();
}
fn validate_byte_{{#lambda.lowercase}}{{{operationIdCamelCase}}}HeaderParams_{{{paramName}}}{{/lambda.lowercase}}(
b: &ByteArray
) -> std::result::Result<(), validator::ValidationError> {
if !RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}HeaderParams_{{{paramName}}}{{/lambda.uppercase}}.is_match(&b.0) {
return Err(validator::ValidationError::new("Character not allowed"));
}
std::result::Result::Ok(())
}
{{/isByteArray}}
{{/pattern}}
{{/hasValidation}}
{{/headerParams}}
{{/headerParams.size}}
{{#pathParams.size}}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct {{{operationIdCamelCase}}}PathParams {
{{#pathParams}}
{{#description}}
/// {{{.}}}
{{/description}}
{{#isEnum}}
/// Note: inline enums are not fully supported by openapi-generator
{{/isEnum}}
{{#hasValidation}}
#[validate(
{{#maxLength}}
{{#minLength}}
length(min = {{minLength}}, max = {{maxLength}}),
{{/minLength}}
{{^minLength}}
length(max = {{maxLength}}),
{{/minLength}}
{{/maxLength}}
{{^maxLength}}
{{#minLength}}
length(min = {{minLength}}),
{{/minLength}}
{{/maxLength}}
{{#pattern}}
{{^isByteArray}}
regex(path = *RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}PathParams_{{{paramName}}}{{/lambda.uppercase}}),
{{/isByteArray}}
{{#isByteArray}}
custom(function = "validate_byte_{{#lambda.lowercase}}{{{operationIdCamelCase}}}PathParams_{{{paramName}}}{{/lambda.lowercase}}"),
{{/isByteArray}}
{{/pattern}}
{{#maximum}}
{{#minimum}}
range(min = {{minimum}}, max = {{maximum}}),
{{/minimum}}
{{^minimum}}
range(max = {{maximum}}),
{{/minimum}}
{{/maximum}}
{{#minimum}}
{{^maximum}}
range(min = {{minimum}}),
{{/maximum}}
{{/minimum}}
{{#maxItems}}
{{#minItems}}
length(min = {{minItems}}, max = {{maxItems}}),
{{/minItems}}
{{^minItems}}
length(max = {{maxItems}}),
{{/minItems}}
{{/maxItems}}
{{^maxItems}}
{{#minItems}}
length(min = {{minItems}}),
{{/minItems}}
{{/maxItems}}
)]
{{/hasValidation}}
{{#required}}
pub {{{paramName}}}: {{#isNullable}}Nullable<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}},
{{/required}}
{{^required}}
{{#isNullable}}
#[serde(deserialize_with = "deserialize_optional_nullable")]
#[serde(default = "default_optional_nullable")]
{{/isNullable}}
#[serde(skip_serializing_if="Option::is_none")]
pub {{{paramName}}}: Option<{{#isNullable}}Nullable<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}}>,
{{/required}}
{{/pathParams}}
}
{{#pathParams}}
{{#hasValidation}}
{{#pattern}}
{{^isByteArray}}
lazy_static::lazy_static! {
static ref RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}PathParams_{{{paramName}}}{{/lambda.uppercase}}: regex::Regex = regex::Regex::new(r"{{ pattern }}").unwrap();
}
{{/isByteArray}}
{{#isByteArray}}
lazy_static::lazy_static! {
static ref RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}PathParams_{{{paramName}}}{{/lambda.uppercase}}: regex::bytes::Regex = regex::bytes::Regex::new(r"{{ pattern }}").unwrap();
}
fn validate_byte_{{#lambda.lowercase}}{{{operationIdCamelCase}}}PathParams_{{{paramName}}}{{/lambda.lowercase}}(
b: &ByteArray
) -> std::result::Result<(), validator::ValidationError> {
if !RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}PathParams_{{{paramName}}}{{/lambda.uppercase}}.is_match(&b.0) {
return Err(validator::ValidationError::new("Character not allowed"));
}
std::result::Result::Ok(())
}
{{/isByteArray}}
{{/pattern}}
{{/hasValidation}}
{{/pathParams}}
{{/pathParams.size}}
{{#queryParams.size}}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct {{{operationIdCamelCase}}}QueryParams {
{{#queryParams}}
{{#vendorExtensions}}
{{#description}}
/// {{{.}}}
{{/description}}
{{#isEnum}}
/// Note: inline enums are not fully supported by openapi-generator
{{/isEnum}}
#[serde(rename = "{{{baseName}}}")]
{{#hasValidation}}
#[validate(
{{#maxLength}}
{{#minLength}}
length(min = {{minLength}}, max = {{maxLength}}),
{{/minLength}}
{{^minLength}}
length(max = {{maxLength}}),
{{/minLength}}
{{/maxLength}}
{{^maxLength}}
{{#minLength}}
length(min = {{minLength}}),
{{/minLength}}
{{/maxLength}}
{{#pattern}}
{{^isByteArray}}
regex(path = *RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}QueryParams_{{{paramName}}}{{/lambda.uppercase}}),
{{/isByteArray}}
{{#isByteArray}}
custom(function = "validate_byte_{{#lambda.lowercase}}{{{operationIdCamelCase}}}QueryParams_{{{paramName}}}{{/lambda.lowercase}}"),
{{/isByteArray}}
{{/pattern}}
{{#maximum}}
{{#minimum}}
range(min = {{minimum}}, max = {{maximum}}),
{{/minimum}}
{{^minimum}}
range(max = {{maximum}}),
{{/minimum}}
{{/maximum}}
{{#minimum}}
{{^maximum}}
range(min = {{minimum}}),
{{/maximum}}
{{/minimum}}
{{#maxItems}}
{{#minItems}}
length(min = {{minItems}}, max = {{maxItems}}),
{{/minItems}}
{{^minItems}}
length(max = {{maxItems}}),
{{/minItems}}
{{/maxItems}}
{{^maxItems}}
{{#minItems}}
length(min = {{minItems}}),
{{/minItems}}
{{/maxItems}}
)]
{{/hasValidation}}
{{#required}}
pub {{{paramName}}}: {{#isNullable}}Nullable<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}},
{{/required}}
{{^required}}
{{#isNullable}}
#[serde(deserialize_with = "deserialize_optional_nullable")]
#[serde(default = "default_optional_nullable")]
{{/isNullable}}
#[serde(skip_serializing_if="Option::is_none")]
pub {{{paramName}}}: Option<{{#isNullable}}Nullable<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}}>,
{{/required}}
{{/vendorExtensions}}
{{/queryParams}}
}
{{#queryParams}}
{{#hasValidation}}
{{#pattern}}
{{^isByteArray}}
lazy_static::lazy_static! {
static ref RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}QueryParams_{{{paramName}}}{{/lambda.uppercase}}: regex::Regex = regex::Regex::new(r"{{ pattern }}").unwrap();
}
{{/isByteArray}}
{{#isByteArray}}
lazy_static::lazy_static! {
static ref RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}QueryParams_{{{paramName}}}{{/lambda.uppercase}}: regex::bytes::Regex = regex::bytes::Regex::new(r"{{ pattern }}").unwrap();
}
fn validate_byte_{{#lambda.lowercase}}{{{operationIdCamelCase}}}QueryParams_{{{paramName}}}{{/lambda.lowercase}}(
b: &ByteArray
) -> std::result::Result<(), validator::ValidationError> {
if !RE_{{#lambda.uppercase}}{{{operationIdCamelCase}}}QueryParams_{{{paramName}}}{{/lambda.uppercase}}.is_match(&b.0) {
return Err(validator::ValidationError::new("Character not allowed"));
}
std::result::Result::Ok(())
}
{{/isByteArray}}
{{/pattern}}
{{/hasValidation}}
{{/queryParams}}
{{/queryParams.size}}
{{/vendorExtensions}}
{{/operation}}
{{/operations}}
{{/apis}}
{{/apiInfo}}
{{! Don't "use" structs here - they can conflict with the names of models, and mean that the code won't compile }}
{{#models}}
{{#model}}
{{#description}}
/// {{{.}}}
{{/description}}
{{#isEnum}}
/// Enumeration of values.
/// Since this enum's variants do not hold data, we can easily define them as `#[repr(C)]`
/// which helps with FFI.
#[allow(non_camel_case_types)]
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "conversion", derive(frunk_enum_derive::LabelledGenericEnum))]
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}}
}
}
}
impl std::str::FromStr for {{{classname}}} {
type Err = String;
fn from_str(s: &str) -> std::result::Result {
match s {
{{#allowableValues}}
{{#enumVars}}
{{{value}}} => std::result::Result::Ok({{{classname}}}::{{{name}}}),
{{/enumVars}}
{{/allowableValues}}
_ => std::result::Result::Err(format!("Value not valid: {}", s)),
}
}
}
{{/isEnum}}
{{^isEnum}}
{{#dataType}}
{{#isMap}}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
{{/isMap}}
{{^isMap}}
#[derive(Debug, Clone, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize)]
{{/isMap}}
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct {{{classname}}}({{{dataType}}});
impl validator::Validate for {{{classname}}} {
fn validate(&self) -> std::result::Result<(), validator::ValidationErrors> {
std::result::Result::Ok(())
}
}
impl std::convert::From<{{{dataType}}}> for {{{classname}}} {
fn from(x: {{{dataType}}}) -> Self {
{{{classname}}}(x)
}
}
{{#vendorExtensions.x-is-string}}
impl std::fmt::Display for {{{classname}}} {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.0)
}
}
impl std::str::FromStr for {{{classname}}} {
type Err = std::string::ParseError;
fn from_str(x: &str) -> std::result::Result {
std::result::Result::Ok({{{classname}}}(x.to_string()))
}
}
{{/vendorExtensions.x-is-string}}
impl std::convert::From<{{{classname}}}> for {{{dataType}}} {
fn from(x: {{{classname}}}) -> Self {
x.0
}
}
impl std::ops::Deref for {{{classname}}} {
type Target = {{{dataType}}};
fn deref(&self) -> &{{{dataType}}} {
&self.0
}
}
impl std::ops::DerefMut for {{{classname}}} {
fn deref_mut(&mut self) -> &mut {{{dataType}}} {
&mut self.0
}
}
{{#additionalPropertiesType}}
/// Converts the {{{classname}}} value to the Query Parameters representation (style=form, explode=false)
/// specified in https://swagger.io/docs/specification/serialization/
/// Should be implemented in a serde serializer
impl std::fmt::Display for {{{classname}}} {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// Skipping additionalProperties in query parameter serialization
write!(f, "")
}
}
/// Converts Query Parameters representation (style=form, explode=false) to a {{{classname}}} value
/// as specified in https://swagger.io/docs/specification/serialization/
/// Should be implemented in a serde deserializer
impl ::std::str::FromStr for {{{classname}}} {
type Err = &'static str;
fn from_str(s: &str) -> std::result::Result {
std::result::Result::Err("Parsing additionalProperties for {{{classname}}} is not supported")
}
}
{{/additionalPropertiesType}}
{{/dataType}}
{{^dataType}}
{{#arrayModelType}}
{{! vec}}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct {{{classname}}}(Vec<{{{arrayModelType}}}>);
impl validator::Validate for {{{classname}}} {
fn validate(&self) -> std::result::Result<(), validator::ValidationErrors> {
std::result::Result::Ok(())
}
}
impl std::convert::From> for {{{classname}}} {
fn from(x: Vec<{{{arrayModelType}}}>) -> Self {
{{{classname}}}(x)
}
}
impl std::convert::From<{{{classname}}}> for Vec<{{{arrayModelType}}}> {
fn from(x: {{{classname}}}) -> Self {
x.0
}
}
impl std::iter::FromIterator<{{{arrayModelType}}}> for {{{classname}}} {
fn from_iter>(u: U) -> Self {
{{{classname}}}(Vec::<{{{arrayModelType}}}>::from_iter(u))
}
}
impl std::iter::IntoIterator for {{{classname}}} {
type Item = {{{arrayModelType}}};
type IntoIter = std::vec::IntoIter<{{{arrayModelType}}}>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
impl<'a> std::iter::IntoIterator for &'a {{{classname}}} {
type Item = &'a {{{arrayModelType}}};
type IntoIter = std::slice::Iter<'a, {{{arrayModelType}}}>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
}
impl<'a> std::iter::IntoIterator for &'a mut {{{classname}}} {
type Item = &'a mut {{{arrayModelType}}};
type IntoIter = std::slice::IterMut<'a, {{{arrayModelType}}}>;
fn into_iter(self) -> Self::IntoIter {
self.0.iter_mut()
}
}
impl std::ops::Deref for {{{classname}}} {
type Target = Vec<{{{arrayModelType}}}>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl std::ops::DerefMut for {{{classname}}} {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
/// Converts the {{{classname}}} value to the Query Parameters representation (style=form, explode=false)
/// specified in https://swagger.io/docs/specification/serialization/
/// Should be implemented in a serde serializer
impl std::fmt::Display for {{{classname}}} {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.iter().map(|x| x.to_string()).collect::>().join(","))
}
}
/// Converts Query Parameters representation (style=form, explode=false) to a {{{classname}}} value
/// as specified in https://swagger.io/docs/specification/serialization/
/// Should be implemented in a serde deserializer
impl std::str::FromStr for {{{classname}}} {
type Err = <{{{arrayModelType}}} as std::str::FromStr>::Err;
fn from_str(s: &str) -> std::result::Result {
let mut items = vec![];
for item in s.split(',')
{
items.push(item.parse()?);
}
std::result::Result::Ok({{{classname}}}(items))
}
}
{{/arrayModelType}}
{{^arrayModelType}}
{{! general struct}}
{{#anyOf.size}}
/// Any of:
{{#anyOf}}
/// - {{{.}}}
{{/anyOf}}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct {{{classname}}}(Box);
impl validator::Validate for {{{classname}}}
{
fn validate(&self) -> std::result::Result<(), validator::ValidationErrors> {
std::result::Result::Ok(())
}
}
/// Converts Query Parameters representation (style=form, explode=false) to a {{{classname}}} value
/// as specified in https://swagger.io/docs/specification/serialization/
/// Should be implemented in a serde deserializer
impl std::str::FromStr for {{{classname}}} {
type Err = serde_json::Error;
fn from_str(s: &str) -> std::result::Result {
serde_json::from_str(s)
}
}
impl PartialEq for {{{classname}}} {
fn eq(&self, other: &Self) -> bool {
self.0.get() == other.0.get()
}
}
{{/anyOf.size}}
{{#oneOf.size}}
/// One of:
{{#oneOf}}
/// - {{{.}}}
{{/oneOf}}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct {{{classname}}}(Box);
impl validator::Validate for {{{classname}}}
{
fn validate(&self) -> std::result::Result<(), validator::ValidationErrors> {
std::result::Result::Ok(())
}
}
/// Converts Query Parameters representation (style=form, explode=false) to a {{{classname}}} value
/// as specified in https://swagger.io/docs/specification/serialization/
/// Should be implemented in a serde deserializer
impl std::str::FromStr for {{{classname}}} {
type Err = serde_json::Error;
fn from_str(s: &str) -> std::result::Result {
serde_json::from_str(s)
}
}
impl PartialEq for {{{classname}}} {
fn eq(&self, other: &Self) -> bool {
self.0.get() == other.0.get()
}
}
{{/oneOf.size}}
{{^anyOf.size}}
{{^oneOf.size}}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct {{{classname}}} {
{{#vars}}
{{#description}}
/// {{{.}}}
{{/description}}
{{#isEnum}}
/// Note: inline enums are not fully supported by openapi-generator
{{/isEnum}}
#[serde(rename = "{{{baseName}}}")]
{{#hasValidation}}
#[validate(
{{#maxLength}}
{{#minLength}}
length(min = {{minLength}}, max = {{maxLength}}),
{{/minLength}}
{{^minLength}}
length(max = {{maxLength}}),
{{/minLength}}
{{/maxLength}}
{{^maxLength}}
{{#minLength}}
length(min = {{minLength}}),
{{/minLength}}
{{/maxLength}}
{{#pattern}}
{{^isByteArray}}
regex(path = *RE_{{#lambda.uppercase}}{{{classname}}}_{{{name}}}{{/lambda.uppercase}}),
{{/isByteArray}}
{{#isByteArray}}
custom(function = "validate_byte_{{#lambda.lowercase}}{{{classname}}}_{{{name}}}{{/lambda.lowercase}}"),
{{/isByteArray}}
{{/pattern}}
{{#maximum}}
{{#minimum}}
range(min = {{minimum}}, max = {{maximum}}),
{{/minimum}}
{{^minimum}}
range(max = {{maximum}}),
{{/minimum}}
{{/maximum}}
{{#minimum}}
{{^maximum}}
range(min = {{minimum}}),
{{/maximum}}
{{/minimum}}
{{#maxItems}}
{{#minItems}}
length(min = {{minItems}}, max = {{maxItems}}),
{{/minItems}}
{{^minItems}}
length(max = {{maxItems}}),
{{/minItems}}
{{/maxItems}}
{{^maxItems}}
{{#minItems}}
length(min = {{minItems}}),
{{/minItems}}
{{/maxItems}}
)]
{{/hasValidation}}
{{#required}}
pub {{{name}}}: {{#isNullable}}Nullable<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}},
{{/required}}
{{^required}}
{{#isNullable}}
#[serde(deserialize_with = "deserialize_optional_nullable")]
#[serde(default = "default_optional_nullable")]
{{/isNullable}}
#[serde(skip_serializing_if="Option::is_none")]
pub {{{name}}}: Option<{{#isNullable}}Nullable<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}}>,
{{/required}}
{{/vars}}
}
{{#vars}}
{{#hasValidation}}
{{#pattern}}
{{^isByteArray}}
lazy_static::lazy_static! {
static ref RE_{{#lambda.uppercase}}{{{classname}}}_{{{name}}}{{/lambda.uppercase}}: regex::Regex = regex::Regex::new(r"{{ pattern }}").unwrap();
}
{{/isByteArray}}
{{#isByteArray}}
lazy_static::lazy_static! {
static ref RE_{{#lambda.uppercase}}{{{classname}}}_{{{name}}}{{/lambda.uppercase}}: regex::bytes::Regex = regex::bytes::Regex::new(r"{{ pattern }}").unwrap();
}
fn validate_byte_{{#lambda.lowercase}}{{{classname}}}_{{{name}}}{{/lambda.lowercase}}(
b: &ByteArray
) -> std::result::Result<(), validator::ValidationError> {
if !RE_{{#lambda.uppercase}}{{{classname}}}_{{{name}}}{{/lambda.uppercase}}.is_match(&b.0) {
return Err(validator::ValidationError::new("Character not allowed"));
}
std::result::Result::Ok(())
}
{{/isByteArray}}
{{/pattern}}
{{/hasValidation}}
{{/vars}}
impl {{{classname}}} {
#[allow(clippy::new_without_default, clippy::too_many_arguments)]
pub fn new({{#vars}}{{^defaultValue}}{{{name}}}: {{#isNullable}}Nullable<{{/isNullable}}{{{dataType}}}{{#isNullable}}>{{/isNullable}}, {{/defaultValue}}{{/vars}}) -> {{{classname}}} {
{{{classname}}} {
{{#vars}} {{#defaultValue}}{{{name}}}: {{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}{{{name}}}{{/defaultValue}},
{{/vars}}
}
}
}
/// Converts the {{{classname}}} value to the Query Parameters representation (style=form, explode=false)
/// specified in https://swagger.io/docs/specification/serialization/
/// Should be implemented in a serde serializer
impl std::fmt::Display for {{{classname}}} {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let params: Vec
© 2015 - 2024 Weber Informatics LLC | Privacy Policy