Skip to content

Commit

Permalink
Merge pull request #627 from k1LoW/fix-server-path
Browse files Browse the repository at this point in the history
Consider the path of `servers:` in OpenAPI Spec and endpoint of HTTP runners for coverage path resolution.
  • Loading branch information
k1LoW authored Oct 8, 2023
2 parents 6679c73 + 8858675 commit 1aa646b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"net/url"
"regexp"
"strings"

Expand Down Expand Up @@ -65,15 +66,21 @@ func (o *operator) collectCoverage(ctx context.Context) (*coverage, error) {
i := ov.doc.Paths.Find(varRep.ReplaceAllString(qRep.ReplaceAllString(p, ""), "{x}"))
if i == nil {
// Find path using router (e.g. /v1/users/1)
const host = "https://runn.test"
for _, s := range ov.doc.Servers {
s.URL = host
for _, server := range ov.doc.Servers {
su, err := url.Parse(server.URL)
if err != nil {
return nil, err
}
su.Host = r.endpoint.Host
su.Opaque = r.endpoint.Opaque
su.Scheme = r.endpoint.Scheme
server.URL = su.String()
}
router, err := legacyrouter.NewRouter(ov.doc)
if err != nil {
return nil, err
}
req, err := http.NewRequest(method, host+p, nil)
req, err := http.NewRequest(method, r.endpoint.String()+p, nil)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 1aa646b

Please sign in to comment.