Skip to content

Commit bbd3bb5

Browse files
authored
Strict unmarshalling for generator.yaml
This validates whether `generator.yaml` are using real defined fields from `pkg/config/*.go`. Strict unmarshalling rejects unknown fields. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
2 parents 917b9ac + 9e5b476 commit bbd3bb5

9 files changed

Lines changed: 11 additions & 15 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ require (
114114
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
115115
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
116116
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
117-
sigs.k8s.io/yaml v1.4.0 // indirect
117+
sigs.k8s.io/yaml v1.4.0
118118
)
119119

120120
require (

pkg/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package config
1616
import (
1717
"io/ioutil"
1818

19-
"github.com/ghodss/yaml"
19+
"sigs.k8s.io/yaml"
2020
)
2121

2222
// Config represents instructions to the ACK code generator for a particular
@@ -194,7 +194,7 @@ func New(
194194
return Config{}, err
195195
}
196196
gc := defaultConfig
197-
if err = yaml.Unmarshal(content, &gc); err != nil {
197+
if err = yaml.UnmarshalStrict(content, &gc); err != nil {
198198
return Config{}, err
199199
}
200200
return gc, nil

pkg/config/documentation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package config
33
import (
44
"io/ioutil"
55

6-
"github.com/ghodss/yaml"
6+
"sigs.k8s.io/yaml"
77
)
88

99
// DocumentationConfig represents the configuration of the documentation file,
@@ -44,7 +44,7 @@ func NewDocumentationConfig(
4444
return DocumentationConfig{}, err
4545
}
4646
gc := DocumentationConfig{}
47-
if err = yaml.Unmarshal(content, &gc); err != nil {
47+
if err = yaml.UnmarshalStrict(content, &gc); err != nil {
4848
return DocumentationConfig{}, err
4949
}
5050
return gc, nil

pkg/testdata/models/apis/emrcontainers/0000-00-00/generator-with-cycle.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ ignore:
99
# - JobRun
1010
- ManagedEndpoint
1111
shape_names: null
12-
model_name: emr-containers
12+
sdk_names:
13+
model_name: emr-containers
1314
operations:
1415
StartJobRun:
1516
operation_type: Create

pkg/testdata/models/apis/firehose/0000-00-00/generator-set-for-nested-field.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
model_name: firehose
1+
sdk_names:
2+
model_name: firehose
23
ignore:
34
resource_names:
45
# - DeliveryStream

pkg/testdata/models/apis/mq/0000-00-00/generator-only-set-unchanged-fields.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ignore:
2-
resources:
2+
resource_names:
33
- Configuration
44
- User
55
field_paths:

pkg/testdata/models/apis/mq/0000-00-00/generator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ignore:
2-
resources:
2+
resource_names:
33
- Configuration
44
- User
55
field_paths:

pkg/testdata/models/apis/rds/0000-00-00/generator.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,11 @@ resources:
184184
from:
185185
operation: ModifyDBClusterParameterGroup
186186
path: Parameters
187-
documentation: DEPRECATED - do not use. Prefer ParameterOverrides instead.
188187
ParameterOverrides:
189188
custom_field:
190189
# Map keys are the parameter name and the values are the parameter value.
191190
# We automatically determine the "apply method" for parameters.
192191
map_of: String
193-
documentation: These are ONLY user-defined parameter overrides for the
194-
DB cluster parameter group. This does not contain default or system
195-
parameters.
196192
Tags:
197193
compare:
198194
# We have a custom comparison function...

pkg/testdata/models/apis/route53/0000-00-00/generator.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ resources:
4949
is_immutable: true
5050
ID:
5151
is_primary_key: true
52-
documentation: "ID represents the ChangeID that is returned after a successful
53-
ChangeResourceRecordSet request"
5452
MultiValueAnswer:
5553
from:
5654
operation: ListResourceRecordSets

0 commit comments

Comments
 (0)