Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
return
}
{{/isInteger}}
{{#isDateTime}}
{{paramName}}Param, err := time.Parse(time.RFC3339, {{#routers}}{{#mux}}params["{{baseName}}"]{{/mux}}{{#chi}}chi.URLParam(r, "{{baseName}}"){{/chi}}{{/routers}})
if err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
{{/isDateTime}}
{{^isNumber}}
{{^isFloat}}
{{^isDouble}}
Expand All @@ -190,6 +197,26 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
{{/isNumber}}
{{/isPathParam}}
{{#isQueryParam}}
{{#isDateTime}}
{{#required}}
if !query.Has("{{baseName}}"){
c.errorHandler(w, r, &RequiredError{"{{baseName}}"}, nil)
return
}
{{paramName}}Param, err := parseTime(query.Get("{{baseName}}"))
if err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
{{/required}}
{{^required}}
{{paramName}}Param, err := parseTime(query.Get("{{baseName}}"))
if err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
{{/required}}
{{/isDateTime}}
{{#isNumber}}
{{paramName}}Param, err := parseNumericParameter[float32](
query.Get("{{baseName}}"),{{#defaultValue}}
Expand Down Expand Up @@ -333,6 +360,13 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
return
}
{{/items.isInteger}}
{{#items.isDateTime}}
{{paramName}}Param, err := parseTimes(query.Get("{{baseName"}}))
if err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
{{/items.isDateTime}}
{{^items.isNumber}}
{{^items.isFloat}}
{{^items.isDouble}}
Expand Down Expand Up @@ -372,6 +406,7 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
{{^isInteger}}
{{^isBoolean}}
{{^isArray}}
{{^isDateTime}}
{{#defaultValue}}
{{paramName}}Param := "{{defaultValue}}"
if query.Has("{{baseName}}") {
Expand Down Expand Up @@ -412,6 +447,7 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
{{/isEnumOrRef}}
{{/required}}
{{/defaultValue}}
{{/isDateTime}}
{{/isArray}}
{{/isBoolean}}
{{/isInteger}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package {{packageName}}
import (
"encoding/json"
"errors"
"time"
{{#routers}}
{{#mux}}
"github.com/gorilla/mux"
Expand Down Expand Up @@ -183,6 +184,27 @@ func readFileHeaderToTempFile(fileHeader *multipart.FileHeader) (*os.File, error
return file, nil
}

func parseTimes(param string) ([]time.Time, error) {
splits := strings.Split(param, ",")
times := make([]time.Time, 0, len(splits))
for _, v := range splits {
t, err := parseTime(v)
if err != nil {
return nil, err
}
times = append(times, t)
}
return times, nil
}

// parseTime will parses a string parameter into a time.Time using the RFC3339 format
func parseTime(param string) (time.Time, error) {
if param == "" {
return time.Time{}, nil
}
return time.Parse(time.RFC3339, param)
}

type Number interface {
~int32 | ~int64 | ~float32 | ~float64
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,24 @@ paths:
type: array
items:
type: string
- name: bornAfter
in: query
description: Find pets born after this date
required: true
style: form
explode: false
schema:
type: string
format: date-time
- name: bornBefore
in: query
description: Find pets born before this date
required: false
style: form
explode: false
schema:
type: string
format: date-time
responses:
'200':
description: successful operation
Expand Down
22 changes: 22 additions & 0 deletions samples/openapi3/server/petstore/go/go-petstore/go/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package petstoreserver
import (
"encoding/json"
"errors"
"time"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"io"
Expand Down Expand Up @@ -150,6 +151,27 @@ func readFileHeaderToTempFile(fileHeader *multipart.FileHeader) (*os.File, error
return file, nil
}

func parseTimes(param string) ([]time.Time, error) {
splits := strings.Split(param, ",")
times := make([]time.Time, 0, len(splits))
for _, v := range splits {
t, err := parseTime(v)
if err != nil {
return nil, err
}
times = append(times, t)
}
return times, nil
}

// parseTime will parses a string parameter into a time.Time using the RFC3339 format
func parseTime(param string) (time.Time, error) {
if param == "" {
return time.Time{}, nil
}
return time.Parse(time.RFC3339, param)
}

type Number interface {
~int32 | ~int64 | ~float32 | ~float64
}
Expand Down
18 changes: 18 additions & 0 deletions samples/server/petstore/go-api-server/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,24 @@ paths:
type: string
type: array
style: form
- description: Find pets born after this date
explode: false
in: query
name: bornAfter
required: true
schema:
format: date-time
type: string
style: form
- description: Find pets born before this date
explode: false
in: query
name: bornBefore
required: false
schema:
format: date-time
type: string
style: form
responses:
"200":
content:
Expand Down
3 changes: 2 additions & 1 deletion samples/server/petstore/go-api-server/go/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package petstoreserver
import (
"context"
"net/http"
"time"
"os"
)

Expand Down Expand Up @@ -68,7 +69,7 @@ type PetAPIServicer interface {
FilterPetsByCategory(context.Context, Gender, Species, []Species) (ImplResponse, error)
FindPetsByStatus(context.Context, []string) (ImplResponse, error)
// Deprecated
FindPetsByTags(context.Context, []string) (ImplResponse, error)
FindPetsByTags(context.Context, []string, time.Time, time.Time) (ImplResponse, error)
GetPetById(context.Context, int64) (ImplResponse, error)
GetPetImageById(context.Context, int64) (ImplResponse, error)
UpdatePet(context.Context, Pet) (ImplResponse, error)
Expand Down
16 changes: 15 additions & 1 deletion samples/server/petstore/go-api-server/go/api_pet.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,21 @@ func (c *PetAPIController) FindPetsByTags(w http.ResponseWriter, r *http.Request
if query.Has("tags") {
tagsParam = strings.Split(query.Get("tags"), ",")
}
result, err := c.service.FindPetsByTags(r.Context(), tagsParam)
if !query.Has("bornAfter"){
c.errorHandler(w, r, &RequiredError{"bornAfter"}, nil)
return
}
bornAfterParam, err := parseTime(query.Get("bornAfter"))
if err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
bornBeforeParam, err := parseTime(query.Get("bornBefore"))
if err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
result, err := c.service.FindPetsByTags(r.Context(), tagsParam, bornAfterParam, bornBeforeParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
Expand Down
3 changes: 2 additions & 1 deletion samples/server/petstore/go-api-server/go/api_pet_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"context"
"net/http"
"errors"
"time"
"os"
)

Expand Down Expand Up @@ -82,7 +83,7 @@ func (s *PetAPIService) FindPetsByStatus(ctx context.Context, status []string) (

// FindPetsByTags - Finds Pets by tags
// Deprecated
func (s *PetAPIService) FindPetsByTags(ctx context.Context, tags []string) (ImplResponse, error) {
func (s *PetAPIService) FindPetsByTags(ctx context.Context, tags []string, bornAfter time.Time, bornBefore time.Time) (ImplResponse, error) {
// TODO - update FindPetsByTags 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.

Expand Down
22 changes: 22 additions & 0 deletions samples/server/petstore/go-api-server/go/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package petstoreserver
import (
"encoding/json"
"errors"
"time"
"github.com/gorilla/mux"
"io"
"mime/multipart"
Expand Down Expand Up @@ -154,6 +155,27 @@ func readFileHeaderToTempFile(fileHeader *multipart.FileHeader) (*os.File, error
return file, nil
}

func parseTimes(param string) ([]time.Time, error) {
splits := strings.Split(param, ",")
times := make([]time.Time, 0, len(splits))
for _, v := range splits {
t, err := parseTime(v)
if err != nil {
return nil, err
}
times = append(times, t)
}
return times, nil
}

// parseTime will parses a string parameter into a time.Time using the RFC3339 format
func parseTime(param string) (time.Time, error) {
if param == "" {
return time.Time{}, nil
}
return time.Parse(time.RFC3339, param)
}

type Number interface {
~int32 | ~int64 | ~float32 | ~float64
}
Expand Down
18 changes: 18 additions & 0 deletions samples/server/petstore/go-chi-server/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,24 @@ paths:
type: string
type: array
style: form
- description: Find pets born after this date
explode: false
in: query
name: bornAfter
required: true
schema:
format: date-time
type: string
style: form
- description: Find pets born before this date
explode: false
in: query
name: bornBefore
required: false
schema:
format: date-time
type: string
style: form
responses:
"200":
content:
Expand Down
3 changes: 2 additions & 1 deletion samples/server/petstore/go-chi-server/go/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package petstoreserver
import (
"context"
"net/http"
"time"
"os"
)

Expand Down Expand Up @@ -68,7 +69,7 @@ type PetAPIServicer interface {
FilterPetsByCategory(context.Context, Gender, Species, []Species) (ImplResponse, error)
FindPetsByStatus(context.Context, []string) (ImplResponse, error)
// Deprecated
FindPetsByTags(context.Context, []string) (ImplResponse, error)
FindPetsByTags(context.Context, []string, time.Time, time.Time) (ImplResponse, error)
GetPetById(context.Context, int64) (ImplResponse, error)
GetPetImageById(context.Context, int64) (ImplResponse, error)
UpdatePet(context.Context, Pet) (ImplResponse, error)
Expand Down
16 changes: 15 additions & 1 deletion samples/server/petstore/go-chi-server/go/api_pet.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,21 @@ func (c *PetAPIController) FindPetsByTags(w http.ResponseWriter, r *http.Request
if query.Has("tags") {
tagsParam = strings.Split(query.Get("tags"), ",")
}
result, err := c.service.FindPetsByTags(r.Context(), tagsParam)
if !query.Has("bornAfter"){
c.errorHandler(w, r, &RequiredError{"bornAfter"}, nil)
return
}
bornAfterParam, err := parseTime(query.Get("bornAfter"))
if err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
bornBeforeParam, err := parseTime(query.Get("bornBefore"))
if err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
result, err := c.service.FindPetsByTags(r.Context(), tagsParam, bornAfterParam, bornBeforeParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
Expand Down
3 changes: 2 additions & 1 deletion samples/server/petstore/go-chi-server/go/api_pet_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"context"
"net/http"
"errors"
"time"
"os"
)

Expand Down Expand Up @@ -82,7 +83,7 @@ func (s *PetAPIService) FindPetsByStatus(ctx context.Context, status []string) (

// FindPetsByTags - Finds Pets by tags
// Deprecated
func (s *PetAPIService) FindPetsByTags(ctx context.Context, tags []string) (ImplResponse, error) {
func (s *PetAPIService) FindPetsByTags(ctx context.Context, tags []string, bornAfter time.Time, bornBefore time.Time) (ImplResponse, error) {
// TODO - update FindPetsByTags 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.

Expand Down
Loading