INNER CODE UNIT · Go
ConvertAnnotationsToSections
open-policy-agent/conftest · document/metadata.go:85
func ConvertAnnotationsToSections(as ast.FlatAnnotationsRefSet) (Document, error) {
var d Document
var currentDepth = 0
var offset = 1
for i, entry := range as {
// offset at least by one because all path starts with `data.`
depth := len(entry.Path) - offset
// If the user is targeting a submodule we need to adjust the depth an offset base on the first annotation found
if i == 0 && depth > 1 {
offset = depth
}
// We need to compensate for unexpected jump in depth
// otherwise we would start at h3 if no package documentation is present
// or jump form h2 to h4 unexpectedly in subpackages