Skip to content

Commit

Permalink
feat(specs): update composition specs according to upcoming API chang…
Browse files Browse the repository at this point in the history
…es (#4234)

Co-authored-by: shortcuts <vannicattec@gmail.com>
  • Loading branch information
e-krebs and shortcuts authored Dec 18, 2024
1 parent 9002538 commit 448aad7
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 53 deletions.
53 changes: 26 additions & 27 deletions playground/javascript/node/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,35 @@ const client = compositionClient(appId, apiKey);

async function testComposition() {
try {
console.log(appId, apiKey)
// create a new composition
/*
const res = await client.multipleBatch({
requests: [
{
action: 'upsert',
body: {
objectID: 'id1',
description: 'the first ever composition from the client',
behavior: {
injection: {
main: {
source: {
search: {
index: 'cts_e2e_small',
},
},
},
},
},
},
},
],
});
console.log(`[OK]`, res);
*/
// const res = await client.multipleBatch({
// requests: [
// {
// action: 'upsert',
// body: {
// objectID: 'id1',
// name: 'my first composition',
// description: 'the first ever composition from the client',
// behavior: {
// injection: {
// main: {
// source: {
// search: {
// index: 'cts_e2e_small',
// },
// },
// },
// },
// },
// },
// },
// ],
// });
// console.log(`[OK]`, res);

const compos = await client.listCompositions();
console.log(await client.listCompositions())

console.log(`[OK]`, compos);
} catch (e) {
if (e instanceof ApiError) {
return console.log(`[${e.status}] ${e.message}`, e.stackTrace, e);
Expand Down
20 changes: 11 additions & 9 deletions specs/composition/common/schemas/Hit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ compositionRankingInfo:
composed:
title: composedRankingInfo
type: object
additionalProperties: false
properties:
index:
type: string
inset:
type: string
required:
- index
- inset
additionalProperties:
title: compositionIdRankingInfo
type: object
properties:
index:
type: string
injectedItemKey:
type: string
required:
- index
- injectedItemKey
4 changes: 2 additions & 2 deletions specs/composition/common/schemas/SearchParams.yml
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,8 @@ mainInjectionQueryParameters:
x-categories:
- Filtering

InsetsQueryParameters:
title: Composition Insets Query parameters as object
injectedItemsQueryParameters:
title: Composition injectedItems Query parameters as object
type: object
additionalProperties: false
properties:
Expand Down
85 changes: 83 additions & 2 deletions specs/composition/common/schemas/SearchResponse.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
searchResponse:
additionalProperties: true
allOf:
- $ref: '../../../common/schemas/SearchResponse.yml#/baseSearchResponse'
- $ref: '#/compositionBaseSearchResponse'
- $ref: '#/searchResults'

searchResults:
Expand All @@ -16,8 +16,10 @@ searchResults:

searchResultsItem:
allOf:
- $ref: '#/searchHits'
- $ref: '../../../common/schemas/SearchResponse.yml#/baseSearchResponse'
- $ref: '../../../common/schemas/SearchResponse.yml#/SearchPagination'
- $ref: '#/searchHits'
- $ref: '#/resultsCompositionsResponse'

searchHits:
type: object
Expand All @@ -33,3 +35,82 @@ searchHits:
$ref: 'Hit.yml#/hit'
required:
- hits

resultsCompositionsResponse:
type: object
additionalProperties: true
properties:
compositions:
title: resultsCompositionsInfoResponse
type: object
additionalProperties:
title: resultsCompositionInfoResponse
type: object
properties:
injectedItems:
type: array
items:
$ref: '#/resultsInjectedItemInfoResponse'
required:
- injectedItems
required:
- compositions

resultsInjectedItemInfoResponse:
type: object
additionalProperties: true
properties:
key:
type: string
appliedRules:
type: array
items:
title: resultsInjectedItemAppliedRulesInfoResponse
type: object
properties:
objectID:
$ref: '../../../common/parameters.yml#/objectID'
required:
- objectID
required:
- key

# copy of specs/common/schemas/SearchResponse.yml/#baseSearchResponse without appliedRules
compositionBaseSearchResponse:
type: object
additionalProperties: true
required:
- processingTimeMS
properties:
compositions:
$ref: '#/compositionsSearchResponse'

compositionsSearchResponse:
type: object
additionalProperties: true
properties:
run:
type: array
items:
$ref: '#/compositionRunSearchResponse'
required:
- run

compositionRunSearchResponse:
type: object
additionalProperties: true
properties:
objectID:
$ref: '../../../common/parameters.yml#/objectID'
appliedRules:
type: array
items:
title: compositionRunAppliedRules
type: object
properties:
objectID:
$ref: '../../../common/parameters.yml#/objectID'
required:
- objectID
required:
- objectID
20 changes: 10 additions & 10 deletions specs/composition/common/schemas/compositionBehavior.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,32 @@ compositionBehavior:
- search
required:
- source
insets:
injectedItems:
type: array
description: list of insets of the current Composition.
description: list of injected items of the current Composition.
minItems: 0
maxItems: 2
items:
$ref: '#/compositionInset'
$ref: '#/injectedItem'
required:
- main
required:
- injection

compositionInset:
injectedItem:
type: object
additionalProperties: false
properties:
name:
key:
type: string
description: Inset name.
description: injected Item unique identifier.
source:
title: compositionInsetSource
title: injectedItemSource
type: object
additionalProperties: false
properties:
search:
title: compositionInsetSourceSearch
title: injectedItemSourceSearch
type: object
additionalProperties: false
properties:
Expand All @@ -68,7 +68,7 @@ compositionInset:
description: Composition Main Index name.
example: Products
params:
$ref: './SearchParams.yml#/InsetsQueryParameters'
$ref: './SearchParams.yml#/injectedItemsQueryParameters'
required:
- index
required:
Expand All @@ -82,7 +82,7 @@ compositionInset:
minimum: 0
maximum: 20
required:
- name
- key
- source
- position
- length
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ composition:
properties:
objectID:
$ref: '../../../common/parameters.yml#/objectID'
description:
name:
type: string
description: Composition name.
example: 'my lovely crafted composition'
description:
type: string
description: Composition description.
example: 'my lovely crafted composition that is used for X purpose'
behavior:
$ref: './compositionBehavior.yml#/compositionBehavior'
required:
- objectID
- behavior
- name
1 change: 1 addition & 0 deletions tests/CTS/requests/composition/listCompositions.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"items": [
{
"objectID": "id1",
"name": "my first composition",
"description": "the first ever composition from the client",
"behavior": {
"injection": {
Expand Down
6 changes: 4 additions & 2 deletions tests/CTS/requests/composition/multipleBatch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"action": "upsert",
"body": {
"objectID": "foo",
"name": "my first composition",
"behavior": {
"injection": {
"main": {
Expand All @@ -15,7 +16,7 @@
}
}
},
"insets": []
"injectedItems": []
}
}
}
Expand All @@ -38,7 +39,7 @@
"body": {
"behavior": {
"injection": {
"insets": [],
"injectedItems": [],
"main": {
"source": {
"search": {
Expand All @@ -48,6 +49,7 @@
}
}
},
"name": "my first composition",
"objectID": "foo"
}
},
Expand Down

0 comments on commit 448aad7

Please sign in to comment.