mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-03 14:10:56 +00:00
added int32 support for go-server (#7123)
This commit is contained in:
parent
4a7c4ac81d
commit
742b8bd650
@ -41,32 +41,49 @@ func (c *{{classname}}Controller) {{nickname}}(w http.ResponseWriter, r *http.Re
|
||||
{{/hasFormParams}}{{#hasPathParams}}
|
||||
params := mux.Vars(r){{/hasPathParams}}{{#hasQueryParams}}
|
||||
query := r.URL.Query(){{/hasQueryParams}}{{#allParams}}{{#isPathParam}}{{#isLong}}
|
||||
{{paramName}}, err := parseIntParameter(params["{{paramName}}"])
|
||||
{{paramName}}, err := parseInt64Parameter(params["{{paramName}}"])
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}{{/isLong}}{{#isInteger}}
|
||||
{{paramName}}, err := parseInt32Parameter(params["{{paramName}}"])
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
{{/isLong}}{{^isLong}}
|
||||
{{paramName}} := params["{{paramName}}"]{{/isLong}}{{/isPathParam}}{{#isQueryParam}}{{#isLong}}
|
||||
{{paramName}}, err := parseIntParameter(query.Get("{{paramName}}"))
|
||||
{{/isInteger}}{{^isLong}}{{^isInteger}}
|
||||
{{paramName}} := params["{{paramName}}"]{{/isInteger}}{{/isLong}}{{/isPathParam}}{{#isQueryParam}}{{#isLong}}
|
||||
{{paramName}}, err := parseInt64Parameter(query.Get("{{paramName}}"))
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
{{/isLong}}{{^isLong}}
|
||||
{{paramName}} := {{#isListContainer}}strings.Split({{/isListContainer}}query.Get("{{paramName}}"){{#isListContainer}}, ","){{/isListContainer}}{{/isLong}}{{/isQueryParam}}{{#isFormParam}}{{#isFile}}
|
||||
{{/isLong}}{{#isInteger}}
|
||||
{{paramName}}, err := parseInt32Parameter(query.Get("{{paramName}}"))
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
{{/isInteger}}{{^isLong}}{{^isInteger}}
|
||||
{{paramName}} := {{#isListContainer}}strings.Split({{/isListContainer}}query.Get("{{paramName}}"){{#isListContainer}}, ","){{/isListContainer}}{{/isInteger}}{{/isLong}}{{/isQueryParam}}{{#isFormParam}}{{#isFile}}
|
||||
{{paramName}}, err := ReadFormFileToTempFile(r, "{{paramName}}")
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
{{/isFile}}{{#isLong}}
|
||||
{{paramName}}, err := parseIntParameter( r.FormValue("{{paramName}}"))
|
||||
{{paramName}}, err := parseInt64Parameter( r.FormValue("{{paramName}}"))
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
{{/isLong}}{{^isFile}}{{^isLong}}
|
||||
{{/isLong}}{{#isInteger}}
|
||||
{{paramName}}, err := parseInt32Parameter( r.FormValue("{{paramName}}"))
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
{{/isInteger}}{{^isFile}}{{^isLong}}
|
||||
{{paramName}} := r.FormValue("{{paramName}}"){{/isLong}}{{/isFile}}{{/isFormParam}}{{#isHeaderParam}}
|
||||
{{paramName}} := r.Header.Get("{{paramName}}"){{/isHeaderParam}}{{#isBodyParam}}
|
||||
{{paramName}} := &{{dataType}}{}
|
||||
|
@ -88,7 +88,16 @@ func ReadFormFileToTempFile(r *http.Request, key string) (*os.File, error) {
|
||||
return file, nil
|
||||
}
|
||||
|
||||
// parseIntParameter parses a sting parameter to an int64
|
||||
func parseIntParameter(param string) (int64, error) {
|
||||
// parseInt64Parameter parses a sting parameter to an int64
|
||||
func parseInt64Parameter(param string) (int64, error) {
|
||||
return strconv.ParseInt(param, 10, 64)
|
||||
}
|
||||
|
||||
// parseInt32Parameter parses a sting parameter to an int32
|
||||
func parseInt32Parameter(param string) (int32, error) {
|
||||
val, err := strconv.ParseInt(param, 10, 32)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
return int32(val), nil
|
||||
}
|
@ -13,6 +13,7 @@ To see how to make this your own, look here:
|
||||
[README](https://openapi-generator.tech)
|
||||
|
||||
- API version: 1.0.0
|
||||
- Build date: 2020-08-04T17:54:56.190+08:00[Asia/Hong_Kong]
|
||||
|
||||
|
||||
### Running the server
|
||||
|
@ -101,12 +101,11 @@ func (c *PetApiController) AddPet(w http.ResponseWriter, r *http.Request) {
|
||||
// DeletePet - Deletes a pet
|
||||
func (c *PetApiController) DeletePet(w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
petId, err := parseIntParameter(params["petId"])
|
||||
petId, err := parseInt64Parameter(params["petId"])
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
apiKey := r.Header.Get("apiKey")
|
||||
result, err := c.service.DeletePet(petId, apiKey)
|
||||
if err != nil {
|
||||
@ -146,12 +145,11 @@ func (c *PetApiController) FindPetsByTags(w http.ResponseWriter, r *http.Request
|
||||
// GetPetById - Find pet by ID
|
||||
func (c *PetApiController) GetPetById(w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
petId, err := parseIntParameter(params["petId"])
|
||||
petId, err := parseInt64Parameter(params["petId"])
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := c.service.GetPetById(petId)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
@ -187,12 +185,11 @@ func (c *PetApiController) UpdatePetWithForm(w http.ResponseWriter, r *http.Requ
|
||||
}
|
||||
|
||||
params := mux.Vars(r)
|
||||
petId, err := parseIntParameter(params["petId"])
|
||||
petId, err := parseInt64Parameter(params["petId"])
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
name := r.FormValue("name")
|
||||
status := r.FormValue("status")
|
||||
result, err := c.service.UpdatePetWithForm(petId, name, status)
|
||||
@ -213,12 +210,11 @@ func (c *PetApiController) UploadFile(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
params := mux.Vars(r)
|
||||
petId, err := parseIntParameter(params["petId"])
|
||||
petId, err := parseInt64Parameter(params["petId"])
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
additionalMetadata := r.FormValue("additionalMetadata")
|
||||
file, err := ReadFormFileToTempFile(r, "file")
|
||||
if err != nil {
|
||||
|
@ -84,12 +84,11 @@ func (c *StoreApiController) GetInventory(w http.ResponseWriter, r *http.Request
|
||||
// GetOrderById - Find purchase order by ID
|
||||
func (c *StoreApiController) GetOrderById(w http.ResponseWriter, r *http.Request) {
|
||||
params := mux.Vars(r)
|
||||
orderId, err := parseIntParameter(params["orderId"])
|
||||
orderId, err := parseInt64Parameter(params["orderId"])
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := c.service.GetOrderById(orderId)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
|
@ -90,7 +90,16 @@ func ReadFormFileToTempFile(r *http.Request, key string) (*os.File, error) {
|
||||
return file, nil
|
||||
}
|
||||
|
||||
// parseIntParameter parses a sting parameter to an int64
|
||||
func parseIntParameter(param string) (int64, error) {
|
||||
// parseInt64Parameter parses a sting parameter to an int64
|
||||
func parseInt64Parameter(param string) (int64, error) {
|
||||
return strconv.ParseInt(param, 10, 64)
|
||||
}
|
||||
|
||||
// parseInt32Parameter parses a sting parameter to an int32
|
||||
func parseInt32Parameter(param string) (int32, error) {
|
||||
val, err := strconv.ParseInt(param, 10, 32)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
return int32(val), nil
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user