Skip to content

Commit

Permalink
Allow yaml-anchors in schema (#2200)
Browse files Browse the repository at this point in the history
## Changes

Allows custom untyped fields in the root config in json-schema so it
doesn't highlight errors when using yaml-anchors.

Example use case:

```
tags: &job-tags
  environment: ${bundle.target}


resources:
  jobs:
    db1:
      tags:
        <<: *job-tags
    db1:
      tags:
        <<: *job-tags
```
  
One downside is that we don't highlight any unknown top-level properties
anymore (but they will still fail during CLI validation)

## Tests

Manually checked behavior in VSCode - it doesn't show validation error.
Also checked that other typed properties are still suggested
  • Loading branch information
ilyakuz-db authored Jan 23, 2025
1 parent ba3a400 commit f60ad32
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
9 changes: 9 additions & 0 deletions bundle/internal/schema/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ func generateSchema(workdir, outputFile string) {
a.addAnnotations,
addInterpolationPatterns,
})

// AdditionalProperties is set to an empty schema to allow non-typed keys used as yaml-anchors
// Example:
// some_anchor: &some_anchor
// file_path: /some/path/
// workspace:
// <<: *some_anchor
s.AdditionalProperties = jsonschema.Schema{}

if err != nil {
log.Fatal(err)
}
Expand Down

This file was deleted.

11 changes: 11 additions & 0 deletions bundle/internal/schema/testdata/pass/yaml_anchors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
tags: &job-tags
environment: "some_environment"

resources:
jobs:
db1:
tags:
<<: *job-tags
db2:
tags:
<<: *job-tags
2 changes: 1 addition & 1 deletion bundle/schema/jsonschema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f60ad32

Please sign in to comment.