Skip to content

fix(spec): cleanup summary #451

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
merged 12 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
overrides: [{
files: ['specs/**/*.yml'],
rules: {
"automation-custom/description-dot": "error",
"automation-custom/end-with-dot": "error",
"automation-custom/single-quote-ref": "error",
},
overrides: [
Expand Down
2 changes: 1 addition & 1 deletion .github/.cache_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.2.0.0
9.2.2
56 changes: 10 additions & 46 deletions .github/actions/cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ inputs:
spec:
description: The name of the spec to restore, used for client matrix gen.
required: false
specPath:
description: The path of the spec to hash
required: false

runs:
using: composite
Expand Down Expand Up @@ -45,14 +48,14 @@ runs:

# Restore bundled specs from input: used during 'client' generation
- name: Restore ${{ inputs.spec }} built spec
if: ${{ inputs.job == 'client' && inputs.spec }}
if: ${{ inputs.job == 'client' && inputs.spec && inputs.specPath }}
uses: actions/cache@v3
with:
path: ${{ format('specs/bundled/{0}.yml', inputs.spec) }}
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
format('specs/{0}/**', inputs.spec),
format('specs/{0}/**', inputs.specPath),
'specs/common/**'
)}}

Expand Down Expand Up @@ -220,10 +223,11 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-javascript/packages/algoliasearch/**',
'clients/algoliasearch-client-javascript/packages/client-search/**',
'clients/algoliasearch-client-javascript/packages/client-analytics/**',
'clients/algoliasearch-client-javascript/packages/client-personalization/**'
'specs/bundled/search.yml',
'specs/bundled/analytics.yml',
'specs/bundled/personalization.yml',
'templates/javascript/**',
'generators/src/**'
)}}

- name: Restore built JavaScript algoliasearch-lite client
Expand All @@ -234,10 +238,6 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-javascript/packages/algoliasearch-lite/src/**',
'clients/algoliasearch-client-javascript/packages/algoliasearch-lite/model/**',
'clients/algoliasearch-client-javascript/packages/algoliasearch-lite/builds/**',
'clients/algoliasearch-client-javascript/packages/algoliasearch-lite/package.json',
'specs/bundled/algoliasearch-lite.yml',
'templates/javascript/**',
'generators/src/**'
Expand All @@ -251,10 +251,6 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-javascript/packages/client-search/src/**',
'clients/algoliasearch-client-javascript/packages/client-search/model/**',
'clients/algoliasearch-client-javascript/packages/client-search/builds/**',
'clients/algoliasearch-client-javascript/packages/client-search/package.json',
'specs/bundled/search.yml',
'templates/javascript/**',
'generators/src/**'
Expand All @@ -268,10 +264,6 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-javascript/packages/recommend/src/**',
'clients/algoliasearch-client-javascript/packages/recommend/model/**',
'clients/algoliasearch-client-javascript/packages/recommend/builds/**',
'clients/algoliasearch-client-javascript/packages/recommend/package.json',
'specs/bundled/recommend.yml',
'templates/javascript/**',
'generators/src/**'
Expand All @@ -285,10 +277,6 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-javascript/packages/client-query-suggestions/src/**',
'clients/algoliasearch-client-javascript/packages/client-query-suggestions/model/**',
'clients/algoliasearch-client-javascript/packages/client-query-suggestions/builds/**',
'clients/algoliasearch-client-javascript/packages/client-query-suggestions/package.json',
'specs/bundled/query-suggestions.yml',
'templates/javascript/**',
'generators/src/**'
Expand All @@ -302,10 +290,6 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-javascript/packages/client-personalization/src/**',
'clients/algoliasearch-client-javascript/packages/client-personalization/model/**',
'clients/algoliasearch-client-javascript/packages/client-personalization/builds/**',
'clients/algoliasearch-client-javascript/packages/client-personalization/package.json',
'specs/bundled/personalization.yml',
'templates/javascript/**',
'generators/src/**'
Expand All @@ -319,10 +303,6 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-javascript/packages/client-analytics/src/**',
'clients/algoliasearch-client-javascript/packages/client-analytics/model/**',
'clients/algoliasearch-client-javascript/packages/client-analytics/builds/**',
'clients/algoliasearch-client-javascript/packages/client-analytics/package.json',
'specs/bundled/analytics.yml',
'templates/javascript/**',
'generators/src/**'
Expand All @@ -336,10 +316,6 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-javascript/packages/client-abtesting/src/**',
'clients/algoliasearch-client-javascript/packages/client-abtesting/model/**',
'clients/algoliasearch-client-javascript/packages/client-abtesting/builds/**',
'clients/algoliasearch-client-javascript/packages/client-abtesting/package.json',
'specs/bundled/abtesting.yml',
'templates/javascript/**',
'generators/src/**'
Expand All @@ -353,10 +329,6 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-javascript/packages/client-insights/src/**',
'clients/algoliasearch-client-javascript/packages/client-insights/model/**',
'clients/algoliasearch-client-javascript/packages/client-insights/builds/**',
'clients/algoliasearch-client-javascript/packages/client-insights/package.json',
'specs/bundled/insights.yml',
'templates/javascript/**',
'generators/src/**'
Expand All @@ -370,10 +342,6 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-javascript/packages/client-sources/src/**',
'clients/algoliasearch-client-javascript/packages/client-sources/model/**',
'clients/algoliasearch-client-javascript/packages/client-sources/builds/**',
'clients/algoliasearch-client-javascript/packages/client-sources/package.json',
'specs/bundled/sources.yml',
'templates/javascript/**',
'generators/src/**'
Expand All @@ -387,10 +355,6 @@ runs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-javascript/packages/client-predict/src/**',
'clients/algoliasearch-client-javascript/packages/client-predict/model/**',
'clients/algoliasearch-client-javascript/packages/client-predict/builds/**',
'clients/algoliasearch-client-javascript/packages/client-predict/package.json',
'specs/bundled/predict.yml',
'templates/javascript/**',
'generators/src/**'
Expand Down
4 changes: 0 additions & 4 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ inputs:
runs:
using: composite
steps:
- name: Read current GitHub Actions cache version
shell: bash
run: echo "CACHE_VERSION=$(< .github/.cache_version)" >> $GITHUB_ENV

- name: Install Node
uses: actions/setup-node@v2
with:
Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ jobs:
job: client
language: javascript
spec: ${{ matrix.client.name }}
specPath: ${{ matrix.client.specPath }}
cache_hash: ${{ needs.setup.outputs.CACHE_COMMON_HASH }}

- name: Cache '${{ matrix.client.name }}' client
Expand All @@ -182,10 +183,6 @@ jobs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
format('{0}/src/**', matrix.client.path),
format('{0}/model/**', matrix.client.path),
format('{0}/builds/**', matrix.client.path),
format('{0}/package.json', matrix.client.path),
format('specs/bundled/{0}.yml', matrix.client.name),
'templates/javascript/**',
'generators/src/**'
Expand Down Expand Up @@ -334,10 +331,11 @@ jobs:
key: |
${{ env.CACHE_VERSION }}-${{
hashFiles(
'clients/algoliasearch-client-javascript/packages/algoliasearch/**',
'clients/algoliasearch-client-javascript/packages/client-search/**',
'clients/algoliasearch-client-javascript/packages/client-analytics/**',
'clients/algoliasearch-client-javascript/packages/client-personalization/**'
'specs/bundled/search.yml',
'specs/bundled/analytics.yml',
'specs/bundled/personalization.yml',
'templates/javascript/**',
'generators/src/**'
)}}

- name: Build 'algoliasearch' client
Expand Down
2 changes: 1 addition & 1 deletion eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"src/**.ts"
],
"scripts": {
"build": "tsc",
"build": "rm -rf dist/ && tsc",
"test": "jest"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions eslint/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { descriptionDot } from './rules/descriptionDot';
import { endWithDot } from './rules/endWithDot';
import { outOfLineEnum } from './rules/outOfLineEnum';
import { singleQuoteRef } from './rules/singleQuoteRef';

const rules = {
'description-dot': descriptionDot,
'end-with-dot': endWithDot,
'out-of-line-enum': outOfLineEnum,
'single-quote-ref': singleQuoteRef,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/* eslint-disable no-console */
import type { Rule } from 'eslint';

