[BUG][GO] go-server does not correctly handle optional query params for boolean and string array types
Created by: mpapale
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Optional query parameters of type boolean or string array, e.g.
parameters:
- name: myFlag
required: false
in: query
schema:
type: boolean
- name: myStrings
required: false
in: query
schema:
type: array
items:
type: string
are not being generated properly via the templates, causing a 500 error if they are not provided in the HTTP call.
openapi-generator version
5.1.1 I don't believe this is a regression.
OpenAPI declaration file content or url
openapi: 3.0.0
info:
description: 'OpenAPI Petstore'
title: OpenAPI Petstore
version: 1.0.0
servers:
- description: The local server
url: https://localhost:8080/{version}
paths:
/pets:
get:
operationId: getPet
parameters:
- description: Only return pets with these tag names
in: query
name: tagNames
required: false
schema:
type: array
items:
type: string
- description: Only return pets with available status
in: query
name: isAvailable
required: false
schema:
type: boolean
responses:
"200":
content: {}
description: ""
Generation Details
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:latest generate \
-i /local/openapi.yaml \
-g go-server -o /local/go-server
Steps to reproduce
Generate the code and look in the routers.go
file for parseBoolParameter
which does
not have a required
flag.
Also notice there is no parseStringArrayParameter
function, so api_pets.go
will do a strings.Split
on tagNames
.
If tagNames
is not provided, it will be set to [""]
which is incorrect.