Skip to content

Commit

Permalink
Use standard src/tests paths.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed May 13, 2024
1 parent 6348527 commit 2aa4911
Show file tree
Hide file tree
Showing 84 changed files with 47 additions and 52 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ on:
branches: ['**']
paths:
- 'spec/**'
- 'tools/linter/**'
- 'src/linter/**'
pull_request:
branches: ['**']
paths:
- 'spec/**'
- 'tools/linter/**'
- 'src/linter/**'

jobs:
lint-spec:
runs-on: ubuntu-latest
defaults:
run:
working-directory: tools
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ on:
push:
branches: ['**']
paths:
- 'tools/**'
- 'src/**'
pull_request:
branches: ['**']
paths:
- 'tools/**'
- 'src/**'

jobs:
tools-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: tools
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
4 changes: 2 additions & 2 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ 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 [src](./src/). All tools have tests (run with `npm run test`) and a linter (run with `npm run lint`).

### Merger

The spec merger "builds", aka combines all `.yaml` files in a spec folder into a complete OpenAPI spec. A [workflow](./.github/workflows/build.yml) performs this task on the [spec folder](spec) of this repo then publishes the output into [releases](https://github.com/opensearch-project/opensearch-api-specification/releases).

### Linter

The spec linter that validates every `.yaml` file in the `./spec` folder to assure that they follow the guidelines we have set. Check out the [Linter README](tools/README.md#spec-linter) for more information on how to run it locally. Make sure to run the linter before submitting a PR.
The spec linter that validates every `.yaml` file in the `./spec` folder to assure that they follow the guidelines we have set. Check out the [Linter README](src/README.md#spec-linter) for more information on how to run it locally. Make sure to run the linter before submitting a PR.
3 changes: 2 additions & 1 deletion 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', 'src']
}
4 changes: 2 additions & 2 deletions 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 tools/merger/merge.ts",
"lint:spec": "ts-node tools/linter/lint.ts",
"merge": "ts-node src/merger/merge.ts",
"lint:spec": "ts-node src/linter/lint.ts",
"lint": "eslint .",
"test": "jest"
},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tools/merger/merge.ts → src/merger/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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('-o, --output <path>', 'output file name').default(resolve(__dirname, '../../build/opensearch-openapi.yaml')))
.allowExcessArguments(false)
.parse()

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import InfoFile from '../../../tools/linter/components/InfoFile'
import InfoFile from 'linter/components/InfoFile'

