diff --git a/tools/cli/internal/changelog/changelog.go b/tools/cli/internal/changelog/changelog.go index 6e9a126433..b7cd10987d 100644 --- a/tools/cli/internal/changelog/changelog.go +++ b/tools/cli/internal/changelog/changelog.go @@ -457,7 +457,7 @@ func findChangelogEntry(changelog []*Entry, date, operationID, version, changeCo } for _, v := range path.Versions { - if v.Version != version { + if version != "" && v.Version != version { continue } diff --git a/tools/cli/internal/changelog/changelog_test.go b/tools/cli/internal/changelog/changelog_test.go index 1e92477781..8357e16fa4 100644 --- a/tools/cli/internal/changelog/changelog_test.go +++ b/tools/cli/internal/changelog/changelog_test.go @@ -612,7 +612,68 @@ func TestFindChangelogEntry(t *testing.T) { changeCode string expectedEntries *Change }{ - + { + name: "find changelog entry no API Version", + entries: []*Entry{ + { + Date: "2023-07-10", + Paths: []*Path{ + { + URI: "/api/atlas/v2/groups/{id}/clusters", + HTTPMethod: "POST", + OperationID: "createCluster", + Tag: "Multi-Cloud Clusters", + Versions: []*Version{ + { + Version: "2023-02-01", + StabilityLevel: "stable", + ChangeType: "remove", + Changes: []*Change{ + { + Description: "endpoint removed", + Code: "endpoint-removed", + BackwardCompatible: true, + }}, + }, + }, + }, + }, + }, + { + Date: "2023-07-11", + Paths: []*Path{ + { + URI: "/api/atlas/v2/groups/{id}/clusters", + HTTPMethod: "POST", + OperationID: "createCluster", + Tag: "Multi-Cloud Clusters", + Versions: []*Version{ + { + Version: "2023-02-01", + StabilityLevel: "stable", + ChangeType: "remove", + Changes: []*Change{ + { + Description: "endpoint removed", + Code: "endpoint-removed", + BackwardCompatible: true, + }}, + }, + }, + }, + }, + }, + }, + operationID: "createCluster", + date: "2023-07-10", + version: "", + changeCode: "endpoint-removed", + expectedEntries: &Change{ + Description: "endpoint removed", + Code: "endpoint-removed", + BackwardCompatible: true, + }, + }, { name: "find changelog entry", entries: []*Entry{ diff --git a/tools/cli/internal/changelog/outputfilter/squash.go b/tools/cli/internal/changelog/outputfilter/squash.go index 92bbba0cee..3b9f881460 100644 --- a/tools/cli/internal/changelog/outputfilter/squash.go +++ b/tools/cli/internal/changelog/outputfilter/squash.go @@ -147,35 +147,35 @@ func squashEntries(entries []*OasDiffEntry) ([]*OasDiffEntry, error) { entriesByIDandOperationID, hiddenEntriesByIDandOperationID := newEntriesMapPerIDAndOperationID(entries) squashHandlers := newSquashHandlers() - squashedEntries := []*OasDiffEntry{} + squashedEntriesOut := []*OasDiffEntry{} for _, entry := range entries { // if no squash handlers implemented for entry's code, // just append the entry to the result if _, ok := findHandler(entry.ID); !ok { - squashedEntries = append(squashedEntries, entry) + squashedEntriesOut = append(squashedEntriesOut, entry) continue } } - squashedEntriesNotHidden, err := appplySquashHandlerToMap(squashHandlers, entriesByIDandOperationID) + squashedEntriesNotHidden, err := applySquashHandlerToMap(squashHandlers, entriesByIDandOperationID) if err != nil { return nil, err } - squashedEntriesHidden, err := appplySquashHandlerToMap(squashHandlers, hiddenEntriesByIDandOperationID) + squashedEntriesHidden, err := applySquashHandlerToMap(squashHandlers, hiddenEntriesByIDandOperationID) if err != nil { return nil, err } - squashedEntries = append(squashedEntries, squashedEntriesNotHidden...) - squashedEntries = append(squashedEntries, squashedEntriesHidden...) + squashedEntriesOut = append(squashedEntriesOut, squashedEntriesNotHidden...) + squashedEntriesOut = append(squashedEntriesOut, squashedEntriesHidden...) - return squashedEntries, nil + return squashedEntriesOut, nil } -func appplySquashHandlerToMap(squashHandlers []handler, entriesMap map[string]map[string][]*OasDiffEntry) ([]*OasDiffEntry, error) { - squashedEntries := []*OasDiffEntry{} +func applySquashHandlerToMap(squashHandlers []handler, entriesMap map[string]map[string][]*OasDiffEntry) ([]*OasDiffEntry, error) { + squashedEntriesOut := []*OasDiffEntry{} for _, handler := range squashHandlers { entryMapPerOperationID, ok := entriesMap[handler.id] if !ok { @@ -187,9 +187,9 @@ func appplySquashHandlerToMap(squashHandlers []handler, entriesMap map[string]ma return nil, err } - squashedEntries = append(squashedEntries, sortEntriesByDescription(entries)...) + squashedEntriesOut = append(squashedEntriesOut, sortEntriesByDescription(entries)...) } - return squashedEntries, nil + return squashedEntriesOut, nil } func sortEntriesByDescription(entries []*OasDiffEntry) []*OasDiffEntry { diff --git a/tools/cli/internal/changelog/sunset.go b/tools/cli/internal/changelog/sunset.go index 4a75d71ae3..63aba1a777 100644 --- a/tools/cli/internal/changelog/sunset.go +++ b/tools/cli/internal/changelog/sunset.go @@ -43,12 +43,14 @@ func (m *Changelog) newOasDiffEntriesFromSunsetEndpoints( continue } - // Avoid adding duplicates in the changelog - if findChangelogEntry(m.BaseChangelog, config.Revision.Sunset, operationID, version, endpointRemovedCode) == nil { + // Avoid adding duplicates in the changelog. + // Passing version="" to findChangelogEntry since the sunset date of the endpoint with API version "version" + // is the same in all the specs. + if findChangelogEntry(m.BaseChangelog, config.Revision.Sunset, operationID, "", endpointRemovedCode) == nil { changes = append(changes, &outputfilter.OasDiffEntry{ Date: config.Revision.Sunset, ID: endpointRemovedCode, - Text: "endpoint removed", + Text: fmt.Sprintf("endpoint with API Version '%s' was removed as it has reached its sunset date '%s'", version, config.Revision.Sunset), Level: int(checker.ERR), Operation: config.Revision.HTTPMethod, OperationID: operationID, diff --git a/tools/cli/internal/changelog/sunset_test.go b/tools/cli/internal/changelog/sunset_test.go index 80a071ff66..eb29db813d 100644 --- a/tools/cli/internal/changelog/sunset_test.go +++ b/tools/cli/internal/changelog/sunset_test.go @@ -126,7 +126,7 @@ func TestNewOasDiffEntriesFromSunsetEndpoints(t *testing.T) { Operation: "GET", OperationID: "listStreamInstances", Path: "/api/atlas/v2/groups/{id}/streams", - Text: "endpoint removed", + Text: "endpoint with API Version '2023-02-01' was removed as it has reached its sunset date '2023-07-12'", }, }