swagger-api / swagger-api/swagger-codegen
[Golang] date-time query parameter does not produce a RFC 3339 time (same as #8039, but with new version of swagger-codegen)
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Generated Golang function parameterToString() (line 195 of client.go) does not generate time in a way that is compliant with RFC3339, This is the same as #8039. For some reason, the generated code does not reflect the fix #325 that was merged in 2018.
// parameterToString convert interface{} parameters to string, using a delimiter if format is provided.
func parameterToString(obj interface{}, collectionFormat string) string {
var delimiter string
switch collectionFormat {
case "pipes":
delimiter = "|"
case "ssv":
delimiter = " "
case "tsv":
delimiter = "\t"
case "csv":
delimiter = ","
}
if reflect.TypeOf(obj).Kind() == reflect.Slice {
return strings.Trim(strings.Replace(fmt.Sprint(obj), " ", delimiter, -1), "[]")
}
return fmt.Sprintf("%v", obj)
}
Swagger-codegen version
$ docker run --rm -v ${PWD}:/client swaggerapi/swagger-codegen-cli version
2.4.29
Swagger declaration file content or url
The json file should include an API method with date-time format:
The json file begins with {"swagger":"2.0".
"/v3/house/{houseId}/inspect":{"put":{"tags":["house-controller"],"summary":"Record house inspection by ID","description":"Record house inspection by ID API","operationId":"inspectHouseUsingPUT","consumes":["application/json"],"produces":["*/*","application/json"],"parameters":[{"name":"houseId","in":"path","description":"houseId","required":true,"type":"string"},{"name":"inspectionTime","in":"query","description":"inspectionTime","required":true,"type":"string","format":"date-time"}],"responses":{"200":{"description":"Successfully recorded house inspection","schema":{"$ref":"#/definitions/HouseInfo"}},"400":{"description":"inspectionTime must follow format yyyy-MM-dd'T'HH:mm:ss.SSSXXX"},"401":{"description":"Unauthorized"},"403":{"description":"Forbidden for non house owners"},"404":{"description":"House not found"}},"security":[{"Bearer":[]}]}}
Command line used for generation
$ docker run --rm -v ${PWD}:/client swaggerapi/swagger-codegen-cli generate -i <api-end-point> -l go -o client/out/go -D io.swagger.parser.util.RemoteUrl.trustAll=true
Steps to reproduce
The above information should give you an idea of how to reproduce the issue. However, these instructions are not sufficient to fully reproduce the issue, because we don’t have a full json file that is ready to be shared publicly yet.
Related issues/PRs
https://github.com/swagger-api/swagger-codegen/issues/8039
https://github.com/OpenAPITools/openapi-generator/pull/325
Suggest a fix/enhancement
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 generated client.go at parameterToString (line 195) and compare its date-time handling with issue #8039 and OpenAPI Generator PR #325. Use the supplied Swagger 2.0 date-time query parameter and documented Docker generation command when a complete input is available. Done means generated Go query parameters serialize date-time values as RFC 3339.
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
- Mostly clear
- Newbie friendliness
- 45/100