Skip to content

Commit 6db8694

Browse files
CLOUDP-276602: FOASCLI: Improve the error message in the event of conflicts (#308)
1 parent 914ff72 commit 6db8694

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

tools/cli/internal/openapi/errors/merge_conflict_error.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,27 @@ func (e ResponseConflictError) Error() string {
4646
}
4747

4848
type SchemaConflictError struct {
49-
Entry string
49+
Entry string
50+
BaseSpecLocation string
51+
ExternalSpecLocation string
5052
}
5153

5254
func (e SchemaConflictError) Error() string {
53-
return fmt.Sprintf("there was a conflict on a Schema component: %q", e.Entry)
55+
return fmt.Sprintf("there was a conflict on a Schema component: %q. Base Spec: %q, External Spec: %q",
56+
e.Entry, e.BaseSpecLocation, e.ExternalSpecLocation)
5457
}
5558

5659
type TagConflictError struct {
57-
Entry string
58-
Description string
60+
Entry string
61+
Description string
62+
BaseSpecLocation string
63+
ExternalSpecLocation string
5964
}
6065

6166
func (e TagConflictError) Error() string {
62-
return fmt.Sprintf("there was a conflict with the Tag %q with the description: %q", e.Entry, e.Description)
67+
return fmt.Sprintf(
68+
"there was a conflict with the Tag %q with the description: %q. Base Spec: %q, External Spec: %q",
69+
e.Entry, e.Description, e.BaseSpecLocation, e.ExternalSpecLocation)
6370
}
6471

6572
type PathDocsDiffConflictError struct {

tools/cli/internal/openapi/oasdiff.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,10 @@ func (o OasDiff) mergeTags() error {
297297
baseTags = append(baseTags, v)
298298
} else {
299299
return errors.TagConflictError{
300-
Entry: v.Name,
301-
Description: v.Description,
300+
Entry: v.Name,
301+
Description: v.Description,
302+
BaseSpecLocation: o.base.Url,
303+
ExternalSpecLocation: o.external.Url,
302304
}
303305
}
304306
}
@@ -419,7 +421,9 @@ func (o OasDiff) mergeSchemas() error {
419421

420422
// The schemas have the same name but different definitions
421423
return errors.SchemaConflictError{
422-
Entry: k,
424+
Entry: k,
425+
BaseSpecLocation: o.base.Url,
426+
ExternalSpecLocation: o.external.Url,
423427
}
424428
}
425429
}

tools/cli/internal/openapi/openapi3.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func (o *OpenAPI3) WithExcludedPrivatePaths() *OpenAPI3 {
4848
func (o *OpenAPI3) CreateOpenAPISpecFromPath(path string) (*load.SpecInfo, error) {
4949
o.Loader.IsExternalRefsAllowed = o.IsExternalRefsAllowed
5050
spec, err := load.NewSpecInfo(o.Loader, load.NewSource(path))
51+
spec.Url = path
5152
if err != nil {
5253
return nil, err
5354
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cli
22

33
import (
44
"bytes"
5+
"fmt"
56
"os"
67
"os/exec"
78
"testing"
@@ -100,7 +101,9 @@ func TestMerge(t *testing.T) {
100101
resp, err := cmd.CombinedOutput()
101102
stringResponse := string(resp)
102103
require.Error(t, err, stringResponse)
103-
assert.Contains(t, stringResponse, "Error: there was a conflict with the Tag \"Events\" with the description: \"Returns information about the MongoDB Atlas Specification.\"") //nolint:lll // Line is over 120 characters
104+
assert.Contains(t, stringResponse, fmt.Sprintf("Error: there was a conflict with the Tag \"Events\""+
105+
" with the description: \"Returns information about the MongoDB Atlas Specification.\"."+
106+
" Base Spec: %q, External Spec: %q", base, authnSpec))
104107
})
105108

106109
t.Run("Expecting Error: not identical component", func(t *testing.T) {
@@ -122,6 +125,9 @@ func TestMerge(t *testing.T) {
122125
resp, err := cmd.CombinedOutput()
123126
stringResponse := string(resp)
124127
require.Error(t, err, stringResponse)
125-
assert.Contains(t, stringResponse, "Error: there was a conflict on a Schema component: \"ApiError\"")
128+
assert.Contains(t, stringResponse,
129+
fmt.Sprintf(
130+
"Error: there was a conflict on a Schema component: \"ApiError\". Base Spec: %q, "+
131+
"External Spec: %q", base, apiRegistrySpec))
126132
})
127133
}

0 commit comments

Comments
 (0)