1- // Copyright 2024 Oxide Computer Company
1+ // Copyright 2025 Oxide Computer Company
22
33#![ allow( dead_code) ]
44
@@ -9,7 +9,7 @@ use std::ops::{Deref, DerefMut};
99use bytes:: Bytes ;
1010use futures_core:: Stream ;
1111use reqwest:: RequestBuilder ;
12- use serde:: { de:: DeserializeOwned , Serialize } ;
12+ use serde:: { de:: DeserializeOwned , ser :: SerializeStruct , Serialize } ;
1313
1414#[ cfg( not( target_arch = "wasm32" ) ) ]
1515type InnerByteStream = std:: pin:: Pin < Box < dyn Stream < Item = reqwest:: Result < Bytes > > + Send + Sync > > ;
@@ -552,12 +552,14 @@ where
552552
553553 fn serialize_unit_variant (
554554 self ,
555- name : & ' static str ,
556- variant_index : u32 ,
555+ _name : & ' static str ,
556+ _variant_index : u32 ,
557557 variant : & ' static str ,
558558 ) -> Result < Self :: Ok , Self :: Error > {
559- self . inner
560- . serialize_unit_variant ( name, variant_index, variant)
559+ // A query parameter with a list of enumerated values will produce an
560+ // enum with unit variants. We treat these as scalar values, ignoring
561+ // the unit variant wrapper.
562+ variant. serialize ( self )
561563 }
562564
563565 fn serialize_newtype_struct < T > (
@@ -574,15 +576,21 @@ where
574576 fn serialize_newtype_variant < T > (
575577 self ,
576578 name : & ' static str ,
577- variant_index : u32 ,
579+ _variant_index : u32 ,
578580 variant : & ' static str ,
579581 value : & T ,
580582 ) -> Result < Self :: Ok , Self :: Error >
581583 where
582584 T : ?Sized + Serialize ,
583585 {
584- self . inner
585- . serialize_newtype_variant ( name, variant_index, variant, value)
586+ // As with serde_json, we treat a newtype variant like a struct with a
587+ // single field. This may seem a little weird, but if an OpenAPI
588+ // document were to specify a query parameter whose schema was a oneOf
589+ // whose elements were objects with a single field, the user would end
590+ // up with an enum like this as a parameter.
591+ let mut map = self . inner . serialize_struct ( name, 1 ) ?;
592+ map. serialize_field ( variant, value) ?;
593+ map. end ( )
586594 }
587595
588596 fn serialize_seq ( self , len : Option < usize > ) -> Result < Self :: SerializeSeq , Self :: Error > {
0 commit comments