Skip to content

Commit

Permalink
Revert "Revert RESTJSON and RESTXML changes of SDK v1.11.0 (aws#1551)"
Browse files Browse the repository at this point in the history
This reverts commit 6a946b2.

Fixes the aws#1550 bug with RESTXML not correctly marshaling Amazon Route53 APIs
  • Loading branch information
jasdel committed Nov 27, 2017
1 parent 70e6003 commit 7a80f55
Show file tree
Hide file tree
Showing 60 changed files with 61,137 additions and 366 deletions.
4 changes: 4 additions & 0 deletions models/protocol_tests/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ func generateTestSuite(filename string) string {
svcPrefix := inout + "Service" + strconv.Itoa(i+1)
suite.API.Metadata.ServiceAbbreviation = svcPrefix + "ProtocolTest"
suite.API.Operations = map[string]*api.Operation{}

for idx, c := range suite.Cases {
c.Given.ExportedName = svcPrefix + "TestCaseOperation" + strconv.Itoa(idx+1)
suite.API.Operations[c.Given.ExportedName] = c.Given
Expand All @@ -395,6 +396,9 @@ func generateTestSuite(filename string) string {
suite.API.Setup()
suite.API.Metadata.EndpointPrefix = suite.API.PackageName()

// TODO until generated marshalers are all supported
suite.API.EnableSelectGeneratedMarshalers()

// Sort in order for deterministic test generation
names := make([]string, 0, len(suite.API.Shapes))
for n := range suite.API.Shapes {
Expand Down
7 changes: 7 additions & 0 deletions private/model/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ type API struct {
// Set to true to not generate struct field accessors
NoGenStructFieldAccessors bool

// Set to true to not generate (un)marshalers
NoGenMarshalers bool
NoGenUnmarshalers bool

SvcClientImportPath string

initialized bool
Expand Down Expand Up @@ -272,6 +276,9 @@ func (a *API) APIGoCode() string {
a.imports["github.com/aws/aws-sdk-go/private/protocol/"+a.ProtocolPackage()] = true
a.imports["github.com/aws/aws-sdk-go/private/protocol"] = true
}
if !a.NoGenMarshalers || !a.NoGenUnmarshalers {
a.imports["github.com/aws/aws-sdk-go/private/protocol"] = true
}

for _, op := range a.Operations {
if op.AuthType == "none" {
Expand Down
15 changes: 15 additions & 0 deletions private/model/api/customization_passes.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ func (a *API) customizationPasses() {
if fn := svcCustomizations[a.PackageName()]; fn != nil {
fn(a)
}

// TODO until generated marshalers are all supported
a.EnableSelectGeneratedMarshalers()
}

func (a *API) EnableSelectGeneratedMarshalers() {
// Selectivily enable generated marshalers as available
a.NoGenMarshalers = true
a.NoGenUnmarshalers = true

// Enable generated marshalers
switch a.Metadata.Protocol {
case "rest-xml", "rest-json":
a.NoGenMarshalers = false
}
}

// s3Customizations customizes the API generation to replace values specific to S3.
Expand Down
9 changes: 9 additions & 0 deletions private/model/api/passes.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ func (a *API) resolveReferences() {
o.ErrorRefs[i].Shape.IsError = true
}
}

for _, s := range a.Shapes {
switch s.Type {
case "list":
s.MemberRef.Shape.UsedInList = true
case "map":
s.ValueRef.Shape.UsedInMap = true
}
}
}

// A referenceResolver provides a way to resolve shape references to
Expand Down
24 changes: 22 additions & 2 deletions private/model/api/shape.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ type Shape struct {

OrigShapeName string `json:"-"`

UsedInMap bool
UsedInList bool

// Defines if the shape is a placeholder and should not be used directly
Placeholder bool

Expand Down Expand Up @@ -185,10 +188,18 @@ func (s *Shape) GoStructValueType(name string, ref *ShapeRef) string {
return v
}

func (s *Shape) IsRefPayload(name string) bool {
return s.Payload == name
}

func (s *Shape) IsRefPayloadReader(name string, ref *ShapeRef) bool {
return (ref.Streaming || ref.Shape.Streaming) && s.IsRefPayload(name)
}

// GoStructType returns the type of a struct field based on the API
// model definition.
func (s *Shape) GoStructType(name string, ref *ShapeRef) string {
if (ref.Streaming || ref.Shape.Streaming) && s.Payload == name {
if s.IsRefPayloadReader(name, ref) {
rtype := "io.ReadSeeker"
if strings.HasSuffix(s.ShapeName, "Output") {
rtype = "io.ReadCloser"
Expand Down Expand Up @@ -513,7 +524,9 @@ func (s *Shape) NestedShape() *Shape {
}

var structShapeTmpl = template.Must(template.New("StructShape").Funcs(template.FuncMap{
"GetCrosslinkURL": GetCrosslinkURL,
"GetCrosslinkURL": GetCrosslinkURL,
"MarshalShapeGoCode": MarshalShapeGoCode,
"UnmarshalShapeGoCode": UnmarshalShapeGoCode,
}).Parse(`
{{ .Docstring }}
{{ if ne $.OrigShapeName "" -}}
Expand Down Expand Up @@ -597,6 +610,13 @@ func (s *{{ $builderShapeName }}) get{{ $name }}() (v {{ $context.GoStructValueT
{{ end }}
{{ end }}
{{ if not $.API.NoGenMarshalers -}}
{{ MarshalShapeGoCode $ }}
{{- end }}
{{ if not $.API.NoGenUnmarshalers -}}
{{ UnmarshalShapeGoCode $ }}
{{- end }}
`))

var enumShapeTmpl = template.Must(template.New("EnumShape").Parse(`
Expand Down
Loading

0 comments on commit 7a80f55

Please sign in to comment.