Skip to content

Commit a9931ad

Browse files
committed
handle back serialization of floats for default value
1 parent ff5bead commit a9931ad

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

mmv1/api/type.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,21 @@ func (t *Type) MarshalYAML() (interface{}, error) {
391391
return nil, err
392392
}
393393

394+
// Fix: Ensure float values (like 0.0) are marshaled as floats (0.0) with !!float tag.
395+
// If we don't set the tag, it might be emitted as '0' (int) or '!!int 0.0' (invalid).
396+
if _, ok := t.DefaultValue.(float64); ok {
397+
for i := 0; i < len(node.Content); i += 2 {
398+
if node.Content[i].Value == "default_value" {
399+
valNode := node.Content[i+1]
400+
if !strings.Contains(valNode.Value, ".") && !strings.Contains(strings.ToLower(valNode.Value), "e") {
401+
valNode.Value = valNode.Value + ".0"
402+
}
403+
valNode.Tag = "!!float"
404+
break
405+
}
406+
}
407+
}
408+
394409
// Special handling for `properties` field.
395410
// If the original `properties` slice was explicitly empty (`[]`), `omitempty`
396411
// would have removed it during the node encoding. We need to add it back in.

mmv1/products/dataproc/AutoscalingPolicy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ properties:
198198
Bounds: [0.0, 1.0].
199199
- name: scaleUpMinWorkerFraction
200200
type: Double
201-
default_value: 0
201+
default_value: 0.0
202202
description: |
203203
Minimum scale-up threshold as a fraction of total cluster size before scaling
204204
occurs. For example, in a 20-worker cluster, a threshold of 0.1 means the autoscaler
@@ -208,7 +208,7 @@ properties:
208208
Bounds: [0.0, 1.0]. Default: 0.0.
209209
- name: scaleDownMinWorkerFraction
210210
type: Double
211-
default_value: 0
211+
default_value: 0.0
212212
description: |
213213
Minimum scale-down threshold as a fraction of total cluster size before scaling occurs.
214214
For example, in a 20-worker cluster, a threshold of 0.1 means the autoscaler must

0 commit comments

Comments
 (0)