Skip to content

Conversation

@yelizhenden-mdb
Copy link
Collaborator

@yelizhenden-mdb yelizhenden-mdb commented Apr 1, 2025

Proposed changes

Jira ticket: CLOUDP-306575

  xgen-IPA-118-no-additional-properties-false:
    description: |
      Schemas must not use `additionalProperties: false`

      ##### Implementation details
      This rule checks that schemas don't restrict additional properties by setting `additionalProperties: false`.
      Schemas without explicit `additionalProperties` settings (which default to true) or with `additionalProperties` set to `true` are compliant.
      This rule checks all nested schemas, but only parent schemas can be marked for exception.

No violations to fix

Checklist

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works

Changes to Spectral

  • I have read the README file for Spectral Updates

Further comments

@yelizhenden-mdb yelizhenden-mdb marked this pull request as ready for review April 1, 2025 14:58
@yelizhenden-mdb yelizhenden-mdb requested a review from a team as a code owner April 1, 2025 14:58
- '**#/components/schemas/UserSecurity/properties/customerX509' # unable to document exceptions, to be covered by CLOUDP-308286
rules:
xgen-IPA-112-field-names-are-camel-case: 'off'
- files:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FYI drive-by fix to sync with MMS

try {
const errors = [];

const results = findAdditionalPropertiesFalsePaths(schemaObject, path);
Copy link
Collaborator

@lovisaberggren lovisaberggren Apr 1, 2025

Choose a reason for hiding this comment

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

Can you add a test case where there are multiple additionalProperties: false? (In the same schema, nested for example)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, added them with the name invalid with multiple nested additionalProperties: false and invalid with multiple nested additionalProperties: false - exceptions. Let me know how it looks

Copy link
Collaborator

Choose a reason for hiding this comment

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

Great, thanks!

@wtrocki wtrocki requested a review from Copilot April 1, 2025 19:58
Copy link

Copilot AI left a 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 introduces a new rule (IPA-118) to prevent schemas from restricting additional properties by setting additionalProperties: false, reinforcing the principle of extensibility by default.

  • Added a utility (findAdditionalPropertiesFalsePaths) to recursively locate instances of additionalProperties: false in schema objects
  • Implemented the IPA118NoAdditionalPropertiesFalse rule that leverages this utility, along with comprehensive tests and documentation updates

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tools/spectral/ipa/rulesets/functions/utils/compareUtils.js Adds a utility function to recursively detect paths with additionalProperties: false in schemas.
tools/spectral/ipa/rulesets/functions/IPA118NoAdditionalPropertiesFalse.js Implements the new rule that checks schemas using the utility function.
tools/spectral/ipa/rulesets/README.md Updates documentation to include the IPA-118 rule details.
tools/spectral/ipa/rulesets/IPA-118.yaml Provides the rule configuration for Spectral.
tools/spectral/ipa/ipa-spectral.yaml Adds the IPA-118 rule file to the overall Spectral configuration.
tools/spectral/ipa/tests/utils/compareUtils.test.js Adds tests to verify the correctness of the new utility function.
tools/spectral/ipa/tests/IPA118NoAdditionalPropertiesFalse.test.js Introduces tests to check the new rule's behavior under various scenarios.

@yelizhenden-mdb yelizhenden-mdb merged commit 9a08ffe into main Apr 2, 2025
8 checks passed
@yelizhenden-mdb yelizhenden-mdb deleted the CLOUDP-306575 branch April 2, 2025 09:15
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.

2 participants