The final swagger.yml and the built files that go with it.

This commit is contained in:
Elf M. Sternberg 2018-03-28 16:21:57 -07:00
parent 013ae484ad
commit f4945676fd
5 changed files with 52 additions and 34 deletions

View File

@ -18,7 +18,7 @@ import (
type ErrorResponse struct {
// code
Code int64 `json:"code,omitempty"`
Code int32 `json:"code,omitempty"`
// message
// Required: true

View File

@ -49,12 +49,10 @@ func init() {
"operationId": "ClockGet",
"parameters": [
{
"type": "string",
"description": "Timezone to return",
"name": "timezone",
"in": "body",
"schema": {
"$ref": "#/definitions/timezone"
}
"in": "query"
}
],
"responses": {
@ -123,7 +121,7 @@ func init() {
"properties": {
"code": {
"type": "integer",
"format": "int64"
"format": "int32"
},
"message": {
"type": "string"
@ -185,12 +183,10 @@ func init() {
"operationId": "ClockGet",
"parameters": [
{
"type": "string",
"description": "Timezone to return",
"name": "timezone",
"in": "body",
"schema": {
"$ref": "#/definitions/timezone"
}
"in": "query"
}
],
"responses": {
@ -259,7 +255,7 @@ func init() {
"properties": {
"code": {
"type": "integer",
"format": "int64"
"format": "int32"
},
"message": {
"type": "string"

View File

@ -12,7 +12,7 @@ import (
"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware"
models "github.com/elfsternberg/timeofday/models"
strfmt "github.com/go-openapi/strfmt"
)
// NewClockGetParams creates a new ClockGetParams object
@ -32,9 +32,9 @@ type ClockGetParams struct {
HTTPRequest *http.Request `json:"-"`
/*Timezone to return
In: body
In: query
*/
Timezone *models.Timezone
Timezone *string
}
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
@ -46,25 +46,32 @@ func (o *ClockGetParams) BindRequest(r *http.Request, route *middleware.MatchedR
o.HTTPRequest = r
if runtime.HasBody(r) {
defer r.Body.Close()
var body models.Timezone
if err := route.Consumer.Consume(r.Body, &body); err != nil {
res = append(res, errors.NewParseError("timezone", "body", "", err))
} else {
qs := runtime.Values(r.URL.Query())
// validate body object
if err := body.Validate(route.Formats); err != nil {
res = append(res, err)
}
if len(res) == 0 {
o.Timezone = &body
}
}
qTimezone, qhkTimezone, _ := qs.GetOK("timezone")
if err := o.bindTimezone(qTimezone, qhkTimezone, route.Formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (o *ClockGetParams) bindTimezone(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: false
// AllowEmptyValue: false
if raw == "" { // empty values pass all other validations
return nil
}
o.Timezone = &raw
return nil
}

View File

@ -13,7 +13,11 @@ import (
// ClockGetURL generates an URL for the clock get operation
type ClockGetURL struct {
Timezone *string
_basePath string
// avoid unkeyed usage
_ struct{}
}
// WithBasePath sets the base path for this url builder, only required when it's different from the
@ -43,6 +47,18 @@ func (o *ClockGetURL) Build() (*url.URL, error) {
}
result.Path = golangswaggerpaths.Join(_basePath, _path)
qs := make(url.Values)
var timezone string
if o.Timezone != nil {
timezone = *o.Timezone
}
if timezone != "" {
qs.Set("timezone", timezone)
}
result.RawQuery = qs.Encode()
return &result, nil
}

View File

@ -44,7 +44,7 @@ definitions:
properties:
code:
type: integer
format: int64
format: int32
message:
type: string
required:
@ -80,12 +80,11 @@ paths:
description: "Returns time of day."
operationId: "ClockGet"
parameters:
- in: "body"
name: "timezone"
- in: query
name: timezone
description: "Timezone to return"
required: false
schema:
$ref: "#/definitions/timezone"
type: string
responses:
200:
description: "Returns the time of day."