Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Golang][client] fix RFC-3339 date-time query param #325

Merged
merged 1 commit into from
Jun 15, 2018

Conversation

grokify
Copy link
Member

@grokify grokify commented Jun 15, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.1.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

@antihax
@bvwells

Description of the PR

The OpenAPI 3.0 Spec and Swagger 2.0 Spec define the date-time string format as:

dateTime | string | date-time | As defined by date-time - RFC3339

An example of RFC-3339 date-time format is 2017-07-21T17:32:28Z. Here is the full spec:

The current SDK will create in an incorrectly formatted time for a query parameter. This happens because client.go parameterToString function uses fmt.Sprintf("%v", obj) which produces the following time format which is not a RFC-3339 time:

2018-01-01 00:00:00 +0000 UTC

This can be resolved by adding the following code to parameterToString(obj interface{}, collectionFormat string) string.

} else if t, ok := obj.(time.Time); ok {
    return t.Format(time.RFC3339)
}

This approach for testing time has been verified to work and is mentioned here:

https://stackoverflow.com/questions/41483505/golang-check-if-a-data-is-time-time

An example is on Go Playground here: https://play.golang.org/p/Jq16Shapio8

A test is not provided because it appears a date-time format string query parameter does not exist in the current Petstore API.

This is a breaking change since the date time format produced by the Client SDK changes.

More info can be seen here where the issue was encountered:

This PR updates client.mustache. Other changed files are from a re-built go-petstore SDK in the sample folder.

@bvwells
Copy link
Contributor

bvwells commented Jun 15, 2018

Looks good to me. Thanks for the PR!

@antihax
Copy link
Contributor

antihax commented Jun 15, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants