Skip to content

Expand the search space for shapes in from.operation #571

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 2 commits into from
Mar 7, 2025
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
12 changes: 12 additions & 0 deletions pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ func (m *Model) GetCRDs() ([]*CRD, error) {
memberShapeRef, found = m.SDKAPI.GetInputShapeRef(
from.Operation, from.Path,
)
// allowing getting spec fields from output shape
if !found {
memberShapeRef, found = m.SDKAPI.GetOutputShapeRef(
from.Operation, from.Path,
)
}
if !found {
// This is a compile-time failure, just bomb out...
msg := fmt.Sprintf(
Expand Down Expand Up @@ -289,6 +295,12 @@ func (m *Model) GetCRDs() ([]*CRD, error) {
memberShapeRef, found = m.SDKAPI.GetOutputShapeRef(
from.Operation, from.Path,
)
// allowing to get status fields from output shapes
if !found {
memberShapeRef, found = m.SDKAPI.GetInputShapeRef(
from.Operation, from.Path,
)
}
if !found {
// This is a compile-time failure, just bomb out...
msg := fmt.Sprintf(
Expand Down
86 changes: 86 additions & 0 deletions pkg/model/model_route53_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package model_test

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/aws-controllers-k8s/code-generator/pkg/testutil"
)

func TestRoute53_RecordSet(t *testing.T) {
assert := assert.New(t)
require := require.New(t)

g := testutil.NewModelForService(t, "route53")

crds, err := g.GetCRDs()
require.Nil(err)

crd := getCRDByName("RecordSet", crds)
require.NotNil(crd)

assert.Equal("RecordSet", crd.Names.Camel)
assert.Equal("recordSet", crd.Names.CamelLower)
assert.Equal("record_set", crd.Names.Snake)

// The Route53 API has CD as one operation +L:
//
// * ChangeResourceRecordSets
// * ChangeResourceRecordSets
// * ListResourceRecordSets
require.NotNil(crd.Ops)

assert.NotNil(crd.Ops.Create)
assert.NotNil(crd.Ops.ReadMany)
assert.NotNil(crd.Ops.Delete)

// But sadly, has no Update or ReadOne operation :(
// for update we still use ChangeResourceRecordSets
assert.Nil(crd.Ops.ReadOne)
assert.Nil(crd.Ops.Update)

specFields := crd.SpecFields
statusFields := crd.StatusFields

expSpecFieldCamel := []string{
"AliasTarget",
// "ChangeBatch", <= Testing that this is removed from spec
"CIDRRoutingConfig",
"Failover",
"GeoLocation",
"HealthCheckID",
"HostedZoneID",
"HostedZoneRef",
"MultiValueAnswer",
"Name",
"RecordType",
"Region",
"ResourceRecords",
"SetIdentifier",
"TTL",
"Weight",
}
assert.Equal(expSpecFieldCamel, attrCamelNames(specFields))

expStatusFieldCamel := []string{
"ID",
"Status",
"SubmittedAt",
}
assert.Equal(expStatusFieldCamel, attrCamelNames(statusFields))
}
Loading