Skip to content

Commit cbe3c2e

Browse files
CLOUDP-315486: Update the foascli changelog command to generate the changelog for upcoming APIs (#759)
1 parent 50da643 commit cbe3c2e

File tree

97 files changed

+2505969
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+2505969
-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" OpenAPI Spec contains only endpoints marked as "upcoming". We need to remove endpoints from
391+
// the base spec that aren't present in the "Upcoming" 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,20 +252,19 @@ 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)
266266
pathEntryVersion.StabilityLevel = stabilityLevelStable
267267
pathEntryVersion.ChangeType = newChangeType(pathEntryVersion.ChangeType, changeType, change.ID)
268-
269268
versionChange := &Change{
270269
Description: change.Text,
271270
Code: change.ID,

0 commit comments

Comments
 (0)