Skip to content

Commit 24d2344

Browse files
Allow member fields from other operations in spec (#139)
Description of changes: Allow the use of member fields contained within other API operations within a resource's spec. For example, `LoggingStatus` for S3 is only in the `PutBucketLogging` operation, but should be settable from spec. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent cae7cb2 commit 24d2344

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

pkg/generate/code/compare_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,29 @@ func TestCompareResource_S3_Bucket(t *testing.T) {
8181
delta.Add("Spec.GrantWriteACP", a.ko.Spec.GrantWriteACP, b.ko.Spec.GrantWriteACP)
8282
}
8383
}
84+
if ackcompare.HasNilDifference(a.ko.Spec.Logging, b.ko.Spec.Logging) {
85+
delta.Add("Spec.Logging", a.ko.Spec.Logging, b.ko.Spec.Logging)
86+
} else if a.ko.Spec.Logging != nil && b.ko.Spec.Logging != nil {
87+
if ackcompare.HasNilDifference(a.ko.Spec.Logging.LoggingEnabled, b.ko.Spec.Logging.LoggingEnabled) {
88+
delta.Add("Spec.Logging.LoggingEnabled", a.ko.Spec.Logging.LoggingEnabled, b.ko.Spec.Logging.LoggingEnabled)
89+
} else if a.ko.Spec.Logging.LoggingEnabled != nil && b.ko.Spec.Logging.LoggingEnabled != nil {
90+
if ackcompare.HasNilDifference(a.ko.Spec.Logging.LoggingEnabled.TargetBucket, b.ko.Spec.Logging.LoggingEnabled.TargetBucket) {
91+
delta.Add("Spec.Logging.LoggingEnabled.TargetBucket", a.ko.Spec.Logging.LoggingEnabled.TargetBucket, b.ko.Spec.Logging.LoggingEnabled.TargetBucket)
92+
} else if a.ko.Spec.Logging.LoggingEnabled.TargetBucket != nil && b.ko.Spec.Logging.LoggingEnabled.TargetBucket != nil {
93+
if *a.ko.Spec.Logging.LoggingEnabled.TargetBucket != *b.ko.Spec.Logging.LoggingEnabled.TargetBucket {
94+
delta.Add("Spec.Logging.LoggingEnabled.TargetBucket", a.ko.Spec.Logging.LoggingEnabled.TargetBucket, b.ko.Spec.Logging.LoggingEnabled.TargetBucket)
95+
}
96+
}
97+
98+
if ackcompare.HasNilDifference(a.ko.Spec.Logging.LoggingEnabled.TargetPrefix, b.ko.Spec.Logging.LoggingEnabled.TargetPrefix) {
99+
delta.Add("Spec.Logging.LoggingEnabled.TargetPrefix", a.ko.Spec.Logging.LoggingEnabled.TargetPrefix, b.ko.Spec.Logging.LoggingEnabled.TargetPrefix)
100+
} else if a.ko.Spec.Logging.LoggingEnabled.TargetPrefix != nil && b.ko.Spec.Logging.LoggingEnabled.TargetPrefix != nil {
101+
if *a.ko.Spec.Logging.LoggingEnabled.TargetPrefix != *b.ko.Spec.Logging.LoggingEnabled.TargetPrefix {
102+
delta.Add("Spec.Logging.LoggingEnabled.TargetPrefix", a.ko.Spec.Logging.LoggingEnabled.TargetPrefix, b.ko.Spec.Logging.LoggingEnabled.TargetPrefix)
103+
}
104+
}
105+
}
106+
}
84107
if ackcompare.HasNilDifference(a.ko.Spec.Name, b.ko.Spec.Name) {
85108
delta.Add("Spec.Name", a.ko.Spec.Name, b.ko.Spec.Name)
86109
} else if a.ko.Spec.Name != nil && b.ko.Spec.Name != nil {

pkg/model/crd.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ func (r *CRD) HasShapeAsMember(toFind string) bool {
143143
}
144144
}
145145
}
146+
for _, field := range r.SpecFields {
147+
if shapeHasMember(field.ShapeRef.Shape, toFind) {
148+
return true
149+
}
150+
}
146151
return false
147152
}
148153

pkg/model/model_s3_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func TestS3_Bucket(t *testing.T) {
7575
"GrantReadACP",
7676
"GrantWrite",
7777
"GrantWriteACP",
78+
"Logging",
7879
// NOTE(jaypipes): Original field name in CreateBucket input is
7980
// "Bucket" but should be renamed to "Name" from the generator.yaml (in
8081
// order to match with the name of the field in the Output shape for a
@@ -88,4 +89,13 @@ func TestS3_Bucket(t *testing.T) {
8889
"Location",
8990
}
9091
assert.Equal(expStatusFieldCamel, attrCamelNames(statusFields))
92+
93+
expTypeDefCamel := []string{
94+
"BucketLoggingStatus",
95+
"LoggingEnabled",
96+
"TargetGrant",
97+
}
98+
for _, typeDef := range expTypeDefCamel {
99+
assert.NotNil(testutil.GetTypeDefByName(t, g, typeDef))
100+
}
91101
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ resources:
2424
# should NOT be in a production generator.yaml...
2525
compare:
2626
is_ignored: true
27+
Logging:
28+
from:
29+
operation: PutBucketLogging
30+
path: BucketLoggingStatus

0 commit comments

Comments
 (0)