smithy4rs-core 0.0.1

Core functionality for smithy4rs.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
//! # Prelude
//! [`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)
//!
//! The prelude consists of public, built-in shapes like `STRING`, `INTEGER`, etc. that
//! are available to all models. Prelude shapes and traits are all in the `smithy.api` namespace
//! and must be hard-coded as they are used by generate shapes.

use std::fmt::Display;

use bigdecimal::Zero;
use regex::Regex;

use crate::{
    BigDecimal, IndexMap, LazyLock, annotation_trait,
    schema::{Document, ShapeId, SmithyTrait, StaticTraitId},
    smithy, static_trait_id, string_trait,
};
// ============================================================================
// Prelude Shape Schemas
// ---------------------
// These are the base shapes of the smithy data model.
// For more information see: https://smithy.io/2.0/spec/index.html
// ============================================================================

// === Simple types ===
smithy!("smithy.api#Blob": {
    /// Smithy [blob](https://smithy.io/2.0/spec/simple-types.html#blob) shape
    blob BLOB
});
smithy!("smithy.api#Boolean": {
    /// Smithy [boolean](https://smithy.io/2.0/spec/simple-types.html#boolean) shape
    boolean BOOLEAN
});
smithy!("smithy.api#String": {
    /// Smithy [string](https://smithy.io/2.0/spec/simple-types.html#string) shape
    string STRING
});
smithy!("smithy.api#Timestamp": {
    /// Smithy [timestamp](https://smithy.io/2.0/spec/simple-types.html#timestamp) shape
    timestamp TIMESTAMP
});
smithy!("smithy.api#Byte": {
    /// Smithy [byte](https://smithy.io/2.0/spec/simple-types.html#byte) shape
    byte BYTE
});
smithy!("smithy.api#Short": {
    /// Smithy [short](https://smithy.io/2.0/spec/simple-types.html#short) shape
    short SHORT
});
smithy!("smithy.api#Integer": {
    /// Smithy [integer](https://smithy.io/2.0/spec/simple-types.html#integer) shape
    integer INTEGER
});
smithy!("smithy.api#Long": {
    /// Smithy [long](https://smithy.io/2.0/spec/simple-types.html#long) shape
    long LONG
});
smithy!("smithy.api#Float": {
    /// Smithy [float](https://smithy.io/2.0/spec/simple-types.html#float) shape
    float FLOAT
});
smithy!("smithy.api#Double": {
    /// Smithy [double](https://smithy.io/2.0/spec/simple-types.html#double) shape
    double DOUBLE
});
smithy!("smithy.api#BigInteger": {
    /// Smithy [bigInteger](https://smithy.io/2.0/spec/simple-types.html#bigInteger) shape
    bigInteger BIG_INTEGER
});
smithy!("smithy.api#BigDecimal": {
    /// Smithy [bigDecimal](https://smithy.io/2.0/spec/simple-types.html#bigDecimal) shape
    bigDecimal BIG_DECIMAL
});
smithy!("smithy.api#Document": {
    /// Smithy [document](https://smithy.io/2.0/spec/simple-types.html#document) shape
    document DOCUMENT
});

// === Primitive types ===
smithy!("smithy.api#PrimitiveBoolean": {
    #[doc(hidden)]
    @DefaultTrait::new(false);
    boolean PRIMITIVE_BOOLEAN
});
smithy!("smithy.api#PrimitiveByte": {
    #[doc(hidden)]
    @DefaultTrait::new(0i8);
    byte PRIMITIVE_BYTE
});
smithy!("smithy.api#PrimitiveShort": {
    #[doc(hidden)]
    @DefaultTrait::new(0i16);
    short PRIMITIVE_SHORT
});
smithy!("smithy.api#PrimitiveInteger": {
    #[doc(hidden)]
    @DefaultTrait::new(0i32);
    integer PRIMITIVE_INTEGER
});
smithy!("smithy.api#PrimitiveLong": {
    #[doc(hidden)]
    @DefaultTrait::new(0i64);
    boolean PRIMITIVE_LONG
});
smithy!("smithy.api#PrimitiveFloat": {
    #[doc(hidden)]
    @DefaultTrait::new(0f32);
    float PRIMITIVE_FLOAT
});
smithy!("smithy.api#PrimitiveDouble": {
    #[doc(hidden)]
    @DefaultTrait::new(0f64);
    double PRIMITIVE_DOUBLE
});

