Skip to content
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

feat(spec): tag POC #435

Merged
merged 14 commits into from
Apr 27, 2022
57 changes: 34 additions & 23 deletions scripts/buildSpecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,39 @@ const ALGOLIASEARCH_LITE_OPERATIONS = [
'post',
];

async function propagateTagsToOperations(
bundledPath: string,
client: string
): Promise<boolean> {
async function propagateTagsToOperations({
bodinsamuel marked this conversation as resolved.
Show resolved Hide resolved
bundledPath,
clientName,
}: {
bundledPath: string;
clientName: string;
}): Promise<void> {
if (!(await exists(bundledPath))) {
throw new Error(`Bundled file not found ${bundledPath}.`);
}

const bundledSpec = yaml.load(
await fsp.readFile(bundledPath, 'utf8')
) as Spec;
const tagsDefinitions = bundledSpec.tags;

for (const pathMethods of Object.values(bundledSpec.paths)) {
for (const specMethod of Object.values(pathMethods)) {
specMethod.tags = [client];
specMethod.tags = [...(specMethod.tags || []), clientName];
for (const tag of specMethod.tags) {
if (tag === clientName) {
return;
}

const tagExists = tagsDefinitions
? tagsDefinitions.find((t) => t.name === tag)
: null;
if (!tagExists) {
throw new Error(
`Tag "${tag}" in "client[${clientName}] -> operation[${specMethod.operationId}]" is not defined`
);
}
}
}
}

Expand All @@ -37,8 +55,6 @@ async function propagateTagsToOperations(
noRefs: true,
})
);

return true;
}

