Skip to content

Commit

Permalink
fix: update sunset header (#368)
Browse files Browse the repository at this point in the history
* fix: update sunset header
  • Loading branch information
corneliu-petrescu authored Aug 23, 2024
1 parent e0c2f94 commit 8266282
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ var Versions embed.FS
func (c *Compiler) BuildAll(ctx context.Context, stopVersion vervet.Version) error {
var errs error
for apiName := range c.apis {
err := c.Build(apiName, stopVersion) //nolint:contextcheck // TODO: fix contextcheck in separate PR
err := c.Build(apiName, stopVersion) //nolint:contextcheck
// TODO: fix contextcheck in separate PR
if err != nil {
errs = multierr.Append(errs, err)
}
Expand Down
43 changes: 43 additions & 0 deletions internal/storage/collator.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ func (c *Collator) Collate() (map[vervet.Version]openapi3.T, error) {
collatorMergeError.WithLabelValues(version.String()).Inc()
return nil, err
}

// Overrides sunset header documentation until we can provide a more definitive fix
overrideSunsetHeader(spec)

if err := c.applyOverlay(spec); err != nil {
log.Error().Err(err).Msgf("failed to merge overlay for version %s", version)
collatorMergeError.WithLabelValues(version.String()).Inc()
Expand All @@ -143,6 +147,45 @@ func (c *Collator) Collate() (map[vervet.Version]openapi3.T, error) {
return specs, nil
}

func overrideSunsetHeader(doc *openapi3.T) {
const headerDescription = "A header containing the date of when the underlying endpoint will be removed. " +
"This header is only present if the endpoint has been deprecated. " +
"For information purposes only. " +
"Returned as a date in the format: YYYY-MM-DD"
const example = "2021-08-02"
const schemaFormat = "date"

for _, path := range doc.Paths.Map() {
for _, operation := range path.Operations() {
for _, responses := range operation.Responses.Map() {
if responses.Value == nil {
continue
}

if sunsetHeader, ok := responses.Value.Headers["sunset"]; ok {
if sunsetHeader.Value == nil {
continue
}
sunsetHeader.Value.Description = headerDescription
sunsetHeader.Value.Example = example
if sunsetHeader.Value.Schema.Value == nil {
continue
}
sunsetHeader.Value.Schema.Value.Format = schemaFormat
}
}
}
}
if doc.Components != nil {
if sunsetHeader, ok := doc.Components.Headers["SunsetHeader"]; ok {
if sunsetHeader.Value == nil {
return
}
sunsetHeader.Value.Description = headerDescription
}
}
}

func mergeRevisions(revisions ContentRevisions) (*openapi3.T, error) {
collator := vervet.NewCollator(vervet.StrictTags(false), vervet.UseFirstRoute(true))
var haveOpenAPI, haveOpenAPIVersion bool
Expand Down

0 comments on commit 8266282

Please sign in to comment.