// ============================================================================
// Prelude Traits
// ============================================================================

// ==== Annotation traits ====
annotation_trait!(
    /// Indicates that data is sensitive and must be handled with care.
    ///
    /// *See* - [`@sensitive`](https://smithy.io/2.0/spec/documentation-traits.html#smithy-api-sensitive-trait)
    SensitiveTrait = "smithy.api#sensitive"
);
annotation_trait!(
    /// Indicates that the data represented by the shape needs to be streamed.
    ///
    /// *See* - [`@streaming`](https://smithy.io/2.0/spec/streaming.html#smithy-api-streaming-trait)
    StreamingTrait = "smithy.api#streaming"
);
annotation_trait!(
    /// Indicates that lists and maps MAY contain null values
    ///
    /// *See* - [`@sparse`](https://smithy.io/2.0/spec/type-refinement-traits.html#smithy-api-sparse-trait)
    SparseTrait = "smithy.api#sparse");
annotation_trait!(
    /// Indicates that a member value MUST be set for the shape to be valid.
    ///
    /// *See* - [`@required`](https://smithy.io/2.0/spec/type-refinement-traits.html#smithy-api-required-trait)
    RequiredTrait = "smithy.api#required"
);
annotation_trait!(
    /// Indicates that a member should be serialized as an event header when sent through an event stream.
    ///
    /// *See* - [`@eventHeader`](https://smithy.io/2.0/spec/streaming.html#smithy-api-eventheader-trait)
    EventHeaderTrait = "smithy.api#eventheader"
);
annotation_trait!(
    /// Indicates that a member should be serialized as the payload of an event when sent through an event stream.
    ///
    /// *See* - [`@eventPayload`](https://smithy.io/2.0/spec/streaming.html#eventpayload-trait)
    EventPayloadTrait = "smithy.api#eventPayload"
);
annotation_trait!(
    /// Indicates that a member is used by the server to identify and discard replayed requests.
    ///
    /// *See* - [`@idempotencyToken`](https://smithy.io/2.0/spec/behavior-traits.html#smithy-api-idempotencytoken-trait)
    IdempotencyTokenTrait = "smithy.api#IdempotencyToken"
);
annotation_trait!(
    /// Binds a member so that it is used as part of an HTTP request URI.
    ///
    /// *See* - [`@httpLabel`](https://smithy.io/2.0/spec/http-bindings.html#smithy-api-httplabel-trait)
    HttpLabelTrait = "smithy.api#httpLabel"
);
annotation_trait!(
    /// Binds a member to the body of an HTTP message.
    ///
    /// *See* - [`@httpPayload`](https://smithy.io/2.0/spec/http-bindings.html#httppayload-trait)
    HttpPayloadTrait = "smithy.api#httpPayload"
);
annotation_trait!(
    /// Binds a map of key-value pairs to query string parameters.
    ///
    /// *See* - [`@httpQueryParams`](https://smithy.io/2.0/spec/http-bindings.html#httpqueryparams-trait)
    HTTPQueryParamsTrait = "smithy.api#httpQueryParams"
);
annotation_trait!(
    /// Binds a member to the HTTP response status code so that an HTTP response status code can be set dynamically.
    ///
    /// *See* - [`@httpResponseCode`](https://smithy.io/2.0/spec/http-bindings.html#httpresponsecode-trait)
    HTTPResponseCodeTrait = "smithy.api#httpResponseCode"
);
annotation_trait!(
    /// Indicates that an operation requires a checksum in HTTP requests.
    ///
    /// *See* - [`@httpChecksumRequired`](https://smithy.io/2.0/spec/http-bindings.html#httpchecksumrequired-trait)
    HTTPChecksumRequiredTrait = "smithy.api#httpChecksumRequired"
);
annotation_trait!(
    /// Binds a top-level operation input structure member to a label in the hostPrefix of an endpoint trait.
    ///
    /// *See* - [`@eventPayload`](https://smithy.io/2.0/spec/endpoint-traits.html#smithy-api-hostlabel-trait)
    HostLabelTrait = "smithy.api#hostLabel"
);
annotation_trait!(
    /// Serializes an object property as an XML attribute rather than a nested XML element.
    ///
    /// *See* - [`@eventPayload`](https://smithy.io/2.0/spec/protocol-traits.html#xmlattribute-trait)
    XmlAttributeTrait = "smithy.api#xmlAttribute"
);

