Allow yaml-anchors in schema (#2200)

## 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
This commit is contained in:
Ilya Kuznetsov 2025-01-23 12:11:44 +01:00 committed by GitHub
parent ba3a400327
commit f60ad32f07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 2 deletions

View File

@ -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)
}

View File

@ -1 +0,0 @@
unknown: value

View File

@ -0,0 +1,11 @@
tags: &job-tags
environment: "some_environment"
resources:
jobs:
db1:
tags:
<<: *job-tags
db2:
tags:
<<: *job-tags

View File

@ -7269,5 +7269,5 @@
"$ref": "#/$defs/github.com/databricks/cli/bundle/config.Workspace"
}
},
"additionalProperties": false
"additionalProperties": {}
}