1414package model
1515
1616import (
17- "fmt"
1817 "sort"
1918 "strings"
2019
@@ -58,14 +57,6 @@ func (ops Ops) IterOps() []*awssdkmodel.Operation {
5857 return res
5958}
6059
61- // PrinterColumn represents a single field in the CRD's Spec or Status objects
62- type PrinterColumn struct {
63- CRD * CRD
64- Name string
65- Type string
66- JSONPath string
67- }
68-
6960// CRD describes a single top-level resource in an AWS service API
7061type CRD struct {
7162 sdkAPI * SDKAPI
@@ -75,10 +66,9 @@ type CRD struct {
7566 Plural string
7667 // Ops are the CRUD operations controlling this resource
7768 Ops Ops
78- // AdditionalPrinterColumns is an array of PrinterColumn objects
69+ // additionalPrinterColumns is an array of PrinterColumn objects
7970 // representing the printer column settings for the CRD
80- // AdditionalPrinterColumns field.
81- AdditionalPrinterColumns []* PrinterColumn
71+ additionalPrinterColumns []* PrinterColumn
8272 // SpecFields is a map, keyed by the **original SDK member name** of
8373 // Field objects representing those fields in the CRD's Spec struct
8474 // field.
@@ -178,22 +168,29 @@ func (r *CRD) InputFieldRename(
178168func (r * CRD ) AddSpecField (
179169 memberNames names.Names ,
180170 shapeRef * awssdkmodel.ShapeRef ,
181- ) * Field {
182- fieldConfigs := r .cfg .ResourceFields (r .Names .Original )
183- f := newField (r , memberNames , shapeRef , fieldConfigs [memberNames .Original ])
171+ ) {
172+ fConfigs := r .cfg .ResourceFields (r .Names .Original )
173+ fConfig := fConfigs [memberNames .Original ]
174+ f := newField (r , memberNames , shapeRef , fConfig )
175+ if fConfig != nil && fConfig .IsPrintable {
176+ r .addSpecPrintableColumn (f )
177+ }
184178 r .SpecFields [memberNames .Original ] = f
185- return f
186179}
187180
188181// AddStatusField adds a new Field of a given name and shape into the Status
189182// field of a CRD
190183func (r * CRD ) AddStatusField (
191184 memberNames names.Names ,
192185 shapeRef * awssdkmodel.ShapeRef ,
193- ) * Field {
194- f := newField (r , memberNames , shapeRef , nil )
186+ ) {
187+ fConfigs := r .cfg .ResourceFields (r .Names .Original )
188+ fConfig := fConfigs [memberNames .Original ]
189+ f := newField (r , memberNames , shapeRef , fConfig )
190+ if fConfig != nil && fConfig .IsPrintable {
191+ r .addStatusPrintableColumn (f )
192+ }
195193 r .StatusFields [memberNames .Original ] = f
196- return f
197194}
198195
199196// AddTypeImport adds an entry in the CRD's TypeImports map for an import line
@@ -218,80 +215,6 @@ func (r *CRD) SpecFieldNames() []string {
218215 return res
219216}
220217
221- // AddPrintableColumn adds an entry to the list of additional printer columns
222- // using the given path and field types.
223- func (r * CRD ) AddPrintableColumn (
224- field * Field ,
225- jsonPath string ,
226- ) * PrinterColumn {
227- fieldColumnType := field .GoTypeElem
228-
229- // Printable columns must be primitives supported by the OpenAPI list of data
230- // types as defined by
231- // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types
232- // This maps Go type to OpenAPI type.
233- acceptableColumnMaps := map [string ]string {
234- "string" : "string" ,
235- "boolean" : "boolean" ,
236- "int" : "integer" ,
237- "int8" : "integer" ,
238- "int16" : "integer" ,
239- "int32" : "integer" ,
240- "int64" : "integer" ,
241- "uint" : "integer" ,
242- "uint8" : "integer" ,
243- "uint16" : "integer" ,
244- "uint32" : "integer" ,
245- "uint64" : "integer" ,
246- "uintptr" : "integer" ,
247- "float32" : "number" ,
248- "float64" : "number" ,
249- }
250- printColumnType , exists := acceptableColumnMaps [fieldColumnType ]
251-
252- if ! exists {
253- msg := fmt .Sprintf (
254- "GENERATION FAILURE! Unable to generate a printer column for the field %s that has type %s." ,
255- field .Names .Camel , fieldColumnType ,
256- )
257- panic (msg )
258- return nil
259- }
260-
261- column := & PrinterColumn {
262- CRD : r ,
263- Name : field .Names .Camel ,
264- Type : printColumnType ,
265- JSONPath : jsonPath ,
266- }
267- r .AdditionalPrinterColumns = append (r .AdditionalPrinterColumns , column )
268- return column
269- }
270-
271- // AddSpecPrintableColumn adds an entry to the list of additional printer columns
272- // using the path of the given spec field.
273- func (r * CRD ) AddSpecPrintableColumn (
274- field * Field ,
275- ) * PrinterColumn {
276- return r .AddPrintableColumn (
277- field ,
278- //TODO(nithomso): Ideally we'd use `r.cfg.PrefixConfig.SpecField` but it uses uppercase
279- fmt .Sprintf ("%s.%s" , ".spec" , field .Names .CamelLower ),
280- )
281- }
282-
283- // AddStatusPrintableColumn adds an entry to the list of additional printer columns
284- // using the path of the given status field.
285- func (r * CRD ) AddStatusPrintableColumn (
286- field * Field ,
287- ) * PrinterColumn {
288- return r .AddPrintableColumn (
289- field ,
290- //TODO(nithomso): Ideally we'd use `r.cfg.PrefixConfig.StatusField` but it uses uppercase
291- fmt .Sprintf ("%s.%s" , ".status" , field .Names .CamelLower ),
292- )
293- }
294-
295218// UnpacksAttributesMap returns true if the underlying API has
296219// Get{Resource}Attributes/Set{Resource}Attributes API calls that map real,
297220// schema'd fields to a raw `map[string]*string` for this resource (see SNS and
@@ -470,7 +393,7 @@ func NewCRD(
470393 Kind : kind ,
471394 Plural : plural ,
472395 Ops : ops ,
473- AdditionalPrinterColumns : make ([]* PrinterColumn , 0 ),
396+ additionalPrinterColumns : make ([]* PrinterColumn , 0 ),
474397 SpecFields : map [string ]* Field {},
475398 StatusFields : map [string ]* Field {},
476399 ShortNames : cfg .ResourceShortNames (kind ),
0 commit comments