Skip to content

Allow member fields from other operations in spec #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pkg/generate/code/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,29 @@ func TestCompareResource_S3_Bucket(t *testing.T) {
delta.Add("Spec.GrantWriteACP", a.ko.Spec.GrantWriteACP, b.ko.Spec.GrantWriteACP)
}
}
if ackcompare.HasNilDifference(a.ko.Spec.Logging, b.ko.Spec.Logging) {
delta.Add("Spec.Logging", a.ko.Spec.Logging, b.ko.Spec.Logging)
} else if a.ko.Spec.Logging != nil && b.ko.Spec.Logging != nil {
if ackcompare.HasNilDifference(a.ko.Spec.Logging.LoggingEnabled, b.ko.Spec.Logging.LoggingEnabled) {
delta.Add("Spec.Logging.LoggingEnabled", a.ko.Spec.Logging.LoggingEnabled, b.ko.Spec.Logging.LoggingEnabled)
} else if a.ko.Spec.Logging.LoggingEnabled != nil && b.ko.Spec.Logging.LoggingEnabled != nil {
if ackcompare.HasNilDifference(a.ko.Spec.Logging.LoggingEnabled.TargetBucket, b.ko.Spec.Logging.LoggingEnabled.TargetBucket) {
delta.Add("Spec.Logging.LoggingEnabled.TargetBucket", a.ko.Spec.Logging.LoggingEnabled.TargetBucket, b.ko.Spec.Logging.LoggingEnabled.TargetBucket)
} else if a.ko.Spec.Logging.LoggingEnabled.TargetBucket != nil && b.ko.Spec.Logging.LoggingEnabled.TargetBucket != nil {
if *a.ko.Spec.Logging.LoggingEnabled.TargetBucket != *b.ko.Spec.Logging.LoggingEnabled.TargetBucket {
delta.Add("Spec.Logging.LoggingEnabled.TargetBucket", a.ko.Spec.Logging.LoggingEnabled.TargetBucket, b.ko.Spec.Logging.LoggingEnabled.TargetBucket)
}
}

if ackcompare.HasNilDifference(a.ko.Spec.Logging.LoggingEnabled.TargetPrefix, b.ko.Spec.Logging.LoggingEnabled.TargetPrefix) {
delta.Add("Spec.Logging.LoggingEnabled.TargetPrefix", a.ko.Spec.Logging.LoggingEnabled.TargetPrefix, b.ko.Spec.Logging.LoggingEnabled.TargetPrefix)
} else if a.ko.Spec.Logging.LoggingEnabled.TargetPrefix != nil && b.ko.Spec.Logging.LoggingEnabled.TargetPrefix != nil {
if *a.ko.Spec.Logging.LoggingEnabled.TargetPrefix != *b.ko.Spec.Logging.LoggingEnabled.TargetPrefix {
delta.Add("Spec.Logging.LoggingEnabled.TargetPrefix", a.ko.Spec.Logging.LoggingEnabled.TargetPrefix, b.ko.Spec.Logging.LoggingEnabled.TargetPrefix)
}
}
}
}
if ackcompare.HasNilDifference(a.ko.Spec.Name, b.ko.Spec.Name) {
delta.Add("Spec.Name", a.ko.Spec.Name, b.ko.Spec.Name)
} else if a.ko.Spec.Name != nil && b.ko.Spec.Name != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/model/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ func (r *CRD) HasShapeAsMember(toFind string) bool {
}
}
}
for _, field := range r.SpecFields {
if shapeHasMember(field.ShapeRef.Shape, toFind) {
return true
}
}
return false
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/model/model_s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func TestS3_Bucket(t *testing.T) {
"GrantReadACP",
"GrantWrite",
"GrantWriteACP",
"Logging",
// NOTE(jaypipes): Original field name in CreateBucket input is
// "Bucket" but should be renamed to "Name" from the generator.yaml (in
// order to match with the name of the field in the Output shape for a
Expand All @@ -88,4 +89,13 @@ func TestS3_Bucket(t *testing.T) {
"Location",
}
assert.Equal(expStatusFieldCamel, attrCamelNames(statusFields))

expTypeDefCamel := []string{
"BucketLoggingStatus",
"LoggingEnabled",
"TargetGrant",
}
for _, typeDef := range expTypeDefCamel {
assert.NotNil(testutil.GetTypeDefByName(t, g, typeDef))
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
4 changes: 4 additions & 0 deletions pkg/testdata/models/apis/s3/0000-00-00/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ resources:
# should NOT be in a production generator.yaml...
compare:
is_ignored: true
Logging:
from:
operation: PutBucketLogging
path: BucketLoggingStatus