-
Notifications
You must be signed in to change notification settings - Fork 0
Fix type-checking rules to accept $ref as valid type specification #42
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
Conversation
…ation Co-authored-by: salliegsoft <115026913+salliegsoft@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the items-must-have-a-type Spectral rule to correctly accept $ref as a valid type specification for array items, eliminating false positive warnings when schemas reference complex types using $ref instead of primitive types.
Key Changes:
- Updated the rule to validate using JSON Schema with
anyOfto accept eithertypeor$reffields - Added test case to verify
$refvalidation works correctly - Updated rule description to clarify that schema references are acceptable
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| .workleap.rules.yaml | Modified the items-must-have-a-type rule to accept both type and $ref using JSON Schema validation with anyOf |
| TestSpecs/items-must-have-a-type-valid-ref.yaml | Added test spec demonstrating valid array items using $ref to reference schema definitions |
| test.ps1 | Added new test case entry for validating $ref support in array items |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
jcbuteau
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think schemas-properties-must-have-a-type also has the same issue
@copilot Can you look into this |
Co-authored-by: salliegsoft <115026913+salliegsoft@users.noreply.github.com>
Fixed in commit 55311cd. Updated both |
Problem
Three Spectral rules were only checking for explicit
typefields, ignoring that$refprovides stronger type information by referencing specific schema definitions. This is the correct and preferred way to specify complex types in OpenAPI 3.0.Example that was incorrectly flagged:
Solution
Updated three related rules to accept either
typeor$refas valid type specifications:Before:
After:
Changes
.workleap.rules.yamlto use JSON Schema validation withanyOfto accept bothtypeand$reffields for:items-must-have-a-type- for array itemsschemas-properties-must-have-a-type- for component schema propertiespath-schema-properties-must-have-a-type- for path/response schema properties$refvalidation:TestSpecs/items-must-have-a-type-valid-ref.yamlTestSpecs/schemas-properties-must-have-a-type-valid-ref.yamlTestSpecs/path-schema-properties-must-have-a-type-valid-ref.yamltest.ps1to include the new tests (now 25 tests total)Testing
✅ All 25 tests pass
✅ Valid items/properties with primitive types:
type: string✅ Valid items/properties with schema references:
$ref: '#/components/schemas/MySchema'✅ Valid items/properties with complex inline types
✅ Invalid items/properties (null/empty) still correctly flagged
✅ Backend and frontend configs work correctly
Impact
$reffor array items or properties could generate false positive warningsThis fix ensures consistency across all type-checking rules and aligns with OpenAPI 3.0 best practices where
$refis the standard approach for referencing complex schemas.Fixes #41
Original prompt
Fixes #41
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.