Skip to content

Commit a26d4b5

Browse files
author
Samuel Bodin
authored
fix(spec): update sources spec (#130)
1 parent 1188f69 commit a26d4b5

File tree

10 files changed

+258
-7
lines changed

10 files changed

+258
-7
lines changed

clients/algoliasearch-client-javascript/client-sources/model/postURLJob.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { PostURLJobInput } from './postURLJobInput';
2+
import type { PostURLJobTarget } from './postURLJobTarget';
23

34
/**
45
* Object containing a URL job.
@@ -8,7 +9,12 @@ export type PostURLJob = {
89
* The type of the file to ingest.
910
*/
1011
type: PostURLJobType;
12+
/**
13+
* The name of the column that hold the unique identifier.
14+
*/
15+
uniqueIDColumn?: string;
1116
input: PostURLJobInput;
17+
target: PostURLJobTarget;
1218
};
1319

1420
export type PostURLJobType = 'csv';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* The authentication scheme for the URL that will be fetched.
3+
*/
4+
export type PostURLJobAuth = {
5+
/**
6+
* The type of authentication to use.
7+
*/
8+
type: PostURLJobAuthType;
9+
/**
10+
* The login to use for Basic Auth.
11+
*/
12+
login: string;
13+
/**
14+
* The password to use for Basic Auth.
15+
*/
16+
password: string;
17+
};
18+
19+
export type PostURLJobAuthType = 'basic';

clients/algoliasearch-client-javascript/client-sources/model/postURLJobInput.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { PostURLJobAuth } from './postURLJobAuth';
2+
13
/**
24
* The input of the job.
35
*/
@@ -6,4 +8,11 @@ export type PostURLJobInput = {
68
* The URL of the file to ingest.
79
*/
810
url: string;
11+
/**
12+
* The HTTP method that will be used to fetch the URL.
13+
*/
14+
method?: PostURLJobInputMethod;
15+
auth?: PostURLJobAuth;
916
};
17+
18+
export type PostURLJobInputMethod = 'GET' | 'POST';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* The target of the job.
3+
*/
4+
export type PostURLJobTarget = {
5+
/**
6+
* The product to target.
7+
*/
8+
type: PostURLJobTargetType;
9+
/**
10+
* The index name of the product.
11+
*/
12+
indexName: string;
13+
/**
14+
* The type of operation to execute.
15+
*/
16+
operation: PostURLJobTargetOperation;
17+
};
18+
19+
export type PostURLJobTargetType = 'search';
20+
21+
export type PostURLJobTargetOperation = 'replace';

clients/algoliasearch-client-javascript/client-sources/src/sourcesApi.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ export const createSourcesApi = (
7373
'Parameter `postURLJob.input` is required when calling `postIngestUrl`.'
7474
);
7575
}
76+
if (!postURLJob.target) {
77+
throw new Error(
78+
'Parameter `postURLJob.target` is required when calling `postIngestUrl`.'
79+
);
80+
}
7681