async function lintCommon(verbose: boolean, useCache: boolean): Promise<void> {
Expand Down Expand Up @@ -84,11 +100,11 @@ async function buildLiteSpec(
outputFormat: string,
verbose: boolean
): Promise<void> {
const searchSpec = yaml.load(
const parsed = yaml.load(
await fsp.readFile(toAbsolutePath(bundledPath), 'utf8')
) as Spec;

searchSpec.paths = Object.entries(searchSpec.paths).reduce(
parsed.paths = Object.entries(parsed.paths).reduce(
(acc, [path, operations]) => {
for (const [method, operation] of Object.entries(operations)) {
if (
Expand All @@ -105,15 +121,12 @@ async function buildLiteSpec(
);

const liteBundledPath = `specs/bundled/${spec}.${outputFormat}`;
await fsp.writeFile(toAbsolutePath(liteBundledPath), yaml.dump(searchSpec));
await fsp.writeFile(toAbsolutePath(liteBundledPath), yaml.dump(parsed));

if (
!(await propagateTagsToOperations(toAbsolutePath(liteBundledPath), spec))
) {
throw new Error(
`Unable to propage tags to operations for \`${spec}\` spec.`
);
}
await propagateTagsToOperations({
bundledPath: toAbsolutePath(liteBundledPath),
clientName: spec,
});

await run(`yarn specs:fix bundled/${spec}.${outputFormat}`, {
verbose,
Expand Down Expand Up @@ -165,12 +178,10 @@ async function buildSpec(
{ verbose }
);

if (!(await propagateTagsToOperations(toAbsolutePath(bundledPath), client))) {
spinner.fail();
throw new Error(
`Unable to propage tags to operations for \`${client}\` spec.`
);
}
await propagateTagsToOperations({
bundledPath: toAbsolutePath(bundledPath),
clientName: spec,
});

spinner.text = `linting ${client} spec`;
await run(`yarn specs:fix ${client}`, { verbose });
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/advanced/getLogs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
get:
tags:
- Advanced
operationId: getLogs
description: Return the lastest log entries.
summary: Return the lastest log entries.
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/advanced/getTask.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
get:
tags:
- Advanced
operationId: getTask
description: Check the current status of a given task.
summary: Check the current status of a given task.
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/dictionaries/batchDictionaryEntries.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
post:
tags:
- Dictionnary
operationId: batchDictionaryEntries
description: Send a batch of dictionary entries.
summary: Send a batch of dictionary entries.
Expand Down
4 changes: 4 additions & 0 deletions specs/search/paths/dictionaries/dictionarySettings.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
put:
tags:
- Dictionnary
operationId: setDictionarySettings
description: Set dictionary settings.
summary: Set dictionary settings.
Expand Down Expand Up @@ -29,6 +31,8 @@ put:
$ref: '../../../common/responses/IndexNotFound.yml'

get:
tags:
- Dictionnary
operationId: getDictionarySettings
description: Retrieve dictionaries settings.
summary: Retrieve dictionaries settings. The API stores languages whose standard entries are disabled. Fetch settings does not return false values.
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/dictionaries/getDictionaryLanguages.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
get:
tags:
- Dictionnary
operationId: getDictionaryLanguages
description: List dictionaries supported per language.
summary: List dictionaries supported per language.
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/dictionaries/searchDictionaryEntries.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
post:
tags:
- Dictionnary
operationId: searchDictionaryEntries
description: Search the dictionary entries.
summary: Search the dictionary entries.
Expand Down
6 changes: 6 additions & 0 deletions specs/search/paths/keys/key.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
put:
tags:
- Api Keys
operationId: updateApiKey
summary: Update an API key.
description: Replace every permission of an existing API key.
Expand Down Expand Up @@ -37,6 +39,8 @@ put:
$ref: '../../../common/responses/IndexNotFound.yml'

get:
tags:
- Api Keys
operationId: getApiKey
summary: Get an API key.
description: Get the permissions of an API key.
Expand All @@ -59,6 +63,8 @@ get:
$ref: '../../../common/responses/IndexNotFound.yml'

delete:
tags:
- Api Keys
operationId: deleteApiKey
summary: Delete an API key.
description: Delete an existing API Key.
Expand Down
4 changes: 4 additions & 0 deletions specs/search/paths/keys/keys.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
post:
tags:
- Api Keys
operationId: addApiKey
summary: Create a new API key.
description: Add a new API Key with specific permissions/restrictions.
Expand All @@ -25,6 +27,8 @@ post:
$ref: '../../../common/responses/IndexNotFound.yml'

get:
tags:
- Api Keys
operationId: listApiKeys
summary: Get the full list of API Keys.
description: List API keys, along with their associated rights.
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/keys/restoreApiKey.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
post:
tags:
- Api Keys
operationId: restoreApiKey
summary: Restore an API key.
description: Restore a deleted API key, along with its associated rights.
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/manage_indices/listIndices.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
get:
tags:
- Index
operationId: listIndices
summary: List existing indexes.
description: List existing indexes from an application.
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/manage_indices/operationIndex.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
post:
tags:
- Index
operationId: operationIndex
summary: Copy/move index.
description: Peforms a copy or a move operation on a index.
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/multiclusters/batchAssignUserIds.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
post:
tags:
- Cluster
operationId: batchAssignUserIds
summary: Batch assign userIDs
description: >
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/multiclusters/getTopUserIds.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
get:
tags:
- Cluster
operationId: getTopUserIds
summary: Get top userID
description: >
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/multiclusters/hasPendingMappings.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
get:
tags:
- Cluster
operationId: hasPendingMappings
summary: Has pending mappings
description: >
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/multiclusters/listClusters.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
get:
tags:
- Cluster
operationId: listClusters
summary: List clusters
description: >
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/multiclusters/searchUserIds.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
post:
tags:
- Cluster
operationId: searchUserIds
summary: Search userID
description: >
Expand Down
4 changes: 4 additions & 0 deletions specs/search/paths/multiclusters/userId.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
get:
tags:
- Cluster
operationId: getUserId
summary: Get userID
description: >
Expand Down Expand Up @@ -26,6 +28,8 @@ get:
$ref: '../../../common/responses/IndexNotFound.yml'

delete:
tags:
- Cluster
operationId: removeUserId
summary: Remove userID
description: >
Expand Down
4 changes: 4 additions & 0 deletions specs/search/paths/multiclusters/userIds.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
post:
tags:
- Cluster
operationId: assignUserId
summary: Assign or Move userID
description: >
Expand Down Expand Up @@ -38,6 +40,8 @@ post:
$ref: '../../../common/responses/IndexNotFound.yml'

get:
tags:
- Cluster
operationId: listUserIds
summary: List userIDs
description: >
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/objects/batch.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
post:
tags:
- Object
operationId: batch
description: Performs multiple write operations in a single API call.
summary: Performs multiple write operations in a single API call.
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/objects/clearObjects.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
post:
tags:
- Object
operationId: clearObjects
summary: clear all objects from an index.
description: Delete an index's content, but leave settings and index-specific API keys untouched.
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/objects/deleteBy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
post:
tags:
- Object
operationId: deleteBy
summary: Delete all records matching the query.
description: >
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/objects/multipleBatch.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
post:
tags:
- Object
operationId: multipleBatch
description: Perform multiple write operations, potentially targeting multiple indices, in a single API call.
summary: Perform multiple write operations.
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/objects/multipleGetObjects.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
post:
tags:
- Object
operationId: getObjects
summary: Retrieve one or more objects.
description: Retrieve one or more objects, potentially from different indices, in a single API call.
Expand Down
6 changes: 6 additions & 0 deletions specs/search/paths/objects/object.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
put:
tags:
- Object
operationId: addOrUpdateObject
summary: Add or replace an object with a given object ID.
description: Add or replace an object with a given object ID. If the object does not exist, it will be created. If it already exists, it will be replaced.
Expand All @@ -25,6 +27,8 @@ put:
$ref: '../../../common/responses/IndexNotFound.yml'

get:
tags:
- Object
operationId: getObject
summary: Retrieve one object from the index.
description: Retrieve one object from the index.
Expand Down Expand Up @@ -59,6 +63,8 @@ get:
$ref: '../../../common/responses/IndexNotFound.yml'

delete:
tags:
- Object
operationId: deleteObject
summary: Delete object.
description: Delete an existing object.
Expand Down
4 changes: 4 additions & 0 deletions specs/search/paths/objects/objects.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
post:
tags:
- Object
operationId: saveObject
description: Add an object to the index, automatically assigning it an object ID.
summary: Add an object to the index.
Expand Down Expand Up @@ -37,6 +39,8 @@ post:
$ref: '../../../common/responses/IndexNotFound.yml'

delete:
tags:
- Object
operationId: deleteIndex
summary: Delete index.
description: Delete an existing index.
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/objects/partialUpdate.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
post:
tags:
- Object
operationId: partialUpdateObject
summary: Partially update an object.
description: >
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/rules/batchRules.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
post:
tags:
- Rule
operationId: batchRules
summary: Batch Rules.
description: Create or update a batch of Rules.
Expand Down
2 changes: 2 additions & 0 deletions specs/search/paths/rules/clearRules.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
post:
tags:
- Rule
operationId: clearRules
summary: Clear Rules.
description: Delete all Rules in the index.
Expand Down
Loading