Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions tools/cli/internal/changelog/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"log"
"os"
"strings"
"time"

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

// Skip upcoming version. It will be included in CLOUDP-315486
if apiversion.IsUpcomingStabilityLevel(fromVersion) || apiversion.IsUpcomingStabilityLevel(toVersion) {
continue
}

entry, err := newEntriesBetweenVersion(revisionMetadata, fromVersion, toVersion, exceptionFilePath)
if err != nil {
return nil, err
Expand Down Expand Up @@ -389,6 +385,14 @@ func newBaseAndRevisionSpecs(baseMetadata, revisionMetadata *Metadata) (baseSpec
if err != nil {
return nil, nil, err
}

if strings.Contains(revisionMetadata.ActiveVersion, ".upcoming") {
// "Upcoming" OpenAPI Spec contains only endpoints marked as "upcoming". We need to remove endpoints from
// the base spec that aren't present in the "Upcoming" revision spec to avoid generating
// incorrect "endpoint deleted" changelog entries.
removePathsAndOperationsNotInRevision(baseSpec, revisionSpec)
}

baseSpec.Version = baseMetadata.ActiveVersion
revisionSpec.Version = revisionMetadata.ActiveVersion

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

// removePathsAndOperationsNotInRevision removes paths and operations not in the revision spec.
func removePathsAndOperationsNotInRevision(baseSpec, revisionSpec *load.SpecInfo) {
pathsFromRevision := revisionSpec.Spec.Paths.Map()
for pathKeyFromBase, pathValueFromBase := range baseSpec.Spec.Paths.Map() {
if _, ok := pathsFromRevision[pathKeyFromBase]; !ok {
baseSpec.Spec.Paths.Delete(pathKeyFromBase)
continue
}

operationsFromRevision := pathsFromRevision[pathKeyFromBase].Operations()
for operationKeyFromBase := range pathValueFromBase.Operations() {
if _, ok := operationsFromRevision[operationKeyFromBase]; !ok {
delete(pathValueFromBase.Operations(), operationKeyFromBase)
}
}
}
}

func newOpeAPISpecFromPathAndVersion(path, version string) (*load.SpecInfo, error) {
loader := openapi.NewOpenAPI3().WithExcludedPrivatePaths()
return loader.CreateOpenAPISpecFromPath(fmt.Sprintf("%s/openapi-%s.json", path, version))
Expand Down
13 changes: 6 additions & 7 deletions tools/cli/internal/changelog/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ func (m *Changelog) newPathsFromDeprecatedChanges(
changes []*outputfilter.OasDiffEntry,
changelogPath *[]*Path,
conf map[string]*outputfilter.OperationConfigs) ([]*Path, error) {
depreactedChanges := m.newDeprecatedByNewerVersionOasDiffEntries(changes, conf)
return newMergedChanges(depreactedChanges, changeTypeDeprecated, m.BaseMetadata.ActiveVersion, changelogPath, conf)
deprecatedChanges := m.newDeprecatedByNewerVersionOasDiffEntries(changes, conf)
return newMergedChanges(deprecatedChanges, changeTypeDeprecated, m.BaseMetadata.ActiveVersion, changelogPath, conf)
}

func (m *Changelog) newOasDiffEntries() ([]*outputfilter.OasDiffEntry, error) {
Expand Down Expand Up @@ -252,20 +252,19 @@ func newMergedChanges(changes []*outputfilter.OasDiffEntry,

for _, change := range changes {
pathEntry := newPathEntry(changelogPath, change.Path, change.Operation)
operationdID := change.OperationID
operationID := change.OperationID

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

pathEntry.OperationID = operationdID
pathEntry.OperationID = operationID
pathEntry.Tag = conf.Tag()

pathEntryVersion := newEntryVersion(&pathEntry.Versions, version)
pathEntryVersion.StabilityLevel = stabilityLevelStable
pathEntryVersion.ChangeType = newChangeType(pathEntryVersion.ChangeType, changeType, change.ID)

versionChange := &Change{
Description: change.Text,
Code: change.ID,
Expand Down
Loading
Loading