mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 20:47:49 +00:00
Bumping coverage on 0.6.0
This commit is contained in:
@@ -296,11 +296,9 @@ func (index *SpecIndex) performExternalLookup(uri []string, componentId string,
|
|||||||
} else {
|
} else {
|
||||||
j, _ = url.Parse(uri[0])
|
j, _ = url.Parse(uri[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
path := GenerateCleanSpecConfigBaseURL(j, uri[0], false)
|
path := GenerateCleanSpecConfigBaseURL(j, uri[0], false)
|
||||||
|
newUrl, _ := url.Parse(path)
|
||||||
newUrl, e := url.Parse(path)
|
if newUrl != nil {
|
||||||
if e == nil {
|
|
||||||
newConfig := &SpecIndexConfig{
|
newConfig := &SpecIndexConfig{
|
||||||
BaseURL: newUrl,
|
BaseURL: newUrl,
|
||||||
AllowRemoteLookup: index.config.AllowRemoteLookup,
|
AllowRemoteLookup: index.config.AllowRemoteLookup,
|
||||||
@@ -318,9 +316,6 @@ func (index *SpecIndex) performExternalLookup(uri []string, componentId string,
|
|||||||
index.AddChild(newIndex)
|
index.AddChild(newIndex)
|
||||||
index.refLock.Unlock()
|
index.refLock.Unlock()
|
||||||
externalSpecIndex = newIndex
|
externalSpecIndex = newIndex
|
||||||
|
|
||||||
} else {
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
101
index/find_component_test.go
Normal file
101
index/find_component_test.go
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
// Copyright 2023 Princess B33f Heavy Industries / Dave Shanley
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package index
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSpecIndex_performExternalLookup(t *testing.T) {
|
||||||
|
yml := `{
|
||||||
|
"openapi": "3.1.0",
|
||||||
|
"paths": [
|
||||||
|
{"/": {
|
||||||
|
"get": {}
|
||||||
|
}}
|
||||||
|
]
|
||||||
|
}`
|
||||||
|
var rootNode yaml.Node
|
||||||
|
_ = yaml.Unmarshal([]byte(yml), &rootNode)
|
||||||
|
|
||||||
|
c := CreateOpenAPIIndexConfig()
|
||||||
|
index := NewSpecIndexWithConfig(&rootNode, c)
|
||||||
|
assert.Len(t, index.GetPathsNode().Content, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSpecIndex_performExternalLookup_invalidURL(t *testing.T) {
|
||||||
|
yml := `openapi: 3.1.0
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
thing:
|
||||||
|
properties:
|
||||||
|
thong:
|
||||||
|
$ref: 'httpssss://not-gonna-work.com'`
|
||||||
|
var rootNode yaml.Node
|
||||||
|
_ = yaml.Unmarshal([]byte(yml), &rootNode)
|
||||||
|
|
||||||
|
c := CreateOpenAPIIndexConfig()
|
||||||
|
index := NewSpecIndexWithConfig(&rootNode, c)
|
||||||
|
assert.Len(t, index.GetReferenceIndexErrors(), 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSpecIndex_FindComponentInRoot(t *testing.T) {
|
||||||
|
yml := `openapi: 3.1.0
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
thing:
|
||||||
|
properties:
|
||||||
|
thong: hi!`
|
||||||
|
var rootNode yaml.Node
|
||||||
|
_ = yaml.Unmarshal([]byte(yml), &rootNode)
|
||||||
|
|
||||||
|
c := CreateOpenAPIIndexConfig()
|
||||||
|
index := NewSpecIndexWithConfig(&rootNode, c)
|
||||||
|
|
||||||
|
thing := index.FindComponentInRoot("#/$splish/$.../slash#$///./")
|
||||||
|
assert.Nil(t, thing)
|
||||||
|
assert.Len(t, index.GetReferenceIndexErrors(), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSpecIndex_FailLookupRemoteComponent_badPath(t *testing.T) {
|
||||||
|
yml := `openapi: 3.1.0
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
thing:
|
||||||
|
properties:
|
||||||
|
thong:
|
||||||
|
$ref: 'https://pb33f.io/site.webmanifest#/....$.ok../oh#/$$_-'`
|
||||||
|
|
||||||
|
var rootNode yaml.Node
|
||||||
|
_ = yaml.Unmarshal([]byte(yml), &rootNode)
|
||||||
|
|
||||||
|
c := CreateOpenAPIIndexConfig()
|
||||||
|
index := NewSpecIndexWithConfig(&rootNode, c)
|
||||||
|
|
||||||
|
thing := index.FindComponentInRoot("#/$splish/$.../slash#$///./")
|
||||||
|
assert.Nil(t, thing)
|
||||||
|
assert.Len(t, index.GetReferenceIndexErrors(), 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSpecIndex_FailLookupRemoteComponent_Ok_butNotFound(t *testing.T) {
|
||||||
|
yml := `openapi: 3.1.0
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
thing:
|
||||||
|
properties:
|
||||||
|
thong:
|
||||||
|
$ref: 'https://pb33f.io/site.webmanifest#/valid-but-missing'`
|
||||||
|
|
||||||
|
var rootNode yaml.Node
|
||||||
|
_ = yaml.Unmarshal([]byte(yml), &rootNode)
|
||||||
|
|
||||||
|
c := CreateOpenAPIIndexConfig()
|
||||||
|
index := NewSpecIndexWithConfig(&rootNode, c)
|
||||||
|
|
||||||
|
thing := index.FindComponentInRoot("#/valid-but-missing")
|
||||||
|
assert.Nil(t, thing)
|
||||||
|
assert.Len(t, index.GetReferenceIndexErrors(), 1)
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ func TestSpecIndex_SearchIndexForReference(t *testing.T) {
|
|||||||
assert.NotNil(t, ref)
|
assert.NotNil(t, ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSpecIndex_SearchIndexForReferene_ExternalSpecs(t *testing.T) {
|
func TestSpecIndex_SearchIndexForReference_ExternalSpecs(t *testing.T) {
|
||||||
|
|
||||||
// load up an index with lots of references
|
// load up an index with lots of references
|
||||||
petstore, _ := ioutil.ReadFile("../test_specs/digitalocean.yaml")
|
petstore, _ := ioutil.ReadFile("../test_specs/digitalocean.yaml")
|
||||||
@@ -46,4 +46,8 @@ func TestSpecIndex_SearchIndexForReferene_ExternalSpecs(t *testing.T) {
|
|||||||
assert.NotNil(t, ref)
|
assert.NotNil(t, ref)
|
||||||
assert.Equal(t, "description", ref[0].Node.Content[0].Value)
|
assert.Equal(t, "description", ref[0].Node.Content[0].Value)
|
||||||
|
|
||||||
|
ref = idx.SearchIndexForReference("../models/options.yml")
|
||||||
|
assert.NotNil(t, ref)
|
||||||
|
assert.Equal(t, "kubernetes_options", ref[0].Node.Content[0].Value)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -546,21 +546,6 @@ func TestSpecIndex_FindComponenth(t *testing.T) {
|
|||||||
assert.Nil(t, index.FindComponent("I-do-not-exist", nil))
|
assert.Nil(t, index.FindComponent("I-do-not-exist", nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSpecIndex_performExternalLookup(t *testing.T) {
|
|
||||||
yml := `{
|
|
||||||
"openapi": "3.1.0",
|
|
||||||
"paths": [
|
|
||||||
{"/": {
|
|
||||||
"get": {}
|
|
||||||
}}
|
|
||||||
]
|
|
||||||
}`
|
|
||||||
var rootNode yaml.Node
|
|
||||||
yaml.Unmarshal([]byte(yml), &rootNode)
|
|
||||||
|
|
||||||
index := NewSpecIndex(&rootNode)
|
|
||||||
assert.Len(t, index.GetPathsNode().Content, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSpecIndex_TestPathsNodeAsArray(t *testing.T) {
|
func TestSpecIndex_TestPathsNodeAsArray(t *testing.T) {
|
||||||
yml := `components:
|
yml := `components:
|
||||||
|
|||||||
@@ -25,3 +25,9 @@ func TestGenerateCleanSpecConfigBaseURL_RelativeDeep(t *testing.T) {
|
|||||||
assert.Equal(t, "https://pb33f.io/things/stuff/foo/bar/baz/crap.yaml#thang",
|
assert.Equal(t, "https://pb33f.io/things/stuff/foo/bar/baz/crap.yaml#thang",
|
||||||
GenerateCleanSpecConfigBaseURL(u, path, true))
|
GenerateCleanSpecConfigBaseURL(u, path, true))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSpecIndex_extractDefinitionRequiredRefProperties(t *testing.T) {
|
||||||
|
c := CreateOpenAPIIndexConfig()
|
||||||
|
idx := NewSpecIndexWithConfig(nil, c)
|
||||||
|
assert.Nil(t, idx.extractDefinitionRequiredRefProperties(nil, nil))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user