smithy4rs_core/schema/prelude.rs
1//! # Prelude
2//! [`crate::schema::Schema`] definitions for the [Smithy prelude](https://github.com/smithy-lang/smithy/blob/65b473ddb94f9edda933f00bab988d465b2bd2fe/smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude.smithy)
3//!
4//! The prelude consists of public, built-in shapes like `STRING`, `INTEGER`, etc. that
5//! are available to all models. Prelude shapes and traits are all in the `smithy.api` namespace
6//! and must be hard-coded as they are used by generate shapes.
7
8use std::fmt::Display;
9
10use bigdecimal::Zero;
11use regex::Regex;
12
13use crate::{
14 BigDecimal, IndexMap, LazyLock, annotation_trait,
15 schema::{Document, ShapeId, SmithyTrait, StaticTraitId},
16 smithy, static_trait_id, string_trait,
17};
18// ============================================================================
19// Prelude Shape Schemas
20// ---------------------
21// These are the base shapes of the smithy data model.
22// For more information see: https://smithy.io/2.0/spec/index.html
23// ============================================================================
24
25// === Simple types ===
26smithy!("smithy.api#Blob": {
27 /// Smithy [blob](https://smithy.io/2.0/spec/simple-types.html#blob) shape
28 blob BLOB
29});
30smithy!("smithy.api#Boolean": {
31 /// Smithy [boolean](https://smithy.io/2.0/spec/simple-types.html#boolean) shape
32 boolean BOOLEAN
33});
34smithy!("smithy.api#String": {
35 /// Smithy [string](https://smithy.io/2.0/spec/simple-types.html#string) shape
36 string STRING
37});
38smithy!("smithy.api#Timestamp": {
39 /// Smithy [timestamp](https://smithy.io/2.0/spec/simple-types.html#timestamp) shape
40 timestamp TIMESTAMP
41});
42smithy!("smithy.api#Byte": {
43 /// Smithy [byte](https://smithy.io/2.0/spec/simple-types.html#byte) shape
44 byte BYTE
45});
46smithy!("smithy.api#Short": {
47 /// Smithy [short](https://smithy.io/2.0/spec/simple-types.html#short) shape
48 short SHORT
49});
50smithy!("smithy.api#Integer": {
51 /// Smithy [integer](https://smithy.io/2.0/spec/simple-types.html#integer) shape
52 integer INTEGER
53});
54smithy!("smithy.api#Long": {
55 /// Smithy [long](https://smithy.io/2.0/spec/simple-types.html#long) shape
56 long LONG
57});
58smithy!("smithy.api#Float": {
59 /// Smithy [float](https://smithy.io/2.0/spec/simple-types.html#float) shape
60 float FLOAT
61});
62smithy!("smithy.api#Double": {
63 /// Smithy [double](https://smithy.io/2.0/spec/simple-types.html#double) shape
64 double DOUBLE
65});
66smithy!("smithy.api#BigInteger": {
67 /// Smithy [bigInteger](https://smithy.io/2.0/spec/simple-types.html#bigInteger) shape
68 bigInteger BIG_INTEGER
69});
70smithy!("smithy.api#BigDecimal": {
71 /// Smithy [bigDecimal](https://smithy.io/2.0/spec/simple-types.html#bigDecimal) shape
72 bigDecimal BIG_DECIMAL
73});
74smithy!("smithy.api#Document": {
75 /// Smithy [document](https://smithy.io/2.0/spec/simple-types.html#document) shape
76 document DOCUMENT
77});
78
79// === Primitive types ===
80smithy!("smithy.api#PrimitiveBoolean": {
81 #[doc(hidden)]
82 @DefaultTrait::new(false);
83 boolean PRIMITIVE_BOOLEAN
84});
85smithy!("smithy.api#PrimitiveByte": {
86 #[doc(hidden)]
87 @DefaultTrait::new(0i8);
88 byte PRIMITIVE_BYTE
89});
90smithy!("smithy.api#PrimitiveShort": {
91 #[doc(hidden)]
92 @DefaultTrait::new(0i16);
93 short PRIMITIVE_SHORT
94});
95smithy!("smithy.api#PrimitiveInteger": {
96 #[doc(hidden)]
97 @DefaultTrait::new(0i32);
98 integer PRIMITIVE_INTEGER
99});
100smithy!("smithy.api#PrimitiveLong": {
101 #[doc(hidden)]
102 @DefaultTrait::new(0i64);
103 boolean PRIMITIVE_LONG
104});
105smithy!("smithy.api#PrimitiveFloat": {
106 #[doc(hidden)]
107 @DefaultTrait::new(0f32);
108 float PRIMITIVE_FLOAT
109});
110smithy!("smithy.api#PrimitiveDouble": {
111 #[doc(hidden)]
112 @DefaultTrait::new(0f64);
113 double PRIMITIVE_DOUBLE
114});
115
116// ============================================================================
117// Prelude Traits
118// ============================================================================
119
120// ==== Annotation traits ====
121annotation_trait!(
122 /// Indicates that data is sensitive and must be handled with care.
123 ///
124 /// *See* - [`@sensitive`](https://smithy.io/2.0/spec/documentation-traits.html#smithy-api-sensitive-trait)
125 SensitiveTrait = "smithy.api#sensitive"
126);
127annotation_trait!(
128 /// Indicates that the data represented by the shape needs to be streamed.
129 ///
130 /// *See* - [`@streaming`](https://smithy.io/2.0/spec/streaming.html#smithy-api-streaming-trait)
131 StreamingTrait = "smithy.api#streaming"
132);
133annotation_trait!(
134 /// Indicates that lists and maps MAY contain null values
135 ///
136 /// *See* - [`@sparse`](https://smithy.io/2.0/spec/type-refinement-traits.html#smithy-api-sparse-trait)
137 SparseTrait = "smithy.api#sparse");
138annotation_trait!(
139 /// Indicates that a member value MUST be set for the shape to be valid.
140 ///
141 /// *See* - [`@required`](https://smithy.io/2.0/spec/type-refinement-traits.html#smithy-api-required-trait)
142 RequiredTrait = "smithy.api#required"
143);
144annotation_trait!(
145 /// Indicates that a member should be serialized as an event header when sent through an event stream.
146 ///
147 /// *See* - [`@eventHeader`](https://smithy.io/2.0/spec/streaming.html#smithy-api-eventheader-trait)
148 EventHeaderTrait = "smithy.api#eventheader"
149);
150annotation_trait!(
151 /// Indicates that a member should be serialized as the payload of an event when sent through an event stream.
152 ///
153 /// *See* - [`@eventPayload`](https://smithy.io/2.0/spec/streaming.html#eventpayload-trait)
154 EventPayloadTrait = "smithy.api#eventPayload"
155);
156annotation_trait!(
157 /// Indicates that a member is used by the server to identify and discard replayed requests.
158 ///
159 /// *See* - [`@idempotencyToken`](https://smithy.io/2.0/spec/behavior-traits.html#smithy-api-idempotencytoken-trait)
160 IdempotencyTokenTrait = "smithy.api#IdempotencyToken"
161);
162annotation_trait!(
163 /// Binds a member so that it is used as part of an HTTP request URI.
164 ///
165 /// *See* - [`@httpLabel`](https://smithy.io/2.0/spec/http-bindings.html#smithy-api-httplabel-trait)
166 HttpLabelTrait = "smithy.api#httpLabel"
167);
168annotation_trait!(
169 /// Binds a member to the body of an HTTP message.
170 ///
171 /// *See* - [`@httpPayload`](https://smithy.io/2.0/spec/http-bindings.html#httppayload-trait)
172 HttpPayloadTrait = "smithy.api#httpPayload"
173);
174annotation_trait!(
175 /// Binds a map of key-value pairs to query string parameters.
176 ///
177 /// *See* - [`@httpQueryParams`](https://smithy.io/2.0/spec/http-bindings.html#httpqueryparams-trait)
178 HTTPQueryParamsTrait = "smithy.api#httpQueryParams"
179);
180annotation_trait!(
181 /// Binds a member to the HTTP response status code so that an HTTP response status code can be set dynamically.
182 ///
183 /// *See* - [`@httpResponseCode`](https://smithy.io/2.0/spec/http-bindings.html#httpresponsecode-trait)
184 HTTPResponseCodeTrait = "smithy.api#httpResponseCode"
185);
186annotation_trait!(
187 /// Indicates that an operation requires a checksum in HTTP requests.
188 ///
189 /// *See* - [`@httpChecksumRequired`](https://smithy.io/2.0/spec/http-bindings.html#httpchecksumrequired-trait)
190 HTTPChecksumRequiredTrait = "smithy.api#httpChecksumRequired"
191);
192annotation_trait!(
193 /// Binds a top-level operation input structure member to a label in the hostPrefix of an endpoint trait.
194 ///
195 /// *See* - [`@eventPayload`](https://smithy.io/2.0/spec/endpoint-traits.html#smithy-api-hostlabel-trait)
196 HostLabelTrait = "smithy.api#hostLabel"
197);
198annotation_trait!(
199 /// Serializes an object property as an XML attribute rather than a nested XML element.
200 ///
201 /// *See* - [`@eventPayload`](https://smithy.io/2.0/spec/protocol-traits.html#xmlattribute-trait)
202 XmlAttributeTrait = "smithy.api#xmlAttribute"
203);
204
205// ==== Traits that take just a string value ====
206string_trait!(
207 /// Describes the contents of a blob or string shape using a design-time media type.
208 ///
209 /// *See* - [`@mediaType`](https://smithy.io/2.0/spec/protocol-traits.html#smithy-api-mediatype-trait)
210 "smithy.api#mediaType": MediaTypeTrait(media_type)
211);
212string_trait!(
213 /// Allows a serialized object property name in a JSON document to differ from a structure or union
214 /// member name used in the model.
215 ///
216 /// *See* - [`@jsonName`](https://smithy.io/2.0/spec/protocol-traits.html#smithy-api-jsonname-trait)
217 "smithy.api#jsonName": JsonNameTrait(name)
218);
219string_trait!(
220 /// Allows a serialized object property name in an XML document to differ from name used in model.
221 ///
222 /// *See* - [`@xmlName`](https://smithy.io/2.0/spec/protocol-traits.html#xmlname-trait)
223 "smithy.api#xmlName": XmlNameTrait(name)
224);
225string_trait!(
226 /// Binds a structure member to an HTTP header.
227 ///
228 /// *See* - [`@httpHeader`](https://smithy.io/2.0/spec/http-bindings.html#smithy-api-httpheader-trait)
229 "smithy.api#httpHeader": HTTPHeaderTrait(name)
230);
231string_trait!(
232 /// Binds a map of key-value pairs to prefixed HTTP headers.
233 ///
234 /// *See* - [`@httpPrefixHeaders`](https://smithy.io/2.0/spec/http-bindings.html#httpprefixheaders-trait)
235 "smithy.api#httpPrefixHeaders": HTTPPrefixHeadersTrait(prefix)
236);
237string_trait!(
238 /// Binds an operation input structure member to a query string parameter.
239 ///
240 /// *See* - [`@httpQuery`](https://smithy.io/2.0/spec/http-bindings.html#httpquery-trait)
241 "smithy.api#httpQuery": HTTPQueryTrait(key)
242);
243string_trait!(
244 /// Configures a custom operation endpoint.
245 ///
246 /// *See* - [`@endpoint`](https://smithy.io/2.0/spec/endpoint-traits.html#smithy-api-endpoint-trait)
247 "smithy.api#endpoint": EndpointTrait(host_prefix)
248);
249
250// ==== Traits with other values ====
251
252/// Provides a structure member with a default value.
253///
254/// *See* - [Default Trait](https://smithy.io/2.0/spec/type-refinement-traits.html#smithy-api-default-trait)
255pub struct DefaultTrait(Box<dyn Document>);
256static_trait_id!(DefaultTrait, "smithy.api#default");
257impl SmithyTrait for DefaultTrait {
258 fn id(&self) -> &ShapeId {
259 DefaultTrait::trait_id()
260 }
261
262 fn value(&self) -> &Box<dyn Document> {
263 &self.0
264 }
265}
266impl DefaultTrait {
267 /// Create a new [`DefaultTrait`] instance
268 pub fn new<D: Into<Box<dyn Document>>>(doc: D) -> Self {
269 DefaultTrait(doc.into())
270 }
271}
272
273macro_rules! smithy_trait_impl {
274 ($t:ident) => {
275 impl SmithyTrait for $t {
276 fn id(&self) -> &ShapeId {
277 $t::trait_id()
278 }
279
280 fn value(&self) -> &Box<dyn Document> {
281 &self.value
282 }
283 }
284 };
285}
286
287/// Indicates that a structure shape represents an error.
288///
289/// *See* - [Error Trait](https://smithy.io/2.0/spec/type-refinement-traits.html#smithy-api-error-trait)
290#[derive(Debug)]
291pub struct ErrorTrait {
292 error: ErrorFault,
293 value: Box<dyn Document>,
294}
295impl ErrorTrait {
296 /// Get whether the Error was the fault of the client or server.
297 #[must_use]
298 pub fn error(&self) -> &ErrorFault {
299 &self.error
300 }
301
302 /// Create a new [`ErrorTrait`] instance
303 #[must_use]
304 pub fn new(error: ErrorFault) -> Self {
305 ErrorTrait {
306 value: error.to_string().into(),
307 error,
308 }
309 }
310}
311static_trait_id!(ErrorTrait, "smithy.api#error");
312smithy_trait_impl!(ErrorTrait);
313
314/// Indicates if the client or server is at fault for a given error.
315#[derive(Debug)]
316#[doc(hidden)]
317pub enum ErrorFault {
318 Client,
319 Server,
320}
321impl Display for ErrorFault {
322 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
323 match self {
324 ErrorFault::Client => write!(f, "client"),
325 ErrorFault::Server => write!(f, "server"),
326 }
327 }
328}
329
330/// Defines an HTTP response code for an operation error.
331///
332/// *See* - [HttpError Trait](https://smithy.io/2.0/spec/http-bindings.html#smithy-api-httperror-trait)
333#[derive(Debug)]
334pub struct HttpErrorTrait {
335 code: i32,
336 value: Box<dyn Document>,
337}
338impl HttpErrorTrait {
339 /// Get the code contained by this trait.
340 #[must_use]
341 pub fn code(&self) -> i32 {
342 self.code
343 }
344
345 /// Create a new [`HttpErrorTrait`] instance
346 ///
347 /// # Panics
348 /// Http error codes should be between 200 and 600. This
349 /// constructor panics when an error code is outside of
350 /// this range is provided.
351 ///
352 /// Smithy validation will check this constraint in models.
353 #[must_use]
354 pub fn new(code: i32) -> Self {
355 assert!(
356 200 < code && code < 599,
357 "HTTPErrorTrait code out of range: {code}"
358 );
359 HttpErrorTrait {
360 code,
361 value: code.into(),
362 }
363 }
364}
365static_trait_id!(HttpErrorTrait, "smithy.api#httpError");
366smithy_trait_impl!(HttpErrorTrait);
367
368// ============================================================================
369// Constraint Traits
370// ============================================================================
371
372/// Defines a range constraint for numeric values.
373///
374/// *See* - [Range Trait](https://smithy.io/2.0/spec/constraint-traits.html#range-trait)
375#[derive(Debug)]
376pub struct RangeTrait {
377 min: Option<BigDecimal>,
378 max: Option<BigDecimal>,
379 value: Box<dyn Document>,
380}
381static_trait_id!(RangeTrait, "smithy.api#range");
382smithy_trait_impl!(RangeTrait);
383
384static ZERO: LazyLock<BigDecimal> = LazyLock::new(BigDecimal::zero);
385static MAX: LazyLock<BigDecimal> = LazyLock::new(|| BigDecimal::from(u64::MAX));
386
387impl RangeTrait {
388 /// Get the minimum value allowed by this range constraint.
389 ///
390 /// Defaults to zero
391 #[inline]
392 #[must_use]
393 pub fn min(&self) -> &BigDecimal {
394 self.min.as_ref().unwrap_or_else(|| &ZERO)
395 }
396
397 /// Get the maximum value allowed by this range constraint.
398 ///
399 /// Defaults to `u64::MAX`
400 #[inline]
401 #[must_use]
402 pub fn max(&self) -> &BigDecimal {
403 self.max.as_ref().unwrap_or_else(|| &MAX)
404 }
405
406 /// Get a new builder instance for this trait.
407 #[must_use]
408 pub const fn builder() -> RangeTraitBuilder {
409 RangeTraitBuilder::new()
410 }
411}
412
413/// Builder for the [`RangeTrait`]
414#[derive(Debug)]
415pub struct RangeTraitBuilder {
416 min: Option<BigDecimal>,
417 max: Option<BigDecimal>,
418}
419impl RangeTraitBuilder {
420 pub(super) const fn new() -> Self {
421 RangeTraitBuilder {
422 min: None,
423 max: None,
424 }
425 }
426
427 /// Set a minimum value for this constraint.
428 #[must_use]
429 pub fn min(mut self, min: BigDecimal) -> Self {
430 self.min = Some(min);
431 self
432 }
433
434 /// Set a maximum value for this constraint.
435 #[must_use]
436 pub fn max(mut self, max: BigDecimal) -> Self {
437 self.max = Some(max);
438 self
439 }
440
441 /// Construct a new [`RangeTrait`] instance.
442 #[must_use]
443 pub fn build(self) -> RangeTrait {
444 let mut value_map: IndexMap<String, Box<dyn Document>> = IndexMap::new();
445 if let Some(min) = &self.min {
446 value_map.insert("min".to_string(), min.clone().into());
447 }
448 if let Some(max) = &self.max {
449 value_map.insert("min".to_string(), max.clone().into());
450 }
451 RangeTrait {
452 min: self.min,
453 max: self.max,
454 value: value_map.into(),
455 }
456 }
457}
458
459/// Length constraint for lists, maps, and strings.
460///
461/// *See* - [LengthTrait](https://smithy.io/2.0/spec/constraint-traits.html#length-trait)
462#[derive(Debug)]
463pub struct LengthTrait {
464 min: Option<usize>,
465 max: Option<usize>,
466 value: Box<dyn Document>,
467}
468static_trait_id!(LengthTrait, "smithy.api#length");
469smithy_trait_impl!(LengthTrait);
470
471impl LengthTrait {
472 /// Get the minimum length for this constraint.
473 ///
474 /// Defaults to 0 if not set.
475 #[must_use]
476 pub fn min(&self) -> usize {
477 self.min.unwrap_or(0)
478 }
479
480 /// Get the maximum length for this constraint.
481 ///
482 /// Defaults to `usize::MAX` if not set.
483 #[must_use]
484 pub fn max(&self) -> usize {
485 self.max.unwrap_or(usize::MAX)
486 }
487
488 /// Get a new [`LengthTraitBuilder`] instance.
489 #[must_use]
490 pub const fn builder() -> LengthTraitBuilder {
491 LengthTraitBuilder::new()
492 }
493}
494
495/// Builder for creating a [`LengthTrait`] instance
496#[derive(Debug)]
497pub struct LengthTraitBuilder {
498 min: Option<usize>,
499 max: Option<usize>,
500}
501impl LengthTraitBuilder {
502 pub(super) const fn new() -> Self {
503 LengthTraitBuilder {
504 min: None,
505 max: None,
506 }
507 }
508
509 /// Set a minimum length for this constraint.
510 #[must_use]
511 pub fn min(mut self, min: usize) -> Self {
512 self.min = Some(min);
513 self
514 }
515
516 /// Set a maximum length for this constraint.
517 #[must_use]
518 pub fn max(mut self, max: usize) -> Self {
519 self.max = Some(max);
520 self
521 }
522
523 /// Create a new [`LengthTrait`] instance.
524 #[must_use]
525 pub fn build(self) -> LengthTrait {
526 let mut value_map: IndexMap<String, Box<dyn Document>> = IndexMap::new();
527 if let Some(min) = self.min {
528 value_map.insert("min".to_string(), (min as i32).into());
529 }
530 if let Some(max) = self.max {
531 value_map.insert("min".to_string(), (max as i32).into());
532 }
533 LengthTrait {
534 min: self.min,
535 max: self.max,
536 value: value_map.into(),
537 }
538 }
539}
540
541annotation_trait!(
542 /// Requires that items in a list are unique.
543 ///
544 /// *See* - [`@uniqueItems`](https://smithy.io/2.0/spec/constraint-traits.html#smithy-api-uniqueitems-trait)
545 UniqueItemsTrait = "smithy.api#uniqueItems"
546);
547
548/// Regex pattern used to constrian string values
549///
550/// *See* - [LengthTrait](https://smithy.io/2.0/spec/constraint-traits.html#pattern-trait)
551#[derive(Debug)]
552pub struct PatternTrait {
553 pattern: Regex,
554 value: Box<dyn Document>,
555}
556static_trait_id!(PatternTrait, "smithy.api#pattern");
557smithy_trait_impl!(PatternTrait);
558
559impl PatternTrait {
560 /// Get the regex constraint
561 #[must_use]
562 pub fn pattern(&self) -> &Regex {
563 &self.pattern
564 }
565
566 #[must_use]
567 /// Create a new [`PatternTrait`]
568 ///
569 /// # Panics
570 /// Will panic if the pattern is invalid.
571 ///
572 /// Smithy validation will check this constraint in models
573 pub fn new(pattern: &str) -> Self {
574 PatternTrait {
575 pattern: Regex::new(pattern).unwrap(),
576 value: pattern.into(),
577 }
578 }
579}
580
581// ============================================================================
582// Auth Traits
583// ============================================================================
584
585annotation_trait!(
586 /// Indicates that a service supports HTTP Basic Authentication.
587 ///
588 /// *See* - [`@httpBasicAuth`](https://smithy.io/2.0/spec/authentication-traits.html#smithy-api-httpbasicauth-trait)
589 HttpBasicAuthTrait = "smithy.api#httpBasicAuth"
590);
591annotation_trait!(
592 /// Indicates that a service supports HTTP Digest Authentication.
593 ///
594 /// *See* - [`@httpDigestAuth`](https://smithy.io/2.0/spec/authentication-traits.html#httpdigestauth-trait)
595 HttpDigestAuthTrait = "smithy.api#httpDigestAuth"
596);
597annotation_trait!(
598 /// Indicates that a service supports HTTP Bearer Authentication .
599 ///
600 /// *See* - [`@httpBearerAuth`](https://smithy.io/2.0/spec/authentication-traits.html#httpbearerauth-trait)
601 HttpBearerAuthTrait = "smithy.api#httpBearerAuth"
602);
603
604/// Trait indicating that a service supports HTTP-specific authentication
605/// using an API key sent in a header or query string parameter.
606///
607/// *See* - [`@httpApiKeyAuth`](https://smithy.io/2.0/spec/authentication-traits.html#httpapikeyauth-trait)
608#[derive(Debug)]
609pub struct HttpApiKeyAuthTrait {
610 name: String,
611 in_location: String,
612 scheme: Option<String>,
613 value: Box<dyn Document>,
614}
615static_trait_id!(HttpApiKeyAuthTrait, "smithy.api#httpApiKeyAuth");
616smithy_trait_impl!(HttpApiKeyAuthTrait);
617
618impl HttpApiKeyAuthTrait {
619 /// Get the `name`
620 #[must_use]
621 pub fn name(&self) -> &String {
622 &self.name
623 }
624
625 /// Get the `location`
626 #[must_use]
627 pub fn in_location(&self) -> &String {
628 &self.in_location
629 }
630
631 /// Get the `scheme`
632 #[must_use]
633 pub fn scheme(&self) -> &Option<String> {
634 &self.scheme
635 }
636
637 /// Get a new [`HttpApiKeyAuthTraitBuilder`] instance.
638 #[must_use]
639 pub fn builder() -> HttpApiKeyAuthTraitBuilder {
640 HttpApiKeyAuthTraitBuilder::new()
641 }
642}
643
644/// Builder for [`HttpApiKeyAuthTrait`] instances
645pub struct HttpApiKeyAuthTraitBuilder {
646 name: Option<String>,
647 in_location: Option<String>,
648 scheme: Option<String>,
649}
650impl HttpApiKeyAuthTraitBuilder {
651 fn new() -> Self {
652 HttpApiKeyAuthTraitBuilder {
653 name: None,
654 in_location: None,
655 scheme: None,
656 }
657 }
658
659 /// Set the `name` to use
660 #[must_use]
661 pub fn name(mut self, name: &str) -> Self {
662 self.name = Some(name.to_string());
663 self
664 }
665
666 /// Set the `location` to use
667 #[must_use]
668 pub fn in_location(mut self, in_location: &str) -> Self {
669 self.in_location = Some(in_location.to_string());
670 self
671 }
672
673 /// Set the `scheme` to use
674 #[must_use]
675 pub fn scheme(mut self, scheme: &str) -> Self {
676 self.scheme = Some(scheme.to_string());
677 self
678 }
679
680 /// Build a new [`HttpApiKeyAuthTrait`] instance
681 ///
682 /// # Panics
683 /// If the location or name are not set.
684 ///
685 /// Smithy validation will check this constraint in models.
686 #[must_use]
687 pub fn build(self) -> HttpApiKeyAuthTrait {
688 let mut value_map: IndexMap<String, Box<dyn Document>> = IndexMap::new();
689 if let Some(name) = &self.name {
690 value_map.insert("name".to_string(), name.clone().into());
691 }
692 if let Some(location) = &self.in_location {
693 value_map.insert("location".to_string(), location.clone().into());
694 }
695 if let Some(scheme) = &self.scheme {
696 value_map.insert("scheme".to_string(), scheme.clone().into());
697 }
698 HttpApiKeyAuthTrait {
699 name: self.name.unwrap(),
700 in_location: self.in_location.unwrap(),
701 scheme: self.scheme,
702 value: value_map.into(),
703 }
704 }
705}