swagger-api / swagger-api/swagger-codegen
go api_* files fail to import time module
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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
Swagger-codegen version
3.0.20
Swagger 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':
content:
"application/json":
schema:
type: string
format: date-time
Command line used for generation
java -jar swagger-codegen-cli.jar generate -l go -i dt_test1.yml -o test/go -c swagger.json
$ cat swagger.json
{
"packageName": "main"
}
Steps to reproduce
Define an operaiton returning date-time string value and generate go bindings. The results will refer time.Time type and not import the time module
package main
import (
"context"
"io/ioutil"
"net/http"
"net/url"
"strings"
)
.......
func (a *DefaultApiService) DateTimeImportFail(ctx context.Context) (time.Time, *http.Response, error) {
This does not reproduce for data objects/models containing date time values
Related issues/PRs
Cannot find any
Suggest a fix/enhancement
import go time module when 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 the generated api_*.go import block and reproduce the failure using dt_test1.yml, swagger.json, and the documented swagger-codegen generate command. Done means the generated DateTimeImportFail method's time.Time reference has its required import and the generated Go client compiles.
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
- 45/100