@@ -100,6 +100,7 @@ pub enum Feature {
100100 Required ( attributes:: Required ) ,
101101 ContentEncoding ( attributes:: ContentEncoding ) ,
102102 ContentMediaType ( attributes:: ContentMediaType ) ,
103+ Discriminator ( attributes:: Discriminator ) ,
103104 MultipleOf ( validation:: MultipleOf ) ,
104105 Maximum ( validation:: Maximum ) ,
105106 Minimum ( validation:: Minimum ) ,
@@ -166,73 +167,74 @@ impl Feature {
166167impl ToTokensDiagnostics for Feature {
167168 fn to_tokens ( & self , tokens : & mut proc_macro2:: TokenStream ) -> Result < ( ) , Diagnostics > {
168169 let feature = match & self {
169- Feature :: Default ( default) => quote ! { . default ( #default ) } ,
170- Feature :: Example ( example) => quote ! { . example( Some ( #example) ) } ,
171- Feature :: Examples ( examples) => quote ! { . examples( #examples) } ,
172- Feature :: XmlAttr ( xml) => quote ! { . xml( Some ( #xml) ) } ,
173- Feature :: Format ( format) => quote ! { . format( Some ( #format) ) } ,
174- Feature :: WriteOnly ( write_only) => quote ! { . write_only( Some ( #write_only) ) } ,
175- Feature :: ReadOnly ( read_only) => quote ! { . read_only( Some ( #read_only) ) } ,
176- Feature :: Title ( title) => quote ! { . title( Some ( #title) ) } ,
177- Feature :: Nullable ( _nullable) => return Err ( Diagnostics :: new ( "Nullable does not support `ToTokens`" ) ) ,
178- Feature :: Rename ( rename) => rename. to_token_stream ( ) ,
179- Feature :: Style ( style) => quote ! { . style( Some ( #style) ) } ,
180- Feature :: ParameterIn ( parameter_in) => quote ! { . parameter_in( #parameter_in) } ,
181- Feature :: MultipleOf ( multiple_of) => quote ! { . multiple_of( Some ( #multiple_of) ) } ,
182- Feature :: AllowReserved ( allow_reserved) => {
183- quote ! { . allow_reserved( Some ( #allow_reserved) ) }
184- }
185- Feature :: Explode ( explode) => quote ! { . explode( Some ( #explode) ) } ,
186- Feature :: Maximum ( maximum) => quote ! { . maximum( Some ( #maximum) ) } ,
187- Feature :: Minimum ( minimum) => quote ! { . minimum( Some ( #minimum) ) } ,
188- Feature :: ExclusiveMaximum ( exclusive_maximum) => {
189- quote ! { . exclusive_maximum( Some ( #exclusive_maximum) ) }
190- }
191- Feature :: ExclusiveMinimum ( exclusive_minimum) => {
192- quote ! { . exclusive_minimum( Some ( #exclusive_minimum) ) }
193- }
194- Feature :: MaxLength ( max_length) => quote ! { . max_length( Some ( #max_length) ) } ,
195- Feature :: MinLength ( min_length) => quote ! { . min_length( Some ( #min_length) ) } ,
196- Feature :: Pattern ( pattern) => quote ! { . pattern( Some ( #pattern) ) } ,
197- Feature :: MaxItems ( max_items) => quote ! { . max_items( Some ( #max_items) ) } ,
198- Feature :: MinItems ( min_items) => quote ! { . min_items( Some ( #min_items) ) } ,
199- Feature :: MaxProperties ( max_properties) => {
200- quote ! { . max_properties( Some ( #max_properties) ) }
201- }
202- Feature :: MinProperties ( min_properties) => {
203- quote ! { . max_properties( Some ( #min_properties) ) }
204- }
205- Feature :: SchemaWith ( schema_with) => schema_with. to_token_stream ( ) ,
206- Feature :: Description ( description) => quote ! { . description( Some ( #description) ) } ,
207- Feature :: Deprecated ( deprecated) => quote ! { . deprecated( Some ( #deprecated) ) } ,
208- Feature :: AdditionalProperties ( additional_properties) => {
209- quote ! { . additional_properties( Some ( #additional_properties) ) }
210- }
211- Feature :: ContentEncoding ( content_encoding) => quote ! { . content_encoding( #content_encoding) } ,
212- Feature :: ContentMediaType ( content_media_type) => quote ! { . content_media_type( #content_media_type) } ,
213- Feature :: RenameAll ( _) => {
214- return Err ( Diagnostics :: new ( "RenameAll feature does not support `ToTokens`" ) )
215- }
216- Feature :: ValueType ( _) => {
217- return Err ( Diagnostics :: new ( "ValueType feature does not support `ToTokens`" )
218- . help ( "ValueType is supposed to be used with `TypeTree` in same manner as a resolved struct/field type." ) )
219- }
220- Feature :: Inline ( _) => {
221- // inline feature is ignored by `ToTokens`
222- TokenStream :: new ( )
223- }
224- Feature :: IntoParamsNames ( _) => {
225- return Err ( Diagnostics :: new ( "Names feature does not support `ToTokens`" )
226- . help ( "Names is only used with IntoParams to artificially give names for unnamed struct type `IntoParams`." ) )
227- }
228- Feature :: As ( _) => {
229- return Err ( Diagnostics :: new ( "As does not support `ToTokens`" ) )
230- }
231- Feature :: Required ( required) => {
232- let name = <attributes:: Required as FeatureLike >:: get_name ( ) ;
233- quote ! { . #name( #required) }
234- }
235- } ;
170+ Feature :: Default ( default) => quote ! { . default ( #default ) } ,
171+ Feature :: Example ( example) => quote ! { . example( Some ( #example) ) } ,
172+ Feature :: Examples ( examples) => quote ! { . examples( #examples) } ,
173+ Feature :: XmlAttr ( xml) => quote ! { . xml( Some ( #xml) ) } ,
174+ Feature :: Format ( format) => quote ! { . format( Some ( #format) ) } ,
175+ Feature :: WriteOnly ( write_only) => quote ! { . write_only( Some ( #write_only) ) } ,
176+ Feature :: ReadOnly ( read_only) => quote ! { . read_only( Some ( #read_only) ) } ,
177+ Feature :: Title ( title) => quote ! { . title( Some ( #title) ) } ,
178+ Feature :: Nullable ( _nullable) => return Err ( Diagnostics :: new ( "Nullable does not support `ToTokens`" ) ) ,
179+ Feature :: Rename ( rename) => rename. to_token_stream ( ) ,
180+ Feature :: Style ( style) => quote ! { . style( Some ( #style) ) } ,
181+ Feature :: ParameterIn ( parameter_in) => quote ! { . parameter_in( #parameter_in) } ,
182+ Feature :: MultipleOf ( multiple_of) => quote ! { . multiple_of( Some ( #multiple_of) ) } ,
183+ Feature :: AllowReserved ( allow_reserved) => {
184+ quote ! { . allow_reserved( Some ( #allow_reserved) ) }
185+ }
186+ Feature :: Explode ( explode) => quote ! { . explode( Some ( #explode) ) } ,
187+ Feature :: Maximum ( maximum) => quote ! { . maximum( Some ( #maximum) ) } ,
188+ Feature :: Minimum ( minimum) => quote ! { . minimum( Some ( #minimum) ) } ,
189+ Feature :: ExclusiveMaximum ( exclusive_maximum) => {
190+ quote ! { . exclusive_maximum( Some ( #exclusive_maximum) ) }
191+ }
192+ Feature :: ExclusiveMinimum ( exclusive_minimum) => {
193+ quote ! { . exclusive_minimum( Some ( #exclusive_minimum) ) }
194+ }
195+ Feature :: MaxLength ( max_length) => quote ! { . max_length( Some ( #max_length) ) } ,
196+ Feature :: MinLength ( min_length) => quote ! { . min_length( Some ( #min_length) ) } ,
197+ Feature :: Pattern ( pattern) => quote ! { . pattern( Some ( #pattern) ) } ,
198+ Feature :: MaxItems ( max_items) => quote ! { . max_items( Some ( #max_items) ) } ,
199+ Feature :: MinItems ( min_items) => quote ! { . min_items( Some ( #min_items) ) } ,
200+ Feature :: MaxProperties ( max_properties) => {
201+ quote ! { . max_properties( Some ( #max_properties) ) }
202+ }
203+ Feature :: MinProperties ( min_properties) => {
204+ quote ! { . max_properties( Some ( #min_properties) ) }
205+ }
206+ Feature :: SchemaWith ( schema_with) => schema_with. to_token_stream ( ) ,
207+ Feature :: Description ( description) => quote ! { . description( Some ( #description) ) } ,
208+ Feature :: Deprecated ( deprecated) => quote ! { . deprecated( Some ( #deprecated) ) } ,
209+ Feature :: AdditionalProperties ( additional_properties) => {
210+ quote ! { . additional_properties( Some ( #additional_properties) ) }
211+ }
212+ Feature :: ContentEncoding ( content_encoding) => quote ! { . content_encoding( #content_encoding) } ,
213+ Feature :: ContentMediaType ( content_media_type) => quote ! { . content_media_type( #content_media_type) } ,
214+ Feature :: Discriminator ( discriminator) => quote ! { . discriminator( Some ( #discriminator) ) } ,
215+ Feature :: RenameAll ( _) => {
216+ return Err ( Diagnostics :: new ( "RenameAll feature does not support `ToTokens`" ) )
217+ }
218+ Feature :: ValueType ( _) => {
219+ return Err ( Diagnostics :: new ( "ValueType feature does not support `ToTokens`" )
220+ . help ( "ValueType is supposed to be used with `TypeTree` in same manner as a resolved struct/field type." ) )
221+ }
222+ Feature :: Inline ( _) => {
223+ // inline feature is ignored by `ToTokens`
224+ TokenStream :: new ( )
225+ }
226+ Feature :: IntoParamsNames ( _) => {
227+ return Err ( Diagnostics :: new ( "Names feature does not support `ToTokens`" )
228+ . help ( "Names is only used with IntoParams to artificially give names for unnamed struct type `IntoParams`." ) )
229+ }
230+ Feature :: As ( _) => {
231+ return Err ( Diagnostics :: new ( "As does not support `ToTokens`" ) )
232+ }
233+ Feature :: Required ( required) => {
234+ let name = <attributes:: Required as FeatureLike >:: get_name ( ) ;
235+ quote ! { . #name( #required) }
236+ }
237+ } ;
236238
237239 tokens. extend ( feature) ;
238240
@@ -291,6 +293,7 @@ impl Display for Feature {
291293 Feature :: Required ( required) => required. fmt ( f) ,
292294 Feature :: ContentEncoding ( content_encoding) => content_encoding. fmt ( f) ,
293295 Feature :: ContentMediaType ( content_media_type) => content_media_type. fmt ( f) ,
296+ Feature :: Discriminator ( discriminator) => discriminator. fmt ( f) ,
294297 }
295298 }
296299}
@@ -338,6 +341,7 @@ impl Validatable for Feature {
338341 Feature :: Required ( required) => required. is_validatable ( ) ,
339342 Feature :: ContentEncoding ( content_encoding) => content_encoding. is_validatable ( ) ,
340343 Feature :: ContentMediaType ( content_media_type) => content_media_type. is_validatable ( ) ,
344+ Feature :: Discriminator ( discriminator) => discriminator. is_validatable ( ) ,
341345 }
342346 }
343347}
@@ -383,6 +387,7 @@ is_validatable! {
383387 attributes:: Required ,
384388 attributes:: ContentEncoding ,
385389 attributes:: ContentMediaType ,
390+ attributes:: Discriminator ,
386391 validation:: MultipleOf = true ,
387392 validation:: Maximum = true ,
388393 validation:: Minimum = true ,
@@ -607,8 +612,9 @@ impl_feature_into_inner! {
607612 attributes:: Description ,
608613 attributes:: Deprecated ,
609614 attributes:: As ,
610- attributes:: AdditionalProperties ,
611615 attributes:: Required ,
616+ attributes:: AdditionalProperties ,
617+ attributes:: Discriminator ,
612618 validation:: MultipleOf ,
613619 validation:: Maximum ,
614620 validation:: Minimum ,
0 commit comments