Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #9709
Closed
Open
Issue created Jun 07, 2021 by Administrator@rootContributor6 of 6 checklist items completed6/6 checklist items

[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.

Related issues/PRs
Suggest a fix
Assignee
Assign to
Time tracking