mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-10 20:47:44 +00:00
fix: add missing path and parent node to paths index references
This commit is contained in:
committed by
quobix
parent
93f591d4a4
commit
06f6b243a8
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
test-operation.yaml
|
||||
@@ -14,12 +14,13 @@ package index
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/pb33f/libopenapi/utils"
|
||||
"github.com/vmware-labs/yaml-jsonpath/pkg/yamlpath"
|
||||
"golang.org/x/sync/syncmap"
|
||||
"gopkg.in/yaml.v3"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// NewSpecIndexWithConfig will create a new index of an OpenAPI or Swagger spec. It uses the same logic as NewSpecIndex
|
||||
@@ -215,7 +216,6 @@ func (index *SpecIndex) GetOperationParameterReferences() map[string]map[string]
|
||||
// The first elements of at the top of the slice, are all the inline references (using GetAllInlineSchemas),
|
||||
// and then following on are all the references extracted from the components section (using GetAllComponentSchemas).
|
||||
func (index *SpecIndex) GetAllSchemas() []*Reference {
|
||||
|
||||
componentSchemas := index.GetAllComponentSchemas()
|
||||
inlineSchemas := index.GetAllInlineSchemas()
|
||||
|
||||
@@ -929,6 +929,8 @@ func (index *SpecIndex) GetOperationCount() int {
|
||||
Definition: m.Value,
|
||||
Name: m.Value,
|
||||
Node: method.Content[y+1],
|
||||
Path: fmt.Sprintf("$.paths.%s.%s", p.Value, m.Value),
|
||||
ParentNode: m,
|
||||
}
|
||||
index.pathRefsLock.Lock()
|
||||
if index.pathRefs[p.Value] == nil {
|
||||
|
||||
@@ -102,7 +102,6 @@ func TestSpecIndex_DigitalOcean(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSpecIndex_DigitalOcean_FullCheckoutLocalResolve(t *testing.T) {
|
||||
|
||||
// this is a full checkout of the digitalocean API repo.
|
||||
tmp, _ := os.MkdirTemp("", "openapi")
|
||||
cmd := exec.Command("git", "clone", "https://github.com/digitalocean/openapi", tmp)
|
||||
@@ -138,7 +137,6 @@ func TestSpecIndex_DigitalOcean_FullCheckoutLocalResolve(t *testing.T) {
|
||||
|
||||
ref = index.SearchIndexForReference("../models/options.yml")
|
||||
assert.NotNil(t, ref)
|
||||
|
||||
}
|
||||
|
||||
func TestSpecIndex_DigitalOcean_LookupsNotAllowed(t *testing.T) {
|
||||
@@ -341,7 +339,6 @@ func TestSpecIndex_BurgerShop(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSpecIndex_GetAllParametersFromOperations(t *testing.T) {
|
||||
|
||||
yml := `openapi: 3.0.0
|
||||
servers:
|
||||
- url: http://localhost:8080
|
||||
@@ -667,7 +664,6 @@ func TestSpecIndex_lookupRemoteReference_NoComponent(t *testing.T) {
|
||||
|
||||
// Discovered in issue https://github.com/daveshanley/vacuum/issues/225
|
||||
func TestSpecIndex_lookupFileReference_NoComponent(t *testing.T) {
|
||||
|
||||
cwd, _ := os.Getwd()
|
||||
index := new(SpecIndex)
|
||||
index.config = &SpecIndexConfig{BasePath: cwd}
|
||||
@@ -683,7 +679,6 @@ func TestSpecIndex_lookupFileReference_NoComponent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSpecIndex_CheckBadURLRef(t *testing.T) {
|
||||
|
||||
yml := `openapi: 3.1.0
|
||||
paths:
|
||||
/cakes:
|
||||
@@ -700,7 +695,6 @@ paths:
|
||||
}
|
||||
|
||||
func TestSpecIndex_CheckBadURLRefNoRemoteAllowed(t *testing.T) {
|
||||
|
||||
yml := `openapi: 3.1.0
|
||||
paths:
|
||||
/cakes:
|
||||
@@ -720,7 +714,6 @@ paths:
|
||||
}
|
||||
|
||||
func TestSpecIndex_CheckIndexDiscoversNoComponentLocalFileReference(t *testing.T) {
|
||||
|
||||
_ = ioutil.WriteFile("coffee-time.yaml", []byte("name: time for coffee"), 0o664)
|
||||
defer os.Remove("coffee-time.yaml")
|
||||
|
||||
@@ -975,7 +968,6 @@ paths:
|
||||
assert.Len(t, idx.paramInlineDuplicateNames, 2)
|
||||
assert.Len(t, idx.operationParamErrors, 0)
|
||||
assert.Len(t, idx.refErrors, 0)
|
||||
|
||||
}
|
||||
|
||||
func TestSpecIndex_ParamsWithDuplicateNamesAndSameInTypes(t *testing.T) {
|
||||
@@ -1107,3 +1099,47 @@ func ExampleNewSpecIndex() {
|
||||
// 1516 enums
|
||||
// 828 polymorphic references
|
||||
}
|
||||
|
||||
func TestSpecIndex_GetAllPathsHavePathAndParent(t *testing.T) {
|
||||
yml := `openapi: 3.1.0
|
||||
info:
|
||||
title: Test
|
||||
version: 0.0.1
|
||||
servers:
|
||||
- url: http://localhost:35123
|
||||
paths:
|
||||
/test:
|
||||
get:
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
post:
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
/test2:
|
||||
delete:
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
put:
|
||||
responses:
|
||||
"200":
|
||||
description: OK`
|
||||
|
||||
var rootNode yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(yml), &rootNode)
|
||||
|
||||
idx := NewSpecIndexWithConfig(&rootNode, CreateOpenAPIIndexConfig())
|
||||
|
||||
paths := idx.GetAllPaths()
|
||||
|
||||
assert.Equal(t, "$.paths./test.get", paths["/test"]["get"].Path)
|
||||
assert.Equal(t, 9, paths["/test"]["get"].ParentNode.Line)
|
||||
assert.Equal(t, "$.paths./test.post", paths["/test"]["post"].Path)
|
||||
assert.Equal(t, 13, paths["/test"]["post"].ParentNode.Line)
|
||||
assert.Equal(t, "$.paths./test2.delete", paths["/test2"]["delete"].Path)
|
||||
assert.Equal(t, 18, paths["/test2"]["delete"].ParentNode.Line)
|
||||
assert.Equal(t, "$.paths./test2.put", paths["/test2"]["put"].Path)
|
||||
assert.Equal(t, 22, paths["/test2"]["put"].ParentNode.Line)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user