Skip to content

Commit

Permalink
API Generator (#872)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhtruong authored Sep 16, 2024
1 parent a935d7f commit 0bde007
Show file tree
Hide file tree
Showing 38 changed files with 10,271 additions and 1,040 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/generate_api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Generate API from Spec
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 0" # Every Sunday at midnight GMT
jobs:
generate-api:
if: ${{ github.repository == 'opensearch-project/opensearch-js' }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./api_generator
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Config git to rebase
run: git config --global pull.rebase true

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'

- name: Install dependencies
run: npm ci

- name: Generate API
run: |-
npm run download_spec
npm run generate_api
- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_ENV

- name: GitHub App token
id: github_app_token
uses: tibdex/[email protected]
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}

- name: Create pull request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ steps.github_app_token.outputs.token }}
commit-message: "Updated opensearch-js to reflect the latest OpenSearch API spec (${{ env.date }})"
title: "[AUTOCUT] Update opensearch-js to reflect the latest OpenSearch API spec"
body: |
Update `opensearch-js` to reflect the latest [OpenSearch API spec](https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml).
Date: ${{ env.date }}
branch: update-api-from-spec
base: main
signoff: true
labels: |
autocut
28 changes: 28 additions & 0 deletions .github/workflows/lint_api_generator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Lint API Generator
on:
pull_request:
paths:
- 'api_generator/**'
- '.github/workflows/lint_api_generator.yml'
jobs:
lint-api-generator:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./api_generator
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'

- name: Install dependencies
run: npm ci

- name: Lint API Generator
run: npm run lint
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [3.0.0]
### Added
- Added API Generator ([#789](https://github.com/opensearch-project/opensearch-js/issues/789))
- Added missing API functions and modules.
- Added missing request and response types.
### Dependencies
Expand Down
1 change: 1 addition & 0 deletions api_generator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
opensearch-openapi.yaml
75 changes: 75 additions & 0 deletions api_generator/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import path from 'path'
import { fileURLToPath } from 'url'
import { FlatCompat } from '@eslint/eslintrc'
import pluginJs from '@eslint/js'
import licenseHeader from 'eslint-plugin-license-header'

// mimic CommonJS variables -- not needed if using CommonJS
const _filename = fileURLToPath(import.meta.url)
const _dirname = path.dirname(_filename)
const compat = new FlatCompat({ baseDirectory: _dirname, recommendedConfig: pluginJs.configs.recommended })

export default [
pluginJs.configs.recommended,
...compat.extends('standard-with-typescript'),
{
files: ['**/*.{js,ts}'],
plugins: {
'license-header': licenseHeader
},
rules: {
'@typescript-eslint/consistent-indexed-object-style': 'error',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/dot-notation': 'error',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/naming-convention': ['error',
{ selector: 'classProperty', modifiers: ['static', 'readonly'], format: ['UPPER_CASE'], leadingUnderscore: 'allow' },
{ selector: 'memberLike', modifiers: ['public'], format: ['snake_case'], leadingUnderscore: 'forbid' },
{ selector: 'memberLike', modifiers: ['private', 'protected'], format: ['snake_case'], leadingUnderscore: 'require' },
{ selector: 'variableLike', format: ['snake_case', 'UPPER_CASE'], leadingUnderscore: 'allow' },
{ selector: 'typeLike', format: ['PascalCase'] },
{ selector: 'objectLiteralProperty', format: null },
{ selector: 'typeProperty', format: null }
],
'@typescript-eslint/no-confusing-void-expression': 'error',
'@typescript-eslint/no-dynamic-delete': 'error',
'@typescript-eslint/no-invalid-void-type': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-unsafe-argument': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/require-array-sort-compare': 'error',
'@typescript-eslint/strict-boolean-expressions': ['error',
{
allowString: true,
allowNumber: true,
allowNullableObject: true,
allowNullableBoolean: true,
allowNullableString: false,
allowNullableNumber: false,
allowNullableEnum: false,
allowAny: false,
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: false
}
],
'array-callback-return': 'off',
'new-cap': 'off',
'no-return-assign': 'error',
'object-shorthand': 'error',
'license-header/header': [
'error',
[
'/*',
' * Copyright OpenSearch Contributors',
' * SPDX-License-Identifier: Apache-2.0',
' *',
' * The OpenSearch Contributors require contributions made to',
' * this file be licensed under the Apache-2.0 license or a',
' * compatible open source license.',
' *',
' */'
]
]
}
}
]
Loading

0 comments on commit 0bde007

Please sign in to comment.