open-api-spex / open_api_spex

Open API Specifications for Elixir Plug applications
Mozilla Public License 2.0
680 stars 177 forks source link

Accepts non-RFC3339 timestamps in date-time #604

Open lanodan opened 3 months ago

lanodan commented 3 months ago

For example 2024-03-24T14:01:35 is accepted, yet RFC3339 § 5.6 pointed at by OpenAPI requires a time-offset (either "Z" or /[-+]\d{2}:\d{2}/).

mbuhot commented 1 month ago

@lanodan please create a PR with a test to reproduce this. The code uses DateTime.from_iso8601 https://github.com/open-api-spex/open_api_spex/blob/78cf5fd1011d0414a6235fce9978f407d8c63d85/lib/open_api_spex/cast/string.ex#L29 to cast string to DateTime which in doesn't accept the format without an offset:

iex(16)> DateTime.from_iso8601("2024-03-24T14:01:35")
{:error, :missing_offset}
OpenApiSpex.Cast.String.cast(%{value: "2024-03-24T14:01:35", schema: %{format: :"date-time"}, path: [], errors: []})
{:error,
 [
   %OpenApiSpex.Cast.Error{
     reason: :invalid_format,
     value: "2024-03-24T14:01:35",
     format: :"date-time",
     type: nil,
     name: nil,
     path: [],
     length: 0,
     meta: %{}
   }
 ]}