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

Use the standard src/tests paths, move package.json to the root. #292

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ jobs:
node-version: '20'

- name: Build
working-directory: ./tools
run: |-
mkdir -p ../build
mkdir -p ./build
npm install
npm run merge -- --source ../spec --output ../build/opensearch-openapi.yaml
npm run merge -- --source ./spec --output ./build/opensearch-openapi.yaml

- name: Extract Branch Name
id: branch
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/coverage-gather.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ jobs:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Build Spec
working-directory: ./tools
run: |-
mkdir -p ../build
mkdir -p ./build
npm install
npm run merge -- --source ../spec --output ../build/opensearch-openapi.yaml
npm run merge -- --source ./spec --output ./build/opensearch-openapi.yaml
- name: Build and Run Docker Container
run: |
docker build coverage --tag opensearch-with-api-plugin
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
uses: lycheeverse/lychee-action@v1
with:
fail: true
args: --base . --verbose --no-progress './**/*.yaml' './**/*.yml' './**/*.md' './**/*.json' './**/*.ts' --exclude-path ./tools/package-lock.json
args: --base . --verbose --no-progress './**/*.yaml' './**/*.yml' './**/*.md' './**/*.json' './**/*.ts' --exclude-path ./package-lock.json
9 changes: 3 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,21 @@ on:
branches: ['**']
paths:
- 'spec/**'
- 'tools/linter/**'
- 'tools/src/linter/**'
pull_request:
branches: ['**']
paths:
- 'spec/**'
- 'tools/linter/**'
- 'tools/src/linter/**'

jobs:
lint-spec:
runs-on: ubuntu-latest
defaults:
run:
working-directory: tools
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20.10.0
- run: npm install
- run: |
npm run lint:spec -- --source ../spec
npm run lint:spec -- --source ./spec
3 changes: 0 additions & 3 deletions .github/workflows/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ on:
jobs:
tools-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: tools
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ This repository includes several OpenAPI Specification Extensions to fill in any

## Tools

We authored a number of tools to merge and lint specs that live in [tools](tools). All tools have tests (run with `npm run test`) and a linter (run with `npm run lint`).
We authored a number of tools to merge and lint specs that live in [tools](./tools/src/). All tools have tests (run with `npm run test`) and a linter (run with `npm run lint`).

### Merger

Expand Down
6 changes: 2 additions & 4 deletions _plugins/openapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ module OpenAPI
def self.generate(_site, _payload)
return if @generated

Dir.chdir('tools') do
system 'npm install'
system 'npm run merge -- --source ../spec --output ../_site/opensearch-openapi.yaml'
end
system 'npm install'
system 'npm run merge -- --source ./spec --output ./_site/opensearch-openapi.yaml'

@generated = true
end
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion tools/jest.config.js → jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node'
testEnvironment: 'node',
moduleDirectories: ['node_modules', './tools/src']
}
File renamed without changes.
4 changes: 2 additions & 2 deletions tools/package.json → package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"author": "opensearch-project",
"license": "Apache-2.0",
"scripts": {
"merge": "ts-node merger/merge.ts",
"lint:spec": "ts-node linter/lint.ts",
"merge": "ts-node tools/src/merger/merge.ts",
"lint:spec": "ts-node tools/src/linter/lint.ts",
"lint": "eslint .",
"test": "jest"
},
Expand Down
2 changes: 1 addition & 1 deletion spec/_info.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$schema: ../json_schemas/_info.schema.yaml
$schema: ./json_schemas/_info.schema.yaml

title: OpenSearch API Specification
version: 1.0.0
2 changes: 1 addition & 1 deletion spec/_superseded_operations.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$schema: ../json_schemas/_superseded_operations.schema.yaml
$schema: ./json_schemas/_superseded_operations.schema.yaml

/_opendistro/_alerting/destinations:
superseded_by: /_plugins/_alerting/destinations
Expand Down
14 changes: 7 additions & 7 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

This folder contains tools for the repo:

- [Merger](./merger): merges multiple OpenAPI files into one
- [Linter](./linter): validates files in the spec folder
- [Merger](./src/merger): merges multiple OpenAPI files into one
- [Linter](./src/linter): validates files in the spec folder

## Setup

