Skip to content

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

@MustansirS

Description

@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

if localVarHTTPResponse.StatusCode >= 500

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions