Skip to content

refactor(ipa): CLOUDP-453872 defineRule collects results, generated Applies to docs - #1564

Merged
wtrocki merged 2 commits into
mainfrom
CLOUDP-453872-ipa-define-rule-collection
Oct 29, 2026
Merged

wtrocki merged 2 commits into
mainfrom
CLOUDP-453872-ipa-define-rule-collection

Conversation

@DatMitro

@DatMitro DatMitro commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Proposed changes

Second of three PRs (CLOUDP-453872). Builds on the framework PR; still no rule uses defineRule, so there is no change to lint results.

  • Collection: defineRule records an adoption, violation or exception from the errors check returns, reading x-xgen-IPA-exception from exceptionTarget (the input by default).
  • Internal errors: onInternalError ('violation', 'return', 'throw') makes each rule's existing try/catch behavior an explicit option instead of a copied block. beforeCheck runs outside the try, for the operation ID rules whose unreadable verb override must keep failing the lint run. checkUses lists conditions the check evaluates itself, for the docs.
  • Generated docs: gen-ipa-docs renders an "Applies to" section for rules built with defineRule and writes rulesets/CONDITIONS.md, a glossary of each condition's definition, examples and the rules that use it. The existing docs check covers both files. Conditions get a label and examples a note for this.

CONDITIONS.md is empty here because no rule uses a condition yet.

Why generate the docs

  • Where a rule applies is written by hand in each rule's YAML description today, and it can drift from what the code does. refactor(ipa): CLOUDP-453872 migrate IPA-104 and IPA-113 to defineRule #1565 corrects two such descriptions.
  • The "Applies to" section and CONDITIONS.md are generated from the conditions the rule declares, so the docs equal what the rule does. The docs check fails if they are out of date.
  • Reviewers and API teams can see what a rule skips, and why, without reading its code.
  • Changing a condition updates the docs of every rule that uses it.

Jira ticket: CLOUDP-453872

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

Stack of three: #1529 (framework, merged), this PR, then #1565 (IPA-104/113 migration), which is based on this PR's branch.

@DatMitro
DatMitro marked this pull request as ready for review October 27, 2026 12:02
@DatMitro
DatMitro requested a review from a team as a code owner October 27, 2026 12:02
@DatMitro
DatMitro force-pushed the CLOUDP-453872-ipa-conditions-define-rule branch from 8ad4ff2 to e970023 Compare October 27, 2026 14:01
@DatMitro
DatMitro force-pushed the CLOUDP-453872-ipa-define-rule-collection branch from 83fb794 to 6cc19ba Compare October 27, 2026 14:01
Base automatically changed from CLOUDP-453872-ipa-conditions-define-rule to main October 27, 2026 15:53
@DatMitro
DatMitro force-pushed the CLOUDP-453872-ipa-define-rule-collection branch from 6cc19ba to e373e5c Compare October 27, 2026 16:10
@@ -0,0 +1,5 @@
<!--- NOTE: This file is generated, please see /scripts/generateRulesetReadme.js --->

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Any reason why we need this as separate md file. Can we append to existing docs?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I considered rulesets/README.md, but kept it separate. That README is already ~1,800 lines, and the glossary is reference material that readers reach from an "Applies to" link rather than by reading top to bottom. On my local branch, with 71 of ~117 rules migrated, it is ~520 lines (34 conditions), which would be about a quarter of the README. CONTRIBUTING.md is for rule authors, and this file is generated from the code. To make it findable, tools/spectral/README.md now links to it next to the ruleset docs. Happy to fold it into the rules README if you would still prefer that.

@@ -0,0 +1,5 @@
<!--- NOTE: This file is generated, please see /scripts/generateRulesetReadme.js --->

# IPA Validation Conditions

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's add fixes description what business purpose this chapter serves before generated content

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added an intro before the generated content, and a "Why generate the docs" section to the PR description on what the generated docs are for.

const dirname = path.dirname(fileURLToPath(import.meta.url));
const readmeFilePath = path.join(dirname, '../rulesets', 'README.md');
const conditionsFilePath = path.join(dirname, '../rulesets', 'CONDITIONS.md');
const CONDITIONS_URL = 'https://github.com/mongodb/openapi/blob/main/tools/spectral/ipa/rulesets/CONDITIONS.md';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[nit] Why do we need whole repository path?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The generated README already uses absolute GitHub URLs (for example the link to ipa-spectral.yaml), so the glossary links follow the same convention. The constant is only there so each "Applies to" link and the glossary's own links are built from one place.

@@ -0,0 +1,467 @@
# Known issues: singleton / nested-resource classification

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this Agentic report file or something we wish to document?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added by mistake: it's a working-notes file that isn't part of this change. Removed it from this PR and from #1565.

@wtrocki wtrocki left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We need more documentation and justification for the framework.
Feel free to reuse existing document you have shared so we surface all the relevant context and impact in the PR and source code.

@wtrocki

wtrocki commented Oct 29, 2026

Copy link
Copy Markdown
Member

Nothing blocking. Will approve once we get documentation updates.

…s docs

defineRule records adoptions, violations and exceptions and makes each rule's internal-error behavior an explicit option. gen-ipa-docs renders an Applies to section for rules built with defineRule and a conditions glossary. Nothing uses either yet.
@DatMitro
DatMitro force-pushed the CLOUDP-453872-ipa-define-rule-collection branch from e373e5c to 98f42b4 Compare October 29, 2026 10:58
@wtrocki
wtrocki merged commit a103ce1 into main Oct 29, 2026
11 checks passed
@wtrocki
wtrocki deleted the CLOUDP-453872-ipa-define-rule-collection branch October 29, 2026 11:30
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