Skip to content

Commit

Permalink
Switch to the modeled serviceId for newly generated clients (#4424)
Browse files Browse the repository at this point in the history
* Support for strict generation of clients using modeled serviceId
* Backfill missing serviceIds
  • Loading branch information
skmcgrail authored Jun 6, 2022
1 parent 9207008 commit 2bd6652
Show file tree
Hide file tree
Showing 12 changed files with 378 additions and 20 deletions.
1 change: 1 addition & 0 deletions models/apis/cloudsearchdomain/2013-01-01/api-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"jsonVersion":"1.1",
"protocol":"rest-json",
"serviceFullName":"Amazon CloudSearch Domain",
"serviceId":"CloudSearch Domain",
"signatureVersion":"v4",
"signingName":"cloudsearch",
"uid":"cloudsearchdomain-2013-01-01"
Expand Down
1 change: 1 addition & 0 deletions models/apis/entitlement.marketplace/2017-01-11/api-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"jsonVersion":"1.1",
"protocol":"json",
"serviceFullName":"AWS Marketplace Entitlement Service",
"serviceId":"Marketplace Entitlement Service",
"signatureVersion":"v4",
"signingName":"aws-marketplace",
"targetPrefix":"AWSMPEntitlementService",
Expand Down
1 change: 1 addition & 0 deletions models/apis/importexport/2010-06-01/api-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"apiVersion":"2010-06-01",
"endpointPrefix":"importexport",
"globalEndpoint":"importexport.amazonaws.com",
"serviceId": "Import Export",
"serviceFullName":"AWS Import/Export",
"signatureVersion":"v2",
"xmlNamespace":"http://importexport.amazonaws.com/doc/2010-06-01/",
Expand Down
1 change: 1 addition & 0 deletions models/apis/mobile/2017-07-01/api-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"jsonVersion":"1.1",
"protocol":"rest-json",
"serviceFullName":"AWS Mobile",
"serviceId":"Mobile",
"signatureVersion":"v4",
"signingName":"AWSMobileHubService",
"uid":"mobile-2017-07-01"
Expand Down
1 change: 1 addition & 0 deletions models/apis/mobileanalytics/2014-06-05/api-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"metadata":{
"apiVersion":"2014-06-05",
"endpointPrefix":"mobileanalytics",
"serviceId": "Mobile Analytics",
"serviceFullName":"Amazon Mobile Analytics",
"signatureVersion":"v4",
"protocol":"rest-json"
Expand Down
1 change: 1 addition & 0 deletions models/apis/sdb/2009-04-15/api-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"metadata":{
"apiVersion":"2009-04-15",
"endpointPrefix":"sdb",
"serviceId": "SimpleDB",
"serviceFullName":"Amazon SimpleDB",
"signatureVersion":"v2",
"xmlNamespace":"http://sdb.amazonaws.com/doc/2009-04-15/",
Expand Down
43 changes: 32 additions & 11 deletions private/model/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ type API struct {
HasAccountIdWithARN bool `json:"-"`

WithGeneratedTypedErrors bool

// Set to true to strictly enforce usage of the serviceId for the package naming
StrictServiceId bool
}

// A Metadata is the metadata about an API's definition.
Expand Down Expand Up @@ -127,21 +130,29 @@ func (a *API) StructName() string {
return a.name
}

name := a.Metadata.ServiceAbbreviation
if len(name) == 0 {
name = a.Metadata.ServiceFullName
var name string
if a.StrictServiceId {
name = a.Metadata.ServiceID
if len(name) == 0 {
panic("expect serviceId to be set, but was not")
}
if legacyName, ok := legacyStructNames[strings.ToLower(name)]; ok {
// The legacy names come from service abbreviations or service full names,
// so we will want to apply the old procedure to them.
name = makeLikeServiceId(legacyName)
}
} else {
name = a.Metadata.ServiceAbbreviation
if len(name) == 0 {
name = a.Metadata.ServiceFullName
}
// If we aren't using the strictly modeled service id, then
// strip out prefix names not reflected in service client symbol names.
name = makeLikeServiceId(name)
}

name = strings.TrimSpace(name)

// Strip out prefix names not reflected in service client symbol names.
for _, prefix := range stripServiceNamePrefixes {
if strings.HasPrefix(name, prefix) {
name = name[len(prefix):]
break
}
}

// Replace all Non-letter/number values with space
runes := []rune(name)
for i := 0; i < len(runes); i++ {
Expand Down Expand Up @@ -1065,3 +1076,13 @@ func getDeprecatedMessage(msg string, name string) string {

return msg
}

func makeLikeServiceId(name string) string {
for _, prefix := range stripServiceNamePrefixes {
if strings.HasPrefix(name, prefix) {
name = name[len(prefix):]
break
}
}
return name
}
13 changes: 12 additions & 1 deletion private/model/api/customization_passes.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,18 @@ func mergeServicesCustomizations(a *API) error {

file := filepath.Join(p, "api-2.json")

serviceAPI := API{}
serviceAPI := API{
IgnoreUnsupportedAPIs: a.IgnoreUnsupportedAPIs,
NoRemoveUnusedShapes: a.NoRemoveUnusedShapes,
NoRenameToplevelShapes: a.NoRenameToplevelShapes,
NoInitMethods: a.NoInitMethods,
NoStringerMethods: a.NoStringerMethods,
NoConstServiceNames: a.NoConstServiceNames,
NoValidataShapeMethods: a.NoValidataShapeMethods,
NoGenStructFieldAccessors: a.NoGenStructFieldAccessors,
NoRemoveUnsupportedJSONValue: a.NoRemoveUnsupportedJSONValue,
StrictServiceId: a.StrictServiceId,
}
serviceAPI.Attach(file)
serviceAPI.Setup()

Expand Down
Loading

0 comments on commit 2bd6652

Please sign in to comment.