Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed panic in path validation (issue #264) #266

Merged
merged 3 commits into from
Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}