Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
blva committed Oct 10, 2024
1 parent 03aa2ac commit 0a3ac12
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 48 deletions.
3 changes: 1 addition & 2 deletions tools/cli/internal/changelog/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ func (m *Changelog) newPathsFromDeprecatedChanges(
}

func (m *Changelog) newOasDiffEntries() ([]*outputfilter.OasDiffEntry, error) {
// CLOUDP-267267: @Todo need to add the logic to hide from exceptions
diffResult, err := m.OasDiff.NewDiffResult()
diffResult, err := m.OasDiff.GetFlattenedDiff(m.Base, m.Revision)
if err != nil {
return nil, err
}
Expand Down
46 changes: 0 additions & 46 deletions tools/cli/internal/openapi/oasdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/getkin/kin-openapi/openapi3"
"github.com/mongodb/openapi/tools/cli/internal/openapi/errors"
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/flatten/allof"
"github.com/tufin/oasdiff/load"
)

Expand All @@ -34,51 +33,6 @@ type OasDiff struct {
parser Parser
}

type OasDiffResult struct {
Report *diff.Diff
SourceMap *diff.OperationsSourcesMap
SpecInfoPair *load.SpecInfoPair
}

func (O *OasDiff) NewDiffResult() (*OasDiffResult, error) {

}

func (o OasDiff) NewDiffResult() (*OasDiffResult, error) {
flattenBaseSpec, err := allof.MergeSpec(o.base.Spec)
if err != nil {
return nil, err
}

baseSpecInfo := &load.SpecInfo{
Spec: flattenBaseSpec,
Url: o.base.Url,
Version: o.base.GetVersion(),
}

flattenExternalSpec, err := allof.MergeSpec(o.external.Spec)
if err != nil {
return nil, err
}

externalSpecInfo := &load.SpecInfo{
Spec: flattenExternalSpec,
Url: o.external.Url,
Version: o.external.GetVersion(),
}

diffReport, operationsSources, err := diff.GetWithOperationsSourcesMap(o.config, baseSpecInfo, externalSpecInfo)
if err != nil {
return nil, err
}

return &OasDiffResult{
Report: diffReport,
SourceMap: operationsSources,
SpecInfoPair: load.NewSpecInfoPair(baseSpecInfo, externalSpecInfo),
}, nil
}

func (o OasDiff) mergeSpecIntoBase() (*load.SpecInfo, error) {
if o.external == nil || o.external.Spec == nil {
return o.base, nil
Expand Down
64 changes: 64 additions & 0 deletions tools/cli/internal/openapi/oasdiff_result.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2024 MongoDB Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package openapi

import (
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/flatten/allof"
"github.com/tufin/oasdiff/load"
)

type OasDiffResult struct {
Report *diff.Diff
SourceMap *diff.OperationsSourcesMap
SpecInfoPair *load.SpecInfoPair
Config *diff.Config
}

// GetFlattenedDiff returns the diff between two OpenAPI specs after flattening them.
func (o OasDiff) GetFlattenedDiff(base, revision *load.SpecInfo) (*OasDiffResult, error) {
flattenBaseSpec, err := allof.MergeSpec(base.Spec)
if err != nil {
return nil, err
}

baseSpecInfo := &load.SpecInfo{
Spec: flattenBaseSpec,
Url: base.Url,
Version: base.GetVersion(),
}

flattenExternalSpec, err := allof.MergeSpec(revision.Spec)
if err != nil {
return nil, err
}

revisionSpecInfo := &load.SpecInfo{
Spec: flattenExternalSpec,
Url: revision.Url,
Version: revision.GetVersion(),
}

diffReport, operationsSources, err := diff.GetWithOperationsSourcesMap(o.config, baseSpecInfo, revisionSpecInfo)
if err != nil {
return nil, err
}

return &OasDiffResult{
Report: diffReport,
SourceMap: operationsSources,
SpecInfoPair: load.NewSpecInfoPair(baseSpecInfo, revisionSpecInfo),
}, nil
}

0 comments on commit 0a3ac12

Please sign in to comment.