Skip to content

Commit de2bbc7

Browse files
committed
feat: openapi3: add PathItemMore{}
1 parent 3769065 commit de2bbc7

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

openapi3/path_more.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package openapi3
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"reflect"
7+
8+
oas3 "github.com/getkin/kin-openapi/openapi3"
9+
"github.com/grokify/mogo/net/http/httputilmore"
10+
)
11+
12+
type PathItemMore struct {
13+
PathItem *oas3.PathItem
14+
}
15+
16+
func (pm *PathItemMore) AddPathItemOperations(add *oas3.PathItem, overwriteOpration bool) error {
17+
if add == nil {
18+
return nil
19+
} else if pm.PathItem == nil {
20+
return errors.New("path item is not set")
21+
}
22+
methods := httputilmore.Methods()
23+
for _, method := range methods {
24+
opAdd := add.GetOperation(method)
25+
if opAdd == nil {
26+
continue
27+
} else if overwriteOpration {
28+
pm.PathItem.SetOperation(method, opAdd)
29+
} else {
30+
opSrc := pm.PathItem.GetOperation(method)
31+
if opSrc == nil {
32+
pm.PathItem.SetOperation(method, opAdd)
33+
} else if !reflect.DeepEqual(opAdd, opSrc) {
34+
return fmt.Errorf("operation collision on op id (%s)", opSrc.OperationID)
35+
}
36+
}
37+
}
38+
return nil
39+
}

0 commit comments

Comments
 (0)