Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix composed mode duplicate endpoints bug #501

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
11 changes: 11 additions & 0 deletions checker/composed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ func TestComposed_Duplicate(t *testing.T) {
require.Error(t, err)
}

func TestComposed_Issue500(t *testing.T) {
s1 := []*load.SpecInfo{
loadFrom(t, "../data/composed/issue500/", 1),
loadFrom(t, "../data/composed/issue500/", 2),
}

config := diff.NewConfig()
_, _, err := diff.GetPathsDiff(config, s1, s1)
require.NoError(t, err)
}

func TestComposed_CompareMostRecent(t *testing.T) {
s1 := []*load.SpecInfo{
loadFrom(t, "../data/composed/base/", 1),
Expand Down
11 changes: 11 additions & 0 deletions data/composed/issue500/spec1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
openapi: 3.0.3
info:
title: Spec #1
version: "0.1"
paths:
'/test':
get:
summary: GET endpoint
responses:
'200':
description: Success
11 changes: 11 additions & 0 deletions data/composed/issue500/spec2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
openapi: 3.0.3
info:
title: Spec #2
version: "0.1"
paths:
'/test':
post:
summary: POST endpoint
responses:
'200':
description: Success
23 changes: 21 additions & 2 deletions diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func mergedPaths(s1 []*load.SpecInfo, includePathParams bool) (*openapi3.Paths,

p := getPathItem(result, path, includePathParams)
if p == nil {
result.Set(path, pathItem)
result.Set(path, copyPathItem(pathItem))
for _, opItem := range pathItem.Operations() {
operationsSources[opItem] = s.Url
}
Expand Down Expand Up @@ -179,12 +179,31 @@ func mergedPaths(s1 []*load.SpecInfo, includePathParams bool) (*openapi3.Paths,
return nil, nil, fmt.Errorf("duplicate endpoint (%s %s) found in %s and %s. You may add the %s extension to specify order", op, path, operationsSources[oldOperation], s.Url, SinceDateExtension)
}
}

}
}
return result, &operationsSources, nil
}

// copyPathItem returns a shallow copy of the path item
func copyPathItem(pathItem *openapi3.PathItem) *openapi3.PathItem {
return &openapi3.PathItem{
Extensions: pathItem.Extensions,
Ref: pathItem.Ref,
Summary: pathItem.Summary,
Description: pathItem.Description,
Get: pathItem.Get,
Put: pathItem.Put,
Post: pathItem.Post,
Delete: pathItem.Delete,
Options: pathItem.Options,
Head: pathItem.Head,
Patch: pathItem.Patch,
Trace: pathItem.Trace,
Servers: pathItem.Servers,
Parameters: pathItem.Parameters,
}
}

func sinceDateFrom(pathItem openapi3.PathItem, operation openapi3.Operation) (civil.Date, error) {
since, _, err := getSinceDate(pathItem.Extensions)
if err != nil {
Expand Down
Loading