// ====  Traits that take just a string value ====
string_trait!(
    /// Describes the contents of a blob or string shape using a design-time media type.
    ///
    /// *See* - [`@mediaType`](https://smithy.io/2.0/spec/protocol-traits.html#smithy-api-mediatype-trait)
    "smithy.api#mediaType": MediaTypeTrait(media_type)
);
string_trait!(
    /// Allows a serialized object property name in a JSON document to differ from a structure or union
    /// member name used in the model.
    ///
    /// *See* - [`@jsonName`](https://smithy.io/2.0/spec/protocol-traits.html#smithy-api-jsonname-trait)
    "smithy.api#jsonName": JsonNameTrait(name)
);
string_trait!(
    /// Allows a serialized object property name in an XML document to differ from name used in model.
    ///
    /// *See* - [`@xmlName`](https://smithy.io/2.0/spec/protocol-traits.html#xmlname-trait)
    "smithy.api#xmlName": XmlNameTrait(name)
);
string_trait!(
    /// Binds a structure member to an HTTP header.
    ///
    /// *See* - [`@httpHeader`](https://smithy.io/2.0/spec/http-bindings.html#smithy-api-httpheader-trait)
    "smithy.api#httpHeader": HTTPHeaderTrait(name)
);
string_trait!(
    /// Binds a map of key-value pairs to prefixed HTTP headers.
    ///
    /// *See* - [`@httpPrefixHeaders`](https://smithy.io/2.0/spec/http-bindings.html#httpprefixheaders-trait)
    "smithy.api#httpPrefixHeaders": HTTPPrefixHeadersTrait(prefix)
);
string_trait!(
    /// Binds an operation input structure member to a query string parameter.
    ///
    /// *See* - [`@httpQuery`](https://smithy.io/2.0/spec/http-bindings.html#httpquery-trait)
    "smithy.api#httpQuery": HTTPQueryTrait(key)
);
string_trait!(
    /// Configures a custom operation endpoint.
    ///
    /// *See* - [`@endpoint`](https://smithy.io/2.0/spec/endpoint-traits.html#smithy-api-endpoint-trait)
    "smithy.api#endpoint": EndpointTrait(host_prefix)
);

// ==== Traits with other values ====

/// Provides a structure member with a default value.
///
/// *See* - [Default Trait](https://smithy.io/2.0/spec/type-refinement-traits.html#smithy-api-default-trait)
pub struct DefaultTrait(Box<dyn Document>);
static_trait_id!(DefaultTrait, "smithy.api#default");
impl SmithyTrait for DefaultTrait {
    fn id(&self) -> &ShapeId {
        DefaultTrait::trait_id()
    }

    fn value(&self) -> &Box<dyn Document> {
        &self.0
    }
}
impl DefaultTrait {
    /// Create a new [`DefaultTrait`] instance
    pub fn new<D: Into<Box<dyn Document>>>(doc: D) -> Self {
        DefaultTrait(doc.into())
    }
}

macro_rules! smithy_trait_impl {
    ($t:ident) => {
        impl SmithyTrait for $t {
            fn id(&self) -> &ShapeId {
                $t::trait_id()
            }

            fn value(&self) -> &Box<dyn Document> {
                &self.value
            }
        }
    };
}

/// Indicates that a structure shape represents an error.
///
/// *See* - [Error Trait](https://smithy.io/2.0/spec/type-refinement-traits.html#smithy-api-error-trait)
#[derive(Debug)]
pub struct ErrorTrait {
    error: ErrorFault,
    value: Box<dyn Document>,
}
impl ErrorTrait {
    /// Get whether the Error was the fault of the client or server.
    #[must_use]
    pub fn error(&self) -> &ErrorFault {
        &self.error
    }

