@@ -169,7 +169,7 @@ func LoadCatalogInfo(r io.Reader) (*CatalogInfo, error) {
169
169
if catalog .service != nil {
170
170
var apiNames []string
171
171
for _ , apiName := range catalog .serviceComponent .Spec .ProvidesAPIs {
172
- // Preserve manually added entries, things are are NOT vervet APIs
172
+ // Preserve manually added entries, things that are NOT vervet APIs
173
173
if _ , ok := vervetAPINames [apiName ]; ! ok {
174
174
apiNames = append (apiNames , apiName )
175
175
}
@@ -273,27 +273,22 @@ func (c *CatalogInfo) vervetAPI(doc *vervet.Document, root string, pivotDate tim
273
273
return nil , err
274
274
}
275
275
276
- name_suffix := fmt .Sprintf ("_%s_%s" , toBackstageName (apiName ), version .DateString ())
277
- // Backstage names can only be a maximum of 63 characters
278
- name_len := 63 - len (name_suffix )
279
- name := fmt .Sprintf ("%." + strconv .Itoa (name_len )+ "s%s" , toBackstageName (doc .Info .Title ), name_suffix )
280
- title := doc .Info .Title + " " + version .DateString ()
276
+ apiNameBS := toBackstageName (apiName )
277
+ docTitleBS := toBackstageName (doc .Info .Title )
278
+ dateStr := version .DateString ()
279
+ nameSuffix := fmt .Sprintf ("_%s_%s" , apiNameBS , dateStr )
280
+
281
+ title := doc .Info .Title + " " + dateStr
281
282
labels := map [string ]string {
282
- snykApiVersionDate : version . DateString () ,
283
+ snykApiVersionDate : dateStr ,
283
284
}
284
285
tags := []string {version .Date .Format ("2006-01" )}
285
- spec := APISpec {
286
- Type : "openapi" ,
287
- Owner : c .serviceComponent .Spec .Owner ,
288
- Lifecycle : "production" ,
289
- Definition : DefinitionRef {
290
- Text : ref ,
291
- },
292
- }
286
+ specLifecycle := "production"
293
287
294
288
// Specs generated after the pivot date have per operation stability, so
295
289
// there is no global stability for the whole document. To preserve
296
290
// backwards compatibility we still output metadata for the older specs.
291
+ var name string
297
292
if version .Date .Before (pivotDate ) {
298
293
lifecycle := version .LifecycleAt (time.Time {})
299
294
var backstageLifecycle string
@@ -302,13 +297,26 @@ func (c *CatalogInfo) vervetAPI(doc *vervet.Document, root string, pivotDate tim
302
297
} else {
303
298
backstageLifecycle = lifecycle .String ()
304
299
}
300
+ specLifecycle = backstageLifecycle
301
+
302
+ stabilityStr := version .Stability .String ()
303
+ stabilitySuffix := "_" + stabilityStr
304
+
305
+ // Backstage names can only be a maximum of 63 characters
306
+ availableTitleLen := 63 - len (nameSuffix ) - len (stabilitySuffix )
307
+ if availableTitleLen < 0 {
308
+ availableTitleLen = 0
309
+ }
310
+ name = fmt .Sprintf ("%." + strconv .Itoa (availableTitleLen )+ "s%s%s" , docTitleBS , nameSuffix , stabilitySuffix )
311
+ title = title + " " + stabilityStr
305
312
306
- name = name + "_" + version .Stability .String ()
307
- title = title + " " + version .Stability .String ()
308
- labels [snykApiStability ] = version .Stability .String ()
313
+ labels [snykApiStability ] = stabilityStr
309
314
labels [snykApiLifecycle ] = lifecycle .String ()
310
- tags = append (tags , version .Stability .String (), lifecycle .String ())
311
- spec .Lifecycle = backstageLifecycle
315
+ tags = append (tags , stabilityStr , lifecycle .String ())
316
+ } else {
317
+ // Backstage names can only be a maximum of 63 characters
318
+ availableTitleLen := 63 - len (nameSuffix )
319
+ name = fmt .Sprintf ("%." + strconv .Itoa (availableTitleLen )+ "s%s" , docTitleBS , nameSuffix )
312
320
}
313
321
314
322
return & API {
@@ -324,7 +332,14 @@ func (c *CatalogInfo) vervetAPI(doc *vervet.Document, root string, pivotDate tim
324
332
snykApiGeneratedBy : "vervet" ,
325
333
},
326
334
},
327
- Spec : spec ,
335
+ Spec : APISpec {
336
+ Type : "openapi" ,
337
+ Owner : c .serviceComponent .Spec .Owner ,
338
+ Lifecycle : specLifecycle ,
339
+ Definition : DefinitionRef {
340
+ Text : ref ,
341
+ },
342
+ },
328
343
}, nil
329
344
}
330
345
0 commit comments