github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/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 // swagger:meta 27 package petstore 28 29 // NewPet represents a new pet within this application 30 // 31 // A new pet is preferable a puppy. 32 // 33 // swagger:model newPet 34 type NewPet struct { 35 // the name for this pet 36 // required: true 37 Name string `json:"name"` 38 } 39 40 // Pet represents a pet within this application 41 // 42 // A pet is preferable cute and fluffy. 43 // 44 // Examples of typical pets are dogs and cats. 45 // 46 // swagger:model pet 47 type Pet struct { 48 // swager:allOf 49 NewPet 50 // the id for this pet 51 // required: true 52 Identifier int64 `json:"id"` 53 } 54 55 // ErrorModel represents a generic error in this application 56 // 57 // An error will typically return this model. 58 // 59 // The code and message of the error, 60 // both get returned. 61 // 62 // swagger:model errorModel 63 type ErrorModel struct { 64 // the code for this error 65 // required: true 66 Code int32 `json:"code"` 67 // the message for this error 68 // required: true 69 Message string `json:"message"` 70 } 71 72 // ServeAPI serves the API for this record store 73 func ServeAPI(host, basePath string, schemes []string) (err error) { 74 // swagger:operation GET /pets getPet 75 // 76 // Returns all pets from the system that the user has access to 77 // 78 // --- 79 // produces: 80 // - application/json 81 // - application/xml 82 // - text/xml 83 // - text/html 84 // parameters: 85 // - name: tags 86 // in: query 87 // description: tags to filter by 88 // required: false 89 // type: array 90 // items: 91 // type: string 92 // collectionFormat: csv 93 // - name: limit 94 // in: query 95 // description: maximum number of results to return 96 // required: false 97 // type: integer 98 // format: int32 99 // responses: 100 // '200': 101 // description: pet response 102 // schema: 103 // type: array 104 // items: 105 // "$ref": "#/definitions/pet" 106 // default: 107 // description: unexpected error 108 // schema: 109 // "$ref": "#/definitions/errorModel" 110 mountItem("GET", basePath+"/pets", nil) 111 112 // swagger:operation POST /pets addPet 113 // 114 // Creates a new pet in the store. 115 // Duplicates are allowed 116 // 117 // --- 118 // produces: 119 // - application/json 120 // parameters: 121 // - name: pet 122 // in: body 123 // description: Pet to add to the store 124 // required: true 125 // schema: 126 // "$ref": "#/definitions/newPet" 127 // 128 // responses: 129 // '200': 130 // description: pet response 131 // schema: 132 // "$ref": "#/definitions/pet" 133 // default: 134 // description: unexpected error 135 // schema: 136 // "$ref": "#/definitions/errorModel" 137 mountItem("POST", basePath+"/pets", nil) 138 139 // swagger:operation GET /pets/{id} findPetById 140 // 141 // Returns a user based on a single ID, 142 // if the user does not have access to the pet 143 // 144 // --- 145 // produces: 146 // - application/json 147 // - application/xml 148 // - text/xml 149 // - text/html 150 // parameters: 151 // - name: id 152 // in: path 153 // description: ID of pet to fetch 154 // required: true 155 // type: integer 156 // format: int64 157 // responses: 158 // '200': 159 // description: pet response 160 // schema: 161 // "$ref": "#/definitions/pet" 162 // default: 163 // description: unexpected error 164 // schema: 165 // "$ref": "#/definitions/errorModel" 166 mountItem("GET", basePath+"/pets/{id}", nil) 167 168 // swagger:operation DELETE /pets/{id} deletePet 169 // 170 // deletes a single pet based on the ID supplied 171 // 172 // --- 173 // parameters: 174 // - name: id 175 // in: path 176 // description: ID of pet to delete 177 // required: true 178 // type: integer 179 // format: int64 180 // responses: 181 // '204': 182 // description: pet deleted 183 // default: 184 // description: unexpected error 185 // schema: 186 // "$ref": "#/definitions/errorModel" 187 mountItem("DELETE", basePath+"/pets/{id}", nil) 188 189 return 190 } 191 192 // not really used but I need a method to decorate the calls to 193 func mountItem(method, path string, handler interface{}) {}