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
  • #3321
Closed
Open
Issue created Jul 09, 2019 by Administrator@rootContributor3 of 3 checklist items completed3/3 checklist items

[BUG][GO] default response not handled for error cases

Created by: thiagoarrais

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
Description

Current golang client does not handle default response data types when the the server returns an HTTP error code (4xx).

openapi-generator version

master

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    post:
      summary: Create a pet
      operationId: createPets
      tags:
        - pets
      responses:
        '201':
          description: Null response
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
components:
  schemas:
    Error:
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
Command line used for generation

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i petstore.yaml -g go -o out

Steps to reproduce
  1. Generate client as per command line above
  2. Verify that generated code at api_pets.go checks HTTP status code against 0:
	if localVarHttpResponse.StatusCode >= 300 {
		newErr := GenericOpenAPIError{
			body:  localVarBody,
			error: localVarHttpResponse.Status,
		}
		if localVarHttpResponse.StatusCode == 0 {
			// ...               
		}
	}

That doesn't work because the status code will never be zero at that point.

Related issues/PRs

Couldn't find any.

Suggest a fix

Do not generate the check for status code when generating code for the default response.

Assignee
Assign to
Time tracking