github.com/josephspurrier/go-swagger@v0.2.1-0.20221129144919-1f672a142a00/fixtures/goparsing/petstore/rest/handlers/pets.go (about)

     1  // Copyright 2015 go-swagger maintainers
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package handlers
    16  
    17  import (
    18  	"net/http"
    19  	"time"
    20  
    21  	"github.com/go-openapi/runtime/middleware/denco"
    22  	"github.com/go-swagger/go-swagger/fixtures/goparsing/petstore/enums"
    23  	"github.com/go-swagger/go-swagger/fixtures/goparsing/petstore/models"
    24  )
    25  
    26  // A GenericError is the default error message that is generated.
    27  // For certain status codes there are more appropriate error structures.
    28  //
    29  // swagger:response genericError
    30  type GenericError struct {
    31  	// in: body
    32  	Body struct {
    33  		Code    int32 `json:"code"`
    34  		Message error `json:"message"`
    35  	} `json:"body"`
    36  }
    37  
    38  // A ValidationError is an that is generated for validation failures.
    39  // It has the same fields as a generic error but adds a Field property.
    40  //
    41  // swagger:response validationError
    42  type ValidationError struct {
    43  	// in: body
    44  	Body struct {
    45  		Code    int32  `json:"code"`
    46  		Message string `json:"message"`
    47  		Field   string `json:"field"`
    48  	} `json:"body"`
    49  }
    50  
    51  // A PetQueryFlags contains the query flags for things that list pets.
    52  // swagger:parameters listPets
    53  type PetQueryFlags struct {
    54  	// Status
    55  	Status enums.Status `json:"status"`
    56  
    57  	// Birthday
    58  	//
    59  	// swagger:strfmt date
    60  	Birthday time.Time `json:"birthday"`
    61  }
    62  
    63  // A PetID parameter model.
    64  //
    65  // This is used for operations that want the ID of an pet in the path
    66  // swagger:parameters getPetById deletePet updatePet
    67  type PetID struct {
    68  	// The ID of the pet
    69  	//
    70  	// in: path
    71  	// required: true
    72  	ID int64 `json:"id"`
    73  }
    74  
    75  // A PetBodyParams model.
    76  //
    77  // This is used for operations that want an Order as body of the request
    78  // swagger:parameters updatePet createPet
    79  type PetBodyParams struct {
    80  	// The pet to submit.
    81  	//
    82  	// in: body
    83  	// required: true
    84  	Pet *models.Pet `json:"pet"`
    85  }
    86  
    87  // GetPets swagger:route GET /pets pets listPets
    88  //
    89  // Lists the pets known to the store.
    90  //
    91  // By default it will only lists pets that are available for sale.
    92  // This can be changed with the status flag.
    93  //
    94  // Deprecated: true
    95  // Responses:
    96  //
    97  //	default: genericError
    98  //	    200: []pet
    99  func GetPets(w http.ResponseWriter, r *http.Request, params denco.Params) {
   100  	// some actual stuff should happen in here
   101  }
   102  
   103  // GetPetByID swagger:route GET /pets/{id} pets getPetById
   104  //
   105  // Gets the details for a pet.
   106  //
   107  // Responses:
   108  //
   109  //	default: genericError
   110  //	    200: pet
   111  func GetPetByID(w http.ResponseWriter, r *http.Request, params denco.Params) {
   112  	// some actual stuff should happen in here
   113  }
   114  
   115  // CreatePet swagger:route POST /pets pets createPet
   116  //
   117  // Creates a new pet in the store.
   118  //
   119  // Responses:
   120  //
   121  //	default: genericError
   122  //	    200: pet
   123  //	    422: validationError
   124  func CreatePet(w http.ResponseWriter, r *http.Request, params denco.Params) {
   125  	// some actual stuff should happen in here
   126  }
   127  
   128  // UpdatePet swagger:route PUT /pets/{id} pets updatePet
   129  //
   130  // Updates the details for a pet.
   131  //
   132  // Responses:
   133  //
   134  //	default: genericError
   135  //	    200: pet
   136  //	    422: validationError
   137  func UpdatePet(w http.ResponseWriter, r *http.Request, params denco.Params) {
   138  	// some actual stuff should happen in here
   139  }
   140  
   141  // DeletePet swagger:route DELETE /pets/{id} pets deletePet
   142  //
   143  // Deletes a pet from the store.
   144  //
   145  // Responses:
   146  //
   147  //	default: genericError
   148  //	    204:
   149  func DeletePet(w http.ResponseWriter, r *http.Request, params denco.Params) {
   150  	// some actual stuff should happen in here
   151  }