Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias variables block in the Target struct #1748

Merged
merged 70 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
75f252e
Improve JSON schema
shreyas-goenka Aug 20, 2024
43325fd
add some more todos:
shreyas-goenka Aug 20, 2024
6d2f882
more progress on the internal functionality
shreyas-goenka Aug 20, 2024
65f1c75
-
shreyas-goenka Aug 20, 2024
7db32fc
-
shreyas-goenka Aug 20, 2024
b899285
-
shreyas-goenka Aug 20, 2024
b023ba0
removed more tests
shreyas-goenka Aug 20, 2024
e24725d
added nested tests
shreyas-goenka Aug 20, 2024
460eeb9
more tests
shreyas-goenka Aug 20, 2024
00e5896
add test for recursive
shreyas-goenka Aug 20, 2024
0813312
Merge remote-tracking branch 'origin' into improve/json-schema
shreyas-goenka Aug 22, 2024
7c70179
add self referential tesT
shreyas-goenka Aug 22, 2024
39efb70
-
shreyas-goenka Aug 22, 2024
790731f
remove generic schema test
shreyas-goenka Aug 22, 2024
535f670
remove most of the debug helpers
shreyas-goenka Aug 22, 2024
11dfdc0
more iteration
shreyas-goenka Aug 26, 2024
870e419
from_type method is mostly complete
shreyas-goenka Aug 27, 2024
2dea889
delete the old schema code
shreyas-goenka Aug 27, 2024
d07192f
merge
shreyas-goenka Aug 27, 2024
fcdccb3
cleanu unused code
shreyas-goenka Aug 27, 2024
e7fd063
-
shreyas-goenka Aug 27, 2024
5b79747
-
shreyas-goenka Aug 27, 2024
ac60163
move gen file
shreyas-goenka Aug 27, 2024
2c30cfa
-
shreyas-goenka Aug 27, 2024
483480f
-
shreyas-goenka Aug 27, 2024
727036b
bundle schema command is OK now
shreyas-goenka Aug 27, 2024
acc4309
fix lint
shreyas-goenka Aug 27, 2024
f194a5b
skip adding patterns for string schemas
shreyas-goenka Aug 27, 2024
ad7503a
cleanup todos
shreyas-goenka Aug 27, 2024
40f4d35
cleanup todos
shreyas-goenka Aug 27, 2024
aac6687
remove more todos
shreyas-goenka Aug 27, 2024
4141f4e
-
shreyas-goenka Aug 27, 2024
cb8d6a9
self pass 1
shreyas-goenka Aug 27, 2024
578019b
-
shreyas-goenka Sep 3, 2024
176ced1
add tests for bfs assertion
shreyas-goenka Sep 4, 2024
3d5c076
jsonTags[0] -> fieldName
shreyas-goenka Sep 4, 2024
be0ad48
str bool
shreyas-goenka Sep 4, 2024
8575c47
json pointer comment
shreyas-goenka Sep 4, 2024
46585bb
type defs as map[string]any
shreyas-goenka Sep 4, 2024
6bd7ad0
clarify interface comments
shreyas-goenka Sep 4, 2024
66cbb54
return typPath from walk
shreyas-goenka Sep 4, 2024
ba3f004
schema local to generator
shreyas-goenka Sep 4, 2024
9d9c612
Merge remote-tracking branch 'origin' into improve/json-schema
shreyas-goenka Sep 4, 2024
446463b
update schema
shreyas-goenka Sep 4, 2024
bfe9cc4
create generated package
shreyas-goenka Sep 4, 2024
a64857e
-
shreyas-goenka Sep 4, 2024
42da1c9
Merge remote-tracking branch 'origin' into improve/json-schema
shreyas-goenka Sep 4, 2024
d0aa493
-
shreyas-goenka Sep 5, 2024
4379d7f
allow artifacts referencing
shreyas-goenka Sep 5, 2024
e55df7b
Merge remote-tracking branch 'origin' into improve/json-schema
shreyas-goenka Sep 5, 2024
1dd399f
new line for s
shreyas-goenka Sep 6, 2024
75a571a
slice for tags
shreyas-goenka Sep 6, 2024
8cd2631
fix test
shreyas-goenka Sep 6, 2024
c69e6d9
loop over keys
shreyas-goenka Sep 6, 2024
2d62c0c
Added testS
shreyas-goenka Sep 6, 2024
5f48b58
add test for bfs final schema
shreyas-goenka Sep 9, 2024
ab3dd7a
add comment
shreyas-goenka Sep 9, 2024
804d379
address comments
shreyas-goenka Sep 9, 2024
4c3facc
Merge remote-tracking branch 'origin' into improve/json-schema
shreyas-goenka Sep 9, 2024
d9432e5
Merge remote-tracking branch 'origin' into improve/json-schema
shreyas-goenka Sep 10, 2024
65ed301
make interpolation pattern better
shreyas-goenka Sep 10, 2024
e1a8e03
regenerate schema with interpolation patterns
shreyas-goenka Sep 10, 2024
48af9d1
Change variables block to map of any in `Targets` struct
shreyas-goenka Sep 4, 2024
176bb4b
fix test
shreyas-goenka Sep 4, 2024
507b99d
-
shreyas-goenka Sep 4, 2024
f26027a
comment
shreyas-goenka Sep 4, 2024
9689a79
address comments
shreyas-goenka Sep 4, 2024
c365fd4
Address comments
shreyas-goenka Sep 5, 2024
3b06a94
regenerate schema with interpolation patterns
shreyas-goenka Sep 10, 2024
ed55a23
merge
shreyas-goenka Sep 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bundle/config/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestRootMergeTargetOverridesWithVariables(t *testing.T) {
},
Targets: map[string]*Target{
"development": {
Variables: map[string]*variable.Variable{
Variables: map[string]*variable.TargetVariable{
"foo": {
Default: "bar",
Description: "wrong",
Expand Down
21 changes: 20 additions & 1 deletion bundle/config/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,26 @@ type Target struct {
// Override default values or lookup name for defined variables
// Does not permit defining new variables or redefining existing ones
// in the scope of an target
Variables map[string]*variable.Variable `json:"variables,omitempty"`
//
// There are two valid ways to define a variable override in a target:
// 1. Direct value override. We normalize this to the variable.Variable
// struct format when loading the configuration YAML:
//
// variables:
// foo: "value"
//
// 2. Override matching the variable.Variable struct.
//
// variables:
// foo:
// default: "value"
//
// OR
//
// variables:
// foo:
// lookup: "resource_name"
Variables map[string]*variable.TargetVariable `json:"variables,omitempty"`

Git Git `json:"git,omitempty"`

Expand Down
5 changes: 5 additions & 0 deletions bundle/config/variable/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const (
VariableTypeComplex VariableType = "complex"
)

// We alias it here to override the JSON schema associated with a variable value
// in a target override. This is because we allow for directly specifying the value
// in addition to the variable.Variable struct format in a target override.
type TargetVariable Variable

// An input variable for the bundle config
type Variable struct {
// A type of the variable. This is used to validate the value of the variable
Expand Down
16 changes: 16 additions & 0 deletions bundle/internal/schema/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ func addInterpolationPatterns(typ reflect.Type, s jsonschema.Schema) jsonschema.
return s
}

// The variables block in a target override allows for directly specifying
// the value of the variable.
if typ == reflect.TypeOf(variable.TargetVariable{}) {
shreyas-goenka marked this conversation as resolved.
Show resolved Hide resolved
return jsonschema.Schema{
AnyOf: []jsonschema.Schema{
// We keep the original schema so that autocomplete suggestions
// continue to work.
s,
// All values are valid for a variable value, be it primitive types
// like string/bool or complex ones like objects/arrays. Thus we override
// the schema to allow all valid JSON values.
{},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shreyas-goenka Could we have an integration test for this as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do, see: bundle/internal/schema/testdata/pass/direct_value_in_target.yml in #1726. Do you mean more coverage?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pointer. I was under the assumption the integration tests were merged before this one, which would imply there is no coverage for this case, but it's the other way around, so all good.

},
}
}

switch s.Type {
case jsonschema.ArrayType, jsonschema.ObjectType:
// arrays and objects can have complex variable values specified.
Expand Down
39 changes: 38 additions & 1 deletion bundle/schema/jsonschema.json

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

Loading