Skip to content

Commit

Permalink
support slash server
Browse files Browse the repository at this point in the history
  • Loading branch information
emilien-puget committed Apr 10, 2024
1 parent 29ed98d commit 169688e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions paths/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ func StripRequestPath(request *http.Request, document *v3.Document) string {
if request.URL.Fragment != "" {
stripped = fmt.Sprintf("%s#%s", stripped, request.URL.Fragment)
}
if len(stripped) > 0 && !strings.HasPrefix(stripped, "/") {
stripped = "/" + stripped
}
return stripped
}

Expand Down
31 changes: 31 additions & 0 deletions validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/pb33f/libopenapi"
"github.com/pb33f/libopenapi-validator/helpers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestNewValidator(t *testing.T) {
Expand Down Expand Up @@ -149,6 +150,36 @@ paths:

}

func TestNewValidator_slash_server_url(t *testing.T) {

spec := `openapi: 3.1.0
servers:
- url: /
paths:
/burgers/{burgerId}/locate:
patch:
operationId: locateBurger
parameters:
- name: burgerId
in: path
required: true
schema:
type: string
format: uuid
`

doc, err := libopenapi.NewDocument([]byte(spec))
require.NoError(t, err)

request, _ := http.NewRequest(http.MethodPatch, "https://things.com/burgers/edd0189c-420b-489c-98f2-0facc5a26f3a/locate", nil)
v, _ := NewValidator(doc)

valid, errors := v.ValidateHttpRequest(request)

assert.True(t, valid)
assert.Len(t, errors, 0)
}

func TestNewValidator_ValidateHttpRequest_SetPath_ValidPostSimpleSchema(t *testing.T) {

spec := `openapi: 3.1.0
Expand Down

0 comments on commit 169688e

Please sign in to comment.