Skip to content

Commit

Permalink
Adds Inline JSON schema reference in func.yaml
Browse files Browse the repository at this point in the history
Signed-off-by: KapilSareen <[email protected]>
  • Loading branch information
KapilSareen committed Feb 27, 2025
1 parent d4cfaa9 commit 9250e2b
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pkg/functions/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,27 @@ func (f Function) Write() (err error) {
}
// TODO: open existing file for writing, such that existing permissions
// are preserved?
err = os.WriteFile(filepath.Join(f.Root, FunctionFile), bb, 0644)
rwFile, err := os.OpenFile(filepath.Join(f.Root, FunctionFile), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return
return err
}
defer rwFile.Close()

tagVersion := f.SpecVersion
fmt.Println("tagVersion: ", tagVersion)

// Write schema header
schemaHeader := fmt.Sprintf(`# $schema: https://raw.githubusercontent.com/knative/func/refs/tags/v%s/schema/func_yaml-schema.json
# yaml-language-server: $schema=https://raw.githubusercontent.com/knative/func/refs/tags/v%s/schema/func_yaml-schema.json
`, tagVersion, tagVersion)

if _, err = rwFile.WriteString(schemaHeader); err != nil {
return err
}

// Write function data
if _, err = rwFile.Write(bb); err != nil {
return err
}

// Write local settings
Expand Down

0 comments on commit 9250e2b

Please sign in to comment.