Skip to content

Commit d0d2847

Browse files
committed
Adds Inline JSON schema reference in func.yaml
Signed-off-by: KapilSareen <kapilsareen584@gmail.com>
1 parent d4cfaa9 commit d0d2847

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

pkg/functions/function.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,26 @@ func (f Function) Write() (err error) {
428428
}
429429
// TODO: open existing file for writing, such that existing permissions
430430
// are preserved?
431-
err = os.WriteFile(filepath.Join(f.Root, FunctionFile), bb, 0644)
431+
rwFile, err := os.OpenFile(filepath.Join(f.Root, FunctionFile), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
432432
if err != nil {
433-
return
433+
return err
434+
}
435+
defer rwFile.Close()
436+
437+
tagVersion := f.SpecVersion
438+
439+
// Write schema header
440+
schemaHeader := fmt.Sprintf(`# $schema: https://raw.githubusercontent.com/knative/func/refs/tags/v%s/schema/func_yaml-schema.json
441+
# yaml-language-server: $schema=https://raw.githubusercontent.com/knative/func/refs/tags/v%s/schema/func_yaml-schema.json
442+
`, tagVersion, tagVersion)
443+
444+
if _, err = rwFile.WriteString(schemaHeader); err != nil {
445+
return err
446+
}
447+
448+
// Write function data
449+
if _, err = rwFile.Write(bb); err != nil {
450+
return err
434451
}
435452

436453
// Write local settings

0 commit comments

Comments
 (0)