Skip to content

Commit

Permalink
Moved source into tools/src and tests into tools/tests.
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 2aa4911 commit 2fb68d5
Show file tree
Hide file tree
Showing 84 changed files with 56 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ on:
branches: ['**']
paths:
- 'spec/**'
- 'src/linter/**'
- 'tools/src/linter/**'
pull_request:
branches: ['**']
paths:
- 'spec/**'
- 'src/linter/**'
- 'tools/src/linter/**'

jobs:
lint-spec:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ on:
push:
branches: ['**']
paths:
- 'src/**'
- 'tools/**'
pull_request:
branches: ['**']
paths:
- 'src/**'
- 'tools/**'

jobs:
tools-tests:
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 [src](./src/). 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

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](src/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](tools/README.md#spec-linter) for more information on how to run it locally. Make sure to run the linter before submitting a PR.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleDirectories: ['node_modules', 'src']
moduleDirectories: ['node_modules', './tools/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 src/merger/merge.ts",
"lint:spec": "ts-node src/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
10 changes: 0 additions & 10 deletions tests/merger/OpenApiMerger.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/README.md → tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

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

Expand Down
File renamed without changes.
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
File renamed without changes.
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 src/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
File renamed without changes.
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
4 changes: 2 additions & 2 deletions src/merger/OpenDistro.ts → tools/src/merger/OpenDistro.ts
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 src/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.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import InfoFile from 'linter/components/InfoFile'

test('validate()', () => {
const validator = new InfoFile('./tests/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
Expand Up @@ -3,7 +3,7 @@ import NamespacesFolder from 'linter/components/NamespacesFolder'
import InlineObjectSchemaValidator from 'linter/InlineObjectSchemaValidator'

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

test('validate() - When there invalid files', () => {
const validator = new NamespacesFolder('./tests/linter/fixtures/folder_validators/namespaces/invalid_files')
const validator = new NamespacesFolder('./tools/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/linter/fixtures/folder_validators/namespaces/invalid_folder')
const validator = new NamespacesFolder('./tools/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
Expand Up @@ -3,7 +3,7 @@ import NamespacesFolder from 'linter/components/NamespacesFolder'
import SchemaRefsValidator from 'linter/SchemaRefsValidator'

test('validate()', () => {
const root_folder = './tests/linter/fixtures/schema_refs_validator'
const root_folder = './tools/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 'linter/SpecValidator'

test('validate()', () => {
const validator = new SpecValidator('./tests/linter/fixtures/empty')
const validator = new SpecValidator('./tools/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 'linter/components/SupersededOperationsFile'

test('validate()', () => {
const validator = new SupersededOperationsFile('./tests/linter/fixtures/_superseded_operations.yaml')
const validator = new SupersededOperationsFile('./tools/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
Expand Up @@ -3,7 +3,7 @@ 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/linter/fixtures/file_validators/namespaces/${fixture_file}`)
return new NamespaceFile(`./tools/tests/linter/fixtures/file_validators/namespaces/${fixture_file}`)
}

interface MockedReturnedValues {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { mocked_schema } from './schema'
import SchemaFile from 'linter/components/SchemaFile'

export function schema_file (fixture: string): SchemaFile {
return new SchemaFile(`./tests/linter/fixtures/file_validators/schemas/${fixture}`)
return new SchemaFile(`./tools/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 tools/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('./tools/tests/merger/fixtures/spec/')
merger.merge('./tools/tests/merger/opensearch-openapi.yaml')
expect(fs.readFileSync('./tools/tests/merger/fixtures/expected.yaml', 'utf8'))
.toEqual(fs.readFileSync('./tools/tests/merger/opensearch-openapi.yaml', 'utf8'))
fs.unlinkSync('./tools/tests/merger/opensearch-openapi.yaml')
})
File renamed without changes.
File renamed without changes.
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": "./src", /* Specify the base directory to resolve non-relative module names. */
"baseUrl": "./tools/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 2fb68d5

Please sign in to comment.