OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.3k stars 6.44k forks source link

[CI] Test server generates invalid RFC 3339 date-time #1292

Open grokify opened 5 years ago

grokify commented 5 years ago
Description

The following error is encountered when running tests for the client:

https://circleci.com/gh/grokify/openapi-generator/91#tests/containers/1

=== RUN   TestPlaceOrder
--- FAIL: TestPlaceOrder (0.02s)
    store_api_test.go:23: Error while placing order
    store_api_test.go:24: parsing time ""2018-10-29T21:02:19.201+0000"" as ""2006-01-02T15:04:05Z07:00"": cannot parse "+0000"" as "Z07:00"

Of note, the date-time value that parsing is being attempted for has an offset that is invalid in RFC 3339 format, namely, the UTC offset is +0000 and does not have a colon (:) which is required by RFC 3339.

The Petstore OpenAPI 2.0 spec shows that the OpenAPI type date-time is used:

https://github.com/OpenAPITools/openapi-generator/blob/8507916d569a8614286708d45a3cbae20e4da6f2/modules/openapi-generator/src/test/resources/2_0/petstore.yaml#L566-L582

Both OpenAPI 2.0 and 3.0 require RFC 3339 format date-time:

RFC 3339 requires a colon:

time-numoffset  = ("+" / "-") time-hour ":" time-minute

https://tools.ietf.org/html/rfc3339#section-5.6

Of note, a +0000 offset without a colon is a valid ISO 8601 date-time offset / timezone designator, but ISO 8601 is not used by OpenAPI spec. Here are the formats for ISO 8601.

<time>Z
<time>±hh:mm
<time>±hhmm
<time>±hh

https://en.wikipedia.org/wiki/ISO_8601

openapi-generator version

master: 8507916d569a8614286708d45a3cbae20e4da6f2

OpenAPI declaration file content or url

https://github.com/OpenAPITools/openapi-generator/blob/8507916d569a8614286708d45a3cbae20e4da6f2/modules/openapi-generator/src/test/resources/2_0/petstore.yaml

Command line used for generation
$ git clone https://github.com/OpenAPITools/openapi-generator
$ cd openapi-generator
$ mvn clean package
$ bin/go-petstore.sh
Steps to reproduce

Run Go tests locally or on CI:

$ mvn verify -f samples/client/petstore/go
Related issues/PRs

Encountered here:

https://github.com/OpenAPITools/openapi-generator/pull/1291

Suggest a fix/enhancement

This appears to be a server issue. If so, have the server return a RFC 3339 compliant date-time format value like either of the following:

grokify commented 5 years ago

I just verified this using the following cURL command which simulates the request made by store_api_test.go when executed by mvn verify -f samples/client/petstore/go:

$ curl -XPOST 'http://petstore.swagger.io:80/v2/store/order' -H 'Content-Type: application/json' -d '{"shipDate":"2018-11-01T00:00:00Z","status":"placed"}'

The petstore.swagger.io server returns the following body which includes a ISO 8601 date-time with a +0000 offset, not a RFC 3339 date-time.

{"id":0,"petId":0,"quantity":0,"shipDate":"2018-11-01T00:00:00.000+0000","status":"placed","complete":false}

cbornet commented 5 years ago

The build uses swaggerapi/petstore which is not ours. We should use openapitools/openapi-petstore instead on which I'm pretty sure this issue doesn't exist.

cbornet commented 5 years ago

The commands to spawn our docker petstore are there but commented. @wing328 do you know why ?