vendor: update all dependencies to latest versions

This commit is contained in:
Nick Craig-Wood 2018-01-16 13:20:59 +00:00
parent 8e83fb6fb9
commit 7d3a17725d
4878 changed files with 1974229 additions and 201215 deletions

View file

@ -10,10 +10,10 @@ import (
"io/ioutil"
"path"
"path/filepath"
"regexp"
"sort"
"strings"
"text/template"
"unicode"
)
// An API defines a service API's definition. and logic to serialize the definition.
@ -94,23 +94,53 @@ func (a *API) InterfacePackageName() string {
return a.PackageName() + "iface"
}
var nameRegex = regexp.MustCompile(`^Amazon|AWS\s*|\(.*|\s+|\W+`)
var stripServiceNamePrefixes = []string{
"Amazon",
"AWS",
}
// StructName returns the struct name for a given API.
func (a *API) StructName() string {
if a.name == "" {
name := a.Metadata.ServiceAbbreviation
if name == "" {
name = a.Metadata.ServiceFullName
}
if len(a.name) != 0 {
return a.name
}
name = nameRegex.ReplaceAllString(name, "")
name := a.Metadata.ServiceAbbreviation
if len(name) == 0 {
name = a.Metadata.ServiceFullName
}
a.name = name
if name, ok := serviceAliases[strings.ToLower(name)]; ok {
a.name = 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++ {
if r := runes[i]; !(unicode.IsNumber(r) || unicode.IsLetter(r)) {
runes[i] = ' '
}
}
name = string(runes)
// Title case name so its readable as a symbol.
name = strings.Title(name)
// Strip out spaces.
name = strings.Replace(name, " ", "", -1)
// Swap out for alias name if one is defined.
if alias, ok := serviceAliases[strings.ToLower(name)]; ok {
name = alias
}
a.name = name
return a.name
}
@ -307,6 +337,12 @@ var noCrossLinkServices = map[string]struct{}{
"swf": {},
}
// HasCrosslinks will return whether or not a service has crosslinking .
func HasCrosslinks(service string) bool {
_, ok := noCrossLinkServices[service]
return !ok
}
// GetCrosslinkURL returns the crosslinking URL for the shape based on the name and
// uid provided. Empty string is returned if no crosslink link could be determined.
func GetCrosslinkURL(baseURL, uid string, params ...string) string {
@ -314,14 +350,16 @@ func GetCrosslinkURL(baseURL, uid string, params ...string) string {
return ""
}
if _, ok := noCrossLinkServices[strings.ToLower(serviceIDFromUID(uid))]; ok {
if !HasCrosslinks(strings.ToLower(ServiceIDFromUID(uid))) {
return ""
}
return strings.Join(append([]string{baseURL, "goto", "WebAPI", uid}, params...), "/")
}
func serviceIDFromUID(uid string) string {
// ServiceIDFromUID will parse the service id from the uid and return
// the service id that was found.
func ServiceIDFromUID(uid string) string {
found := 0
i := len(uid) - 1
for ; i >= 0; i-- {
@ -363,7 +401,7 @@ var tplServiceDoc = template.Must(template.New("service docs").Funcs(template.Fu
//
// Using the Client
//
// To {{ .Metadata.ServiceFullName }} with the SDK use the New function to create
// To contact {{ .Metadata.ServiceFullName }} with the SDK use the New function to create
// a new service client. With that client you can make API requests to the service.
// These clients are safe to use concurrently.
//

View file

@ -1,4 +1,4 @@
// +build 1.6,codegen
// +build go1.8,codegen
package api
@ -6,49 +6,66 @@ import (
"testing"
)
func TestStructNameWithFullName(t *testing.T) {
a := API{
Metadata: Metadata{
ServiceFullName: "Amazon Service Name-100",
func TestAPI_StructName(t *testing.T) {
origAliases := serviceAliases
defer func() { serviceAliases = origAliases }()
cases := map[string]struct {
Aliases map[string]string
Metadata Metadata
StructName string
}{
"FullName": {
Metadata: Metadata{
ServiceFullName: "Amazon Service Name-100",
},
StructName: "ServiceName100",
},
"Abbreviation": {
Metadata: Metadata{
ServiceFullName: "Amazon Service Name-100",
ServiceAbbreviation: "AWS SN100",
},
StructName: "SN100",
},
"Lowercase Name": {
Metadata: Metadata{
EndpointPrefix: "other",
ServiceFullName: "AWS Lowercase service",
ServiceAbbreviation: "lowercase",
},
StructName: "Lowercase",
},
"Lowercase Name Mixed": {
Metadata: Metadata{
EndpointPrefix: "other",
ServiceFullName: "AWS Lowercase service",
ServiceAbbreviation: "lowercase name Goes heRe",
},
StructName: "LowercaseNameGoesHeRe",
},
"Alias": {
Aliases: map[string]string{
"elasticloadbalancing": "ELB",
},
Metadata: Metadata{
ServiceFullName: "Elastic Load Balancing",
},
StructName: "ELB",
},
}
if a.StructName() != "ServiceName100" {
t.Errorf("API struct name should have been %s, but received %s", "ServiceName100", a.StructName())
}
}
func TestStructNameWithAbbreviation(t *testing.T) {
a := API{
Metadata: Metadata{
ServiceFullName: "AWS Service Name-100",
ServiceAbbreviation: "AWS SN100",
},
}
if a.StructName() != "SN100" {
t.Errorf("API struct name should have been %s, but received %s", "SN100", a.StructName())
}
}
func TestStructNameForExceptions(t *testing.T) {
serviceAliases = map[string]string{}
serviceAliases["elasticloadbalancing"] = "ELB"
serviceAliases["config"] = "ConfigService"
a := API{
Metadata: Metadata{
ServiceFullName: "Elastic Load Balancing",
},
}
if a.StructName() != "ELB" {
t.Errorf("API struct name should have been %s, but received %s", "ELB", a.StructName())
}
a = API{
Metadata: Metadata{
ServiceFullName: "AWS Config",
},
}
if a.StructName() != "ConfigService" {
t.Errorf("API struct name should have been %s, but received %s", "ConfigService", a.StructName())
for k, c := range cases {
t.Run(k, func(t *testing.T) {
serviceAliases = c.Aliases
a := API{
Metadata: c.Metadata,
}
if e, o := c.StructName, a.StructName(); e != o {
t.Errorf("expect %v structName, got %v", e, o)
}
})
}
}

View file

@ -58,6 +58,8 @@ func (a *API) Setup() {
if !a.NoRenameToplevelShapes {
a.renameToplevelShapes()
}
a.renameCollidingFields()
a.updateTopLevelShapeReferences()
a.createInputOutputShapes()
a.customizationPasses()

View file

@ -95,7 +95,7 @@ const op{{ .ExportedName }} = "{{ .Name }}"
{{ $crosslinkURL := GetCrosslinkURL $.API.BaseCrosslinkURL $.API.Metadata.UID $.ExportedName -}}
{{ if ne $crosslinkURL "" -}}
//
// Please also see {{ $crosslinkURL }}
// See also, {{ $crosslinkURL }}
{{ end -}}
func (c *{{ .API.StructName }}) {{ .ExportedName }}Request(` +
`input {{ .InputRef.GoType }}) (req *request.Request, output {{ .OutputRef.GoType }}) {
@ -152,7 +152,7 @@ func (c *{{ .API.StructName }}) {{ .ExportedName }}Request(` +
{{ end -}}
{{ $crosslinkURL := GetCrosslinkURL $.API.BaseCrosslinkURL $.API.Metadata.UID $.ExportedName -}}
{{ if ne $crosslinkURL "" -}}
// Please also see {{ $crosslinkURL }}
// See also, {{ $crosslinkURL }}
{{ end -}}
func (c *{{ .API.StructName }}) {{ .ExportedName }}(` +
`input {{ .InputRef.GoType }}) ({{ .OutputRef.GoType }}, error) {

View file

@ -4,6 +4,7 @@ package api
import (
"fmt"
"encoding/json"
"reflect"
"strings"
@ -79,6 +80,19 @@ func (f paramFiller) paramsStructAny(value interface{}, shape *Shape) string {
if v.IsValid() {
return fmt.Sprintf("aws.Time(time.Unix(%d, 0))", int(v.Float()))
}
case "jsonvalue":
v, err := json.Marshal(value)
if err != nil {
panic("failed to marshal JSONValue, "+err.Error())
}
const tmpl = `func() aws.JSONValue {
var m aws.JSONValue
if err := json.Unmarshal([]byte(%q), &m); err != nil {
panic("failed to unmarshal JSONValue, "+err.Error())
}
return m
}()`
return fmt.Sprintf(tmpl, string(v))
default:
panic("Unhandled type " + shape.Type)
}

View file

@ -164,7 +164,7 @@ func (a *API) fixStutterNames() {
for name, op := range a.Operations {
newName := re.ReplaceAllString(name, "")
if newName != name {
if newName != name && len(newName) > 0 {
delete(a.Operations, name)
a.Operations[newName] = op
}
@ -173,7 +173,7 @@ func (a *API) fixStutterNames() {
for k, s := range a.Shapes {
newName := re.ReplaceAllString(k, "")
if newName != s.ShapeName {
if newName != s.ShapeName && len(newName) > 0 {
s.Rename(newName)
}
}
@ -244,6 +244,50 @@ func (a *API) renameExportable() {
}
}
// renameCollidingFields will rename any fields that uses an SDK or Golang
// specific name.
func (a *API) renameCollidingFields() {
for _, v := range a.Shapes {
namesWithSet := map[string]struct{}{}
for k, field := range v.MemberRefs {
if strings.HasPrefix(k, "Set") {
namesWithSet[k] = struct{}{}
}
if collides(k) {
renameCollidingField(k, v, field)
}
}
// checks if any field names collide with setters.
for name := range namesWithSet {
if field, ok := v.MemberRefs["Set"+name]; ok {
renameCollidingField(name, v, field)
}
}
}
}
func renameCollidingField(name string, v *Shape, field *ShapeRef) {
newName := name + "_"
fmt.Printf("Shape %s's field %q renamed to %q\n", v.ShapeName, name, newName)
delete(v.MemberRefs, name)
v.MemberRefs[newName] = field
}
// collides will return true if it is a name used by the SDK or Golang.
func collides(name string) bool {
switch name {
case "String",
"GoString",
"Validate":
return true
default:
return false
}
}
// createInputOutputShapes creates toplevel input/output shapes if they
// have not been defined in the API. This normalizes all APIs to always
// have an input and output structure in the signature.

View file

@ -22,7 +22,7 @@ func TestUniqueInputAndOutputs(t *testing.T) {
v.output = true
shamelist["FooService"]["OpBothNoRename"] = v
testCases := [][]struct {
cases := [][]struct {
expectedInput string
expectedOutput string
operation string
@ -113,7 +113,7 @@ func TestUniqueInputAndOutputs(t *testing.T) {
},
}
for _, c := range testCases {
for _, c := range cases {
a := &API{
name: "FooService",
Operations: map[string]*Operation{},
@ -167,3 +167,45 @@ func TestUniqueInputAndOutputs(t *testing.T) {
}
}
func TestCollidingFields(t *testing.T) {
cases := []struct {
api *API
expected []*Shapes
}{
{
&API{
name: "FooService",
Shapes: []*Shapes{
{
MemberRefs: map[string]*ShapeRef{
"String": &ShapeRef{},
"GoString": &ShapeRef{},
"Validate": &ShapeRef{},
"Foo": &ShapeRef{},
"SetFoo": &ShapeRef{},
},
},
},
},
[]*Shapes{
{
MemberRefs: map[string]*ShapeRef{
"String_": &ShapeRef{},
"GoString_": &ShapeRef{},
"Validate_": &ShapeRef{},
"Foo": &ShapeRef{},
"SetFoo_": &ShapeRef{},
},
},
},
},
}
for _, c := range testCases {
c.api.renameCollidingFields()
if !reflect.DeepEqual(c.api.Shapes, c.expected) {
t.Errorf("expected %v, but received %v", c.expected, c.api.Shapes)
}
}
}

View file

@ -519,12 +519,12 @@ var structShapeTmpl = template.Must(template.New("StructShape").Funcs(template.F
{{ if ne $.OrigShapeName "" -}}
{{ $crosslinkURL := GetCrosslinkURL $.API.BaseCrosslinkURL $.API.Metadata.UID $.OrigShapeName -}}
{{ if ne $crosslinkURL "" -}}
// Please also see {{ $crosslinkURL }}
// See also, {{ $crosslinkURL }}
{{ end -}}
{{ else -}}
{{ $crosslinkURL := GetCrosslinkURL $.API.BaseCrosslinkURL $.API.Metadata.UID $.ShapeName -}}
{{ if ne $crosslinkURL "" -}}
// Please also see {{ $crosslinkURL }}
// See also, {{ $crosslinkURL }}
{{ end -}}
{{ end -}}
{{ $context := . -}}

View file

@ -183,6 +183,7 @@ func writeServiceFiles(g *generateInfo, filename string) {
if r := recover(); r != nil {
fmt.Fprintf(os.Stderr, "Error generating %s\n%s\n%s\n",
filename, r, debug.Stack())
os.Exit(1)
}
}()