From 8c0c19f6fe8babc35c11b0c85a3b7879fa49a462 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Tue, 19 Mar 2024 13:47:14 +0900 Subject: [PATCH] Added test for panic when path is missing --- paths/paths_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/paths/paths_test.go b/paths/paths_test.go index 4437223..5eff42f 100644 --- a/paths/paths_test.go +++ b/paths/paths_test.go @@ -634,3 +634,28 @@ paths: assert.Equal(t, "two", pathItem.Post.OperationId) } + +func TestNewValidator_FindPathMissingWithBaseURLInServer(t *testing.T) { + + spec := `openapi: 3.1.0 +servers: + - url: 'https://things.com/' +paths: + /dishy: + get: + operationId: one +` + + doc, err := libopenapi.NewDocument([]byte(spec)) + if err != nil { + t.Fatal(err) + } + m, _ := doc.BuildV3Model() + + request, _ := http.NewRequest(http.MethodGet, "https://things.com/not_here", nil) + + _, errs, _ := FindPath(request, &m.Model) + assert.Len(t, errs, 1) + assert.Equal(t, "GET Path '/not_here' not found", errs[0].Message) + +}