11{ {> partial_header} }
22use crate::models;
3+ use ::std::borrow::Cow;
34use serde::{ Deserialize, Serialize} ;
45{ {#models} }
56{ {#model} }
@@ -123,11 +124,12 @@ impl Default for {{classname}} {
123124{{^discriminator}}
124125{{#vendorExtensions.x-rust-builder}}
125126#[derive(bon::Builder)]
127+ #[builder(on(Cow<' _, str> , into))]
126128#[builder(on(String, into))]
127- {{/vendorExtensions.x-rust-builder}}
128- {{#vendorExtensions.x-rust-has-byte-array}}#[serde_as]
129- {{/vendorExtensions.x-rust-has-byte-array }}{{#oneOf.isEmpty}}#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
130- pub struct {{{classname}}}{{{ vendorExtensions.x-rust-generic-parameter}}} {
129+ {{/vendorExtensions.x-rust-builder} }{ { !
130+ } } { {#vendorExtensions.x-rust-has-byte-array} }#[serde_as]{ {/vendorExtensions.x-rust-has-byte-array } } { { !
131+ } }{ {#oneOf.isEmpty} }#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
132+ pub struct { {{classname} }}{ {#vendorExtensions.x-rust-has-borrowed-data } }<'a { {# vendorExtensions.x-rust-generic-parameter} }, { {{. } }} { {/vendorExtensions.x-rust-generic-parameter } }> { {/vendorExtensions.x-rust-has-borrowed-data } } { {^vendorExtensions.x-rust-has-borrowed-data } } { {#vendorExtensions.x-rust-generic-parameter } }< { {{. } }}> { {/vendorExtensions.x-rust-generic-parameter } } { {/vendorExtensions.x-rust-has-borrowed-data } } {
131133{{#vars} }
132134 { {#description} }
133135 /// { {{.} }}
@@ -145,32 +147,52 @@ pub struct {{{classname}}}{{{vendorExtensions.x-rust-generic-parameter}}} {
145147 } }{ {#isNullable} }Option<{ {/isNullable} }{ {^required} }Option<{ {/required} }{ {!
146148 ### Enums
147149 } }{ {#isEnum} }{ {#isArray} }{ {#uniqueItems} }std::collections::HashSet<{ {/uniqueItems} }{ {^uniqueItems} }Vec<{ {/uniqueItems} }{ {/isArray} }{ {{enumName} }}{ {#isArray} }>{ {/isArray} }{ {/isEnum} }{ {!
148- ### Non-Enums Start
149- }}{{^isEnum}}{{!
150150 ### Models
151- }}{{#isModel}}{{^avoidBoxedModels}}Box<{{/avoidBoxedModels}}{{{dataType}}}{{^avoidBoxedModels}}>{{/avoidBoxedModels}}{{/isModel}}{{!
152- ### Primative datatypes
153- }}{{^isModel}}{{#isByteArray}}Vec<u8>{{/isByteArray}}{{^isByteArray}}{{{dataType}}}{{/isByteArray}}{{/isModel}}{{!
154- ### Non-Enums End
155- }}{{/isEnum}}{{!
151+ } }{ {^isEnum} }{ {#isModel} }{ {^avoidBoxedModels} }Box<{ {/avoidBoxedModels} }{ {{dataType} }}{ {#vendorExtensions.x-rust-has-borrowed-data} }{ {#model} }{ {#vendorExtensions.x-rust-has-borrowed-data} }<'a>{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {^vendorExtensions.x-rust-has-borrowed-data} }<'static>{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {/model} }{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {^avoidBoxedModels} }>{ {/avoidBoxedModels} }{ {/isModel} }{ {!
152+ ### ByteArray
153+ } }{ {^isModel} }{ {#isByteArray} }Vec<u8 >{ {/isByteArray} }{ {!
154+ ### String
155+ } }{ {^isByteArray} }{ {#isString} }{ {#model} }{ {#vendorExtensions.x-rust-has-borrowed-data} }Cow<'a, str>{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {^vendorExtensions.x-rust-has-borrowed-data} }String{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {/model} }{ {/isString} }{ {!
156+ ### Arrays
157+ } }{ {^isString} }{ {#isArray} }Vec<{ {#items} }{ {!
158+ ### Array Models
159+ } }{ {#isModel} }{ {{dataType} }}{ {#vendorExtensions.x-rust-has-borrowed-data} }{ {#model} }{ {#vendorExtensions.x-rust-has-borrowed-data} }<'a>{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {^vendorExtensions.x-rust-has-borrowed-data} }<'static>{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {/model} }{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {/isModel} }{ {!
160+ ### Array other datatypes
161+ } }{ {^isModel} }{ {{dataType} }}{ {/isModel} }{ {/items} }>{ {/isArray} }{ {!
162+ ### Primitive datatypes
163+ } }{ {^isArray} }{ {#isPrimitiveType} }{ {{dataType} }}{ {/isPrimitiveType} }{ {!
164+ ### Any other Non-Primitive datatypes
165+ } }{ {^isPrimitiveType} }{ {{dataType} }}{ {!
166+ ### Closing tags
167+ } }{ {/isPrimitiveType} }{ {/isArray} }{ {/isString} }{ {/isByteArray} }{ {/isModel} }{ {/isEnum} }{ {!
156168 ### Option End (and trailing comma)
157169 } }{ {#isNullable} }>{ {/isNullable} }{ {^required} }>{ {/required} },
158170 { {/vendorExtensions.x-rust-type} }
159171{ {/vars} }
160172}
161173
162- impl{{{vendorExtensions.x-rust-generic-parameter}}} {{{classname}}}{{{vendorExtensions.x-rust-generic-parameter}}} {
174+ impl{ {#vendorExtensions.x-rust-has-borrowed-data} }<'a{ {#vendorExtensions.x-rust-generic-parameter} }, { {{.} }}{ {/vendorExtensions.x-rust-generic-parameter} }>{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {^vendorExtensions.x-rust-has-borrowed-data} }{ {#vendorExtensions.x-rust-generic-parameter} }<{ {{.} }}>{ {/vendorExtensions.x-rust-generic-parameter} }{ {/vendorExtensions.x-rust-has-borrowed-data} } { {!
175+ } }{ {{classname} }}{ {#vendorExtensions.x-rust-has-borrowed-data} }<'a{ {#vendorExtensions.x-rust-generic-parameter} }, { {{.} }}{ {/vendorExtensions.x-rust-generic-parameter} }>{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {^vendorExtensions.x-rust-has-borrowed-data} }{ {#vendorExtensions.x-rust-generic-parameter} }<{ {{.} }}>{ {/vendorExtensions.x-rust-generic-parameter} }{ {/vendorExtensions.x-rust-has-borrowed-data} } {
163176 {{#description} }
164177 /// { {{.} }}
165178 { {/description} }
166179 pub fn new({ {#requiredVars} }{ {{name} }}: { {!
167180 ### CHANGE 1: If x-rust-type is available for a required var, use it for the parameter type.
168181 } }{ {#vendorExtensions.x-rust-type} }{ {{.} }}{ {/vendorExtensions.x-rust-type} }{ {!
169182 ### Fallback to original logic if x-rust-type is not present.
170- }}{{^vendorExtensions.x-rust-type}}{{#isNullable}}Option<{{/isNullable}}{{#isEnum}}{{#isArray}}{{#uniqueItems}}std::collections::HashSet<{{/uniqueItems}}{{^uniqueItems}}Vec<{{/uniqueItems}}{{/isArray}}{{{enumName}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{#isByteArray}}Vec<u8>{{/isByteArray}}{{^isByteArray}}{{{dataType}}}{{/isByteArray}}{{/isEnum}}{{#isNullable}}>{{/isNullable}}{{/vendorExtensions.x-rust-type}}{{!
183+ } }{ {^vendorExtensions.x-rust-type} }{ {#isNullable} }Option<{ {/isNullable} }{ {!
184+ } }{ {#isEnum} }{ {#isArray} }{ {#uniqueItems} }std::collections::HashSet<{ {/uniqueItems} }{ {^uniqueItems} }Vec<{ {/uniqueItems} }{ {/isArray} }{ {{enumName} }}{ {#isArray} }>{ {/isArray} }{ {/isEnum} }{ {!
185+ } }{ {^isEnum} }{ {#isByteArray} }Vec<u8 >{ {/isByteArray} }{ {!
186+ } }{ {^isByteArray} }{ {#isString} }{ {#model} }{ {#vendorExtensions.x-rust-has-borrowed-data} }Cow<'a, str>{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {^vendorExtensions.x-rust-has-borrowed-data} }String{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {/model} }{ {/isString} }{ {!
187+ } }{ {^isString} }{ {#isArray} }Vec<{ {#items} }{ {!
188+ } }{ {#isModel} }{ {{dataType} }}{ {#vendorExtensions.x-rust-has-borrowed-data} }{ {#model} }{ {#vendorExtensions.x-rust-has-borrowed-data} }<'a>{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {^vendorExtensions.x-rust-has-borrowed-data} }<'static>{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {/model} }{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {/isModel} }{ {!
189+ } }{ {^isModel} }{ {{dataType} }}{ {/isModel} }{ {/items} }>{ {/isArray} }{ {!
190+ } }{ {^isArray} }{ {{dataType} }}{ {#isModel} }{ {#vendorExtensions.x-rust-has-borrowed-data} }{ {#model} }{ {#vendorExtensions.x-rust-has-borrowed-data} }<'a>{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {^vendorExtensions.x-rust-has-borrowed-data} }<'static>{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {/model} }{ {/vendorExtensions.x-rust-has-borrowed-data} }{ {/isModel} }{ {!
191+ } }{ {/isArray} }{ {/isString} }{ {/isByteArray} }{ {/isEnum} }{ {!
192+ } }{ {#isNullable} }>{ {/isNullable} }{ {/vendorExtensions.x-rust-type} }{ {!
171193 ### Comma for next arguement
172- }}{{^-last}}, {{/-last}}{{/requiredVars}}) -> {{{classname}}}{{{vendorExtensions.x-rust-generic-parameter}}} {
173- {{{classname}}} {
194+ } }{ {^-last} }, { {/-last} }{ {/requiredVars} }) -> Self {
195+ Self {
174196 {{#vars} }
175197 { {#vendorExtensions.x-rust-type} }
176198 { {! Differentiate between required and optional fields with x-rust-type.} }
@@ -196,16 +218,16 @@ impl{{{vendorExtensions.x-rust-generic-parameter}}} {{{classname}}}{{{vendorExte
196218{ {/description} }
197219#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
198220#[serde(untagged)]
199- pub enum {{classname}} {
221+ pub enum { {classname} }{ {#vendorExtensions.x-rust-has-borrowed-data } }<'a> { {/vendorExtensions.x-rust-has-borrowed-data } } {
200222{{#composedSchemas.oneOf} }
201223 { {#description} }
202224 /// { {{.} }}
203225 { {/description} }
204- {{{name}}}({{#isModel}}{{^avoidBoxedModels}}Box<{{/avoidBoxedModels}}{{/isModel}}{{{ dataType}}}{{#isModel}}{{^avoidBoxedModels}}>{{/avoidBoxedModels}}{{/isModel}}),
226+ { {{name} }}({ {#isModel} }{ {^avoidBoxedModels} }Box<{ {/avoidBoxedModels} }{ {/isModel} }{ {#isArray } }Vec< { {{items. dataType} }} { {#vendorExtensions.x-rust-has-borrowed-data } }<'a> { {/vendorExtensions.x-rust-has-borrowed-data } }> { {/isArray } } { {^isArray } } { {{dataType } }} { {#vendorExtensions.x-rust-has-borrowed-data } }<'a> { {/vendorExtensions.x-rust-has-borrowed-data } } { {/isArray } }{ {#isModel} }{ {^avoidBoxedModels} }>{ {/avoidBoxedModels} }{ {/isModel} }),
205227{ {/composedSchemas.oneOf} }
206228}
207229
208- impl Default for {{classname}} {
230+ impl Default for { {classname} }{ {#vendorExtensions.x-rust-has-borrowed-data } }<'_> { {/vendorExtensions.x-rust-has-borrowed-data } } {
209231 fn default () -> Self {
210232 {{#composedSchemas.oneOf} }{ {#-first} }Self::{ {{name} }}(Default::default()){ {/-first} }{ {/composedSchemas.oneOf} }
211233 }
0 commit comments