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