/
petstore.go
194 lines (185 loc) · 4.39 KB
/
petstore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// Package petstore API
//
// The purpose of this application is to provie an application
// that is using plain go to define an API.
//
// This should demonstrate many comment annotations
// that are available to turn go code into a fully compliant swagger 2.0 spec
//
// Terms Of Service:
//
// there are no TOS at this moment, use at your own risk we take no responsibility
//
// Schemes: http
// Host: petstore.swagger.wordnik.com
// BasePath: /api
// Version: 1.0.0
// License: MIT http://opensource.org/licenses/MIT
// Contact: John Doe<john.doe@example.com> http://john.doe.com
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
//
// swagger:meta
package petstore
// NewPet represents a new pet within this application
//
// A new pet is preferable a puppy.
//
// swagger:model newPet
type NewPet struct {
// the name for this pet
// required: true
Name string `json:"name"`
}
// Pet represents a pet within this application
//
// A pet is preferable cute and fluffy.
//
// Examples of typical pets are dogs and cats.
//
// swagger:model pet
type Pet struct {
// swager:allOf
NewPet
// the id for this pet
// required: true
Identifier int64 `json:"id"`
}
// ErrorModel represents a generic error in this application
//
// An error will typically return this model.
//
// The code and message of the error,
// both get returned.
//
// swagger:model errorModel
type ErrorModel struct {
// the code for this error
// required: true
Code int32 `json:"code"`
// the message for this error
// required: true
Message string `json:"message"`
}
// ServeAPI serves the API for this record store
func ServeAPI(host, basePath string, schemes []string) (err error) {
// swagger:operation GET /pets getPet
//
// Returns all pets from the system that the user has access to
//
// ---
// produces:
// - application/json
// - application/xml
// - text/xml
// - text/html
// parameters:
// - name: tags
// in: query
// description: tags to filter by
// required: false
// type: array
// items:
// type: string
// collectionFormat: csv
// - name: limit
// in: query
// description: maximum number of results to return
// required: false
// type: integer
// format: int32
// responses:
// '200':
// description: pet response
// schema:
// type: array
// items:
// "$ref": "#/definitions/pet"
// default:
// description: unexpected error
// schema:
// "$ref": "#/definitions/errorModel"
mountItem("GET", basePath+"/pets", nil)
// swagger:operation POST /pets addPet
//
// Creates a new pet in the store.
// Duplicates are allowed
//
// ---
// produces:
// - application/json
// parameters:
// - name: pet
// in: body
// description: Pet to add to the store
// required: true
// schema:
// "$ref": "#/definitions/newPet"
//
// responses:
// '200':
// description: pet response
// schema:
// "$ref": "#/definitions/pet"
// default:
// description: unexpected error
// schema:
// "$ref": "#/definitions/errorModel"
mountItem("POST", basePath+"/pets", nil)
// swagger:operation GET /pets/{id} findPetById
//
// Returns a user based on a single ID,
// if the user does not have access to the pet
//
// ---
// produces:
// - application/json
// - application/xml
// - text/xml
// - text/html
// parameters:
// - name: id
// in: path
// description: ID of pet to fetch
// required: true
// type: integer
// format: int64
// responses:
// '200':
// description: pet response
// schema:
// "$ref": "#/definitions/pet"
// default:
// description: unexpected error
// schema:
// "$ref": "#/definitions/errorModel"
mountItem("GET", basePath+"/pets/{id}", nil)
// swagger:operation DELETE /pets/{id} deletePet
//
// deletes a single pet based on the ID supplied
//
// ---
// parameters:
// - name: id
// in: path
// description: ID of pet to delete
// required: true
// type: integer
// format: int64
// responses:
// '204':
// description: pet deleted
// default:
// description: unexpected error
// schema:
// "$ref": "#/definitions/errorModel"
mountItem("DELETE", basePath+"/pets/{id}", nil)
return
}
// not really used but I need a method to decorate the calls to
func mountItem(method, path string, handler interface{}) {}