    /// Create a new [`ErrorTrait`] instance
    #[must_use]
    pub fn new(error: ErrorFault) -> Self {
        ErrorTrait {
            value: error.to_string().into(),
            error,
        }
    }
}
static_trait_id!(ErrorTrait, "smithy.api#error");
smithy_trait_impl!(ErrorTrait);

/// Indicates if the client or server is at fault for a given error.
#[derive(Debug)]
#[doc(hidden)]
pub enum ErrorFault {
    Client,
    Server,
}
impl Display for ErrorFault {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ErrorFault::Client => write!(f, "client"),
            ErrorFault::Server => write!(f, "server"),
        }
    }
}

/// Defines an HTTP response code for an operation error.
///
/// *See* - [HttpError Trait](https://smithy.io/2.0/spec/http-bindings.html#smithy-api-httperror-trait)
#[derive(Debug)]
pub struct HttpErrorTrait {
    code: i32,
    value: Box<dyn Document>,
}
impl HttpErrorTrait {
    /// Get the code contained by this trait.
    #[must_use]
    pub fn code(&self) -> i32 {
        self.code
    }

    /// Create a new [`HttpErrorTrait`] instance
    ///
    /// # Panics
    /// Http error codes should be between 200 and 600. This
    /// constructor panics when an error code is outside of
    /// this range is provided.
    ///
    /// Smithy validation will check this constraint in models.
    #[must_use]
    pub fn new(code: i32) -> Self {
        assert!(
            200 < code && code < 599,
            "HTTPErrorTrait code out of range: {code}"
        );
        HttpErrorTrait {
            code,
            value: code.into(),
        }
    }
}
static_trait_id!(HttpErrorTrait, "smithy.api#httpError");
smithy_trait_impl!(HttpErrorTrait);

// ============================================================================
// Constraint Traits
// ============================================================================

/// Defines a range constraint for numeric values.
///
/// *See* - [Range Trait](https://smithy.io/2.0/spec/constraint-traits.html#range-trait)
#[derive(Debug)]
pub struct RangeTrait {
    min: Option<BigDecimal>,
    max: Option<BigDecimal>,
    value: Box<dyn Document>,
}
static_trait_id!(RangeTrait, "smithy.api#range");
smithy_trait_impl!(RangeTrait);

static ZERO: LazyLock<BigDecimal> = LazyLock::new(BigDecimal::zero);
static MAX: LazyLock<BigDecimal> = LazyLock::new(|| BigDecimal::from(u64::MAX));

impl RangeTrait {
    /// Get the minimum value allowed by this range constraint.
    ///
    /// Defaults to zero
    #[inline]
    #[must_use]
    pub fn min(&self) -> &BigDecimal {
        self.min.as_ref().unwrap_or_else(|| &ZERO)
    }

    /// Get the maximum value allowed by this range constraint.
    ///
    /// Defaults to `u64::MAX`
    #[inline]
    #[must_use]
    pub fn max(&self) -> &BigDecimal {
        self.max.as_ref().unwrap_or_else(|| &MAX)
    }

    /// Get a new builder instance for this trait.
    #[must_use]
    pub const fn builder() -> RangeTraitBuilder {
        RangeTraitBuilder::new()
    }
}

/// Builder for the [`RangeTrait`]
#[derive(Debug)]
pub struct RangeTraitBuilder {
    min: Option<BigDecimal>,
    max: Option<BigDecimal>,
}
impl RangeTraitBuilder {
    pub(super) const fn new() -> Self {
        RangeTraitBuilder {
            min: None,
            max: None,
        }
    }

    /// Set a minimum value for this constraint.
    #[must_use]
    pub fn min(mut self, min: BigDecimal) -> Self {
        self.min = Some(min);
        self
    }

    /// Set a maximum value for this constraint.
    #[must_use]
    pub fn max(mut self, max: BigDecimal) -> Self {
        self.max = Some(max);
        self
    }

