forked from loafle/openapi-generator-original
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:
parent
5693eee4e0
commit
2f655f1a9c
@ -169,7 +169,7 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
|
||||
}
|
||||
{{/isInteger}}
|
||||
{{#isDateTime}}
|
||||
{{paramName}}Param, err := time.Parse(time.RFC3339, {{#routers}}{{#mux}}params["{{baseName}}"]{{/mux}}{{#chi}}chi.URLParam(r, "{{baseName}}"){{/chi}}{{/routers}})
|
||||
{{paramName}}Param, err := parseTime({{#routers}}{{#mux}}params["{{baseName}}"]{{/mux}}{{#chi}}chi.URLParam(r, "{{baseName}}"){{/chi}}{{/routers}})
|
||||
if err != nil {
|
||||
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
|
||||
return
|
||||
@ -180,6 +180,7 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
|
||||
{{^isDouble}}
|
||||
{{^isLong}}
|
||||
{{^isInteger}}
|
||||
{{^isDateTime}}
|
||||
{{^isEnumOrRef}}
|
||||
{{paramName}}Param := {{#routers}}{{#mux}}params["{{baseName}}"]{{/mux}}{{#chi}}chi.URLParam(r, "{{baseName}}"){{/chi}}{{/routers}}
|
||||
{{/isEnumOrRef}}
|
||||
@ -190,6 +191,7 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
|
||||
return
|
||||
}
|
||||
{{/isEnumOrRef}}
|
||||
{{/isDateTime}}
|
||||
{{/isInteger}}
|
||||
{{/isLong}}
|
||||
{{/isDouble}}
|
||||
|
@ -745,6 +745,26 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ApiResponse'
|
||||
/pets/byTime/{createdTime}:
|
||||
get:
|
||||
tags:
|
||||
- pet
|
||||
summary: Get the pets by time
|
||||
operationId: GetPetsByTime
|
||||
parameters:
|
||||
- in: path
|
||||
name: createdTime
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
format: date-time
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ApiResponse'
|
||||
externalDocs:
|
||||
description: Find out more about Swagger
|
||||
url: 'http://swagger.io'
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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.
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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",
|
||||
@ -290,6 +295,23 @@ 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) {
|
||||
createdTimeParam, err := parseTime(chi.URLParam(r, "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()
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user