Skip to content
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

private/model/api: Add docs for errors to API operations #881

Merged
merged 3 commits into from
Oct 11, 2016
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: 9 additions & 3 deletions private/model/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,16 @@ func (a *API) ShapeNames() []string {
}

// ShapeList returns a slice of shape pointers used by the API.
//
// Will exclude error shapes from the list of shapes returned.
func (a *API) ShapeList() []*Shape {
list := make([]*Shape, len(a.Shapes))
for i, n := range a.ShapeNames() {
list[i] = a.Shapes[n]
list := make([]*Shape, 0, len(a.Shapes))
for _, n := range a.ShapeNames() {
// Ignore error shapes in list
if a.Shapes[n].IsError {
continue
}
list = append(list, a.Shapes[n])
}
return list
}
Expand Down
2 changes: 1 addition & 1 deletion private/model/api/docstring.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (d *apiDocumentation) setup() {
}

for op, doc := range d.Operations {
d.API.Operations[op].Documentation = docstring(doc)
d.API.Operations[op].Documentation = strings.TrimSpace(docstring(doc))
}

for shape, info := range d.Shapes {
Expand Down
32 changes: 29 additions & 3 deletions private/model/api/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ type Operation struct {
Name string
Documentation string
HTTP HTTPInfo
InputRef ShapeRef `json:"input"`
OutputRef ShapeRef `json:"output"`
InputRef ShapeRef `json:"input"`
OutputRef ShapeRef `json:"output"`
ErrorRefs []ShapeRef `json:"errors"`
Paginator *Paginator
Deprecated bool `json:"deprecated"`
AuthType string `json:"authtype"`
Expand Down Expand Up @@ -49,6 +50,8 @@ const op{{ .ExportedName }} = "{{ .Name }}"
// value can be used to capture response data after the request's "Send" method
// is called.
//
// See {{ .ExportedName }} for usage and error information.
//
// Creating a request object using this method should be used when you want to inject
// custom logic into the request's lifecycle using a custom handler, or if you want to
// access properties on the request object before or after sending the request. If
Expand Down Expand Up @@ -97,7 +100,30 @@ func (c *{{ .API.StructName }}) {{ .ExportedName }}Request(` +
return
}

{{ .Documentation }}func (c *{{ .API.StructName }}) {{ .ExportedName }}(` +
// {{ .ExportedName }} API operation for {{ .API.Metadata.ServiceFullName }}.
{{ if .Documentation -}}
//
{{ .Documentation }}
{{ end -}}
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for {{ .API.Metadata.ServiceFullName }}'s
// API operation {{ .ExportedName }} for usage and error information.
{{ if .ErrorRefs -}}
//
// Returned Error Codes:
{{ range $_, $err := .ErrorRefs -}}
{{ $errDoc := $err.IndentedDocstring -}}
// * {{ $err.Shape.ErrorName }}
{{ if $errDoc -}}
{{ $errDoc }}{{ end }}
//
{{ end -}}
{{ end -}}
func (c *{{ .API.StructName }}) {{ .ExportedName }}(` +
`input {{ .InputRef.GoType }}) ({{ .OutputRef.GoType }}, error) {
req, out := c.{{ .ExportedName }}Request(input)
err := req.Send()
Expand Down
6 changes: 6 additions & 0 deletions private/model/api/passes.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ func (a *API) resolveReferences() {

resolver.resolveReference(&o.InputRef)
resolver.resolveReference(&o.OutputRef)

// Resolve references for errors also
for i := range o.ErrorRefs {
resolver.resolveReference(&o.ErrorRefs[i])
o.ErrorRefs[i].Shape.IsError = true
}
}
}

Expand Down
30 changes: 30 additions & 0 deletions private/model/api/shape.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ type ShapeRef struct {
Deprecated bool `json:"deprecated"`
}

// ErrorInfo represents the error block of a shape's structure
type ErrorInfo struct {
Code string
HTTPStatusCode int
}

// A XMLInfo defines URL and prefix for Shapes when rendered as XML
type XMLInfo struct {
Prefix string
Expand Down Expand Up @@ -67,6 +73,24 @@ type Shape struct {
Deprecated bool `json:"deprecated"`

Validations ShapeValidations

// Error information that is set if the shape is an error shape.
IsError bool
ErrorInfo ErrorInfo `json:"error"`
}

// ErrorName will return the shape's name or error code if available based
// on the API's protocol.
func (s *Shape) ErrorName() string {
name := s.ShapeName
switch s.API.Metadata.Protocol {
case "query", "ec2query", "rest-xml":
if len(s.ErrorInfo.Code) > 0 {
name = s.ErrorInfo.Code
}
}

return name
}

// GoTags returns the struct tags for a shape.
Expand Down Expand Up @@ -347,6 +371,12 @@ func (s *Shape) Docstring() string {
return strings.Trim(s.Documentation, "\n ")
}

// IndentedDocstring is the indented form of the doc string.
func (ref *ShapeRef) IndentedDocstring() string {
doc := ref.Docstring()
return strings.Replace(doc, "// ", "// ", -1)
}

var goCodeStringerTmpl = template.Must(template.New("goCodeStringerTmpl").Parse(`
// String returns the string representation
func (s {{ .ShapeName }}) String() string {
Expand Down
100 changes: 100 additions & 0 deletions private/protocol/ec2query/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ const opInputService1TestCaseOperation1 = "OperationName"
// value can be used to capture response data after the request's "Send" method
// is called.
//
// See InputService1TestCaseOperation1 for usage and error information.
//
// Creating a request object using this method should be used when you want to inject
// custom logic into the request's lifecycle using a custom handler, or if you want to
// access properties on the request object before or after sending the request. If
Expand Down Expand Up @@ -139,6 +141,14 @@ func (c *InputService1ProtocolTest) InputService1TestCaseOperation1Request(input
return
}

// InputService1TestCaseOperation1 API operation for .
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for 's
// API operation InputService1TestCaseOperation1 for usage and error information.
func (c *InputService1ProtocolTest) InputService1TestCaseOperation1(input *InputService1TestShapeInputService1TestCaseOperation1Input) (*InputService1TestShapeInputService1TestCaseOperation1Output, error) {
req, out := c.InputService1TestCaseOperation1Request(input)
err := req.Send()
Expand Down Expand Up @@ -218,6 +228,8 @@ const opInputService2TestCaseOperation1 = "OperationName"
// value can be used to capture response data after the request's "Send" method
// is called.
//
// See InputService2TestCaseOperation1 for usage and error information.
//
// Creating a request object using this method should be used when you want to inject
// custom logic into the request's lifecycle using a custom handler, or if you want to
// access properties on the request object before or after sending the request. If
Expand Down Expand Up @@ -253,6 +265,14 @@ func (c *InputService2ProtocolTest) InputService2TestCaseOperation1Request(input
return
}

// InputService2TestCaseOperation1 API operation for .
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for 's
// API operation InputService2TestCaseOperation1 for usage and error information.
func (c *InputService2ProtocolTest) InputService2TestCaseOperation1(input *InputService2TestShapeInputService2TestCaseOperation1Input) (*InputService2TestShapeInputService2TestCaseOperation1Output, error) {
req, out := c.InputService2TestCaseOperation1Request(input)
err := req.Send()
Expand Down Expand Up @@ -334,6 +354,8 @@ const opInputService3TestCaseOperation1 = "OperationName"
// value can be used to capture response data after the request's "Send" method
// is called.
//
// See InputService3TestCaseOperation1 for usage and error information.
//
// Creating a request object using this method should be used when you want to inject
// custom logic into the request's lifecycle using a custom handler, or if you want to
// access properties on the request object before or after sending the request. If
Expand Down Expand Up @@ -369,6 +391,14 @@ func (c *InputService3ProtocolTest) InputService3TestCaseOperation1Request(input
return
}

// InputService3TestCaseOperation1 API operation for .
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for 's
// API operation InputService3TestCaseOperation1 for usage and error information.
func (c *InputService3ProtocolTest) InputService3TestCaseOperation1(input *InputService3TestShapeInputService3TestCaseOperation1Input) (*InputService3TestShapeInputService3TestCaseOperation1Output, error) {
req, out := c.InputService3TestCaseOperation1Request(input)
err := req.Send()
Expand Down Expand Up @@ -452,6 +482,8 @@ const opInputService4TestCaseOperation1 = "OperationName"
// value can be used to capture response data after the request's "Send" method
// is called.
//
// See InputService4TestCaseOperation1 for usage and error information.
//
// Creating a request object using this method should be used when you want to inject
// custom logic into the request's lifecycle using a custom handler, or if you want to
// access properties on the request object before or after sending the request. If
Expand Down Expand Up @@ -487,6 +519,14 @@ func (c *InputService4ProtocolTest) InputService4TestCaseOperation1Request(input
return
}

// InputService4TestCaseOperation1 API operation for .
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for 's
// API operation InputService4TestCaseOperation1 for usage and error information.
func (c *InputService4ProtocolTest) InputService4TestCaseOperation1(input *InputService4TestShapeInputService4TestCaseOperation1Input) (*InputService4TestShapeInputService4TestCaseOperation1Output, error) {
req, out := c.InputService4TestCaseOperation1Request(input)
err := req.Send()
Expand Down Expand Up @@ -564,6 +604,8 @@ const opInputService5TestCaseOperation1 = "OperationName"
// value can be used to capture response data after the request's "Send" method
// is called.
//
// See InputService5TestCaseOperation1 for usage and error information.
//
// Creating a request object using this method should be used when you want to inject
// custom logic into the request's lifecycle using a custom handler, or if you want to
// access properties on the request object before or after sending the request. If
Expand Down Expand Up @@ -599,6 +641,14 @@ func (c *InputService5ProtocolTest) InputService5TestCaseOperation1Request(input
return
}

// InputService5TestCaseOperation1 API operation for .
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for 's
// API operation InputService5TestCaseOperation1 for usage and error information.
func (c *InputService5ProtocolTest) InputService5TestCaseOperation1(input *InputService5TestShapeInputService5TestCaseOperation1Input) (*InputService5TestShapeInputService5TestCaseOperation1Output, error) {
req, out := c.InputService5TestCaseOperation1Request(input)
err := req.Send()
Expand Down Expand Up @@ -676,6 +726,8 @@ const opInputService6TestCaseOperation1 = "OperationName"
// value can be used to capture response data after the request's "Send" method
// is called.
//
// See InputService6TestCaseOperation1 for usage and error information.
//
// Creating a request object using this method should be used when you want to inject
// custom logic into the request's lifecycle using a custom handler, or if you want to
// access properties on the request object before or after sending the request. If
Expand Down Expand Up @@ -711,6 +763,14 @@ func (c *InputService6ProtocolTest) InputService6TestCaseOperation1Request(input
return
}

// InputService6TestCaseOperation1 API operation for .
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for 's
// API operation InputService6TestCaseOperation1 for usage and error information.
func (c *InputService6ProtocolTest) InputService6TestCaseOperation1(input *InputService6TestShapeInputService6TestCaseOperation1Input) (*InputService6TestShapeInputService6TestCaseOperation1Output, error) {
req, out := c.InputService6TestCaseOperation1Request(input)
err := req.Send()
Expand Down Expand Up @@ -788,6 +848,8 @@ const opInputService7TestCaseOperation1 = "OperationName"
// value can be used to capture response data after the request's "Send" method
// is called.
//
// See InputService7TestCaseOperation1 for usage and error information.
//
// Creating a request object using this method should be used when you want to inject
// custom logic into the request's lifecycle using a custom handler, or if you want to
// access properties on the request object before or after sending the request. If
Expand Down Expand Up @@ -823,6 +885,14 @@ func (c *InputService7ProtocolTest) InputService7TestCaseOperation1Request(input
return
}

// InputService7TestCaseOperation1 API operation for .
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for 's
// API operation InputService7TestCaseOperation1 for usage and error information.
func (c *InputService7ProtocolTest) InputService7TestCaseOperation1(input *InputService7TestShapeInputService7TestCaseOperation1Input) (*InputService7TestShapeInputService7TestCaseOperation1Output, error) {
req, out := c.InputService7TestCaseOperation1Request(input)
err := req.Send()
Expand Down Expand Up @@ -901,6 +971,8 @@ const opInputService8TestCaseOperation1 = "OperationName"
// value can be used to capture response data after the request's "Send" method
// is called.
//
// See InputService8TestCaseOperation1 for usage and error information.
//
// Creating a request object using this method should be used when you want to inject
// custom logic into the request's lifecycle using a custom handler, or if you want to
// access properties on the request object before or after sending the request. If
Expand Down Expand Up @@ -936,6 +1008,14 @@ func (c *InputService8ProtocolTest) InputService8TestCaseOperation1Request(input
return
}

// InputService8TestCaseOperation1 API operation for .
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for 's
// API operation InputService8TestCaseOperation1 for usage and error information.
func (c *InputService8ProtocolTest) InputService8TestCaseOperation1(input *InputService8TestShapeInputService8TestCaseOperation1Input) (*InputService8TestShapeInputService8TestCaseOperation1Output, error) {
req, out := c.InputService8TestCaseOperation1Request(input)
err := req.Send()
Expand Down Expand Up @@ -1013,6 +1093,8 @@ const opInputService9TestCaseOperation1 = "OperationName"
// value can be used to capture response data after the request's "Send" method
// is called.
//
// See InputService9TestCaseOperation1 for usage and error information.
//
// Creating a request object using this method should be used when you want to inject
// custom logic into the request's lifecycle using a custom handler, or if you want to
// access properties on the request object before or after sending the request. If
Expand Down Expand Up @@ -1049,6 +1131,14 @@ func (c *InputService9ProtocolTest) InputService9TestCaseOperation1Request(input
return
}

// InputService9TestCaseOperation1 API operation for .
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for 's
// API operation InputService9TestCaseOperation1 for usage and error information.
func (c *InputService9ProtocolTest) InputService9TestCaseOperation1(input *InputService9TestShapeInputShape) (*InputService9TestShapeInputService9TestCaseOperation1Output, error) {
req, out := c.InputService9TestCaseOperation1Request(input)
err := req.Send()
Expand All @@ -1062,6 +1152,8 @@ const opInputService9TestCaseOperation2 = "OperationName"
// value can be used to capture response data after the request's "Send" method
// is called.
//
// See InputService9TestCaseOperation2 for usage and error information.
//
// Creating a request object using this method should be used when you want to inject
// custom logic into the request's lifecycle using a custom handler, or if you want to
// access properties on the request object before or after sending the request. If
Expand Down Expand Up @@ -1098,6 +1190,14 @@ func (c *InputService9ProtocolTest) InputService9TestCaseOperation2Request(input
return
}

// InputService9TestCaseOperation2 API operation for .
//
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
// with awserr.Error's Code and Message methods to get detailed information about
// the error.
//
// See the AWS API reference guide for 's
// API operation InputService9TestCaseOperation2 for usage and error information.
func (c *InputService9ProtocolTest) InputService9TestCaseOperation2(input *InputService9TestShapeInputShape) (*InputService9TestShapeInputService9TestCaseOperation2Output, error) {
req, out := c.InputService9TestCaseOperation2Request(input)
err := req.Send()
Expand Down
Loading