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 { type ErrorResponse struct {
// code // code
Code int64 `json:"code,omitempty"` Code int32 `json:"code,omitempty"`
// message // message
// Required: true // Required: true

View File

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

View File

@ -12,7 +12,7 @@ import (
"github.com/go-openapi/runtime" "github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware" "github.com/go-openapi/runtime/middleware"
models "github.com/elfsternberg/timeofday/models" strfmt "github.com/go-openapi/strfmt"
) )
// NewClockGetParams creates a new ClockGetParams object // NewClockGetParams creates a new ClockGetParams object
@ -32,9 +32,9 @@ type ClockGetParams struct {
HTTPRequest *http.Request `json:"-"` HTTPRequest *http.Request `json:"-"`
/*Timezone to return /*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 // 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 o.HTTPRequest = r
if runtime.HasBody(r) { qs := runtime.Values(r.URL.Query())
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 {
// validate body object qTimezone, qhkTimezone, _ := qs.GetOK("timezone")
if err := body.Validate(route.Formats); err != nil { if err := o.bindTimezone(qTimezone, qhkTimezone, route.Formats); err != nil {
res = append(res, err) res = append(res, err)
}
if len(res) == 0 {
o.Timezone = &body
}
}
} }
if len(res) > 0 { if len(res) > 0 {
return errors.CompositeValidationError(res...) return errors.CompositeValidationError(res...)
} }
return nil 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 // ClockGetURL generates an URL for the clock get operation
type ClockGetURL struct { type ClockGetURL struct {
Timezone *string
_basePath string _basePath string
// avoid unkeyed usage
_ struct{}
} }
// WithBasePath sets the base path for this url builder, only required when it's different from the // 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) 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 return &result, nil
} }

View File

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