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

[OpenAPI] Support date types in Alba serializers #112

Merged
merged 1 commit into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/rage/openapi/parsers/ext/alba.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ def get_type_definition(type_id)
{ "type" => "number" }
when "Float"
{ "type" => "number", "format" => "float" }
when "Date"
{ "type" => "string", "format" => "date" }
when "DateTime", "Time"
{ "type" => "string", "format" => "date-time" }
else
{ "type" => "string" }
end
Expand Down
13 changes: 13 additions & 0 deletions spec/openapi/parsers/ext/alba_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,19 @@ def id
is_expected.to eq({ "type" => "object", "properties" => { "data" => { "type" => "object", "properties" => { "name" => { "type" => "string" }, "id" => { "type" => "integer" }, "admin" => { "type" => "boolean" }, "salary" => { "type" => "number", "format" => "float" } } } } })
end
end

context "with dates" do
let_class("UserResource") do
<<~'RUBY'
include Alba::Resource
attributes created_at: DateTime, dob: Date
RUBY
end

it do
is_expected.to eq({ "type" => "object", "properties" => { "created_at" => { "type" => "string", "format" => "date-time" }, "dob" => { "type" => "string", "format" => "date" } } })
end
end
end

context "with automatic resource inference" do
Expand Down
Loading