Skip to content

Commit 843e3dd

Browse files
Generate typedefs for payload fields in Spec and Status (#146)
Issue #, if available: aws-controllers-k8s/community#864 Description of changes: When checking payload type defs, if they are used in the spec or status are included, otherwise they are still excluded. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 0427c5e commit 843e3dd

File tree

4 files changed

+118
-2
lines changed

4 files changed

+118
-2
lines changed

pkg/model/crd.go

+5
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ func (r *CRD) HasShapeAsMember(toFind string) bool {
148148
return true
149149
}
150150
}
151+
for _, field := range r.StatusFields {
152+
if shapeHasMember(field.ShapeRef.Shape, toFind) {
153+
return true
154+
}
155+
}
151156
return false
152157
}
153158

pkg/model/model.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ func (m *Model) GetTypeDefs() ([]*TypeDef, error) {
293293
payloads := m.SDKAPI.GetPayloads()
294294

295295
for shapeName, shape := range m.SDKAPI.API.Shapes {
296-
if util.InStrings(shapeName, payloads) {
297-
// Payloads are not type defs
296+
if util.InStrings(shapeName, payloads) && !m.IsShapeUsedInCRDs(shapeName) {
297+
// Payloads are not type defs, unless explicitly used
298298
continue
299299
}
300300
if shape.Type != "structure" {

pkg/model/model_ec2_test.go

+51
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,54 @@ func TestEC2_LaunchTemplate(t *testing.T) {
101101
assert.Nil(crd.Ops.ReadOne)
102102
assert.NotNil(crd.Ops.ReadMany)
103103
}
104+
105+
func TestEC2_Volume(t *testing.T) {
106+
assert := assert.New(t)
107+
require := require.New(t)
108+
109+
g := testutil.NewModelForService(t, "ec2")
110+
111+
crds, err := g.GetCRDs()
112+
require.Nil(err)
113+
114+
crd := getCRDByName("Volume", crds)
115+
require.NotNil(crd)
116+
117+
assert.Equal("Volume", crd.Names.Camel)
118+
assert.Equal("volume", crd.Names.CamelLower)
119+
assert.Equal("volume", crd.Names.Snake)
120+
121+
specFields := crd.SpecFields
122+
statusFields := crd.StatusFields
123+
124+
expSpecFieldCamel := []string{
125+
"AvailabilityZone",
126+
"DryRun",
127+
"Encrypted",
128+
"IOPS",
129+
"KMSKeyID",
130+
"MultiAttachEnabled",
131+
"OutpostARN",
132+
"Size",
133+
"SnapshotID",
134+
"TagSpecifications",
135+
"VolumeType",
136+
}
137+
assert.Equal(expSpecFieldCamel, attrCamelNames(specFields))
138+
139+
expStatusFieldCamel := []string{
140+
"Attachments",
141+
"CreateTime",
142+
"FastRestored",
143+
"State",
144+
"Tags",
145+
"VolumeID",
146+
}
147+
assert.Equal(expStatusFieldCamel, attrCamelNames(statusFields))
148+
149+
// Ensure that we generate TypeDefs for the VolumeAttachment field.
150+
// This field is the payload of the `AttachVolume` payload, but should
151+
// be included because it is the field value for the `attachments` status
152+
// field
153+
assert.NotNil(testutil.GetTypeDefByName(t, g, "VolumeAttachment"))
154+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
ignore:
2+
resource_names:
3+
- AccountAttribute
4+
- CapacityReservation
5+
- CarrierGateway
6+
- ClientVpnEndpoint
7+
- ClientVpnRoute
8+
- CustomerGateway
9+
- DefaultSubnet
10+
- DefaultVpc
11+
- EgressOnlyInternetGateway
12+
- Fleet
13+
- FpgaImage
14+
- Image
15+
- Instance
16+
- InstanceExportTask
17+
- InternetGateway
18+
- KeyPair
19+
- LaunchTemplateVersion
20+
# - LaunchTemplate
21+
- LocalGatewayRouteTableVpcAssociation
22+
- LocalGatewayRoute
23+
- ManagedPrefixList
24+
- NatGateway
25+
- NetworkAclEntry
26+
- NetworkAcl
27+
- NetworkInsightsPath
28+
- NetworkInterfacePermission
29+
- NetworkInterface
30+
- PlacementGroup
31+
- ReservedInstancesListing
32+
- RouteTable
33+
- Route
34+
- SecurityGroup
35+
- Snapshot
36+
- SpotDatafeedSubscription
37+
- Subnet
38+
- TrafficMirrorFilterRule
39+
- TrafficMirrorFilter
40+
- TrafficMirrorSession
41+
- TrafficMirrorTarget
42+
- TransitGatewayConnectPeer
43+
- TransitGatewayConnect
44+
- TransitGatewayMulticastDomain
45+
- TransitGatewayPeeringAttachment
46+
- TransitGatewayPrefixListReference
47+
- TransitGatewayRouteTable
48+
- TransitGatewayRoute
49+
- TransitGatewayVpcAttachment
50+
- TransitGateway
51+
# - Volume
52+
- VpcEndpointConnectionNotification
53+
- VpcEndpointServiceConfiguration
54+
- VpcEndpoint
55+
- Vpc
56+
- VpcCidrBlock
57+
- VpcPeeringConnection
58+
- VpnConnectionRoute
59+
- VpnConnection
60+
- VpnGateway

0 commit comments

Comments
 (0)