func()

in code/go/internal/specschema/folder_spec.go [88:138]


func (l *FolderSpecLoader) loadContents(s *folderItemSpec, fs fs.FS, specPath string) error {
	var content *folderItemSpec
	contents := append([]*folderItemSpec{}, s.Contents...)

	for len(contents) > 0 {
		content, contents = contents[0], contents[1:]

		// TODO: Visibility not used at the moment.
		if v := content.Visibility; v != "" && v != visibilityTypePrivate && v != visibilityTypePublic {
			return fmt.Errorf("item [%s] visibility is expected to be private or public, not [%s]", path.Join(specPath, content.Name), content.Visibility)
		}

		// All folders inside a development folder are too.
		if s.DevelopmentFolder {
			content.DevelopmentFolder = true
		}

		if content.Ref != "" {
			// Resolve references.
			switch content.ItemType {
			case spectypes.ItemTypeFile:
				if l.fileSpecLoader == nil {
					break
				}
				specPath := path.Join(path.Dir(specPath), content.Ref)
				options := spectypes.FileSchemaLoadOptions{
					SpecVersion: l.specVersion,
					Limits:      &ItemSpec{content},
					ContentType: content.ContentMediaType,
				}
				schema, err := l.fileSpecLoader.Load(fs, specPath, options)
				if err != nil {
					return fmt.Errorf("could not load schema for %q: %w", path.Dir(specPath), err)
				}
				content.schema = schema
			case spectypes.ItemTypeFolder:
				p := path.Join(path.Dir(specPath), content.Ref)
				err := l.loadFolderSpec(content, p)
				if err != nil {
					return fmt.Errorf("could not load spec for %q: %w", p, err)
				}
			}

		} else if len(content.Contents) > 0 {
			// Walk over folders defined inline.
			contents = append(contents, content.Contents...)
		}
	}

	return nil
}