[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
- Generate client as per command line above
- 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.