    /// Construct a new [`RangeTrait`] instance.
    #[must_use]
    pub fn build(self) -> RangeTrait {
        let mut value_map: IndexMap<String, Box<dyn Document>> = IndexMap::new();
        if let Some(min) = &self.min {
            value_map.insert("min".to_string(), min.clone().into());
        }
        if let Some(max) = &self.max {
            value_map.insert("min".to_string(), max.clone().into());
        }
        RangeTrait {
            min: self.min,
            max: self.max,
            value: value_map.into(),
        }
    }
}

/// Length constraint for lists, maps, and strings.
///
/// *See* - [LengthTrait](https://smithy.io/2.0/spec/constraint-traits.html#length-trait)
#[derive(Debug)]
pub struct LengthTrait {
    min: Option<usize>,
    max: Option<usize>,
    value: Box<dyn Document>,
}
static_trait_id!(LengthTrait, "smithy.api#length");
smithy_trait_impl!(LengthTrait);

impl LengthTrait {
    /// Get the minimum length for this constraint.
    ///
    /// Defaults to 0 if not set.
    #[must_use]
    pub fn min(&self) -> usize {
        self.min.unwrap_or(0)
    }

    /// Get the maximum length for this constraint.
    ///
    /// Defaults to `usize::MAX` if not set.
    #[must_use]
    pub fn max(&self) -> usize {
        self.max.unwrap_or(usize::MAX)
    }

    /// Get a new [`LengthTraitBuilder`] instance.
    #[must_use]
    pub const fn builder() -> LengthTraitBuilder {
        LengthTraitBuilder::new()
    }
}

/// Builder for creating a [`LengthTrait`] instance
#[derive(Debug)]
pub struct LengthTraitBuilder {
    min: Option<usize>,
    max: Option<usize>,
}
impl LengthTraitBuilder {
    pub(super) const fn new() -> Self {
        LengthTraitBuilder {
            min: None,
            max: None,
        }
    }

    /// Set a minimum length for this constraint.
    #[must_use]
    pub fn min(mut self, min: usize) -> Self {
        self.min = Some(min);
        self
    }

    /// Set a maximum length for this constraint.
    #[must_use]
    pub fn max(mut self, max: usize) -> Self {
        self.max = Some(max);
        self
    }

    /// Create a new [`LengthTrait`] instance.
    #[must_use]
    pub fn build(self) -> LengthTrait {
        let mut value_map: IndexMap<String, Box<dyn Document>> = IndexMap::new();
        if let Some(min) = self.min {
            value_map.insert("min".to_string(), (min as i32).into());
        }
        if let Some(max) = self.max {
            value_map.insert("min".to_string(), (max as i32).into());
        }
        LengthTrait {
            min: self.min,
            max: self.max,
            value: value_map.into(),
        }
    }
}

annotation_trait!(
    /// Requires that items in a list are unique.
    ///
    /// *See* - [`@uniqueItems`](https://smithy.io/2.0/spec/constraint-traits.html#smithy-api-uniqueitems-trait)
    UniqueItemsTrait = "smithy.api#uniqueItems"
);

/// Regex pattern used to constrian string values
///
/// *See* - [LengthTrait](https://smithy.io/2.0/spec/constraint-traits.html#pattern-trait)
#[derive(Debug)]
pub struct PatternTrait {
    pattern: Regex,
    value: Box<dyn Document>,
}
static_trait_id!(PatternTrait, "smithy.api#pattern");
smithy_trait_impl!(PatternTrait);

impl PatternTrait {
    /// Get the regex constraint
    #[must_use]
    pub fn pattern(&self) -> &Regex {
        &self.pattern
    }

    #[must_use]
    /// Create a new [`PatternTrait`]
    ///
    /// # Panics
    /// Will panic if the pattern is invalid.
    ///
    /// Smithy validation will check this constraint in models
    pub fn new(pattern: &str) -> Self {
        PatternTrait {
            pattern: Regex::new(pattern).unwrap(),
            value: pattern.into(),
        }
    }
}

// ============================================================================
// Auth Traits
// ============================================================================

