OpenAPITools / OpenAPITools/openapi-generator
[BUG][GO] go api_* files fail to import time module
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What's the version of OpenAPI Generator used? 4.3.1, 5.0.0 Beta in both go and go-experiemental modes
- Have you search for related issues/PRs? Yes .I filed similar in swagger-codegen
- What's the actual output vs expected output? actual api*.go files lack "time" module import while expected out has it
- [Optional] Bounty to sponsor the fix (example)
Description
go client api_* files do not import time module when the generated code contains references to time.Time.
This results in go compilation failure
openapi-generator version
I tested both 4.3.1 and 5.0.0 Beta in both go and go-experiemental modes
OpenAPI declaration file content or url
dt_test1.yml
openapi: 3.0.0
info:
title: DateTime DataObject Test
version: version.version0
paths:
/test_fail:
post:
operationId: DateTimeImportFail
responses:
'200':
description: test
content:
"application/json":
schema:
type: string
format: date-time
Command line used for generation
I used 4 command lines to test all combinations
4.3.1 Go - java -jar openapi-generator-cli.jar generate -g go -i dt_test1.yml -o og_dt/go
4.3.1 Go experimental - java -jar openapi-generator-cli.jar generate -g go-experimental -i dt_test1.yml -o og_dt/goe
5 Beta go - java -jar openapi-generator-cli-5.0.0-beta.jar generate -g go -i dt_test1.yml -o og5_dt/go
5 Beta Go Experimental - java -jar openapi-generator-cli-5.0.0-beta.jar generate -g go-experimental -i dt_test1.yml -o og5_dt/goe
Steps to reproduce
Define an operation returning date-time string value and generate go bindings. The results will refer time.Time type and not import the time module
For example 5.0.0 Beta go experiemental produces with the above api_default.go like the following
....
import (
_context "context"
_ioutil "io/ioutil"
_nethttp "net/http"
_neturl "net/url"
)
....
/*
Execute executes the request
@return time.Time
*/
func (r apiDateTimeImportFailRequest) Execute() (time.Time, *_nethttp.Response, error) {
Related issues/PRs
No
Suggest a fix
Import the time module when time.Time is used in api_*.go files
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with dt_test1.yml and run the listed openapi-generator CLI command using the Go generator to reproduce the generated api_default.go output. Inspect how imports are selected for the generated time.Time return type; done means the generated api_*.go files import time and compile successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100