feat(api): improve codegen outputs (#41)

* Use `[]byte` for generated request bodies when the source schema has `format: byte`
* Gzip-compress request bodies when `Content-Encoding: gzip` is set
* Require that all models returned as error conditions in our API implement the `error` interface
* Move the implementation for `api.HealthCheck` out of `ping.go` and into `api/error.go`


Co-authored-by: William Baker <55118525+wbaker85@users.noreply.github.com>
This commit is contained in:
Daniel Moran
2021-04-26 10:10:45 -04:00
committed by GitHub
parent 5328b1fdc8
commit 73dc5ef63b
11 changed files with 147 additions and 40 deletions

View File

@ -5,7 +5,8 @@ import (
"strings"
)
// Extension to let our API error type be used as a "standard" error.
// Extensions to let our API error types be used as "standard" errors.
func (o *Error) Error() string {
if o.Message != "" && o.Err != nil {
var b strings.Builder
@ -20,3 +21,17 @@ func (o *Error) Error() string {
}
return fmt.Sprintf("<%s>", o.Code)
}
func (o *HealthCheck) Error() string {
if o.Status == HEALTHCHECKSTATUS_PASS {
// Make sure we aren't misusing HealthCheck responses.
panic("successful healthcheck used as an error!")
}
var message string
if o.Message != nil {
message = *o.Message
} else {
message = fmt.Sprintf("check %s failed", o.Name)
}
return fmt.Sprintf("health check failed: %s", message)
}