Updated index to count schemas, even if they are refs.

This was brought up in chat, that the expectation is that all schemas are included, refs or not. This update fixes that for the index and adds in a new individual property to count just the references `GetAllReferenceSchemas `

Signed-off-by: Dave Shanley <dave@quobix.com>
This commit is contained in:
Dave Shanley
2023-08-09 07:32:41 -04:00
committed by quobix
parent 832f3765c9
commit f7ab737f0a
5 changed files with 57 additions and 31 deletions

View File

@@ -125,32 +125,33 @@ components:
assert.Len(t, index.GetReferenceIndexErrors(), 1)
}
func TestSpecIndex_LocateRemoteDocsWithNoBaseURLSupplied(t *testing.T) {
// This test will push the index to do try and locate remote references that use relative references
spec := `openapi: 3.0.2
info:
title: Test
version: 1.0.0
paths:
/test:
get:
parameters:
- $ref: "https://schemas.opengis.net/ogcapi/features/part2/1.0/openapi/ogcapi-features-2.yaml#/components/parameters/crs"`
var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(spec), &rootNode)
c := CreateOpenAPIIndexConfig()
index := NewSpecIndexWithConfig(&rootNode, c)
// extract crs param from index
crsParam := index.GetMappedReferences()["https://schemas.opengis.net/ogcapi/features/part2/1.0/openapi/ogcapi-features-2.yaml#/components/parameters/crs"]
assert.NotNil(t, crsParam)
assert.True(t, crsParam.IsRemote)
assert.Equal(t, "crs", crsParam.Node.Content[1].Value)
assert.Equal(t, "query", crsParam.Node.Content[3].Value)
assert.Equal(t, "form", crsParam.Node.Content[9].Value)
}
// disabled test because remote host is flaky.
//func TestSpecIndex_LocateRemoteDocsWithNoBaseURLSupplied(t *testing.T) {
// // This test will push the index to do try and locate remote references that use relative references
// spec := `openapi: 3.0.2
//info:
// title: Test
// version: 1.0.0
//paths:
// /test:
// get:
// parameters:
// - $ref: "https://schemas.opengis.net/ogcapi/features/part2/1.0/openapi/ogcapi-features-2.yaml#/components/parameters/crs"`
//
// var rootNode yaml.Node
// _ = yaml.Unmarshal([]byte(spec), &rootNode)
//
// c := CreateOpenAPIIndexConfig()
// index := NewSpecIndexWithConfig(&rootNode, c)
//
// // extract crs param from index
// crsParam := index.GetMappedReferences()["https://schemas.opengis.net/ogcapi/features/part2/1.0/openapi/ogcapi-features-2.yaml#/components/parameters/crs"]
// assert.NotNil(t, crsParam)
// assert.True(t, crsParam.IsRemote)
// assert.Equal(t, "crs", crsParam.Node.Content[1].Value)
// assert.Equal(t, "query", crsParam.Node.Content[3].Value)
// assert.Equal(t, "form", crsParam.Node.Content[9].Value)
//}
func TestSpecIndex_LocateRemoteDocsWithRemoteURLHandler(t *testing.T) {
// This test will push the index to do try and locate remote references that use relative references