File tree 4 files changed +55
-8
lines changed
4 files changed +55
-8
lines changed Original file line number Diff line number Diff line change @@ -90,16 +90,17 @@ type Shape struct {
90
90
OriginalShapeName string `json:"-"`
91
91
92
92
// Map of exported member names to the ShapeReference.
93
- MemberRefs map [string ]* ShapeRef `json:"members"`
94
- MemberRef ShapeRef `json:"member"` // List ref
95
- KeyRef ShapeRef `json:"key"` // map key ref
96
- ValueRef ShapeRef `json:"value"` // map value ref
97
- Required []string
98
- Payload string
99
- Type string
93
+ MemberRefs map [string ]* ShapeRef `json:"members"`
94
+ MemberRef ShapeRef `json:"member"` // List ref
95
+ KeyRef ShapeRef `json:"key"` // map key ref
96
+ ValueRef ShapeRef `json:"value"` // map value ref
97
+ Pattern string `json:"pattern"`
98
+ Required []string
99
+ Payload string
100
+ Type string
100
101
// this is being added for type union specifically. We want to generate
101
102
// api as struct and handle setSDK and setResource differently
102
- RealType string
103
+ RealType string
103
104
Exception bool
104
105
Enum []string
105
106
EnumConsts []string
Original file line number Diff line number Diff line change @@ -231,6 +231,12 @@ func createApiShape(shape Shape) (*awssdkmodel.Shape, error) {
231
231
if ok {
232
232
apiShape .DefaultValue = fmt .Sprintf ("%v" , val )
233
233
}
234
+
235
+ pattern , ok := shape .Traits ["smithy.api#pattern" ]
236
+ if ok {
237
+ apiShape .Pattern = pattern .(string )
238
+ }
239
+
234
240
documentation , _ := shape .Traits ["smithy.api#documentation" ].(string )
235
241
apiShape .Documentation = awssdkmodel .AppendDocstring ("" , documentation )
236
242
Original file line number Diff line number Diff line change @@ -104,6 +104,15 @@ func (f *Field) GetDocumentation() string {
104
104
out .WriteString (f .ShapeRef .Documentation )
105
105
}
106
106
}
107
+
108
+ if f .ShapeRef != nil && f .ShapeRef .Shape != nil && f .ShapeRef .Shape .Pattern != "" {
109
+ if hasShapeDoc {
110
+ out .WriteString ("\n //\n " )
111
+ }
112
+ out .WriteString ("// " )
113
+ out .WriteString (fmt .Sprintf ("Regex Pattern: `%s`" , f .ShapeRef .Shape .Pattern ))
114
+ }
115
+
107
116
if cfg == nil {
108
117
return out .String ()
109
118
}
Original file line number Diff line number Diff line change @@ -338,3 +338,34 @@ func TestFieldPathWithUnderscore(t *testing.T) {
338
338
field .Path = "subPathA.subPathB.MyField"
339
339
assert .Equal ("subPathA_subPathB_MyField" , field .FieldPathWithUnderscore ())
340
340
}
341
+
342
+ func TestFieldWithPattern (t * testing.T ) {
343
+ require := require .New (t )
344
+
345
+ g := testutil .NewModelForServiceWithOptions (t , "eks" ,
346
+ & testutil.TestingModelOptions {
347
+ GeneratorConfigFile : "generator.yaml" ,
348
+ DocumentationConfigFile : "documentation.yaml" ,
349
+ },
350
+ )
351
+
352
+ crds , err := g .GetCRDs ()
353
+ require .Nil (err )
354
+
355
+ crd := getCRDByName ("AddOn" , crds )
356
+ require .NotNil (crd )
357
+
358
+ specFields := crd .SpecFields
359
+
360
+ // We have not altered the docstring for Version from the
361
+ // docstring that comes in the doc-2.json file...
362
+ ltdField := specFields ["ClusterName" ]
363
+ require .NotNil (ltdField )
364
+ require .NotNil (ltdField .ShapeRef )
365
+ require .NotEmpty (ltdField .ShapeRef .Shape .Pattern )
366
+
367
+ require .Equal (
368
+ "// The name of your cluster.\n //\n // Regex Pattern: `^[0-9A-Za-z][A-Za-z0-9\\ -_]*$`" ,
369
+ ltdField .GetDocumentation (),
370
+ )
371
+ }
You can’t perform that action at this time.
0 commit comments