From 295692fa76142b5ea2baf5c0a5163dd4fca0312c Mon Sep 17 00:00:00 2001 From: abhishek kumar tiwari Date: Fri, 18 Oct 2024 21:45:35 +0000 Subject: [PATCH] feat: Support display metadata AlternateDefault validate (#2661) --- .../schema/gcp-blueprint-metadata.json | 4 +- cli/bpmetadata/schema/generate.go | 4 ++ cli/bpmetadata/validate_test.go | 5 ++ ...d-display-metadata-alternate-defaults.yaml | 50 +++++++++++++++++++ 4 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 cli/testdata/bpmetadata/schema/valid-display-metadata-alternate-defaults.yaml diff --git a/cli/bpmetadata/schema/gcp-blueprint-metadata.json b/cli/bpmetadata/schema/gcp-blueprint-metadata.json index 979fcb0579e..2cb1d61944d 100644 --- a/cli/bpmetadata/schema/gcp-blueprint-metadata.json +++ b/cli/bpmetadata/schema/gcp-blueprint-metadata.json @@ -856,9 +856,7 @@ } ] }, - "value": { - "$ref": "#/$defs/Value" - } + "value": true }, "additionalProperties": false, "type": "object" diff --git a/cli/bpmetadata/schema/generate.go b/cli/bpmetadata/schema/generate.go index 3d350dbe570..9dadd2c6a28 100644 --- a/cli/bpmetadata/schema/generate.go +++ b/cli/bpmetadata/schema/generate.go @@ -57,6 +57,10 @@ func GenerateSchema() ([]byte, error) { if defExists { oDef.Properties.Set("type", jsonschema.TrueSchema) } + altDefaultDef, defExists := s.Definitions["DisplayVariable_AlternateDefault"] + if defExists { + altDefaultDef.Properties.Set("value", jsonschema.TrueSchema) + } sData, err := json.MarshalIndent(s, "", " ") if err != nil { diff --git a/cli/bpmetadata/validate_test.go b/cli/bpmetadata/validate_test.go index f75b6ac77a4..a8a142a2daf 100644 --- a/cli/bpmetadata/validate_test.go +++ b/cli/bpmetadata/validate_test.go @@ -32,6 +32,11 @@ func TestValidateMetadata(t *testing.T) { path: "valid-metadata-connections.yaml", wantErr: false, }, + { + name: "valid display metadata with alternate defaults", + path: "valid-display-metadata-alternate-defaults.yaml", + wantErr: false, + }, { name: "invalid metadata - title missing", path: "invalid-metadata.yaml", diff --git a/cli/testdata/bpmetadata/schema/valid-display-metadata-alternate-defaults.yaml b/cli/testdata/bpmetadata/schema/valid-display-metadata-alternate-defaults.yaml new file mode 100644 index 00000000000..43404b1f506 --- /dev/null +++ b/cli/testdata/bpmetadata/schema/valid-display-metadata-alternate-defaults.yaml @@ -0,0 +1,50 @@ +apiVersion: blueprints.cloud.google.com/v1alpha1 +kind: BlueprintMetadata +metadata: + name: terraform-google-module +spec: + info: + title: Terraform Google Module + source: + repo: https://github.com/GoogleCloudPlatform/terraform-google-module.git + sourceType: git + ui: + input: + variables: + string_type: + name: string_type + title: String type + altDefaults: + - type: ALTERNATE_TYPE_DC + value: REGIONAL + bool_type: + name: bool_type + title: Bool type + altDefaults: + - type: ALTERNATE_TYPE_DC + value: true + number_type: + name: number_type + title: Number type + altDefaults: + - type: ALTERNATE_TYPE_DC + value: 1 + object_type: + name: object_type + title: Object type + altDefaults: + - type: ALTERNATE_TYPE_DC + value: + key: value + list_type: + name: list_type + title: List type + altDefaults: + - type: ALTERNATE_TYPE_DC + value: + - item1 + - item2 + runtime: + outputs: + output1: + visibility: VISIBILITY_ROOT