Skip to content

Allow range be Float - #905

Merged
numbata merged 8 commits into
ruby-grape:masterfrom
artyomb:patch-1
Nov 12, 2026
Merged

numbata merged 8 commits into
ruby-grape:masterfrom
artyomb:patch-1

Conversation

@artyomb

@artyomb artyomb commented Sep 5, 2023

Copy link
Copy Markdown
Contributor

#904 (comment)

As described in https://docs.swagger.io/spec.html

minimum | string | number, integer | The minimum valid value for the type, inclusive. If this field is used in conjunction with the defaultValue field, then the default value MUST be higher than or equal to this value. The value type is string and should represent the minimum numeric value. Note: This will change to a numeric value in the future.

The values may be number (float or double)?

@LeFnord

LeFnord commented Sep 6, 2023

Copy link
Copy Markdown
Member

@artyomb … yeah, makes sense to allow any kind of number

please rebase against master, it fixes the rubocop stuff

@artyomb

artyomb commented Sep 6, 2023 •

Copy link
Copy Markdown
Contributor Author

Sorry, if I broke something. I don't know how to rebase with this pull request.

@artyomb

artyomb commented Sep 18, 2023

Copy link
Copy Markdown
Contributor Author

I did "sync fork". Hope it helped?

@LeFnord

LeFnord commented Nov 13, 2023 •

Copy link
Copy Markdown
Member

no … please have a look on the failures, it seems your change is related to it

@artyomb

artyomb commented Nov 13, 2023

Copy link
Copy Markdown
Contributor Author

Ok, sorry. I don't know how complete the request. Please close/reject it. Maybe move to the issues.

@artyomb

artyomb commented Nov 22, 2025

Copy link
Copy Markdown
Contributor Author

The patch is still actual, is it possible to accept the request?

@dblock dblock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@artyomb rebase and write a test + CHANGELOG please?

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Danger Report

No issues found.

View run

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The parameter-range guard can raise on beginless ranges and silently omit BigDecimal bounds, leaving valid Swagger minimum and maximum values undocumented.

1 open issue
What changed in this PR

This PR lets float ranges in a parameter's values option produce minimum and maximum in the generated Swagger output. Before, only integer ranges did. The Swagger spec allows numeric bounds, and the linked issue #904 asks for the same change.

Changes:

  • The range check in parse_enum_or_range_values now accepts ranges whose first value is a Float as well as an Integer.
  • The float range spec in param_values_spec.rb now expects minimum: -5.0 and maximum: 5.0 instead of a string range.
  • A new unit spec in parse_params_spec.rb covers -5.0..5.0, and a CHANGELOG entry records the fix.
File Description
spec/​swagger_v2/​param_values_spec.rb Updates the float range expectation to check numeric minimum and maximum values.
spec/​lib/​parse_params_spec.rb Adds a unit test for a float range passed to parse_enum_or_range_values.
lib/​grape-swagger/​doc_methods/​parse_params.rb Widens the range check to accept float ranges.
CHANGELOG.md Adds a fix entry for float range support.

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two moderate edge-case defects remain: non-real Complex range bounds can abort Swagger generation, and exclusive float ranges can be documented with an incorrectly inclusive maximum.

2 open issues
1 resolved since last review

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A moderate active issue remains because ranges with a non-real bound can still be parsed with that bound silently discarded, affecting both range-handling branches.

1 open issue
2 resolved since last review

Review effort: Lite

artyomb and others added 8 commits November 12, 2026 00:28
The Float range support documents minimum and maximum, which an existing
spec still asserted as absent. Update it, add a unit test for the Float
case and record the change.
A Float range with an infinite bound, such as 1.0..Float::INFINITY, put
Infinity into the parameter and made /swagger_doc fail to serialize.
Only finite numeric bounds are emitted now. Beginless ranges no longer
raise, and BigDecimal ranges, which map to a Swagger double, are
documented as floats.
An exclusive range such as 1.0...5.0 was documented with an inclusive
maximum, so the excluded end looked valid. It now also sets
exclusiveMaximum, which survives in body definitions. A range with a
Complex bound no longer aborts Swagger generation.
Range bounds that are not Integer or Float were always rounded through Float,
so a whole BigDecimal such as 9007199254740993 lost precision and 1 was
documented as 1.0. Whole values now stay Integers; only fractional ones
become Floats.

Specs also cover Rational, NaN bounds, and exclusiveMaximum on the items of
a query array.
A range with a real start and a non-real end, such as 1..Complex(2, 0),
was documented with only its start because the check looked at a single
bound. Checking all bounds drops the whole range instead, matching how
non-real bounds are already handled.
@numbata
numbata merged commit e4fd4b0 into ruby-grape:master Nov 12, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants