From 6b3695187db0cf7a687695f2d0365b35c8d918ab Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Mon, 13 May 2024 17:01:02 +0200 Subject: [PATCH] Use the standard src/tests paths, move package.json to the root. (#292) * Moved package.json to root. Signed-off-by: dblock * Use standard src/tests paths. Signed-off-by: dblock * Moved source into tools/src and tests into tools/tests. Signed-off-by: dblock --------- Signed-off-by: dblock --- .github/workflows/build.yml | 5 ++--- .github/workflows/coverage-gather.yml | 5 ++--- .github/workflows/links.yml | 2 +- .github/workflows/lint.yml | 9 +++------ .github/workflows/tools.yml | 3 --- DEVELOPER_GUIDE.md | 2 +- _plugins/openapi.rb | 6 ++---- tools/eslint.config.mjs => eslint.config.mjs | 0 tools/jest.config.js => jest.config.js | 3 ++- tools/package-lock.json => package-lock.json | 0 tools/package.json => package.json | 4 ++-- spec/_info.yaml | 2 +- spec/_superseded_operations.yaml | 2 +- tools/README.md | 14 +++++++------- .../linter/InlineObjectSchemaValidator.ts | 2 +- tools/{ => src}/linter/SchemaRefsValidator.ts | 2 +- tools/{ => src}/linter/SpecValidator.ts | 2 +- tools/{ => src}/linter/components/InfoFile.ts | 0 tools/{ => src}/linter/components/NamespaceFile.ts | 4 ++-- .../linter/components/NamespacesFolder.ts | 2 +- tools/{ => src}/linter/components/Operation.ts | 2 +- .../{ => src}/linter/components/OperationGroup.ts | 2 +- tools/{ => src}/linter/components/Schema.ts | 2 +- tools/{ => src}/linter/components/SchemaFile.ts | 2 +- tools/{ => src}/linter/components/SchemasFolder.ts | 2 +- .../linter/components/SupersededOperationsFile.ts | 0 .../linter/components/base/FileValidator.ts | 4 ++-- .../linter/components/base/FolderValidator.ts | 2 +- .../linter/components/base/ValidatorBase.ts | 2 +- tools/{ => src}/linter/lint.ts | 2 +- .../{ => src}/linter/utils/SpecificationVisitor.ts | 0 tools/{ => src}/linter/utils/index.ts | 2 +- tools/{ => src}/merger/GlobalParamsGenerator.ts | 2 +- tools/{ => src}/merger/OpenApiMerger.ts | 2 +- tools/{ => src}/merger/OpenDistro.ts | 4 ++-- tools/{ => src}/merger/SupersededOpsGenerator.ts | 4 ++-- tools/{ => src}/merger/merge.ts | 4 ++-- tools/{ => src}/types.ts | 0 tools/test/linter/SupersededOperationsFile.test.ts | 11 ----------- tools/test/linter/fixtures/empty/_info.yaml | 4 ---- .../fixtures/empty/_superseded_operations.yaml | 1 - tools/test/merger/OpenApiMerger.test.ts | 10 ---------- tools/{test => tests}/linter/InfoFile.test.ts | 4 ++-- .../linter/InlineObjectSchemaValidator.test.ts | 8 ++++---- tools/{test => tests}/linter/NamespaceFile.test.ts | 0 .../linter/NamespacesFolder.test.ts | 6 +++--- tools/{test => tests}/linter/Operation.test.ts | 0 .../{test => tests}/linter/OperationGroup.test.ts | 0 tools/{test => tests}/linter/Schema.test.ts | 0 tools/{test => tests}/linter/SchemaFile.test.ts | 0 .../linter/SchemaRefsValidator.test.ts | 8 ++++---- tools/{test => tests}/linter/SpecValidator.test.ts | 4 ++-- .../tests/linter/SupersededOperationsFile.test.ts | 11 +++++++++++ .../linter/factories/namespace_file.ts | 4 ++-- .../{test => tests}/linter/factories/operation.ts | 4 ++-- .../linter/factories/operation_group.ts | 2 +- tools/{test => tests}/linter/factories/schema.ts | 2 +- .../linter/factories/schema_file.ts | 4 ++-- tools/{test => tests}/linter/fixtures/_info.yaml | 0 .../linter/fixtures/_superseded_operations.yaml | 2 +- tools/tests/linter/fixtures/empty/_info.yaml | 4 ++++ .../fixtures/empty/_superseded_operations.yaml | 1 + .../linter/fixtures/empty/namespaces/.gitkeep | 0 .../linter/fixtures/empty/opensearch-openapi.yaml | 0 .../linter/fixtures/empty/schemas/.gitkeep | 0 .../fixtures/file_validators/namespaces/empty.yaml | 0 .../namespaces/invalid_components.yaml | 0 .../file_validators/schemas/_common.empty.yaml | 0 .../namespaces/invalid_files/cat.yaml | 0 .../namespaces/invalid_files/dup_path_a.yaml | 0 .../namespaces/invalid_files/dup_path_b.yaml | 0 .../namespaces/invalid_files/dup_path_c.yaml | 0 .../namespaces/invalid_files/indices.txt | 0 .../namespaces/invalid_files/invalid_spec.yaml | 0 .../namespaces/invalid_files/invalid_yaml.yaml | 0 .../namespaces/invalid_folder/cat.yaml | 0 .../namespaces/invalid_folder/dup_path_a.yaml | 0 .../namespaces/invalid_folder/dup_path_b.yaml | 0 .../namespaces/invalid_folder/dup_path_c.yaml | 0 .../namespaces/ops.yaml | 0 .../schemas/schemas.yaml | 0 .../schema_refs_validator/namespaces/indices.yaml | 0 .../schema_refs_validator/schemas/animals.yaml | 0 .../schema_refs_validator/schemas/others.yaml | 0 tools/tests/merger/OpenApiMerger.test.ts | 10 ++++++++++ .../{test => tests}/merger/fixtures/expected.yaml | 0 .../merger/fixtures/spec/_global_parameters.yaml | 0 .../merger/fixtures/spec/_info.yaml | 0 .../fixtures/spec/_superseded_operations.yaml | 0 .../merger/fixtures/spec/namespaces/indices.yaml | 0 .../merger/fixtures/spec/namespaces/shelter.yaml | 0 .../merger/fixtures/spec/schemas/actions.yaml | 0 .../merger/fixtures/spec/schemas/animals.yaml | 0 tools/tsconfig.json => tsconfig.json | 2 +- 94 files changed, 100 insertions(+), 109 deletions(-) rename tools/eslint.config.mjs => eslint.config.mjs (100%) rename tools/jest.config.js => jest.config.js (54%) rename tools/package-lock.json => package-lock.json (100%) rename tools/package.json => package.json (90%) rename tools/{ => src}/linter/InlineObjectSchemaValidator.ts (97%) rename tools/{ => src}/linter/SchemaRefsValidator.ts (98%) rename tools/{ => src}/linter/SpecValidator.ts (97%) rename tools/{ => src}/linter/components/InfoFile.ts (100%) rename tools/{ => src}/linter/components/NamespaceFile.ts (97%) rename tools/{ => src}/linter/components/NamespacesFolder.ts (95%) rename tools/{ => src}/linter/components/Operation.ts (98%) rename tools/{ => src}/linter/components/OperationGroup.ts (98%) rename tools/{ => src}/linter/components/Schema.ts (93%) rename tools/{ => src}/linter/components/SchemaFile.ts (96%) rename tools/{ => src}/linter/components/SchemasFolder.ts (85%) rename tools/{ => src}/linter/components/SupersededOperationsFile.ts (100%) rename tools/{ => src}/linter/components/base/FileValidator.ts (95%) rename tools/{ => src}/linter/components/base/FolderValidator.ts (94%) rename tools/{ => src}/linter/components/base/ValidatorBase.ts (88%) rename tools/{ => src}/linter/lint.ts (98%) rename tools/{ => src}/linter/utils/SpecificationVisitor.ts (100%) rename tools/{ => src}/linter/utils/index.ts (97%) rename tools/{ => src}/merger/GlobalParamsGenerator.ts (97%) rename tools/{ => src}/merger/OpenApiMerger.ts (98%) rename tools/{ => src}/merger/OpenDistro.ts (91%) rename tools/{ => src}/merger/SupersededOpsGenerator.ts (97%) rename tools/{ => src}/merger/merge.ts (88%) rename tools/{ => src}/types.ts (100%) delete mode 100644 tools/test/linter/SupersededOperationsFile.test.ts delete mode 100644 tools/test/linter/fixtures/empty/_info.yaml delete mode 100644 tools/test/linter/fixtures/empty/_superseded_operations.yaml delete mode 100644 tools/test/merger/OpenApiMerger.test.ts rename tools/{test => tests}/linter/InfoFile.test.ts (63%) rename tools/{test => tests}/linter/InlineObjectSchemaValidator.test.ts (80%) rename tools/{test => tests}/linter/NamespaceFile.test.ts (100%) rename tools/{test => tests}/linter/NamespacesFolder.test.ts (85%) rename tools/{test => tests}/linter/Operation.test.ts (100%) rename tools/{test => tests}/linter/OperationGroup.test.ts (100%) rename tools/{test => tests}/linter/Schema.test.ts (100%) rename tools/{test => tests}/linter/SchemaFile.test.ts (100%) rename tools/{test => tests}/linter/SchemaRefsValidator.test.ts (77%) rename tools/{test => tests}/linter/SpecValidator.test.ts (86%) create mode 100644 tools/tests/linter/SupersededOperationsFile.test.ts rename tools/{test => tests}/linter/factories/namespace_file.ts (93%) rename tools/{test => tests}/linter/factories/operation.ts (95%) rename tools/{test => tests}/linter/factories/operation_group.ts (96%) rename tools/{test => tests}/linter/factories/schema.ts (93%) rename tools/{test => tests}/linter/factories/schema_file.ts (87%) rename tools/{test => tests}/linter/fixtures/_info.yaml (100%) rename tools/{test => tests}/linter/fixtures/_superseded_operations.yaml (57%) create mode 100644 tools/tests/linter/fixtures/empty/_info.yaml create mode 100644 tools/tests/linter/fixtures/empty/_superseded_operations.yaml rename tools/{test => tests}/linter/fixtures/empty/namespaces/.gitkeep (100%) rename tools/{test => tests}/linter/fixtures/empty/opensearch-openapi.yaml (100%) rename tools/{test => tests}/linter/fixtures/empty/schemas/.gitkeep (100%) rename tools/{test => tests}/linter/fixtures/file_validators/namespaces/empty.yaml (100%) rename tools/{test => tests}/linter/fixtures/file_validators/namespaces/invalid_components.yaml (100%) rename tools/{test => tests}/linter/fixtures/file_validators/schemas/_common.empty.yaml (100%) rename tools/{test => tests}/linter/fixtures/folder_validators/namespaces/invalid_files/cat.yaml (100%) rename tools/{test => tests}/linter/fixtures/folder_validators/namespaces/invalid_files/dup_path_a.yaml (100%) rename tools/{test => tests}/linter/fixtures/folder_validators/namespaces/invalid_files/dup_path_b.yaml (100%) rename tools/{test => tests}/linter/fixtures/folder_validators/namespaces/invalid_files/dup_path_c.yaml (100%) rename tools/{test => tests}/linter/fixtures/folder_validators/namespaces/invalid_files/indices.txt (100%) rename tools/{test => tests}/linter/fixtures/folder_validators/namespaces/invalid_files/invalid_spec.yaml (100%) rename tools/{test => tests}/linter/fixtures/folder_validators/namespaces/invalid_files/invalid_yaml.yaml (100%) rename tools/{test => tests}/linter/fixtures/folder_validators/namespaces/invalid_folder/cat.yaml (100%) rename tools/{test => tests}/linter/fixtures/folder_validators/namespaces/invalid_folder/dup_path_a.yaml (100%) rename tools/{test => tests}/linter/fixtures/folder_validators/namespaces/invalid_folder/dup_path_b.yaml (100%) rename tools/{test => tests}/linter/fixtures/folder_validators/namespaces/invalid_folder/dup_path_c.yaml (100%) rename tools/{test => tests}/linter/fixtures/inline_object_schema_validator/namespaces/ops.yaml (100%) rename tools/{test => tests}/linter/fixtures/inline_object_schema_validator/schemas/schemas.yaml (100%) rename tools/{test => tests}/linter/fixtures/schema_refs_validator/namespaces/indices.yaml (100%) rename tools/{test => tests}/linter/fixtures/schema_refs_validator/schemas/animals.yaml (100%) rename tools/{test => tests}/linter/fixtures/schema_refs_validator/schemas/others.yaml (100%) create mode 100644 tools/tests/merger/OpenApiMerger.test.ts rename tools/{test => tests}/merger/fixtures/expected.yaml (100%) rename tools/{test => tests}/merger/fixtures/spec/_global_parameters.yaml (100%) rename tools/{test => tests}/merger/fixtures/spec/_info.yaml (100%) rename tools/{test => tests}/merger/fixtures/spec/_superseded_operations.yaml (100%) rename tools/{test => tests}/merger/fixtures/spec/namespaces/indices.yaml (100%) rename tools/{test => tests}/merger/fixtures/spec/namespaces/shelter.yaml (100%) rename tools/{test => tests}/merger/fixtures/spec/schemas/actions.yaml (100%) rename tools/{test => tests}/merger/fixtures/spec/schemas/animals.yaml (100%) rename tools/tsconfig.json => tsconfig.json (99%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b4507a151..fa3c882e1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/.github/workflows/coverage-gather.yml b/.github/workflows/coverage-gather.yml index 51672435f..887132ebd 100644 --- a/.github/workflows/coverage-gather.yml +++ b/.github/workflows/coverage-gather.yml @@ -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 diff --git a/.github/workflows/links.yml b/.github/workflows/links.yml index c072e4e25..bfdd4df3d 100644 --- a/.github/workflows/links.yml +++ b/.github/workflows/links.yml @@ -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 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 32c35280d..2d7bd2f26 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,19 +5,16 @@ 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 @@ -25,4 +22,4 @@ jobs: node-version: 20.10.0 - run: npm install - run: | - npm run lint:spec -- --source ../spec + npm run lint:spec -- --source ./spec diff --git a/.github/workflows/tools.yml b/.github/workflows/tools.yml index 12155f9aa..0cae7671e 100644 --- a/.github/workflows/tools.yml +++ b/.github/workflows/tools.yml @@ -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 diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index 145d9c2e1..ca19a0bd3 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -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 diff --git a/_plugins/openapi.rb b/_plugins/openapi.rb index 54eb95186..dd44775fa 100644 --- a/_plugins/openapi.rb +++ b/_plugins/openapi.rb @@ -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 diff --git a/tools/eslint.config.mjs b/eslint.config.mjs similarity index 100% rename from tools/eslint.config.mjs rename to eslint.config.mjs diff --git a/tools/jest.config.js b/jest.config.js similarity index 54% rename from tools/jest.config.js rename to jest.config.js index e5fbf09c0..272fc8594 100644 --- a/tools/jest.config.js +++ b/jest.config.js @@ -1,5 +1,6 @@ /** @type {import('ts-jest').JestConfigWithTsJest} */ module.exports = { preset: 'ts-jest', - testEnvironment: 'node' + testEnvironment: 'node', + moduleDirectories: ['node_modules', './tools/src'] } diff --git a/tools/package-lock.json b/package-lock.json similarity index 100% rename from tools/package-lock.json rename to package-lock.json diff --git a/tools/package.json b/package.json similarity index 90% rename from tools/package.json rename to package.json index 95017e76b..974ef1145 100644 --- a/tools/package.json +++ b/package.json @@ -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" }, diff --git a/spec/_info.yaml b/spec/_info.yaml index f71d35dd0..9ba0e9e60 100644 --- a/spec/_info.yaml +++ b/spec/_info.yaml @@ -1,4 +1,4 @@ -$schema: ../json_schemas/_info.schema.yaml +$schema: ./json_schemas/_info.schema.yaml title: OpenSearch API Specification version: 1.0.0 \ No newline at end of file diff --git a/spec/_superseded_operations.yaml b/spec/_superseded_operations.yaml index 70f9e2bf8..9db450730 100644 --- a/spec/_superseded_operations.yaml +++ b/spec/_superseded_operations.yaml @@ -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 diff --git a/tools/README.md b/tools/README.md index 56fc83948..ec95eab7e 100644 --- a/tools/README.md +++ b/tools/README.md @@ -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 @@ -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 @@ -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. diff --git a/tools/linter/InlineObjectSchemaValidator.ts b/tools/src/linter/InlineObjectSchemaValidator.ts similarity index 97% rename from tools/linter/InlineObjectSchemaValidator.ts rename to tools/src/linter/InlineObjectSchemaValidator.ts index f54b641f3..892c9af6a 100644 --- a/tools/linter/InlineObjectSchemaValidator.ts +++ b/tools/src/linter/InlineObjectSchemaValidator.ts @@ -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' diff --git a/tools/linter/SchemaRefsValidator.ts b/tools/src/linter/SchemaRefsValidator.ts similarity index 98% rename from tools/linter/SchemaRefsValidator.ts rename to tools/src/linter/SchemaRefsValidator.ts index 149d40f34..ae5af24fb 100644 --- a/tools/linter/SchemaRefsValidator.ts +++ b/tools/src/linter/SchemaRefsValidator.ts @@ -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 diff --git a/tools/linter/SpecValidator.ts b/tools/src/linter/SpecValidator.ts similarity index 97% rename from tools/linter/SpecValidator.ts rename to tools/src/linter/SpecValidator.ts index 50f489e12..12da4175c 100644 --- a/tools/linter/SpecValidator.ts +++ b/tools/src/linter/SpecValidator.ts @@ -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' diff --git a/tools/linter/components/InfoFile.ts b/tools/src/linter/components/InfoFile.ts similarity index 100% rename from tools/linter/components/InfoFile.ts rename to tools/src/linter/components/InfoFile.ts diff --git a/tools/linter/components/NamespaceFile.ts b/tools/src/linter/components/NamespaceFile.ts similarity index 97% rename from tools/linter/components/NamespaceFile.ts rename to tools/src/linter/components/NamespaceFile.ts index f163c0c28..1373b72f9 100644 --- a/tools/linter/components/NamespaceFile.ts +++ b/tools/src/linter/components/NamespaceFile.ts @@ -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'] diff --git a/tools/linter/components/NamespacesFolder.ts b/tools/src/linter/components/NamespacesFolder.ts similarity index 95% rename from tools/linter/components/NamespacesFolder.ts rename to tools/src/linter/components/NamespacesFolder.ts index 86c544fb3..a1c10003c 100644 --- a/tools/linter/components/NamespacesFolder.ts +++ b/tools/src/linter/components/NamespacesFolder.ts @@ -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 { diff --git a/tools/linter/components/Operation.ts b/tools/src/linter/components/Operation.ts similarity index 98% rename from tools/linter/components/Operation.ts rename to tools/src/linter/components/Operation.ts index 5714473b1..6a9f2ead6 100644 --- a/tools/linter/components/Operation.ts +++ b/tools/src/linter/components/Operation.ts @@ -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' diff --git a/tools/linter/components/OperationGroup.ts b/tools/src/linter/components/OperationGroup.ts similarity index 98% rename from tools/linter/components/OperationGroup.ts rename to tools/src/linter/components/OperationGroup.ts index 681563875..f99cb9ab3 100644 --- a/tools/linter/components/OperationGroup.ts +++ b/tools/src/linter/components/OperationGroup.ts @@ -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 { diff --git a/tools/linter/components/Schema.ts b/tools/src/linter/components/Schema.ts similarity index 93% rename from tools/linter/components/Schema.ts rename to tools/src/linter/components/Schema.ts index 38ac29017..d132f86e3 100644 --- a/tools/linter/components/Schema.ts +++ b/tools/src/linter/components/Schema.ts @@ -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]+$/ diff --git a/tools/linter/components/SchemaFile.ts b/tools/src/linter/components/SchemaFile.ts similarity index 96% rename from tools/linter/components/SchemaFile.ts rename to tools/src/linter/components/SchemaFile.ts index 074b76892..8fa364b13 100644 --- a/tools/linter/components/SchemaFile.ts +++ b/tools/src/linter/components/SchemaFile.ts @@ -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' diff --git a/tools/linter/components/SchemasFolder.ts b/tools/src/linter/components/SchemasFolder.ts similarity index 85% rename from tools/linter/components/SchemasFolder.ts rename to tools/src/linter/components/SchemasFolder.ts index e40ff4f87..d6d30fd6a 100644 --- a/tools/linter/components/SchemasFolder.ts +++ b/tools/src/linter/components/SchemasFolder.ts @@ -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 { constructor (folder_path: string) { diff --git a/tools/linter/components/SupersededOperationsFile.ts b/tools/src/linter/components/SupersededOperationsFile.ts similarity index 100% rename from tools/linter/components/SupersededOperationsFile.ts rename to tools/src/linter/components/SupersededOperationsFile.ts diff --git a/tools/linter/components/base/FileValidator.ts b/tools/src/linter/components/base/FileValidator.ts similarity index 95% rename from tools/linter/components/base/FileValidator.ts rename to tools/src/linter/components/base/FileValidator.ts index a0e0fa7c7..3d3a5d296 100644 --- a/tools/linter/components/base/FileValidator.ts +++ b/tools/src/linter/components/base/FileValidator.ts @@ -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' diff --git a/tools/linter/components/base/FolderValidator.ts b/tools/src/linter/components/base/FolderValidator.ts similarity index 94% rename from tools/linter/components/base/FolderValidator.ts rename to tools/src/linter/components/base/FolderValidator.ts index 30eafbfac..8a63644dc 100644 --- a/tools/linter/components/base/FolderValidator.ts +++ b/tools/src/linter/components/base/FolderValidator.ts @@ -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 extends ValidatorBase { folder_path: string diff --git a/tools/linter/components/base/ValidatorBase.ts b/tools/src/linter/components/base/ValidatorBase.ts similarity index 88% rename from tools/linter/components/base/ValidatorBase.ts rename to tools/src/linter/components/base/ValidatorBase.ts index 7b0deaafe..3790218bf 100644 --- a/tools/linter/components/base/ValidatorBase.ts +++ b/tools/src/linter/components/base/ValidatorBase.ts @@ -1,4 +1,4 @@ -import { type ValidationError } from '../../../types' +import { type ValidationError } from 'types' export default class ValidatorBase { file: string location: string | undefined diff --git a/tools/linter/lint.ts b/tools/src/linter/lint.ts similarity index 98% rename from tools/linter/lint.ts rename to tools/src/linter/lint.ts index 32d2e80a3..6b30fa1d8 100644 --- a/tools/linter/lint.ts +++ b/tools/src/linter/lint.ts @@ -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 to the root folder of the multi-file spec').default(resolve(__dirname, '../../spec'))) + .addOption(new Option('-s, --source ', 'path to the root folder of the multi-file spec').default(resolve(__dirname, '../../../spec'))) .allowExcessArguments(false) .parse() diff --git a/tools/linter/utils/SpecificationVisitor.ts b/tools/src/linter/utils/SpecificationVisitor.ts similarity index 100% rename from tools/linter/utils/SpecificationVisitor.ts rename to tools/src/linter/utils/SpecificationVisitor.ts diff --git a/tools/linter/utils/index.ts b/tools/src/linter/utils/index.ts similarity index 97% rename from tools/linter/utils/index.ts rename to tools/src/linter/utils/index.ts index 5e6bea1c3..db451638f 100644 --- a/tools/linter/utils/index.ts +++ b/tools/src/linter/utils/index.ts @@ -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: MaybeRef): o is OpenAPIV3.ReferenceObject { return '$ref' in o diff --git a/tools/merger/GlobalParamsGenerator.ts b/tools/src/merger/GlobalParamsGenerator.ts similarity index 97% rename from tools/merger/GlobalParamsGenerator.ts rename to tools/src/merger/GlobalParamsGenerator.ts index 612c18fa0..e8da16ea2 100644 --- a/tools/merger/GlobalParamsGenerator.ts +++ b/tools/src/merger/GlobalParamsGenerator.ts @@ -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 diff --git a/tools/merger/OpenApiMerger.ts b/tools/src/merger/OpenApiMerger.ts similarity index 98% rename from tools/merger/OpenApiMerger.ts rename to tools/src/merger/OpenApiMerger.ts index 0bb0be431..c2d8bec6f 100644 --- a/tools/merger/OpenApiMerger.ts +++ b/tools/src/merger/OpenApiMerger.ts @@ -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' diff --git a/tools/merger/OpenDistro.ts b/tools/src/merger/OpenDistro.ts similarity index 91% rename from tools/merger/OpenDistro.ts rename to tools/src/merger/OpenDistro.ts index e35cace6e..b3d1d431d 100644 --- a/tools/merger/OpenDistro.ts +++ b/tools/src/merger/OpenDistro.ts @@ -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. diff --git a/tools/merger/SupersededOpsGenerator.ts b/tools/src/merger/SupersededOpsGenerator.ts similarity index 97% rename from tools/merger/SupersededOpsGenerator.ts rename to tools/src/merger/SupersededOpsGenerator.ts index 747204c61..b673aa3d1 100644 --- a/tools/merger/SupersededOpsGenerator.ts +++ b/tools/src/merger/SupersededOpsGenerator.ts @@ -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 diff --git a/tools/merger/merge.ts b/tools/src/merger/merge.ts similarity index 88% rename from tools/merger/merge.ts rename to tools/src/merger/merge.ts index 6db2f0f9a..c38f29c97 100644 --- a/tools/merger/merge.ts +++ b/tools/src/merger/merge.ts @@ -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 to the root folder of the multi-file spec').default(resolve(__dirname, '../../spec'))) - .addOption(new Option('-o, --output ', 'output file name').default(resolve(__dirname, '../../build/opensearch-openapi.yaml'))) + .addOption(new Option('-s, --source ', 'path to the root folder of the multi-file spec').default(resolve(__dirname, '../../../spec'))) + .addOption(new Option('-o, --output ', 'output file name').default(resolve(__dirname, '../../../build/opensearch-openapi.yaml'))) .allowExcessArguments(false) .parse() diff --git a/tools/types.ts b/tools/src/types.ts similarity index 100% rename from tools/types.ts rename to tools/src/types.ts diff --git a/tools/test/linter/SupersededOperationsFile.test.ts b/tools/test/linter/SupersededOperationsFile.test.ts deleted file mode 100644 index f5c6a7e3a..000000000 --- a/tools/test/linter/SupersededOperationsFile.test.ts +++ /dev/null @@ -1,11 +0,0 @@ -import SupersededOperationsFile from '../../linter/components/SupersededOperationsFile' - -test('validate()', () => { - const validator = new SupersededOperationsFile('./test/linter/fixtures/_superseded_operations.yaml') - expect(validator.validate()).toEqual([ - { - file: 'fixtures/_superseded_operations.yaml', - message: "File content does not match JSON schema found in '../json_schemas/_superseded_operations.schema.yaml':\n [\n {\n \"instancePath\": \"/~1hello~1world/operations/1\",\n \"schemaPath\": \"#/patternProperties/%5E~1/properties/operations/items/enum\",\n \"keyword\": \"enum\",\n \"params\": {\n \"allowedValues\": [\n \"GET\",\n \"POST\",\n \"PUT\",\n \"DELETE\",\n \"HEAD\",\n \"OPTIONS\",\n \"PATCH\"\n ]\n },\n \"message\": \"must be equal to one of the allowed values\"\n }\n]" - } - ]) -}) diff --git a/tools/test/linter/fixtures/empty/_info.yaml b/tools/test/linter/fixtures/empty/_info.yaml deleted file mode 100644 index 66d1923d4..000000000 --- a/tools/test/linter/fixtures/empty/_info.yaml +++ /dev/null @@ -1,4 +0,0 @@ -$schema: ../json_schemas/_info.schema.yaml - -title: '' -version: '' \ No newline at end of file diff --git a/tools/test/linter/fixtures/empty/_superseded_operations.yaml b/tools/test/linter/fixtures/empty/_superseded_operations.yaml deleted file mode 100644 index 6f143f79b..000000000 --- a/tools/test/linter/fixtures/empty/_superseded_operations.yaml +++ /dev/null @@ -1 +0,0 @@ -$schema: ../json_schemas/_superseded_operations.schema.yaml \ No newline at end of file diff --git a/tools/test/merger/OpenApiMerger.test.ts b/tools/test/merger/OpenApiMerger.test.ts deleted file mode 100644 index 22d966404..000000000 --- a/tools/test/merger/OpenApiMerger.test.ts +++ /dev/null @@ -1,10 +0,0 @@ -import OpenApiMerger from '../../merger/OpenApiMerger' -import fs from 'fs' - -test('merge()', async () => { - const merger = new OpenApiMerger('./test/merger/fixtures/spec/') - merger.merge('./test/merger/opensearch-openapi.yaml') - expect(fs.readFileSync('./test/merger/fixtures/expected.yaml', 'utf8')) - .toEqual(fs.readFileSync('./test/merger/opensearch-openapi.yaml', 'utf8')) - fs.unlinkSync('./test/merger/opensearch-openapi.yaml') -}) diff --git a/tools/test/linter/InfoFile.test.ts b/tools/tests/linter/InfoFile.test.ts similarity index 63% rename from tools/test/linter/InfoFile.test.ts rename to tools/tests/linter/InfoFile.test.ts index a0a7652bd..e93f2ea0e 100644 --- a/tools/test/linter/InfoFile.test.ts +++ b/tools/tests/linter/InfoFile.test.ts @@ -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', diff --git a/tools/test/linter/InlineObjectSchemaValidator.test.ts b/tools/tests/linter/InlineObjectSchemaValidator.test.ts similarity index 80% rename from tools/test/linter/InlineObjectSchemaValidator.test.ts rename to tools/tests/linter/InlineObjectSchemaValidator.test.ts index ddc5a47de..6cff2d2c1 100644 --- a/tools/test/linter/InlineObjectSchemaValidator.test.ts +++ b/tools/tests/linter/InlineObjectSchemaValidator.test.ts @@ -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) diff --git a/tools/test/linter/NamespaceFile.test.ts b/tools/tests/linter/NamespaceFile.test.ts similarity index 100% rename from tools/test/linter/NamespaceFile.test.ts rename to tools/tests/linter/NamespaceFile.test.ts diff --git a/tools/test/linter/NamespacesFolder.test.ts b/tools/tests/linter/NamespacesFolder.test.ts similarity index 85% rename from tools/test/linter/NamespacesFolder.test.ts rename to tools/tests/linter/NamespacesFolder.test.ts index 9f2f6b839..08b1ac854 100644 --- a/tools/test/linter/NamespacesFolder.test.ts +++ b/tools/tests/linter/NamespacesFolder.test.ts @@ -1,7 +1,7 @@ -import NamespacesFolder from '../../linter/components/NamespacesFolder' +import NamespacesFolder from 'linter/components/NamespacesFolder' test('validate() - When there invalid files', () => { - const validator = new NamespacesFolder('./test/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', @@ -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('./test/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/', diff --git a/tools/test/linter/Operation.test.ts b/tools/tests/linter/Operation.test.ts similarity index 100% rename from tools/test/linter/Operation.test.ts rename to tools/tests/linter/Operation.test.ts diff --git a/tools/test/linter/OperationGroup.test.ts b/tools/tests/linter/OperationGroup.test.ts similarity index 100% rename from tools/test/linter/OperationGroup.test.ts rename to tools/tests/linter/OperationGroup.test.ts diff --git a/tools/test/linter/Schema.test.ts b/tools/tests/linter/Schema.test.ts similarity index 100% rename from tools/test/linter/Schema.test.ts rename to tools/tests/linter/Schema.test.ts diff --git a/tools/test/linter/SchemaFile.test.ts b/tools/tests/linter/SchemaFile.test.ts similarity index 100% rename from tools/test/linter/SchemaFile.test.ts rename to tools/tests/linter/SchemaFile.test.ts diff --git a/tools/test/linter/SchemaRefsValidator.test.ts b/tools/tests/linter/SchemaRefsValidator.test.ts similarity index 77% rename from tools/test/linter/SchemaRefsValidator.test.ts rename to tools/tests/linter/SchemaRefsValidator.test.ts index e122d2536..7cae50ad1 100644 --- a/tools/test/linter/SchemaRefsValidator.test.ts +++ b/tools/tests/linter/SchemaRefsValidator.test.ts @@ -1,9 +1,9 @@ -import SchemasFolder from '../../linter/components/SchemasFolder' -import NamespacesFolder from '../../linter/components/NamespacesFolder' -import SchemaRefsValidator from '../../linter/SchemaRefsValidator' +import SchemasFolder from 'linter/components/SchemasFolder' +import NamespacesFolder from 'linter/components/NamespacesFolder' +import SchemaRefsValidator from 'linter/SchemaRefsValidator' test('validate()', () => { - const root_folder = './test/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) diff --git a/tools/test/linter/SpecValidator.test.ts b/tools/tests/linter/SpecValidator.test.ts similarity index 86% rename from tools/test/linter/SpecValidator.test.ts rename to tools/tests/linter/SpecValidator.test.ts index 181393f02..0ba8cb576 100644 --- a/tools/test/linter/SpecValidator.test.ts +++ b/tools/tests/linter/SpecValidator.test.ts @@ -1,7 +1,7 @@ -import SpecValidator from '../../linter/SpecValidator' +import SpecValidator from 'linter/SpecValidator' test('validate()', () => { - const validator = new SpecValidator('./test/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' }]) diff --git a/tools/tests/linter/SupersededOperationsFile.test.ts b/tools/tests/linter/SupersededOperationsFile.test.ts new file mode 100644 index 000000000..5c97edfff --- /dev/null +++ b/tools/tests/linter/SupersededOperationsFile.test.ts @@ -0,0 +1,11 @@ +import SupersededOperationsFile from 'linter/components/SupersededOperationsFile' + +test('validate()', () => { + const validator = new SupersededOperationsFile('./tools/tests/linter/fixtures/_superseded_operations.yaml') + expect(validator.validate()).toEqual([ + { + file: 'fixtures/_superseded_operations.yaml', + message: "File content does not match JSON schema found in './json_schemas/_superseded_operations.schema.yaml':\n [\n {\n \"instancePath\": \"/~1hello~1world/operations/1\",\n \"schemaPath\": \"#/patternProperties/%5E~1/properties/operations/items/enum\",\n \"keyword\": \"enum\",\n \"params\": {\n \"allowedValues\": [\n \"GET\",\n \"POST\",\n \"PUT\",\n \"DELETE\",\n \"HEAD\",\n \"OPTIONS\",\n \"PATCH\"\n ]\n },\n \"message\": \"must be equal to one of the allowed values\"\n }\n]" + } + ]) +}) diff --git a/tools/test/linter/factories/namespace_file.ts b/tools/tests/linter/factories/namespace_file.ts similarity index 93% rename from tools/test/linter/factories/namespace_file.ts rename to tools/tests/linter/factories/namespace_file.ts index 7546460a8..7c130de4d 100644 --- a/tools/test/linter/factories/namespace_file.ts +++ b/tools/tests/linter/factories/namespace_file.ts @@ -1,9 +1,9 @@ -import NamespaceFile from '../../../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(`./test/linter/fixtures/file_validators/namespaces/${fixture_file}`) + return new NamespaceFile(`./tools/tests/linter/fixtures/file_validators/namespaces/${fixture_file}`) } interface MockedReturnedValues { diff --git a/tools/test/linter/factories/operation.ts b/tools/tests/linter/factories/operation.ts similarity index 95% rename from tools/test/linter/factories/operation.ts rename to tools/tests/linter/factories/operation.ts index f17e092cb..208dd1e86 100644 --- a/tools/test/linter/factories/operation.ts +++ b/tools/tests/linter/factories/operation.ts @@ -1,5 +1,5 @@ -import Operation from '../../../linter/components/Operation' -import { type OperationSpec } from '../../../types' +import Operation from 'linter/components/Operation' +import { type OperationSpec } from 'types' export function operation (spec: Record, file_name = 'indices.yaml'): Operation { return new Operation(`namespaces/${file_name}`, '/{index}/something/{abc_xyz}', 'post', spec as OperationSpec) diff --git a/tools/test/linter/factories/operation_group.ts b/tools/tests/linter/factories/operation_group.ts similarity index 96% rename from tools/test/linter/factories/operation_group.ts rename to tools/tests/linter/factories/operation_group.ts index 1439a6834..7a8cd6c1b 100644 --- a/tools/test/linter/factories/operation_group.ts +++ b/tools/tests/linter/factories/operation_group.ts @@ -1,4 +1,4 @@ -import OperationGroup from '../../../linter/components/OperationGroup' +import OperationGroup from 'linter/components/OperationGroup' import { operation, mocked_operation } from './operation' export function operation_group (operation_specs: Array>): OperationGroup { diff --git a/tools/test/linter/factories/schema.ts b/tools/tests/linter/factories/schema.ts similarity index 93% rename from tools/test/linter/factories/schema.ts rename to tools/tests/linter/factories/schema.ts index 3eb32c943..bdaec547c 100644 --- a/tools/test/linter/factories/schema.ts +++ b/tools/tests/linter/factories/schema.ts @@ -1,4 +1,4 @@ -import Schema from '../../../linter/components/Schema' +import Schema from 'linter/components/Schema' import { type OpenAPIV3 } from 'openapi-types' export function schema (name: string, spec: Record = {}): Schema { diff --git a/tools/test/linter/factories/schema_file.ts b/tools/tests/linter/factories/schema_file.ts similarity index 87% rename from tools/test/linter/factories/schema_file.ts rename to tools/tests/linter/factories/schema_file.ts index 6d232211a..b19c9724f 100644 --- a/tools/test/linter/factories/schema_file.ts +++ b/tools/tests/linter/factories/schema_file.ts @@ -1,8 +1,8 @@ import { mocked_schema } from './schema' -import SchemaFile from '../../../linter/components/SchemaFile' +import SchemaFile from 'linter/components/SchemaFile' export function schema_file (fixture: string): SchemaFile { - return new SchemaFile(`./test/linter/fixtures/file_validators/schemas/${fixture}`) + return new SchemaFile(`./tools/tests/linter/fixtures/file_validators/schemas/${fixture}`) } interface MockedReturnedValues { diff --git a/tools/test/linter/fixtures/_info.yaml b/tools/tests/linter/fixtures/_info.yaml similarity index 100% rename from tools/test/linter/fixtures/_info.yaml rename to tools/tests/linter/fixtures/_info.yaml diff --git a/tools/test/linter/fixtures/_superseded_operations.yaml b/tools/tests/linter/fixtures/_superseded_operations.yaml similarity index 57% rename from tools/test/linter/fixtures/_superseded_operations.yaml rename to tools/tests/linter/fixtures/_superseded_operations.yaml index 20c92eec9..17341c41f 100644 --- a/tools/test/linter/fixtures/_superseded_operations.yaml +++ b/tools/tests/linter/fixtures/_superseded_operations.yaml @@ -1,4 +1,4 @@ -$schema: ../json_schemas/_superseded_operations.schema.yaml +$schema: ./json_schemas/_superseded_operations.schema.yaml /hello/world: superseded_by: /goodbye/world diff --git a/tools/tests/linter/fixtures/empty/_info.yaml b/tools/tests/linter/fixtures/empty/_info.yaml new file mode 100644 index 000000000..b72517c91 --- /dev/null +++ b/tools/tests/linter/fixtures/empty/_info.yaml @@ -0,0 +1,4 @@ +$schema: ./json_schemas/_info.schema.yaml + +title: '' +version: '' \ No newline at end of file diff --git a/tools/tests/linter/fixtures/empty/_superseded_operations.yaml b/tools/tests/linter/fixtures/empty/_superseded_operations.yaml new file mode 100644 index 000000000..51f11ca88 --- /dev/null +++ b/tools/tests/linter/fixtures/empty/_superseded_operations.yaml @@ -0,0 +1 @@ +$schema: ./json_schemas/_superseded_operations.schema.yaml \ No newline at end of file diff --git a/tools/test/linter/fixtures/empty/namespaces/.gitkeep b/tools/tests/linter/fixtures/empty/namespaces/.gitkeep similarity index 100% rename from tools/test/linter/fixtures/empty/namespaces/.gitkeep rename to tools/tests/linter/fixtures/empty/namespaces/.gitkeep diff --git a/tools/test/linter/fixtures/empty/opensearch-openapi.yaml b/tools/tests/linter/fixtures/empty/opensearch-openapi.yaml similarity index 100% rename from tools/test/linter/fixtures/empty/opensearch-openapi.yaml rename to tools/tests/linter/fixtures/empty/opensearch-openapi.yaml diff --git a/tools/test/linter/fixtures/empty/schemas/.gitkeep b/tools/tests/linter/fixtures/empty/schemas/.gitkeep similarity index 100% rename from tools/test/linter/fixtures/empty/schemas/.gitkeep rename to tools/tests/linter/fixtures/empty/schemas/.gitkeep diff --git a/tools/test/linter/fixtures/file_validators/namespaces/empty.yaml b/tools/tests/linter/fixtures/file_validators/namespaces/empty.yaml similarity index 100% rename from tools/test/linter/fixtures/file_validators/namespaces/empty.yaml rename to tools/tests/linter/fixtures/file_validators/namespaces/empty.yaml diff --git a/tools/test/linter/fixtures/file_validators/namespaces/invalid_components.yaml b/tools/tests/linter/fixtures/file_validators/namespaces/invalid_components.yaml similarity index 100% rename from tools/test/linter/fixtures/file_validators/namespaces/invalid_components.yaml rename to tools/tests/linter/fixtures/file_validators/namespaces/invalid_components.yaml diff --git a/tools/test/linter/fixtures/file_validators/schemas/_common.empty.yaml b/tools/tests/linter/fixtures/file_validators/schemas/_common.empty.yaml similarity index 100% rename from tools/test/linter/fixtures/file_validators/schemas/_common.empty.yaml rename to tools/tests/linter/fixtures/file_validators/schemas/_common.empty.yaml diff --git a/tools/test/linter/fixtures/folder_validators/namespaces/invalid_files/cat.yaml b/tools/tests/linter/fixtures/folder_validators/namespaces/invalid_files/cat.yaml similarity index 100% rename from tools/test/linter/fixtures/folder_validators/namespaces/invalid_files/cat.yaml rename to tools/tests/linter/fixtures/folder_validators/namespaces/invalid_files/cat.yaml diff --git a/tools/test/linter/fixtures/folder_validators/namespaces/invalid_files/dup_path_a.yaml b/tools/tests/linter/fixtures/folder_validators/namespaces/invalid_files/dup_path_a.yaml similarity index 100% rename from tools/test/linter/fixtures/folder_validators/namespaces/invalid_files/dup_path_a.yaml rename to tools/tests/linter/fixtures/folder_validators/namespaces/invalid_files/dup_path_a.yaml diff --git a/tools/test/linter/fixtures/folder_validators/namespaces/invalid_files/dup_path_b.yaml b/tools/tests/linter/fixtures/folder_validators/namespaces/invalid_files/dup_path_b.yaml similarity index 100% rename from tools/test/linter/fixtures/folder_validators/namespaces/invalid_files/dup_path_b.yaml rename to tools/tests/linter/fixtures/folder_validators/namespaces/invalid_files/dup_path_b.yaml diff --git a/tools/test/linter/fixtures/folder_validators/namespaces/invalid_files/dup_path_c.yaml b/tools/tests/linter/fixtures/folder_validators/namespaces/invalid_files/dup_path_c.yaml similarity index 100% rename from tools/test/linter/fixtures/folder_validators/namespaces/invalid_files/dup_path_c.yaml rename to tools/tests/linter/fixtures/folder_validators/namespaces/invalid_files/dup_path_c.yaml diff --git a/tools/test/linter/fixtures/folder_validators/namespaces/invalid_files/indices.txt b/tools/tests/linter/fixtures/folder_validators/namespaces/invalid_files/indices.txt similarity index 100% rename from tools/test/linter/fixtures/folder_validators/namespaces/invalid_files/indices.txt rename to tools/tests/linter/fixtures/folder_validators/namespaces/invalid_files/indices.txt diff --git a/tools/test/linter/fixtures/folder_validators/namespaces/invalid_files/invalid_spec.yaml b/tools/tests/linter/fixtures/folder_validators/namespaces/invalid_files/invalid_spec.yaml similarity index 100% rename from tools/test/linter/fixtures/folder_validators/namespaces/invalid_files/invalid_spec.yaml rename to tools/tests/linter/fixtures/folder_validators/namespaces/invalid_files/invalid_spec.yaml diff --git a/tools/test/linter/fixtures/folder_validators/namespaces/invalid_files/invalid_yaml.yaml b/tools/tests/linter/fixtures/folder_validators/namespaces/invalid_files/invalid_yaml.yaml similarity index 100% rename from tools/test/linter/fixtures/folder_validators/namespaces/invalid_files/invalid_yaml.yaml rename to tools/tests/linter/fixtures/folder_validators/namespaces/invalid_files/invalid_yaml.yaml diff --git a/tools/test/linter/fixtures/folder_validators/namespaces/invalid_folder/cat.yaml b/tools/tests/linter/fixtures/folder_validators/namespaces/invalid_folder/cat.yaml similarity index 100% rename from tools/test/linter/fixtures/folder_validators/namespaces/invalid_folder/cat.yaml rename to tools/tests/linter/fixtures/folder_validators/namespaces/invalid_folder/cat.yaml diff --git a/tools/test/linter/fixtures/folder_validators/namespaces/invalid_folder/dup_path_a.yaml b/tools/tests/linter/fixtures/folder_validators/namespaces/invalid_folder/dup_path_a.yaml similarity index 100% rename from tools/test/linter/fixtures/folder_validators/namespaces/invalid_folder/dup_path_a.yaml rename to tools/tests/linter/fixtures/folder_validators/namespaces/invalid_folder/dup_path_a.yaml diff --git a/tools/test/linter/fixtures/folder_validators/namespaces/invalid_folder/dup_path_b.yaml b/tools/tests/linter/fixtures/folder_validators/namespaces/invalid_folder/dup_path_b.yaml similarity index 100% rename from tools/test/linter/fixtures/folder_validators/namespaces/invalid_folder/dup_path_b.yaml rename to tools/tests/linter/fixtures/folder_validators/namespaces/invalid_folder/dup_path_b.yaml diff --git a/tools/test/linter/fixtures/folder_validators/namespaces/invalid_folder/dup_path_c.yaml b/tools/tests/linter/fixtures/folder_validators/namespaces/invalid_folder/dup_path_c.yaml similarity index 100% rename from tools/test/linter/fixtures/folder_validators/namespaces/invalid_folder/dup_path_c.yaml rename to tools/tests/linter/fixtures/folder_validators/namespaces/invalid_folder/dup_path_c.yaml diff --git a/tools/test/linter/fixtures/inline_object_schema_validator/namespaces/ops.yaml b/tools/tests/linter/fixtures/inline_object_schema_validator/namespaces/ops.yaml similarity index 100% rename from tools/test/linter/fixtures/inline_object_schema_validator/namespaces/ops.yaml rename to tools/tests/linter/fixtures/inline_object_schema_validator/namespaces/ops.yaml diff --git a/tools/test/linter/fixtures/inline_object_schema_validator/schemas/schemas.yaml b/tools/tests/linter/fixtures/inline_object_schema_validator/schemas/schemas.yaml similarity index 100% rename from tools/test/linter/fixtures/inline_object_schema_validator/schemas/schemas.yaml rename to tools/tests/linter/fixtures/inline_object_schema_validator/schemas/schemas.yaml diff --git a/tools/test/linter/fixtures/schema_refs_validator/namespaces/indices.yaml b/tools/tests/linter/fixtures/schema_refs_validator/namespaces/indices.yaml similarity index 100% rename from tools/test/linter/fixtures/schema_refs_validator/namespaces/indices.yaml rename to tools/tests/linter/fixtures/schema_refs_validator/namespaces/indices.yaml diff --git a/tools/test/linter/fixtures/schema_refs_validator/schemas/animals.yaml b/tools/tests/linter/fixtures/schema_refs_validator/schemas/animals.yaml similarity index 100% rename from tools/test/linter/fixtures/schema_refs_validator/schemas/animals.yaml rename to tools/tests/linter/fixtures/schema_refs_validator/schemas/animals.yaml diff --git a/tools/test/linter/fixtures/schema_refs_validator/schemas/others.yaml b/tools/tests/linter/fixtures/schema_refs_validator/schemas/others.yaml similarity index 100% rename from tools/test/linter/fixtures/schema_refs_validator/schemas/others.yaml rename to tools/tests/linter/fixtures/schema_refs_validator/schemas/others.yaml diff --git a/tools/tests/merger/OpenApiMerger.test.ts b/tools/tests/merger/OpenApiMerger.test.ts new file mode 100644 index 000000000..f261aef0b --- /dev/null +++ b/tools/tests/merger/OpenApiMerger.test.ts @@ -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') +}) diff --git a/tools/test/merger/fixtures/expected.yaml b/tools/tests/merger/fixtures/expected.yaml similarity index 100% rename from tools/test/merger/fixtures/expected.yaml rename to tools/tests/merger/fixtures/expected.yaml diff --git a/tools/test/merger/fixtures/spec/_global_parameters.yaml b/tools/tests/merger/fixtures/spec/_global_parameters.yaml similarity index 100% rename from tools/test/merger/fixtures/spec/_global_parameters.yaml rename to tools/tests/merger/fixtures/spec/_global_parameters.yaml diff --git a/tools/test/merger/fixtures/spec/_info.yaml b/tools/tests/merger/fixtures/spec/_info.yaml similarity index 100% rename from tools/test/merger/fixtures/spec/_info.yaml rename to tools/tests/merger/fixtures/spec/_info.yaml diff --git a/tools/test/merger/fixtures/spec/_superseded_operations.yaml b/tools/tests/merger/fixtures/spec/_superseded_operations.yaml similarity index 100% rename from tools/test/merger/fixtures/spec/_superseded_operations.yaml rename to tools/tests/merger/fixtures/spec/_superseded_operations.yaml diff --git a/tools/test/merger/fixtures/spec/namespaces/indices.yaml b/tools/tests/merger/fixtures/spec/namespaces/indices.yaml similarity index 100% rename from tools/test/merger/fixtures/spec/namespaces/indices.yaml rename to tools/tests/merger/fixtures/spec/namespaces/indices.yaml diff --git a/tools/test/merger/fixtures/spec/namespaces/shelter.yaml b/tools/tests/merger/fixtures/spec/namespaces/shelter.yaml similarity index 100% rename from tools/test/merger/fixtures/spec/namespaces/shelter.yaml rename to tools/tests/merger/fixtures/spec/namespaces/shelter.yaml diff --git a/tools/test/merger/fixtures/spec/schemas/actions.yaml b/tools/tests/merger/fixtures/spec/schemas/actions.yaml similarity index 100% rename from tools/test/merger/fixtures/spec/schemas/actions.yaml rename to tools/tests/merger/fixtures/spec/schemas/actions.yaml diff --git a/tools/test/merger/fixtures/spec/schemas/animals.yaml b/tools/tests/merger/fixtures/spec/schemas/animals.yaml similarity index 100% rename from tools/test/merger/fixtures/spec/schemas/animals.yaml rename to tools/tests/merger/fixtures/spec/schemas/animals.yaml diff --git a/tools/tsconfig.json b/tsconfig.json similarity index 99% rename from tools/tsconfig.json rename to tsconfig.json index bc6592779..8312f50b5 100644 --- a/tools/tsconfig.json +++ b/tsconfig.json @@ -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": "./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'. */