annotation_trait!(
    /// Indicates that a service supports HTTP Basic Authentication.
    ///
    /// *See* - [`@httpBasicAuth`](https://smithy.io/2.0/spec/authentication-traits.html#smithy-api-httpbasicauth-trait)
    HttpBasicAuthTrait = "smithy.api#httpBasicAuth"
);
annotation_trait!(
    /// Indicates that a service supports HTTP Digest Authentication.
    ///
    /// *See* - [`@httpDigestAuth`](https://smithy.io/2.0/spec/authentication-traits.html#httpdigestauth-trait)
    HttpDigestAuthTrait = "smithy.api#httpDigestAuth"
);
annotation_trait!(
    /// Indicates that a service supports HTTP Bearer Authentication .
    ///
    /// *See* - [`@httpBearerAuth`](https://smithy.io/2.0/spec/authentication-traits.html#httpbearerauth-trait)
    HttpBearerAuthTrait = "smithy.api#httpBearerAuth"
);

/// Trait indicating that a service supports HTTP-specific authentication
/// using an API key sent in a header or query string parameter.
///
/// *See* - [`@httpApiKeyAuth`](https://smithy.io/2.0/spec/authentication-traits.html#httpapikeyauth-trait)
#[derive(Debug)]
pub struct HttpApiKeyAuthTrait {
    name: String,
    in_location: String,
    scheme: Option<String>,
    value: Box<dyn Document>,
}
static_trait_id!(HttpApiKeyAuthTrait, "smithy.api#httpApiKeyAuth");
smithy_trait_impl!(HttpApiKeyAuthTrait);

impl HttpApiKeyAuthTrait {
    /// Get the `name`
    #[must_use]
    pub fn name(&self) -> &String {
        &self.name
    }

    /// Get the `location`
    #[must_use]
    pub fn in_location(&self) -> &String {
        &self.in_location
    }

    /// Get the `scheme`
    #[must_use]
    pub fn scheme(&self) -> &Option<String> {
        &self.scheme
    }

    /// Get a new [`HttpApiKeyAuthTraitBuilder`] instance.
    #[must_use]
    pub fn builder() -> HttpApiKeyAuthTraitBuilder {
        HttpApiKeyAuthTraitBuilder::new()
    }
}

/// Builder for [`HttpApiKeyAuthTrait`] instances
pub struct HttpApiKeyAuthTraitBuilder {
    name: Option<String>,
    in_location: Option<String>,
    scheme: Option<String>,
}
impl HttpApiKeyAuthTraitBuilder {
    fn new() -> Self {
        HttpApiKeyAuthTraitBuilder {
            name: None,
            in_location: None,
            scheme: None,
        }
    }

    /// Set the `name` to use
    #[must_use]
    pub fn name(mut self, name: &str) -> Self {
        self.name = Some(name.to_string());
        self
    }

    /// Set the `location` to use
    #[must_use]
    pub fn in_location(mut self, in_location: &str) -> Self {
        self.in_location = Some(in_location.to_string());
        self
    }

    /// Set the `scheme` to use
    #[must_use]
    pub fn scheme(mut self, scheme: &str) -> Self {
        self.scheme = Some(scheme.to_string());
        self
    }

    /// Build a new [`HttpApiKeyAuthTrait`] instance
    ///
    /// # Panics
    /// If the location or name are not set.
    ///
    /// Smithy validation will check this constraint in models.
    #[must_use]
    pub fn build(self) -> HttpApiKeyAuthTrait {
        let mut value_map: IndexMap<String, Box<dyn Document>> = IndexMap::new();
        if let Some(name) = &self.name {
            value_map.insert("name".to_string(), name.clone().into());
        }
        if let Some(location) = &self.in_location {
            value_map.insert("location".to_string(), location.clone().into());
        }
        if let Some(scheme) = &self.scheme {
            value_map.insert("scheme".to_string(), scheme.clone().into());
        }
        HttpApiKeyAuthTrait {
            name: self.name.unwrap(),
            in_location: self.in_location.unwrap(),
            scheme: self.scheme,
            value: value_map.into(),
        }
    }
}