Skip to content

Commit

Permalink
feat: openapi3edit: add OperationMore.PathMethod(), `OperationMoreS…
Browse files Browse the repository at this point in the history
…et.SummariesMap()`
  • Loading branch information
grokify committed Oct 19, 2022
1 parent 7c87fb6 commit 2ed1d4d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions openapi3edit/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ func (opm *OperationMore) HasParameter(paramNameWant string) bool {
return false
}

func (opm *OperationMore) PathMethod() string {
parts := []string{}
p := strings.TrimSpace(opm.Path)
if len(p) > 0 {
parts = append(parts, p)
}
m := strings.ToUpper(strings.TrimSpace(opm.Method))
if len(m) > 0 {
parts = append(parts, m)
}
return strings.Join(parts, " ")
}

func (opm *OperationMore) AddToSpec(spec *openapi3.Spec, force bool) (bool, error) {
sm := openapi3.SpecMore{Spec: spec}
op, err := sm.OperationByPathMethod(opm.Path, opm.Method)
Expand Down Expand Up @@ -286,6 +299,16 @@ type OperationMoreSet struct {
OperationMores []OperationMore
}

// SummariesMap returns a `map[string]string` where the keys are the operation's
// path and method, while the values are the sumamries.`
func (omSet *OperationMoreSet) SummariesMap() map[string]string {
mss := map[string]string{}
for _, om := range omSet.OperationMores {
mss[om.PathMethod()] = om.Operation.Summary
}
return mss
}

func QueryOperationsByTags(spec *openapi3.Spec, tags []string) *OperationMoreSet {
tagsWantMatch := map[string]int{}
for _, tag := range tags {
Expand Down

0 comments on commit 2ed1d4d

Please sign in to comment.