Repository navigation
feat(ipa): Add IPA-111 validation rules - #1460
Conversation
## Proposed changes Add three new Spectral validation rules enforcing lintable IPA-111 (Default Values) constraints to the IPA Validation Framework: - `xgen-IPA-111-optional-fields-no-default`: optional (non-required) fields must not define a default value. Boolean fields are delegated to the boolean rule below, and fields marked with the new `x-xgen-server-computed-when-client-omitted` extension are exempt. - `xgen-IPA-111-effective-fields-read-only`: effective-value fields (property names prefixed with `effective`) must be `readOnly: true` and must not appear in request schemas. - `xgen-IPA-111-optional-boolean-fields-default-false`: optional boolean fields must default to `false`. Also adds the `IPA-111.yaml` ruleset, registers it in `ipa-spectral.yaml`, regenerates the ruleset README, and introduces shared helpers `isRequiredProperty` (schemaUtils) and `hasServerComputedWhenClientOmittedExtension` (extensions). _Jira ticket:_ CLOUDP-439595 ## Checklist - [ ] I have signed the [MongoDB CLA](https://www.mongodb.com/legal/contributor-agreement) - [x] I have added tests that prove my fix is effective or that my feature works ### Changes to Spectral - [x] I have read the [README](../tools/spectral/README.md) file for Spectral Updates
|
Sage Bot can help with this pull request. Just |
|
❌ Sage Bot - Unexpected Error Sage Bot ran into an unexpected error processing your request. If you need help, reach out in #ask-devprod. |
…lations The original PR had 64 override entries but the Atlas v2 spec has 318 violations for the three new IPA-111 rules. Without the full list, ipa-validation would fail with 254 errors. Added 209 boolean, 96 no-default, and 13 effective overrides (all tracked under CLOUDP-439952). Verified zero violations on v2.yaml.
|
The 3 new rules are correctly implemented and all tests pass. The issue is the override list only covered ~64 of 318 actual violations in the Atlas v2 spec — running ipa-validation against v2.yaml would fail with 254 errors.
Concern — sheer volume of exceptions: 318 overrides for a single IPA rule is a red flag. The majority are boolean fields in response-only schemas (e.g., BackupSnapshot, DiskBackupSnapshotRestoreJob, ClusterDescriptionProcessArgs) where default: false is semantically irrelevant — the server computes these values. @yelizhenden-mdb Once we you back we should align and consider:
I'm going to do provisional change for this so it is easier to make follow up IPA change. |
…schemas only Response schemas and component schemas used in responses are now excluded from the optional-boolean-fields-default-false and optional-fields-no-default rules via pathIsForRequestVersion guard. This reduces the override list from 318 to 13 entries (only effective-fields-read-only requires component-level overrides). Also regenerated ruleset README.
wtrocki
left a comment
There was a problem hiding this comment.
LGTM. Needs additional review as I authored several follow up commits
|
@wtrocki I agree with the argument that default values only make sense in requests, since the default is what the server applies when the client doesn't supply the parameter value in the request. So maybe we can add a validation to prevent default values defined in response schema fields. How does it sound? Because, based on my analysis of the current OpenAPI spec, we have default values defined on the fields of some legacy schemas, and most of them are referenced by both request bodies and responses. It might be worth adding a validation that covers the existing legacy cases and prevents future ones. |
Do we have and if no should we prioritize validation that prevents schema objects from being reused across request and response? If so, that gives us a natural extension point for the "default" response validation. if we are aligned I'd suggest making small targeted fixes. Starting with IPA clarification, then refining the broader steps. I think an AI bot handles the immediate task well — addressing the sensible, non-negotiable IPA gaps.
Yes. Thus this will create +300 exceptions overall and will make even more in future due to reusal of the existing legacy objects in the new feature work. |
|
Discussed offline. @wtrocki to create set of tickets to cover gaps. PR addressing very specific problem as of now and can be approved. |
Proposed changes
Add three new Spectral validation rules enforcing lintable IPA-111 (Default Values) constraints to the IPA Validation Framework:
xgen-IPA-111-optional-fields-no-default: optional (non-required) fields must not define a default value. Boolean fields are delegated to the boolean rule below, and fields marked with the newx-xgen-server-computed-when-client-omittedextension are exempt.xgen-IPA-111-effective-fields-read-only: effective-value fields (property names prefixed witheffective) must bereadOnly: trueand must not appear in request schemas.xgen-IPA-111-optional-boolean-fields-default-false: optional boolean fields must default tofalse.Also adds the
IPA-111.yamlruleset, registers it inipa-spectral.yaml, regenerates the ruleset README, and introduces shared helpersisRequiredProperty(schemaUtils) andhasServerComputedWhenClientOmittedExtension(extensions).Jira ticket: CLOUDP-439595
Checklist
Changes to Spectral
Important
MongoDB Contribution Guidelines
This pull request was generated by sage-bot on behalf of yeliz.henden@mongodb.com (ticket assignee). The assignee must self-review the changes before requesting review from another engineer.
The assignee is not allowed to merge their own PR without approval from another engineer.