Skip to content

Align early SpecValidator rule specs with the later rule spec layout (spec only) - #208

Open
takayamaki wants to merge 4 commits into
ota42y:masterfrom
takayamaki:spec-align-rule-specs
Open

takayamaki wants to merge 4 commits into
ota42y:masterfrom
takayamaki:spec-align-rule-specs

Conversation

@takayamaki

Copy link
Copy Markdown
Contributor

Spec-only follow-up to the SpecValidator series from #152.
No library code changes.

The rule specs added later in the series (#199 onwards) settled on a common layout:

  • a base_doc helper that builds the document skeleton,
    with doc_with_<feature> / doc_without_<feature> helpers on top of it
    instead of one helper taking a flag or a payload argument
  • one example for each version x usage combination
    (3.1 with / 3.1 without / 3.0 with / 3.0 without / unknown version)
  • runtime behaviour specs kept next to the other SchemaValidator specs,
    not inside the rule spec

The earlier rule specs predate that layout.
This PR brings four of them in line so the rule specs read the same way throughout.

Runtime specs moved out of rule specs

type_null_in_30_spec.rb and type_array_in_30_spec.rb each carried a second top-level RSpec.describe
covering the runtime behaviour of type: "null" and array-form type.
Those examples move verbatim into schema_validator_spec.rb,
nested under the existing top-level describe next to the const runtime examples from #200.
This matches where #192 (integer_validator_spec.rb) and #202 (array_validator_spec.rb) put theirs.

Helpers split, missing combinations added

  • PathItemsIn30: the include_path_items: boolean flag becomes doc_with_path_items / doc_without_path_items.
    Adds the "3.1 document without components.pathItems" example.
  • TypeNullIn30 / TypeArrayIn30: the single parameterised helper becomes doc_with_<feature> / doc_without_<feature>.
    Adds the "3.1 document without the feature" example to each.
  • ExampleSingularDeprecation: the payload-taking helper becomes
    doc_with_example / doc_without_example / doc_with_examples_array.
    Adds the "3.0 document without singular example" example.

The ExclusiveMinimum / ExclusiveMaximum / NullableDeprecation specs are left as they are.
They already enumerate more combinations than the common layout
(3.0-style vs 3.1-style form, true vs false), and reshaping them would only shuffle lines.

Each commit passes rake (rspec + steep) on its own.
This PR touches none of the files changed by the two open contentEncoding / contentSchema PRs,
so it can land in any order relative to them.

…or_spec

The rule specs for TypeNullIn30 and TypeArrayIn30 carried a second top-level
describe covering the runtime behaviour of the feature they detect.
Runtime specs belong next to the other SchemaValidator specs,
following the placement used for exclusiveMinimum / exclusiveMaximum (ota42y#192),
const (ota42y#200) and prefixItems (ota42y#202).
No behaviour change; the examples are moved verbatim.
Replace the boolean `include_path_items:` helper flag with explicit
`doc_with_path_items` / `doc_without_path_items` helpers over a shared
`base_doc`, as the later rule specs do.
Add the missing "3.1 document without components.pathItems" example so the
spec covers all four version x usage combinations.
Split the single parameterised helper into `doc_with_<feature>` /
`doc_without_<feature>` helpers over a shared `base_doc`,
as the later rule specs do.
Add the missing "3.1 document without the feature" example to each,
so both specs cover all four version x usage combinations.
Split the single payload-taking helper into `doc_with_example` /
`doc_without_example` / `doc_with_examples_array` helpers over a shared
`base_doc`, as the later rule specs do.
Add the missing "3.0 document without singular example" example so the
spec covers all four version x usage combinations.
end
end

RSpec.describe 'runtime: type as Array semantic in 3.1' do

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

moved to spec/openapi_parser/schema_validator_spec.rb

end
end

RSpec.describe 'runtime: type: "null" semantic' do

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

moved to spec/openapi_parser/schema_validator_spec.rb

'components' => { 'schemas' => { 'Sample' => { 'type' => 'string' } } },
}
root = OpenAPIParser.parse(raw, strict_reference_validation: false)
root = doc_without_type_null('3.0.0')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The inline hash is replaced with the shared helper


context 'with a 3.1 document using type as a plain string' do
it 'reports no violation' do
root = doc_without_type_array('3.1.0')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

missing test case added


context 'with a 3.1 document without type: "null"' do
it 'reports no violation' do
root = doc_without_type_null('3.1.0')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

missing test case added

end

context 'with a 3.1 document without components.pathItems' do
it 'reports no violation' do

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

missing test case added

end

context 'with a 3.0 document without singular example' do
it 'reports no violation' do

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

missing test case added

@takayamaki
takayamaki marked this pull request as ready for review September 12, 2026 01:17
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.

1 participant