Skip to content

feat(ipa): add IPA-132 OperationResponse schema rules - #1437

Open
julius-jogela wants to merge 4 commits into
feat-ipa-132-operations-resource-rulesfrom
feat-ipa-132-operation-response-schema
Open

feat(ipa): add IPA-132 OperationResponse schema rules#1437
julius-jogela wants to merge 4 commits into
feat-ipa-132-operations-resource-rulesfrom
feat-ipa-132-operation-response-schema

Conversation

@julius-jogela

Copy link
Copy Markdown
Collaborator

Proposed changes

This PR adds the IPA-132 rules validating how long-running operation status is communicated through the OperationResponse schema. Stacked on #1435; the base retargets to main once that merges.

Jira ticket: CLOUDP-429837

Rules added

All at warn severity:

Rule Guideline Checks
xgen-IPA-132-operation-endpoints-must-return-operation-response IPA-132-operation-endpoints-must-return-operation-response The single Operation endpoint (.../operations/{operationId}) must reference the OperationResponse schema; the Operations collection endpoint must return a paginated response whose results items reference it. Exceptions at the content media type level
xgen-IPA-132-operation-status-must-use-the-standard-status-enum IPA-132-operation-status-must-use-the-standard-status-enum OperationResponse must define a status property whose enum is exactly PENDING, IN_PROGRESS, SUCCEEDED, FAILED, CANCELED, SUPERSEDED
xgen-IPA-132-operation-response-must-include-core-metadata IPA-132-operation-response-must-include-core-metadata operationId, operationType, createdAt, updatedAt defined and required; operationType enum exactly CREATE, UPDATE, DELETE, CUSTOM; customMethod defined but not required (it applies only to CUSTOM operations, which cannot be validated statically)

The schema rules anchor on $.components.schemas.OperationResponse per the guideline metadata. The OperationResponse schema name, both enums and the exact-enum-match helper live in utils/longRunningOperations.js for reuse by the remaining IPA-132 rules.

Testing

  • 25 new tests: every Correct/Incorrect example from the IPA-132 guidelines is a test case, plus per rule a violation-with-exception (suppressed) and adoption-with-exception (flagged as unnecessary) case, and unit tests for the enum helper.
  • Full suite: 122 suites / 758 tests pass. gen-ipa-docs, prettier and eslint clean.
  • spectral lint openapi/.raw/v2.yaml with the full ruleset: 0 xgen-IPA-132-* findings — the spec defines no OperationResponse schema yet.
  • Live-fire check: a complete compliant LRO spec produces 0 findings across all six IPA-132 rules; planting a non-standard enum value, dropping a field from required, and de-referencing the schemas each fires exactly the right rule.

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

@julius-jogela
julius-jogela force-pushed the feat-ipa-132-operation-response-schema branch 2 times, most recently from 0dd2c21 to ed56aed Compare August 14, 2026 16:20
Add the three rules validating how long-running operation status is
communicated through the OperationResponse schema:

- xgen-IPA-132-operation-endpoints-must-return-operation-response: the
  single Operation endpoint must reference the OperationResponse schema,
  and the Operations collection endpoint must return a paginated
  response whose results reference it.
- xgen-IPA-132-operation-status-must-use-the-standard-status-enum: the
  schema must report progress through a status field using exactly the
  enum PENDING, IN_PROGRESS, SUCCEEDED, FAILED, CANCELED, SUPERSEDED.
- xgen-IPA-132-operation-response-must-include-core-metadata:
  operationId, operationType, createdAt and updatedAt must be defined
  and required, operationType must use exactly the enum CREATE, UPDATE,
  DELETE, CUSTOM, and customMethod must be defined but not required.

The schema name, both enums and the exact-enum-match helper live in
utils/longRunningOperations.js for reuse by the remaining IPA-132 rules.
Per review of the IPA-132 guideline examples, the status field must be
listed as required: an OperationResponse that can legally omit status
defeats polling. The status enum rule now checks required membership in
addition to the exact enum, matching the updated guideline example.
Per review, the test fixtures follow the same pattern across the IPA-132
test files: the operations and schemas under test are defined once at
the top of the file and reused across the test cases.
Address findings from a deeper review of the OperationResponse rules:

- The status enum and core metadata rules read properties and required
  lists through allOf sub-schemas, which Spectral does not flatten, so
  an allOf-composed OperationResponse no longer produces false
  violations.
- The Operations collection endpoint must reference a paginated wrapper
  schema: inline wrappers are rejected, consistent with
  xgen-IPA-110-collections-use-paginated-prefix, which rejects them at
  error severity. The results property of the wrapper may live in one of
  its allOf sub-schemas.
- The single Operation endpoint no longer accepts an array schema whose
  items reference OperationResponse.
- The endpoint rule checks its cheap path and media type gates before
  walking the document.
},
},
// A paginated wrapper composed with allOf, which Spectral does not flatten
PaginatedAllOfOperationResponse: {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we allow allOf? Could you clarify that?

type: 'object',
required: ['operationId', 'operationType', 'createdAt', 'updatedAt'],
properties: {
operationId: { type: 'string' },

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looking at the Technical Design document, I see that there are other required fields, in other words, core metadata. Shouldn't they be involved here as well?


message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-132-operation-response-must-include-core-metadata'
severity: warn
given: $.components.schemas.OperationResponse

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you define an alias for it and re-use later?

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