mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-02 06:41:18 +00:00
67d76248a3
Signed-off-by: jolheiser <john.olheiser@gmail.com>
35 lines
791 B
Go
35 lines
791 B
Go
package schema
|
|
|
|
import (
|
|
_ "embed"
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/xeipuuv/gojsonschema"
|
|
|
|
"github.com/woodpecker-ci/woodpecker/shared/yml"
|
|
)
|
|
|
|
//go:embed schema.json
|
|
var schemaDefinition []byte
|
|
|
|
// Lint lints an io.Reader against the Woodpecker schema.json
|
|
func Lint(r io.Reader) ([]gojsonschema.ResultError, error) {
|
|
schemaLoader := gojsonschema.NewBytesLoader(schemaDefinition)
|
|
j, err := yml.LoadYmlReaderAsJSON(r)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Failed to load yml file %w", err)
|
|
}
|
|
|
|
documentLoader := gojsonschema.NewBytesLoader(j)
|
|
result, err := gojsonschema.Validate(schemaLoader, documentLoader)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Validation failed %w", err)
|
|
}
|
|
|
|
if !result.Valid() {
|
|
return result.Errors(), fmt.Errorf("Config not valid")
|
|
}
|
|
|
|
return nil, nil
|
|
}
|