fix: add paths/parent nodes to schemas as well

This commit is contained in:
Tristan Cartledge
2022-12-16 13:39:01 +00:00
committed by Dave Shanley
parent 53789cbc1b
commit c75a1bfaf4
2 changed files with 23 additions and 0 deletions

View File

@@ -722,6 +722,27 @@ paths:
}
}
func TestSpecIndex_schemaComponentsHaveParentsAndPaths(t *testing.T) {
yml := `components:
schemas:
Pet:
type: object
Dog:
type: object`
var rootNode yaml.Node
yaml.Unmarshal([]byte(yml), &rootNode)
index := NewSpecIndex(&rootNode)
schemas := index.GetAllSchemas()
for _, schema := range schemas {
assert.NotNil(t, schema.ParentNode)
assert.Equal(t, fmt.Sprintf("$.components.schemas.%s", schema.Name), schema.Path)
}
}
// Example of how to load in an OpenAPI Specification and index it.
func ExampleNewSpecIndex() {
// define a rootNode to hold our raw spec AST.