1. Install [Node.js](https://nodejs.org/en/learn/getting-started/how-to-install-nodejs)
2. Run `npm install` in the `tools` folder
2. Run `npm install`.

## Merger

Expand All @@ -19,14 +19,14 @@ It requires a path to the root folder of the multi-file spec (`--source`) and a
Example:

```bash
mkdir -p ../build
npm run merge -- --source ../spec --output ../build/opensearch-openapi.yaml
mkdir -p ./build
npm run merge -- --source ./spec --output ./build/opensearch-openapi.yaml
```

As a shortcut, if those parameters are not provided, the tool will use the default values:

- `../spec` as the root path (i.e. the repo's [spec folder](../spec))
- `../build/opensearch-openapi.yaml` as the output path
- `./build/opensearch-openapi.yaml` as the output path

```bash
npm run merge
Expand All @@ -41,7 +41,7 @@ The linter tool validates the OpenSearch multi-file spec, and will print out all
It requires a path to the root folder of the multi-file spec (`--source`).

```bash
npm run lint:spec -- --source ../spec
npm run lint:spec -- --source ./spec
```

Run `npm run lint:spec -- --help` for all options.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type NamespacesFolder from './components/NamespacesFolder'
import type SchemasFolder from './components/SchemasFolder'
import { type ValidationError } from '../types'
import { type ValidationError } from 'types'
import { SchemaVisitor } from './utils/SpecificationVisitor'
import { is_ref, type MaybeRef, SpecificationContext } from './utils'
import { type OpenAPIV3 } from 'openapi-types'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type NamespacesFolder from './components/NamespacesFolder'
import type SchemasFolder from './components/SchemasFolder'
import { type ValidationError } from '../types'
import { type ValidationError } from 'types'

export default class SchemaRefsValidator {
namespaces_folder: NamespacesFolder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SchemasFolder from './components/SchemasFolder'
import NamespacesFolder from './components/NamespacesFolder'
import { type ValidationError } from '../types'
import { type ValidationError } from 'types'
import SchemaRefsValidator from './SchemaRefsValidator'
import SupersededOperationsFile from './components/SupersededOperationsFile'
import InfoFile from './components/InfoFile'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { type OpenAPIV3 } from 'openapi-types'
import { type OperationSpec, type ValidationError } from '../../types'
import { type OperationSpec, type ValidationError } from 'types'
import OperationGroup from './OperationGroup'
import _ from 'lodash'
import Operation from './Operation'
import { resolve_ref } from '../../helpers'
import { resolve_ref } from '../../../helpers'
import FileValidator from './base/FileValidator'

const HTTP_METHODS = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import NamespaceFile from './NamespaceFile'
import { type ValidationError } from '../../types'
import { type ValidationError } from 'types'
import FolderValidator from './base/FolderValidator'

export default class NamespacesFolder extends FolderValidator<NamespaceFile> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type OperationSpec, type ValidationError } from '../../types'
import { type OperationSpec, type ValidationError } from 'types'
import _ from 'lodash'
import ValidatorBase from './base/ValidatorBase'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type Operation from './Operation'
import { type ValidationError } from '../../types'
import { type ValidationError } from 'types'
import ValidatorBase from './base/ValidatorBase'

export default class OperationGroup extends ValidatorBase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ValidatorBase from './base/ValidatorBase'
import { type OpenAPIV3 } from 'openapi-types'
import { type ValidationError } from '../../types'
import { type ValidationError } from 'types'

const NAME_REGEX = /^[A-Za-z0-9]+$/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import FileValidator from './base/FileValidator'
import { type ValidationError } from '../../types'
import { type ValidationError } from 'types'
import Schema from './Schema'
import { type OpenAPIV3 } from 'openapi-types'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SchemaFile from './SchemaFile'
import FolderValidator from './base/FolderValidator'
import { type ValidationError } from '../../types'
import { type ValidationError } from 'types'

export default class SchemasFolder extends FolderValidator<SchemaFile> {
constructor (folder_path: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ValidatorBase from './ValidatorBase'
import { type ValidationError } from '../../../types'
import { type ValidationError } from 'types'
import { type OpenAPIV3 } from 'openapi-types'
import { read_yaml } from '../../../helpers'
import { read_yaml } from '../../../../helpers'
import AJV from 'ajv'
import addFormats from 'ajv-formats'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs'
import ValidatorBase from './ValidatorBase'
import type FileValidator from './FileValidator'
import { type ValidationError } from '../../../types'
import { type ValidationError } from 'types'

export default class FolderValidator<F extends FileValidator> extends ValidatorBase {
folder_path: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ValidationError } from '../../../types'
import { type ValidationError } from 'types'
export default class ValidatorBase {
file: string
location: string | undefined
Expand Down
2 changes: 1 addition & 1 deletion tools/linter/lint.ts → tools/src/linter/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { resolve } from 'path'

const command = new Command()
.description('Validate the OpenSearch multi-file spec.')
.addOption(new Option('-s, --source <path>', 'path to the root folder of the multi-file spec').default(resolve(__dirname, '../../spec')))
.addOption(new Option('-s, --source <path>', 'path to the root folder of the multi-file spec').default(resolve(__dirname, '../../../spec')))
.allowExcessArguments(false)
.parse()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type OpenAPIV3 } from 'openapi-types'
import { type ValidationError } from '../../types'
import { type ValidationError } from 'types'

export function is_ref<O extends object> (o: MaybeRef<O>): o is OpenAPIV3.ReferenceObject {
return '$ref' in o
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type OpenAPIV3 } from 'openapi-types'
import _ from 'lodash'
import { read_yaml } from '../helpers'
import { read_yaml } from '../../helpers'

export default class GlobalParamsGenerator {
global_params: Record<string, OpenAPIV3.ParameterObject>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type OpenAPIV3 } from 'openapi-types'
import fs from 'fs'
import _ from 'lodash'
import { read_yaml, write_yaml } from '../helpers'
import { read_yaml, write_yaml } from '../../helpers'
import SupersededOpsGenerator from './SupersededOpsGenerator'
import GlobalParamsGenerator from './GlobalParamsGenerator'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type HttpVerb, type OperationPath, type SupersededOperationMap } from '../types'
import { read_yaml, write_yaml } from '../helpers'
import { type HttpVerb, type OperationPath, type SupersededOperationMap } from 'types'
import { read_yaml, write_yaml } from '../../helpers'

// One-time script to generate _superseded_operations.yaml file for OpenDistro
// Keeping this for now in case we need to update the file in the near future. Can be removed after a few months.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type OperationSpec, type SupersededOperationMap } from '../types'
import { type OperationSpec, type SupersededOperationMap } from 'types'
import _ from 'lodash'
import { read_yaml } from '../helpers'
import { read_yaml } from '../../helpers'

export default class SupersededOpsGenerator {
superseded_ops: SupersededOperationMap
Expand Down
4 changes: 2 additions & 2 deletions tools/merger/merge.ts → tools/src/merger/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { resolve } from 'path'

const command = new Command()
.description('Merges the multi-file OpenSearch spec into a single file for programmatic use.')
.addOption(new Option('-s, --source <path>', 'path to the root folder of the multi-file spec').default(resolve(__dirname, '../../spec')))
.addOption(new Option('-o, --output <path>', 'output file name').default(resolve(__dirname, '../../build/opensearch-openapi.yaml')))
.addOption(new Option('-s, --source <path>', 'path to the root folder of the multi-file spec').default(resolve(__dirname, '../../../spec')))
.addOption(new Option('-o, --output <path>', 'output file name').default(resolve(__dirname, '../../../build/opensearch-openapi.yaml')))
.allowExcessArguments(false)
.parse()

Expand Down
File renamed without changes.
11 changes: 0 additions & 11 deletions tools/test/linter/SupersededOperationsFile.test.ts

This file was deleted.

4 changes: 0 additions & 4 deletions tools/test/linter/fixtures/empty/_info.yaml

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions tools/test/merger/OpenApiMerger.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import InfoFile from '../../linter/components/InfoFile'
import InfoFile from 'linter/components/InfoFile'

test('validate()', () => {
const validator = new InfoFile('./test/linter/fixtures/_info.yaml')
const validator = new InfoFile('./tools/tests/linter/fixtures/_info.yaml')
expect(validator.validate()).toEqual([
{
file: 'fixtures/_info.yaml',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import SchemasFolder from '../../linter/components/SchemasFolder'
import NamespacesFolder from '../../linter/components/NamespacesFolder'
import InlineObjectSchemaValidator from '../../linter/InlineObjectSchemaValidator'
import SchemasFolder from 'linter/components/SchemasFolder'
import NamespacesFolder from 'linter/components/NamespacesFolder'
import InlineObjectSchemaValidator from 'linter/InlineObjectSchemaValidator'

test('validate()', () => {
const root_folder = './test/linter/fixtures/inline_object_schema_validator'
const root_folder = './tools/tests/linter/fixtures/inline_object_schema_validator'
const namespaces_folder = new NamespacesFolder(`${root_folder}/namespaces`)
const schemas_folder = new SchemasFolder(`${root_folder}/schemas`)
const validator = new InlineObjectSchemaValidator(namespaces_folder, schemas_folder)
Expand Down
Loading
Loading