Skip to content

Commit 74e91c1

Browse files
authored
fix(specs): compostion run payload example for external injected items (#6291)
1 parent 948527e commit 74e91c1

3 files changed

Lines changed: 64 additions & 6 deletions

File tree

eslint/src/rules/hasType.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ export const hasType: Rule.RuleModule = {
2020
return; // allow everything in properties
2121
}
2222

23+
// allow everything in example
24+
for (let parentNode = node.parent; parentNode; parentNode = parentNode.parent) {
25+
if (isPairWithKey(parentNode, 'example')) {
26+
return;
27+
}
28+
}
29+
2330
const type = node.parent.pairs.find((pair) => isPairWithKey(pair, 'type'));
2431
if (isPairWithKey(node, 'properties') && (!type || !isPairWithValue(type, 'object'))) {
2532
return context.report({

eslint/tests/hasType.test.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { runClassic } from 'eslint-vitest-rule-tester';
2-
import * as yamlParser from "yaml-eslint-parser"
2+
import * as yamlParser from 'yaml-eslint-parser';
33

44
import { hasType } from '../src/rules/hasType.js';
55

@@ -19,6 +19,41 @@ withArray:
1919
type: array
2020
items:
2121
type: string
22+
`,
23+
`
24+
withExample:
25+
type: object
26+
properties:
27+
items:
28+
type: array
29+
items:
30+
type: string
31+
example:
32+
items:
33+
- 'this'
34+
- 'that'
35+
`,
36+
`
37+
withExampleNestedItems:
38+
type: object
39+
additionalProperties:
40+
type: object
41+
properties:
42+
items:
43+
type: array
44+
items:
45+
type: object
46+
properties:
47+
id:
48+
type: string
49+
example:
50+
someKey:
51+
items:
52+
- id: '1'
53+
- id: '2'
54+
someOtherKey:
55+
items:
56+
- id: '3'
2257
`,
2358
],
2459
invalid: [

specs/composition/common/params/Composition.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,28 @@ injectedItems:
4848
additionalProperties:
4949
$ref: '#/externalInjectedItem'
5050
description: |
51-
A list of extenrally injected objectID groups into from an external source.
51+
An object containing keys corresponding to the `key`s from an injection's `injectedItems` and values containing a list of hits to inject.
5252
default: {}
5353
x-categories:
5454
- Retail Media Network
5555
example:
56-
'my-group-key': [{'objectID': 'my-object-1', 'metadata': {'my-field': 'my-value'}}, {'objectID': 'my-object-2'}]
56+
my-group-key:
57+
items:
58+
- objectID: 'my-object-1'
59+
metadata:
60+
my-field: 'my-value'
61+
- objectID: 'my-object-2'
62+
metadata:
63+
my-field: 'my-value-2'
64+
my-other-group-key:
65+
items:
66+
- objectID: 'my-other-object-1'
67+
- objectID: 'my-other-object-2'
5768

5869
externalInjectedItem:
5970
type: object
71+
description: |
72+
Contains a list of objects to inject from an external source.
6073
properties:
6174
items:
6275
type: array
@@ -67,19 +80,22 @@ externalInjectedItem:
6780
properties:
6881
objectID:
6982
type: string
70-
description: An objectID injected into an external source.
83+
description: An objectID injected from an external source and also present in the targeted index.
7184
metadata:
7285
type: object
7386
additionalProperties: true
7487
description: |
7588
User-defined key-values that will be added to the injected item in the response.
7689
This is identical to Hits metadata defined in Composition or Composition Rule,
7790
with the benefit of being set at runtime.
78-
example: {'my-field': 'my-value'}
91+
example:
92+
my-field: 'my-value'
7993
required:
8094
- objectID
8195
example:
82-
{'objectID': 'my-object-1', 'metadata': {'my-field': 'my-value'}}
96+
objectID: 'my-object-1'
97+
metadata':
98+
my-field: 'my-value'
8399
required:
84100
- items
85101

0 commit comments

Comments
 (0)