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
  • #13596
Closed
Open
Issue created Oct 05, 2022 by Administrator@rootContributor3 of 6 checklist items completed3/6 checklist items

[BUG][Go] Syntax error: missing '{' in go client template for '5XX' status code responses

Created by: MustansirS

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

When generating a GoLang client from specs where API responses with '5XX' status codes are defined, there is a syntax error in the generated client originating from the mustache template for GoLang which is missing an opening '{' for an if statement comparing statusCode >= 500

openapi-generator version

6.2.0

OpenAPI declaration file content or url

gobug.yaml:

openapi: 3.0.2
info:
  title: Bug API
  version: '0.0'
  contact:
    name: Curvegrid
  description: Go Client Bug API.
servers:
  - url: 'https://{hostname}'
    variables:
      hostname:
        default: localhost:8080
        description: Bug Test Server.
tags:
  - name: test
paths:
  /test:
    get:
      operationId: test
      summary: Test
      description: Test Go Client Bug.
      tags:
        - test
      responses:
        '200':
          description: OK
        4XX:
          $ref: '#/components/responses/ClientError'
        5XX:
          $ref: '#/components/responses/ServerError'
components:
  schemas:
    Error:
      type: object
      x-tags:
        - error
      example:
        status: 404
        message: Page Not Found
      description: An error response.
      additionalProperties: false
      properties:
        status:
          type: integer
          description: The unique error code.
        message:
          type: string
          description: The human-readable error message.
      required:
        - status
        - message
  responses:
    ClientError:
      description: Client error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    ServerError:
      description: Server error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
Generation Details
Steps to reproduce
  • openapi-generator generate -g go -i gobug.yaml -o go_client
  • cd go_client Observe syntax error: missing opening '{' at api_test_.go line 117
Related issues/PRs
Suggest a fix

Fixable by adding mentioned missing { to https://github.com/OpenAPITools/openapi-generator/blob/085e1e58e5efbe7f259cf6689819ed0fa357dd56/modules/openapi-generator/src/main/resources/go/api.mustache#L374

Assignee
Assign to
Time tracking