7782
const request: Request = {
7883
method: 'POST',

specs/sources/paths/ingest/postUrl.yml

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,82 @@ post:
1616
required:
1717
- type
1818
- input
19+
- target
1920
properties:
2021
type:
2122
type: string
2223
description: The type of the file to ingest.
2324
enum:
2425
- csv
26+
uniqueIDColumn:
27+
type: string
28+
description: The name of the column that hold the unique identifier
29+
example: objectID
2530
input:
2631
type: object
2732
title: postURLJobInput
2833
description: The input of the job.
34+
additionalProperties: false
35+
required:
36+
- url
2937
properties:
3038
url:
3139
type: string
3240
description: The URL of the file to ingest.
41+
method:
42+
type: string
43+
description: The HTTP method that will be used to fetch the URL.
44+
default: GET
45+
enum:
46+
- GET
47+
- POST
48+
auth:
49+
type: object
50+
title: postURLJobAuth
51+
description: The authentication scheme for the URL that will be fetched.
52+
additionalProperties: false
53+
required:
54+
- type
55+
- login
56+
- password
57+
properties:
58+
type:
59+
type: string
60+
description: The type of authentication to use.
61+
enum:
62+
- basic
63+
login:
64+
type: string
65+
description: The login to use for Basic Auth.
66+
example: johndoe
67+
password:
68+
type: string
69+
description: The password to use for Basic Auth.
70+
example: mypassword
71+
target:
72+
type: object
73+
title: postURLJobTarget
74+
description: The target of the job.
75+
additionalProperties: false
3376
required:
34-
- url
77+
- type
78+
- indexName
79+
- operation
80+
properties:
81+
type:
82+
type: string
83+
description: The product to target
84+
enum:
85+
- search
86+
indexName:
87+
type: string
88+
description: The index name of the product
89+
example: my_index_name
90+
operation:
91+
type: string
92+
description: The type of operation to execute
93+
enum:
94+
- replace
3595
responses:
3696
'200':
3797
description: OK

tests/CTS/client/sources/api.json

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@
66
"type": "method",
77
"object": "$client",
88
"path": "postIngestUrl",
9-
"parameters": [{ "type": "csv", "input": { "url": "..." } }],
9+
"parameters": [
10+
{
11+
"type": "csv",
12+
"input": {
13+
"url": "https://example.com/file.csv"
14+
},
15+
"target": {
16+
"type": "search",
17+
"indexName": "pageviews",
18+
"operation": "replace"
19+
}
20+
}
21+
],
1022
"expected": {
1123
"match": {
1224
"objectContaining": {
@@ -24,7 +36,19 @@
2436
"type": "method",
2537
"object": "$client",
2638
"path": "postIngestUrl",
27-
"parameters": [{ "type": "csv", "input": { "url": "..." } }],
39+
"parameters": [
40+
{
41+
"type": "csv",
42+
"input": {
43+
"url": "https://example.com/file.csv"
44+
},
45+
"target": {
46+
"type": "search",
47+
"indexName": "pageviews",
48+
"operation": "replace"
49+
}
50+
}
51+
],
2852
"expected": {
2953
"testSubject": "actual.userAgent",
3054
"match": {
@@ -41,7 +65,19 @@
4165
"type": "method",
4266
"object": "$client",
4367
"path": "postIngestUrl",
44-
"parameters": [{ "type": "csv", "input": { "url": "..." } }],
68+
"parameters": [
69+
{
70+
"type": "csv",
71+
"input": {
72+
"url": "https://example.com/file.csv"
73+
},
74+
"target": {
75+
"type": "search",
76+
"indexName": "pageviews",
77+
"operation": "replace"
78+
}
79+
}
80+
],
4581
"expected": {
4682
"match": {
4783
"objectContaining": {

tests/CTS/methods/requests/sources/postIngestUrl.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
"type": "csv",
77
"input": {
88
"url": "https://example.com/file.csv"
9+
},
10+
"target": {
11+
"type": "search",
12+
"indexName": "pageviews",
13+
"operation": "replace"
914
}
1015
},
1116
"request": {
@@ -15,6 +20,55 @@
1520
"type": "csv",
1621
"input": {
1722
"url": "https://example.com/file.csv"
23+
},
24+
"target": {
25+
"type": "search",
26+
"indexName": "pageviews",
27+
"operation": "replace"
28+
}
29+
}
30+
}
31+
},
32+
{
33+
"method": "postIngestUrl",
34+
"testName": "post postIngestUrl with all parameters",
35+
"parameters": {
36+
"type": "csv",
37+
"uniqueIDColumn": "foobar",
38+
"input": {
39+
"url": "https://example.com/file.csv",
40+
"method": "POST",
41+
"auth": {
42+
"type": "basic",
43+
"login": "johndoe",
44+
"password": "password"
45+
}
46+
},
47+
"target": {
48+
"type": "search",
49+
"indexName": "pageviews",
50+
"operation": "replace"
51+
}
52+
},
53+
"request": {
54+
"path": "/1/ingest/url",
55+
"method": "POST",
56+
"data": {
57+
"type": "csv",
58+
"uniqueIDColumn": "foobar",
59+
"input": {
60+
"url": "https://example.com/file.csv",
61+
"method": "POST",
62+
"auth": {
63+
"type": "basic",
64+
"login": "johndoe",
65+
"password": "password"
66+
}
67+
},
68+
"target": {
69+
"type": "search",
70+
"indexName": "pageviews",
71+
"operation": "replace"
1872
}
1973
}
2074
}

tests/output/javascript/src/client/sources.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ describe('api', () => {
1818

1919
let actual;
2020

21-
actual = $client.postIngestUrl({ type: 'csv', input: { url: '...' } });
21+
actual = $client.postIngestUrl({
22+
type: 'csv',
23+
input: { url: 'https://example.com/file.csv' },
24+
target: { type: 'search', indexName: 'pageviews', operation: 'replace' },
25+
});
2226

2327
if (actual instanceof Promise) {
2428
actual = await actual;
@@ -35,7 +39,11 @@ describe('api', () => {
3539

3640
let actual;
3741

38-
actual = $client.postIngestUrl({ type: 'csv', input: { url: '...' } });
42+
actual = $client.postIngestUrl({
43+
type: 'csv',
44+
input: { url: 'https://example.com/file.csv' },
45+
target: { type: 'search', indexName: 'pageviews', operation: 'replace' },
46+
});
3947

4048
if (actual instanceof Promise) {
4149
actual = await actual;
@@ -52,7 +60,11 @@ describe('api', () => {
5260

5361
let actual;
5462

55-
actual = $client.postIngestUrl({ type: 'csv', input: { url: '...' } });
63+
actual = $client.postIngestUrl({
64+
type: 'csv',
65+
input: { url: 'https://example.com/file.csv' },
66+
target: { type: 'search', indexName: 'pageviews', operation: 'replace' },
67+
});
5668

5769
if (actual instanceof Promise) {
5870
actual = await actual;

tests/output/javascript/src/methods/requests/sources.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,42 @@ describe('postIngestUrl', () => {
1414
const req = (await client.postIngestUrl({
1515
type: 'csv',
1616
input: { url: 'https://example.com/file.csv' },
17+
target: { type: 'search', indexName: 'pageviews', operation: 'replace' },
1718
})) as unknown as EchoResponse;
1819

1920
expect(req.path).toEqual('/1/ingest/url');
2021
expect(req.method).toEqual('POST');
2122
expect(req.data).toEqual({
2223
type: 'csv',
2324
input: { url: 'https://example.com/file.csv' },
25+
target: { type: 'search', indexName: 'pageviews', operation: 'replace' },
26+
});
27+
expect(req.searchParams).toEqual(undefined);
28+
});
29+
30+
test('post postIngestUrl with all parameters', async () => {
31+
const req = (await client.postIngestUrl({
32+
type: 'csv',
33+
uniqueIDColumn: 'foobar',
34+
input: {
35+
url: 'https://example.com/file.csv',
36+
method: 'POST',
37+
auth: { type: 'basic', login: 'johndoe', password: 'password' },
38+
},
39+
target: { type: 'search', indexName: 'pageviews', operation: 'replace' },
40+
})) as unknown as EchoResponse;
41+
42+
expect(req.path).toEqual('/1/ingest/url');
43+
expect(req.method).toEqual('POST');
44+
expect(req.data).toEqual({
45+
type: 'csv',
46+
uniqueIDColumn: 'foobar',
47+
input: {
48+
url: 'https://example.com/file.csv',
49+
method: 'POST',
50+
auth: { type: 'basic', login: 'johndoe', password: 'password' },
51+
},
52+
target: { type: 'search', indexName: 'pageviews', operation: 'replace' },
2453
});
2554
expect(req.searchParams).toEqual(undefined);
2655
});

0 commit comments

Comments
 (0)