Skip to content

Commit 57b71e7

Browse files
CLOUDP-315486: Update the foascli changelog command to generate the changelog for "upcoming" APIs
1 parent 50da643 commit 57b71e7

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed

tools/cli/internal/changelog/changelog.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"log"
2121
"os"
22+
"strings"
2223
"time"
2324

2425
"github.com/mongodb/openapi/tools/cli/internal/apiversion"
@@ -230,11 +231,6 @@ func NewEntriesBetweenRevisionVersions(revisionPath, exceptionFilePath string) (
230231
continue
231232
}
232233

233-
// Skip upcoming version. It will be included in CLOUDP-315486
234-
if apiversion.IsUpcomingStabilityLevel(fromVersion) || apiversion.IsUpcomingStabilityLevel(toVersion) {
235-
continue
236-
}
237-
238234
entry, err := newEntriesBetweenVersion(revisionMetadata, fromVersion, toVersion, exceptionFilePath)
239235
if err != nil {
240236
return nil, err
@@ -389,6 +385,14 @@ func newBaseAndRevisionSpecs(baseMetadata, revisionMetadata *Metadata) (baseSpec
389385
if err != nil {
390386
return nil, nil, err
391387
}
388+
389+
if strings.Contains(revisionMetadata.ActiveVersion, ".upcoming") {
390+
// Upcoming API Spec contains only endpoints marked as "upcoming". We need to remove endpoints from
391+
// the base spec that aren't present in the revision spec to avoid generating
392+
// incorrect "endpoint deleted" changelog entries.
393+
removePathsAndOperationsNotInRevision(baseSpec, revisionSpec)
394+
}
395+
392396
baseSpec.Version = baseMetadata.ActiveVersion
393397
revisionSpec.Version = revisionMetadata.ActiveVersion
394398

@@ -412,6 +416,24 @@ func newBaseAndRevisionSpecs(baseMetadata, revisionMetadata *Metadata) (baseSpec
412416
return baseSpec, revisionSpec, nil
413417
}
414418

419+
// removePathsAndOperationsNotInRevision removes paths and operations not in the revision spec.
420+
func removePathsAndOperationsNotInRevision(baseSpec, revisionSpec *load.SpecInfo) {
421+
pathsFromRevision := revisionSpec.Spec.Paths.Map()
422+
for pathKeyFromBase, pathValueFromBase := range baseSpec.Spec.Paths.Map() {
423+
if _, ok := pathsFromRevision[pathKeyFromBase]; !ok {
424+
baseSpec.Spec.Paths.Delete(pathKeyFromBase)
425+
continue
426+
}
427+
428+
operationsFromRevision := pathsFromRevision[pathKeyFromBase].Operations()
429+
for operationKeyFromBase := range pathValueFromBase.Operations() {
430+
if _, ok := operationsFromRevision[operationKeyFromBase]; !ok {
431+
delete(pathValueFromBase.Operations(), operationKeyFromBase)
432+
}
433+
}
434+
}
435+
}
436+
415437
func newOpeAPISpecFromPathAndVersion(path, version string) (*load.SpecInfo, error) {
416438
loader := openapi.NewOpenAPI3().WithExcludedPrivatePaths()
417439
return loader.CreateOpenAPISpecFromPath(fmt.Sprintf("%s/openapi-%s.json", path, version))

tools/cli/internal/changelog/merge.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ func (m *Changelog) newPathsFromDeprecatedChanges(
199199
changes []*outputfilter.OasDiffEntry,
200200
changelogPath *[]*Path,
201201
conf map[string]*outputfilter.OperationConfigs) ([]*Path, error) {
202-
depreactedChanges := m.newDeprecatedByNewerVersionOasDiffEntries(changes, conf)
203-
return newMergedChanges(depreactedChanges, changeTypeDeprecated, m.BaseMetadata.ActiveVersion, changelogPath, conf)
202+
deprecatedChanges := m.newDeprecatedByNewerVersionOasDiffEntries(changes, conf)
203+
return newMergedChanges(deprecatedChanges, changeTypeDeprecated, m.BaseMetadata.ActiveVersion, changelogPath, conf)
204204
}
205205

206206
func (m *Changelog) newOasDiffEntries() ([]*outputfilter.OasDiffEntry, error) {
@@ -252,18 +252,17 @@ func newMergedChanges(changes []*outputfilter.OasDiffEntry,
252252

253253
for _, change := range changes {
254254
pathEntry := newPathEntry(changelogPath, change.Path, change.Operation)
255-
operationdID := change.OperationID
255+
operationID := change.OperationID
256256

257-
conf, ok := operationConfig[operationdID]
257+
conf, ok := operationConfig[operationID]
258258
if !ok {
259-
return nil, fmt.Errorf("operation %s not found in operation config", operationdID)
259+
return nil, fmt.Errorf("operation %s not found in operation config", operationID)
260260
}
261261

262-
pathEntry.OperationID = operationdID
262+
pathEntry.OperationID = operationID
263263
pathEntry.Tag = conf.Tag()
264264

265265
pathEntryVersion := newEntryVersion(&pathEntry.Versions, version)
266-
pathEntryVersion.StabilityLevel = stabilityLevelStable
267266
pathEntryVersion.ChangeType = newChangeType(pathEntryVersion.ChangeType, changeType, change.ID)
268267

269268
versionChange := &Change{

tools/cli/test/e2e/cli/changelog_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestChangelog(t *testing.T) {
4848
t.Run("Generate Changelog with same API Version", func(t *testing.T) {
4949
base := NewChangelogBasePathSameAPIVersion(t)
5050
revision := NewChangelogRevisionPathSameAPIVersion(t)
51-
exemptions := NewChangelogExepmtionFilePathSameAPIVersion(t)
51+
exemptions := NewChangelogExemptionFilePathSameAPIVersion(t)
5252
commandOut := getOutputFolder(t, "changelog")
5353

5454
cmd := exec.Command(cliPath,
@@ -74,7 +74,7 @@ func TestChangelog(t *testing.T) {
7474
t.Run("Generate Changelog with new Preview API Version", func(t *testing.T) {
7575
base := newChangelogBasePathNewPreviewAPIVersion(t)
7676
revision := newChangelogRevisionPathNewPreviewAPIVersion(t)
77-
exemptions := newChangelogExepmtionFilePathNewPreviewAPIVersion(t)
77+
exemptions := newChangelogExemptionFilePathNewPreviewAPIVersion(t)
7878
commandOut := getOutputFolder(t, "changelog")
7979

8080
cmd := exec.Command(cliPath,

tools/cli/test/e2e/cli/cli.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func NewChangelogRevisionPathSameAPIVersion(t *testing.T) string {
7373
return cliPath
7474
}
7575

76-
func NewChangelogExepmtionFilePathSameAPIVersion(t *testing.T) string {
76+
func NewChangelogExemptionFilePathSameAPIVersion(t *testing.T) string {
7777
t.Helper()
7878
cliPath, err := filepath.Abs("../../data/changelog/same-api-version/exemptions.yaml")
7979
require.NoError(t, err)
@@ -108,7 +108,7 @@ func newChangelogRevisionPathNewPreviewAPIVersion(t *testing.T) string {
108108
return cliPath
109109
}
110110

111-
func newChangelogExepmtionFilePathNewPreviewAPIVersion(t *testing.T) string {
111+
func newChangelogExemptionFilePathNewPreviewAPIVersion(t *testing.T) string {
112112
t.Helper()
113113
cliPath, err := filepath.Abs("../../data/changelog/new-api-preview-version/exemptions.yaml")
114114
require.NoError(t, err)

0 commit comments

Comments
 (0)