Skip to content

Commit 3a3076d

Browse files
authored
Output deprecated annotations in the JSON schema (#2422)
## Changes Start outputting `deprecated` and `deprecationMessage` annotations in the JSON schema ## Why So that deprecated fields are shown as deprecated in VSCode (and other editors) ## Tests - manually tested |||| |---|---|---| |<img width="682" alt="Screenshot 2025-03-03 at 16 04 21" src="https://github.com/user-attachments/assets/9712aa2f-0f41-48a9-8bd0-ec92b8b75c3f" />|<img width="682" alt="Screenshot 2025-03-03 at 16 04 29" src="https://github.com/user-attachments/assets/a14f3523-ad85-4fed-96d7-2a8cf3a458e5" />|<img width="682" alt="Screenshot 2025-03-03 at 16 06 03" src="https://github.com/user-attachments/assets/b9ab1050-048e-4c14-b183-96d615a4fbc1" />|
1 parent a26461c commit 3a3076d

File tree

10 files changed

+47
-15
lines changed

10 files changed

+47
-15
lines changed

.github/workflows/push.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ jobs:
145145
go run main.go bundle schema > schema.json
146146
147147
# Add markdownDescription keyword to ajv
148-
echo "module.exports=function(a){a.addKeyword('markdownDescription')}" >> keywords.js
148+
echo "module.exports = function(a) {
149+
a.addKeyword('markdownDescription');
150+
a.addKeyword('deprecationMessage');
151+
}" >> keywords.js
149152
150153
for file in ./bundle/internal/schema/testdata/pass/*.yml; do
151154
ajv test -s schema.json -d $file --valid -c=./keywords.js

bundle/config/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type Root struct {
5252
Targets map[string]*Target `json:"targets,omitempty"`
5353

5454
// DEPRECATED. Left for backward compatibility with Targets
55-
Environments map[string]*Target `json:"environments,omitempty" bundle:"deprecated"`
55+
Environments map[string]*Target `json:"environments,omitempty"`
5656

5757
// Sync section specifies options for files synchronization
5858
Sync Sync `json:"sync,omitempty"`

bundle/internal/annotation/descriptor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type Descriptor struct {
77
Default any `json:"default,omitempty"`
88
Enum []any `json:"enum,omitempty"`
99
MarkdownExamples string `json:"markdown_examples,omitempty"`
10+
DeprecationMessage string `json:"deprecation_message,omitempty"`
1011
}
1112

1213
const Placeholder = "PLACEHOLDER"

bundle/internal/schema/annotations.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ func assignAnnotation(s *jsonschema.Schema, a annotation.Descriptor) {
127127
if a.Default != nil {
128128
s.Default = a.Default
129129
}
130+
131+
if a.DeprecationMessage != "" {
132+
s.Deprecated = true
133+
s.DeprecationMessage = a.DeprecationMessage
134+
}
135+
130136
s.MarkdownDescription = convertLinksToAbsoluteUrl(a.MarkdownDescription)
131137
s.Title = a.Title
132138
s.Enum = a.Enum

bundle/internal/schema/annotations.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ github.com/databricks/cli/bundle/config.Experimental:
6161
"pydabs":
6262
"description": |-
6363
The PyDABs configuration.
64+
"deprecation_message": |-
65+
Deprecated: please use python instead
6466
"python":
6567
"description": |-
6668
Configures loading of Python code defined with 'databricks-bundles' package.
@@ -220,6 +222,11 @@ github.com/databricks/cli/bundle/config.Root:
220222
The bundle attributes when deploying to this target.
221223
"markdown_description": |-
222224
The bundle attributes when deploying to this target,
225+
"environments":
226+
"description": |-
227+
PLACEHOLDER
228+
"deprecation_message": |-
229+
Deprecated: please use targets instead
223230
"experimental":
224231
"description": |-
225232
Defines attributes for experimental features.
@@ -308,6 +315,8 @@ github.com/databricks/cli/bundle/config.Target:
308315
"compute_id":
309316
"description": |-
310317
Deprecated. The ID of the compute to use for this target.
318+
"deprecation_message": |-
319+
Deprecated: please use cluster_id instead
311320
"default":
312321
"description": |-
313322
Whether this target is the default target.

bundle/schema/jsonschema.json

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/jsonschema/extension.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,8 @@ type Extension struct {
4040
// https://code.visualstudio.com/docs/languages/json#_use-rich-formatting-in-hovers
4141
// Also it can be used in documentation generation.
4242
MarkdownDescription string `json:"markdownDescription,omitempty"`
43+
44+
// This field is not in the JSON schema spec, but it is supported in VSCode
45+
// It is used to provide a warning for deprectated fields
46+
DeprecationMessage string `json:"deprecationMessage,omitempty"`
4347
}

libs/jsonschema/from_type.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ var skipTags = []string{
1818
// Annotation for internal bundle fields that should not be exposed to customers.
1919
// Fields can be tagged as "internal" to remove them from the generated schema.
2020
"internal",
21-
22-
// Annotation for bundle fields that have been deprecated.
23-
// Fields tagged as "deprecated" are omitted from the generated schema.
24-
"deprecated",
2521
}
2622

2723
type constructor struct {
@@ -259,8 +255,8 @@ func (c *constructor) fromTypeStruct(typ reflect.Type) (Schema, error) {
259255
structFields := getStructFields(typ)
260256
for _, structField := range structFields {
261257
bundleTags := strings.Split(structField.Tag.Get("bundle"), ",")
262-
// Fields marked as "readonly", "internal" or "deprecated" are skipped
263-
// while generating the schema
258+
// Fields marked as "readonly" or "internal" are skipped while generating
259+
// the schema
264260
skip := false
265261
for _, tag := range skipTags {
266262
if slices.Contains(bundleTags, tag) {

libs/jsonschema/from_type_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ func TestFromTypeBasic(t *testing.T) {
1717
TriplePointer ***int `json:"triple_pointer,omitempty"`
1818

1919
// These fields should be ignored in the resulting schema.
20-
NotAnnotated string
21-
DashedTag string `json:"-"`
22-
InternalTagged string `json:"internal_tagged" bundle:"internal"`
23-
DeprecatedTagged string `json:"deprecated_tagged" bundle:"deprecated"`
24-
ReadOnlyTagged string `json:"readonly_tagged" bundle:"readonly"`
20+
NotAnnotated string
21+
DashedTag string `json:"-"`
22+
InternalTagged string `json:"internal_tagged" bundle:"internal"`
23+
ReadOnlyTagged string `json:"readonly_tagged" bundle:"readonly"`
2524
}
2625

2726
strRef := "#/$defs/string"

libs/jsonschema/schema.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ type Schema struct {
8080
// Examples of the value for properties in the schema.
8181
// https://json-schema.org/understanding-json-schema/reference/annotations
8282
Examples any `json:"examples,omitempty"`
83+
84+
// A boolean that indicates the field should not be used and may be removed
85+
// in the future.
86+
// https://json-schema.org/understanding-json-schema/reference/annotations
87+
Deprecated bool `json:"deprecated,omitempty"`
8388
}
8489

8590
// Default value defined in a JSON Schema, represented as a string.

0 commit comments

Comments
 (0)