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

Fix float type #11

Merged
merged 1 commit into from
Nov 13, 2020
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
17 changes: 15 additions & 2 deletions lib/rspec/openapi/schema_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def build_request_body(record)

def build_property(value)
property = { type: build_type(value) }

format = build_format(value)
property[:format] = format if format

case value
when Array
property[:items] = build_property(value.first)
Expand All @@ -97,10 +101,10 @@ def build_type(value)
case value
when String
'string'
when Float
'float'
when Integer
'integer'
when Numeric
'number'
when TrueClass, FalseClass
'boolean'
when Array
Expand All @@ -114,6 +118,15 @@ def build_type(value)
end
end

def build_format(value)
case value
when Float
'float'
else
nil
end
end

# Convert an always-String param to an appropriate type
def try_cast(value)
begin
Expand Down
15 changes: 10 additions & 5 deletions spec/rails/doc/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ paths:
name:
type: string
storage_size:
type: float
type: number
format: float
created_at:
type: string
updated_at:
Expand Down Expand Up @@ -115,7 +116,8 @@ paths:
name:
type: string
storage_size:
type: float
type: number
format: float
created_at:
type: string
updated_at:
Expand Down Expand Up @@ -164,7 +166,8 @@ paths:
name:
type: string
storage_size:
type: float
type: number
format: float
created_at:
type: string
updated_at:
Expand Down Expand Up @@ -234,7 +237,8 @@ paths:
name:
type: string
storage_size:
type: float
type: number
format: float
created_at:
type: string
updated_at:
Expand Down Expand Up @@ -282,7 +286,8 @@ paths:
name:
type: string
storage_size:
type: float
type: number
format: float
created_at:
type: string
updated_at:
Expand Down