Skip to content

Commit

Permalink
fixed panic in path validation (issue #264) (#266)
Browse files Browse the repository at this point in the history
Co-authored-by: Samuel Monderer <samuelmo@radware.com>
  • Loading branch information
schmilmo and Samuel Monderer committed Nov 15, 2020
1 parent 2e4cbb2 commit da714f4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions openapi3/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ func (paths Paths) Validate(c context.Context) error {
return fmt.Errorf("path %q does not start with a forward slash (/)", path)
}

if pathItem == nil {
paths[path] = &PathItem{}
pathItem = paths[path]
}

normalizedPath, pathParamsCount := normalizeTemplatedPath(path)
if oldPath, ok := normalizedPaths[normalizedPath]; ok {
return fmt.Errorf("conflicting paths %q and %q", path, oldPath)
Expand Down
28 changes: 28 additions & 0 deletions openapi3/paths_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package openapi3

import (
"context"
"testing"

"github.com/stretchr/testify/require"
)

var emptyPathSpec = `
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
`

func TestPathValidate(t *testing.T) {
swagger, err := NewSwaggerLoader().LoadSwaggerFromData([]byte(emptyPathSpec))
require.NoError(t, err)
err = swagger.Paths.Validate(context.Background())
require.NoError(t, err)
}

0 comments on commit da714f4

Please sign in to comment.