Time parameters in the path resulted in code that would not compile (#17021)

This is probably a pretty rare case as it just seems weird to have a time
path parameter, but it's good to fix.
This commit is contained in:
Ian Cubbon
2023-11-12 19:01:32 -07:00
committed by GitHub
parent 5693eee4e0
commit 2f655f1a9c
10 changed files with 138 additions and 1 deletions

View File

@@ -761,6 +761,28 @@ paths:
summary: Get the pets by only using boolean query parameters
tags:
- pet
/pets/byTime/{createdTime}:
get:
operationId: GetPetsByTime
parameters:
- explode: false
in: path
name: createdTime
required: true
schema:
format: date-time
type: string
style: simple
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
description: successful operation
summary: Get the pets by time
tags:
- pet
components:
requestBodies:
UserArray:

View File

@@ -30,6 +30,7 @@ type PetAPIRouter interface {
FindPetsByTags(http.ResponseWriter, *http.Request)
GetPetById(http.ResponseWriter, *http.Request)
GetPetImageById(http.ResponseWriter, *http.Request)
GetPetsByTime(http.ResponseWriter, *http.Request)
GetPetsUsingBooleanQueryParameters(http.ResponseWriter, *http.Request)
UpdatePet(http.ResponseWriter, *http.Request)
UpdatePetWithForm(http.ResponseWriter, *http.Request)
@@ -73,6 +74,7 @@ type PetAPIServicer interface {
FindPetsByTags(context.Context, []string, time.Time, time.Time) (ImplResponse, error)
GetPetById(context.Context, int64) (ImplResponse, error)
GetPetImageById(context.Context, int64) (ImplResponse, error)
GetPetsByTime(context.Context, time.Time) (ImplResponse, error)
GetPetsUsingBooleanQueryParameters(context.Context, bool, bool, bool) (ImplResponse, error)
UpdatePet(context.Context, Pet) (ImplResponse, error)
UpdatePetWithForm(context.Context, int64, string, string) (ImplResponse, error)

View File

@@ -85,6 +85,11 @@ func (c *PetAPIController) Routes() Routes {
"/v2/pet/{petId}/uploadImage",
c.GetPetImageById,
},
"GetPetsByTime": Route{
strings.ToUpper("Get"),
"/v2/pets/byTime/{createdTime}",
c.GetPetsByTime,
},
"GetPetsUsingBooleanQueryParameters": Route{
strings.ToUpper("Get"),
"/v2/pets/boolean/parsing",
@@ -294,6 +299,24 @@ func (c *PetAPIController) GetPetImageById(w http.ResponseWriter, r *http.Reques
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
}
// GetPetsByTime - Get the pets by time
func (c *PetAPIController) GetPetsByTime(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
createdTimeParam, err := parseTime(params["createdTime"])
if err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
result, err := c.service.GetPetsByTime(r.Context(), createdTimeParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, result.Headers, w)
}
// GetPetsUsingBooleanQueryParameters - Get the pets by only using boolean query parameters
func (c *PetAPIController) GetPetsUsingBooleanQueryParameters(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()

View File

@@ -130,6 +130,17 @@ func (s *PetAPIService) GetPetImageById(ctx context.Context, petId int64) (ImplR
return Response(http.StatusNotImplemented, nil), errors.New("GetPetImageById method not implemented")
}
// GetPetsByTime - Get the pets by time
func (s *PetAPIService) GetPetsByTime(ctx context.Context, createdTime time.Time) (ImplResponse, error) {
// TODO - update GetPetsByTime with the required logic for this service method.
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
// TODO: Uncomment the next line to return response Response(200, ApiResponse{}) or use other options such as http.Ok ...
// return Response(200, ApiResponse{}), nil
return Response(http.StatusNotImplemented, nil), errors.New("GetPetsByTime method not implemented")
}
// GetPetsUsingBooleanQueryParameters - Get the pets by only using boolean query parameters
func (s *PetAPIService) GetPetsUsingBooleanQueryParameters(ctx context.Context, expr bool, grouping bool, inactive bool) (ImplResponse, error) {
// TODO - update GetPetsUsingBooleanQueryParameters with the required logic for this service method.