Skip to content

Commit d25485a

Browse files
melinathJianweiQ
authored andcommitted
Removed unused key_description and value_type.name properties usage and added validation to prevent additions (GoogleCloudPlatform#16179)
1 parent 3962f70 commit d25485a

40 files changed

+17
-109
lines changed

docs/content/develop/add-fields.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,12 @@ Replace `String` in the field type with one of the following options:
165165
description: |
166166
MULTILINE_FIELD_DESCRIPTION
167167
key_name: 'key_name'
168-
key_description: |
169-
MULTILINE_KEY_FIELD_DESCRIPTION
170168
# Map of primitive values
171169
value_type:
172-
name: mapIntegerName
173170
type: Integer
174171

175172
# Map of complex values
176173
value_type:
177-
name: mapObjectName
178174
type: NestedObject
179175
properties:
180176
- name: 'FIELD_NAME'
@@ -185,7 +181,7 @@ Replace `String` in the field type with one of the following options:
185181
186182
This type is used for general-case string -> non-string type mappings, use "KeyValuePairs" for string -> string mappings. Complex maps can't be represented natively in Terraform, and this type is transformed into an associative array (TypeSet) with the key merged into the object alongside other top-level fields.
187183
188-
For `key_name` and `key_description`, provide a domain-appropriate name and description. For example, a map that references a specific type of resource would generally use the singular resource kind as the key name (such as "topic" for PubSub Topic) and a descriptor of the expected format depending on the context (such as resourceId vs full resource name).
184+
For `key_name`, provide a domain-appropriate field name. For example, a map that references a specific type of resource would generally use the singular resource kind as the key name (such as "topic" for PubSub Topic).
189185

190186
{{< /tab >}}
191187
{{< /tabs >}}

mmv1/api/type.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ type Type struct {
240240
// The name of the key. Used in the Terraform schema as a field name.
241241
KeyName string `yaml:"key_name,omitempty"`
242242

243-
// A description of the key's format. Used in Terraform to describe
243+
// Deprecated. A description of the key's format. Used in Terraform to describe
244244
// the field in documentation.
245245
KeyDescription string `yaml:"key_description,omitempty"`
246246

@@ -467,7 +467,9 @@ func (t *Type) SetDefault(r *Resource) {
467467
if t.ValueType != nil {
468468
t.ValueType.ParentName = t.Name
469469
t.ValueType.ParentMetadata = t
470-
t.ValueType.SetDefault(r) // Recurse
470+
oldName := t.ValueType.Name
471+
t.ValueType.SetDefault(r) // Recurse
472+
t.ValueType.Name = oldName // unset name if it was previously unset
471473
}
472474
case t.IsA("NestedObject"):
473475
for _, p := range t.Properties {
@@ -498,13 +500,25 @@ func (t *Type) Validate(rName string) {
498500
log.Fatalf("Property %s cannot be write_only and sensitive at the same time in resource %s", t.Name, rName)
499501
}
500502

503+
if t.KeyDescription != "" {
504+
log.Fatalf("Property %s.key_description can't be set in resource %s; it's deprecated", t.Name, rName)
505+
}
506+
501507
t.validateLabelsField()
502508

503509
switch {
504510
case t.IsA("Array"):
505511
t.ItemType.Validate(rName)
506512
case t.IsA("Map"):
513+
// ValueType.Name should be empty (because it's unused) but we require types to have names in all other cases.
514+
// This logic allows both to be validated.
515+
oldName := t.ValueType.Name
516+
t.ValueType.Name = "any_value"
507517
t.ValueType.Validate(rName)
518+
t.ValueType.Name = oldName
519+
if t.ValueType.Name != "" {
520+
log.Fatalf("Property %s.name can't be set in resource %s", t.Name, rName)
521+
}
508522
case t.IsA("NestedObject"):
509523
for _, p := range t.Properties {
510524
p.Validate(rName)
@@ -1310,7 +1324,6 @@ func (t Type) fieldMinVersion() string {
13101324
// func (t *Type) validate
13111325
// super
13121326
// check :key_name, type: ::String, required: true
1313-
// check :key_description, type: ::String
13141327
// check :value_type, type: Api::Type::NestedObject, required: true
13151328
// raise "Invalid type //{@value_type}" unless type?(@value_type)
13161329
// end

mmv1/openapi_generate/parser.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,6 @@ func WriteObject(name string, obj *openapi3.SchemaRef, objType openapi3.Types, u
509509
field.Type = "Map"
510510
field.KeyName = "TODO: CHANGEME"
511511
var valueType api.Type
512-
valueType.Name = "TODO: CHANGEME"
513512
valueType.Type = "NestedObject"
514513
valueType.Properties = buildProperties(obj.Value.AdditionalProperties.Schema.Value.Properties, obj.Value.AdditionalProperties.Schema.Value.Required)
515514
field.ValueType = &valueType

mmv1/products/apigee/SecurityProfileV2.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ properties:
7777
required: true
7878
key_name: 'assessment'
7979
value_type:
80-
name: profileAssessmentConfig
8180
type: NestedObject
8281
properties:
8382
- name: 'weight'

mmv1/products/appengine/FlexibleAppVersion.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,7 @@ properties:
551551
- 'deployment.0.files'
552552
- 'deployment.0.container'
553553
key_name: 'name'
554-
key_description: |
555-
name of file
556554
value_type:
557-
name: files
558555
type: NestedObject
559556
properties:
560557
- name: 'sha1Sum'

mmv1/products/appengine/StandardAppVersion.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,7 @@ properties:
285285
- 'deployment.0.zip'
286286
- 'deployment.0.files'
287287
key_name: 'name'
288-
key_description: |
289-
name of file
290288
value_type:
291-
name: files
292289
type: NestedObject
293290
properties:
294291
- name: 'sha1Sum'

mmv1/products/artifactregistry/Repository.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,8 @@ properties:
376376
Map keys are policy IDs supplied by users during policy creation. They must
377377
unique within a repository and be under 128 characters in length.
378378
key_name: 'id'
379-
key_description: |-
380-
The policy ID. Must be unique within a repository.
381379
set_hash_func: 'mapHashID'
382380
value_type:
383-
name: cleanupPolicies
384381
type: NestedObject
385382
properties:
386383
- name: 'action'

mmv1/products/backupdr/RestoreWorkload.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ properties:
370370
type: Map
371371
key_name: key
372372
value_type:
373-
name: value
374373
type: NestedObject
375374
properties:
376375
- name: 'value'
@@ -527,7 +526,6 @@ properties:
527526
type: Map
528527
key_name: key
529528
value_type:
530-
name: value
531529
type: NestedObject
532530
properties:
533531
- name: 'value'
@@ -751,7 +749,6 @@ properties:
751749
type: Map
752750
key_name: key
753751
value_type:
754-
name: value
755752
type: NestedObject
756753
properties:
757754
- name: 'value'
@@ -761,7 +758,6 @@ properties:
761758
type: Map
762759
key_name: key
763760
value_type:
764-
name: value
765761
type: NestedObject
766762
properties:
767763
- name: 'value'

mmv1/products/beyondcorp/SecurityGateway.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,8 @@ properties:
111111
Optional. Map of Hubs that represents regional data path deployment with GCP region
112112
as a key.
113113
key_name: region
114-
key_description: The region to deploy the hub in.
115114
set_hash_func: 'beyondcorpSecurityGatewayHubsHash'
116115
value_type:
117-
name: Hub
118116
type: NestedObject
119117
properties:
120118
- name: internetGateway

mmv1/products/bigqueryanalyticshub/DataExchangeSubscription.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@ properties:
207207
e.g. projects/123/locations/us/dataExchanges/456/listings/789 -> projects/123/datasets/my_dataset
208208
For Data Exchange subscriptions, this map may contain multiple entries if the Data Exchange has multiple listings.
209209
key_name: resource_name
210-
key_description: The associated linked resource
211210
value_type:
212-
name: linked_resource
213211
type: NestedObject
214212
properties:
215213
- name: 'listing'

0 commit comments

Comments
 (0)