-
Notifications
You must be signed in to change notification settings - Fork 139
feat(shared): read items in pattern validation #3060
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
Merged
markscott-ms
merged 12 commits into
finos:main
from
YoofiTT96:feat/2859-validation-items-catalog
Sep 17, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6f534f7
feat(shared): read items in pattern validation
YoofiTT96 e03257e
fix(shared): order items declarations after prefixItems entries
YoofiTT96 c6425ef
feat(shared): reject maxItems that leaves no room for items
YoofiTT96 80cc8fb
docs: record three limits the contract did not state
YoofiTT96 6e3e2ea
docs: say why a fixed half beside alternatives cannot work
YoofiTT96 df040a7
refactor(shared): read the decision marker without JSONPath
YoofiTT96 538c276
Merge branch 'main' into feat/2859-validation-items-catalog
YoofiTT96 fc95b8b
Merge branch 'main' into feat/2859-validation-items-catalog
YoofiTT96 8375890
fix(shared): reject decision options declared in items
YoofiTT96 d1f552d
Merge remote-tracking branch 'origin/feat/2859-validation-items-catal…
YoofiTT96 dbf5bbe
test(shared): pin that a decision may reference an items member
YoofiTT96 af9851f
test(cli): count the new decision-options rule in the junit fixture
YoofiTT96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
shared/src/spectral/functions/pattern/decision-is-declared-in-prefix-items.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { RulesetFunctionContext } from '@stoplight/spectral-core'; | ||
| import { decisionIsDeclaredInPrefixItems } from './decision-is-declared-in-prefix-items'; | ||
|
|
||
| const asContext = () => ({ path: ['properties', 'relationships', 'items', 'oneOf', 0] } as unknown as RulesetFunctionContext); | ||
|
|
||
| const decision = (id: string) => ({ | ||
| properties: { | ||
| 'unique-id': { const: id }, | ||
| 'relationship-type': { properties: { options: { prefixItems: [] } } } | ||
| } | ||
| }); | ||
|
|
||
| const connects = (id: string) => ({ | ||
| properties: { | ||
| 'unique-id': { const: id }, | ||
| 'relationship-type': { const: { connects: { source: { node: 'a' }, destination: { node: 'b' } } } } | ||
| } | ||
| }); | ||
|
|
||
| describe('decisionIsDeclaredInPrefixItems', () => { | ||
| it('reports a decision', () => { | ||
| const results = decisionIsDeclaredInPrefixItems(decision('add-ons'), null, asContext()); | ||
| expect(results).toHaveLength(1); | ||
| expect(results[0].message).toContain('The decision \'add-ons\' is declared in items'); | ||
| }); | ||
|
|
||
| it('reports at the path of the declaration', () => { | ||
| const results = decisionIsDeclaredInPrefixItems(decision('add-ons'), null, asContext()); | ||
| expect(results[0].path).toEqual(['properties', 'relationships', 'items', 'oneOf', 0]); | ||
| }); | ||
|
|
||
| it('names the decision as unknown when it declares no id', () => { | ||
| const anonymous = { properties: { 'relationship-type': { properties: { options: {} } } } }; | ||
| expect(decisionIsDeclaredInPrefixItems(anonymous, null, asContext())[0].message).toContain('\'unknown\''); | ||
| }); | ||
|
|
||
| it('accepts a relationship that is not a decision', () => { | ||
| expect(decisionIsDeclaredInPrefixItems(connects('w-d'), null, asContext())).toEqual([]); | ||
| }); | ||
|
|
||
| it('accepts no input', () => { | ||
| expect(decisionIsDeclaredInPrefixItems(undefined, null, asContext())).toEqual([]); | ||
| }); | ||
| }); |
19 changes: 19 additions & 0 deletions
19
shared/src/spectral/functions/pattern/decision-is-declared-in-prefix-items.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { IFunctionResult, RulesetFunctionContext } from '@stoplight/spectral-core'; | ||
| import { declaredId, declaresOptions } from './declaration-paths'; | ||
|
|
||
| /** | ||
| * An architecture always contains every relationship a pattern declares in prefixItems, so | ||
| * a decision declared there is always asked. An items member may be left out, so a | ||
| * decision declared there can vanish, and declining it stops being a choice. | ||
| */ | ||
| export function decisionIsDeclaredInPrefixItems(input: unknown, _: unknown, context: RulesetFunctionContext): IFunctionResult[] { | ||
| const relationship = input as object; | ||
| if (!relationship || !declaresOptions(relationship)) { | ||
| return []; | ||
| } | ||
|
|
||
| return [{ | ||
| message: `The decision '${declaredId(relationship) ?? 'unknown'}' is declared in items. Declare a decision in relationships prefixItems, so that an answer can decline it.`, | ||
| path: [...context.path], | ||
| }]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.