test('validate()', () => {
const validator = new InfoFile('./tests/tools/linter/fixtures/_info.yaml')
const validator = new InfoFile('./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 '../../../tools/linter/components/SchemasFolder'
import NamespacesFolder from '../../../tools/linter/components/NamespacesFolder'
import InlineObjectSchemaValidator from '../../../tools/linter/InlineObjectSchemaValidator'
import SchemasFolder from 'linter/components/SchemasFolder'
import NamespacesFolder from 'linter/components/NamespacesFolder'
import InlineObjectSchemaValidator from 'linter/InlineObjectSchemaValidator'

test('validate()', () => {
const root_folder = './tests/tools/linter/fixtures/inline_object_schema_validator'
const root_folder = './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
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import NamespacesFolder from '../../../tools/linter/components/NamespacesFolder'
import NamespacesFolder from 'linter/components/NamespacesFolder'

test('validate() - When there invalid files', () => {
const validator = new NamespacesFolder('./tests/tools/linter/fixtures/folder_validators/namespaces/invalid_files')
const validator = new NamespacesFolder('./tests/linter/fixtures/folder_validators/namespaces/invalid_files')
expect(validator.validate()).toEqual([
{
file: 'invalid_files/indices.txt',
Expand Down Expand Up @@ -37,7 +37,7 @@ test('validate() - When there invalid files', () => {
})

test('validate() - When the files are valid but the folder is not', () => {
const validator = new NamespacesFolder('./tests/tools/linter/fixtures/folder_validators/namespaces/invalid_folder')
const validator = new NamespacesFolder('./tests/linter/fixtures/folder_validators/namespaces/invalid_folder')
expect(validator.validate()).toEqual([
{
file: 'invalid_folder/',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import SchemasFolder from '../../../tools/linter/components/SchemasFolder'
import NamespacesFolder from '../../../tools/linter/components/NamespacesFolder'
import SchemaRefsValidator from '../../../tools/linter/SchemaRefsValidator'
import SchemasFolder from 'linter/components/SchemasFolder'
import NamespacesFolder from 'linter/components/NamespacesFolder'
import SchemaRefsValidator from 'linter/SchemaRefsValidator'

test('validate()', () => {
const root_folder = './tests/tools/linter/fixtures/schema_refs_validator'
const root_folder = './tests/linter/fixtures/schema_refs_validator'
const namespaces_folder = new NamespacesFolder(`${root_folder}/namespaces`)
const schemas_folder = new SchemasFolder(`${root_folder}/schemas`)
const validator = new SchemaRefsValidator(namespaces_folder, schemas_folder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SpecValidator from '../../../tools/linter/SpecValidator'
import SpecValidator from 'linter/SpecValidator'

test('validate()', () => {
const validator = new SpecValidator('./tests/tools/linter/fixtures/empty')
const validator = new SpecValidator('./tests/linter/fixtures/empty')
expect(validator.validate()).toEqual([])

validator.namespaces_folder.validate = jest.fn().mockReturnValue([{ file: 'namespaces/', message: 'namespace error' }])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SupersededOperationsFile from '../../../tools/linter/components/SupersededOperationsFile'
import SupersededOperationsFile from 'linter/components/SupersededOperationsFile'

test('validate()', () => {
const validator = new SupersededOperationsFile('./tests/tools/linter/fixtures/_superseded_operations.yaml')
const validator = new SupersededOperationsFile('./tests/linter/fixtures/_superseded_operations.yaml')
expect(validator.validate()).toEqual([
{
file: 'fixtures/_superseded_operations.yaml',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import NamespaceFile from '../../../../tools/linter/components/NamespaceFile'
import NamespaceFile from 'linter/components/NamespaceFile'
import { type OpenAPIV3 } from 'openapi-types'
import { mocked_operation_group } from './operation_group'

export function namespace_file (fixture_file: string): NamespaceFile {
return new NamespaceFile(`./tests/tools/linter/fixtures/file_validators/namespaces/${fixture_file}`)
return new NamespaceFile(`./tests/linter/fixtures/file_validators/namespaces/${fixture_file}`)
}

interface MockedReturnedValues {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Operation from '../../../../tools/linter/components/Operation'
import { type OperationSpec } from '../../../../tools/types'
import Operation from 'linter/components/Operation'
import { type OperationSpec } from 'types'

export function operation (spec: Record<string, any>, file_name = 'indices.yaml'): Operation {
return new Operation(`namespaces/${file_name}`, '/{index}/something/{abc_xyz}', 'post', spec as OperationSpec)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import OperationGroup from '../../../../tools/linter/components/OperationGroup'
import OperationGroup from 'linter/components/OperationGroup'
import { operation, mocked_operation } from './operation'

export function operation_group (operation_specs: Array<Record<string, any>>): OperationGroup {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Schema from '../../../../tools/linter/components/Schema'
import Schema from 'linter/components/Schema'
import { type OpenAPIV3 } from 'openapi-types'

export function schema (name: string, spec: Record<string, any> = {}): Schema {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { mocked_schema } from './schema'
import SchemaFile from '../../../../tools/linter/components/SchemaFile'
import SchemaFile from 'linter/components/SchemaFile'

export function schema_file (fixture: string): SchemaFile {
return new SchemaFile(`./tests/tools/linter/fixtures/file_validators/schemas/${fixture}`)
return new SchemaFile(`./tests/linter/fixtures/file_validators/schemas/${fixture}`)
}

interface MockedReturnedValues {
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions tests/merger/OpenApiMerger.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import OpenApiMerger from 'merger/OpenApiMerger'
import fs from 'fs'

test('merge()', async () => {
const merger = new OpenApiMerger('./tests/merger/fixtures/spec/')
merger.merge('./tests/merger/opensearch-openapi.yaml')
expect(fs.readFileSync('./tests/merger/fixtures/expected.yaml', 'utf8'))
.toEqual(fs.readFileSync('./tests/merger/opensearch-openapi.yaml', 'utf8'))
fs.unlinkSync('./tests/merger/opensearch-openapi.yaml')
})
File renamed without changes.
File renamed without changes.
10 changes: 0 additions & 10 deletions tests/tools/merger/OpenApiMerger.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"module": "commonjs", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
"baseUrl": "./src", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
Expand Down

0 comments on commit 2aa4911

Please sign in to comment.