import { isBLockScalar, isPairWithKey, isScalar } from '../utils';

export const descriptionDot: Rule.RuleModule = {
export const endWithDot: Rule.RuleModule = {
meta: {
docs: {
description: 'description must end with a dot',
description: '`description`, `summary` must end with a dot',
},
messages: {
descriptionNoDot: 'description does not end with a dot',
endWithDot: 'content does not end with a dot',
},
fixable: 'code',
},
Expand All @@ -20,12 +19,17 @@ export const descriptionDot: Rule.RuleModule = {

return {
YAMLPair(node): void {
if (!isPairWithKey(node, 'description')) {
if (
!isPairWithKey(node, 'description') &&
!isPairWithKey(node, 'summary')
) {
return;
}

if (!isScalar(node.value)) {
return;
}

const value = node.value;
if (
typeof value.value !== 'string' ||
Expand All @@ -46,7 +50,7 @@ export const descriptionDot: Rule.RuleModule = {
}
context.report({
node: node as any,
messageId: 'descriptionNoDot',
messageId: 'endWithDot',
fix(fixer) {
return fixer.insertTextAfterRange(
[0, value.range[1] - toTrim],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { RuleTester } from 'eslint';

import { descriptionDot } from '../src/rules/descriptionDot';
import { endWithDot } from '../src/rules/endWithDot';

const ruleTester = new RuleTester({
parser: require.resolve('yaml-eslint-parser'),
});

ruleTester.run('description-dot', descriptionDot, {
ruleTester.run('end-with-dot', endWithDot, {
valid: [
`
simple:
Expand Down
33 changes: 24 additions & 9 deletions scripts/buildSpecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ const ALGOLIASEARCH_LITE_OPERATIONS = [
'post',
];

async function propagateTagsToOperations({
/**
* This function will transform properties in the bundle depending on the context.
* E.g:
* - Check tags definition
* - Add name of the client in tags
* - Remove unecessary punctuation for documentation
* - etc...
*/
async function transformBundle({
bundledPath,
withDoc,
clientName,
Expand Down Expand Up @@ -50,16 +58,23 @@ async function propagateTagsToOperations({
// because open-api-generator will use this to determine the name of the client
specMethod.tags = [clientName];

if (
!withDoc ||
!bundledDocSpec ||
!bundledDocSpec.paths[pathKey][method].tags
) {
// Doc special cases
if (!withDoc || !bundledDocSpec) {
continue;
}

const docMethod = bundledDocSpec.paths[pathKey][method];
if (docMethod.summary) {
// Remove dot at the end of summary for better sidebar display
docMethod.summary = docMethod.summary.replace(/\.$/gm, '');
}

if (!docMethod.tags) {
continue;
}

// Checks that specified tags are well defined at root level
for (const tag of bundledDocSpec.paths[pathKey][method].tags) {
for (const tag of docMethod.tags) {
if (tag === clientName || (alias && tag === alias)) {
return;
}
Expand Down Expand Up @@ -162,7 +177,7 @@ async function buildLiteSpec({
const liteBundledPath = `specs/bundled/${spec}.${outputFormat}`;
await fsp.writeFile(toAbsolutePath(liteBundledPath), yaml.dump(parsed));

await propagateTagsToOperations({
await transformBundle({
bundledPath: toAbsolutePath(liteBundledPath),
clientName: spec,
// Lite does not need documentation because it's just a subset
Expand Down Expand Up @@ -223,7 +238,7 @@ async function buildSpec(

// Add the correct tags to be able to generate the proper client
if (!isLite) {
await propagateTagsToOperations({
await transformBundle({
bundledPath: toAbsolutePath(bundledPath),
clientName: spec,
withDoc: BUNDLE_WITH_DOC,
Expand Down
2 changes: 2 additions & 0 deletions scripts/ci/createMatrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ClientMatrix = BaseMatrix & {
api: string;
capitalizedName: string;
camelizedName: string;
specPath: string;
};

type SpecMatrix = BaseMatrix;
Expand Down Expand Up @@ -66,6 +67,7 @@ async function getClientMatrix({
api: `${clientName}Client`,
capitalizedName: clientName,
camelizedName: camelize(client),
specPath: client === 'algoliasearch-lite' ? 'search' : client,
});
}

Expand Down
4 changes: 2 additions & 2 deletions specs/search/paths/advanced/getLogs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ get:
tags:
- Advanced
operationId: getLogs
description: Return the lastest log entries.
summary: Return the lastest log entries.
description: Return the latest log entries.
summary: Return the latest log entries.
parameters:
- name: offset
in: query
Expand Down
2 changes: 1 addition & 1 deletion specs/search/paths/advanced/getTask.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ get:
- Indices
operationId: getTask
description: Check the current status of a given task.
summary: Check the current status of a given task.
summary: Check the status of a task.
parameters:
- $ref: '../../../common/parameters.yml#/IndexName'
- name: taskID
Expand Down
Loading