Return openapi_version as a Gem::Version so SpecValidator rules can compare ranges - #209
Open
takayamaki wants to merge 3 commits into
Open
takayamaki wants to merge 3 commits into
takayamaki wants to merge 3 commits into
Conversation
List the cases for returning openapi_version as a Gem::Version, for the version range helpers on SpecValidator::Rule, and for the 3.1-or-later rules applied to 3.2 documents.
Rules compare the declared version with == against a Symbol today, which cannot express "3.1 or later". version_before? and version_at_least? take a boundary string and compare against a Gem::Version, returning false for an unknown version.
openapi_version returned :v3_0 / :v3_1 / :unknown and every rule
compared it with ==, so a 3.2 document fell into :unknown and no
rule ran on it.
It now returns Gem::Version (prerelease dropped) or nil when the
field is missing or not a major.minor[.patch] string.
Rules use version_before?('3.1') / version_at_least?('3.1'),
so the 3.1-or-later rules (nullable, singular example,
Boolean exclusiveMinimum / exclusiveMaximum) also cover 3.2.
takayamaki
marked this pull request as ready for review
September 19, 2026 07:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
OpenAPI#openapi_versionreturns a Symbol (:v3_0/:v3_1/:unknown),and every
SpecValidatorrule compares it with==.A 3.2 document therefore falls into
:unknown, and no rule runs on it.This blocks 3.2 support (see #152).
What
openapi_versionnow returns aGem::Version, ornilwhen theopenapifield is missing or is not amajor.minor[.patch]string.A prerelease tag is dropped (
3.1.0-rc1=>3.1.0), matching the old prefix behavior.SpecValidator::Rulegetsversion_before?(boundary)andversion_at_least?(boundary).Both return
falsefor an unknown version.*In30rules useversion_before?('3.1').NullableDeprecation,ExampleSingularDeprecation,ExclusiveMinimumandExclusiveMaximumuseversion_at_least?('3.1'),so a 3.2 document is checked by them too.
4.0.0document is no longer special-cased as unknown; it is simply a version greater than 3.1.The "unknown version" spec contexts now use a non-version string.
openapi_versionis not released yet (added in #192), so this is not a breaking change.Tests
spec/openapi_parser/schemas/open_api_spec.rb: the accessor cases, including 3.2.0, prerelease, 4.0.0, missing, non-string, and non-version stringsspec/openapi_parser/spec_validator/rule_spec.rb: the two range helpersbundle exec rakepasses on Ruby 3.3 / 4.0 (rspec 497 examples, steep clean).Ruby 2.7 checked by loading the library directly.