Skip to content

Commit

Permalink
Moved package.json to root.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <dblock@amazon.com>
  • Loading branch information
dblock committed May 13, 2024
1 parent 52463ce commit 6348527
Show file tree
Hide file tree
Showing 69 changed files with 68 additions and 72 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ jobs:
node-version: '20'

- name: Build
working-directory: ./tools
run: |-
mkdir -p ../build
mkdir -p ./build
npm install
npm run merge -- --source ../spec --output ../build/opensearch-openapi.yaml
npm run merge -- --source ./spec --output ./build/opensearch-openapi.yaml
- name: Extract Branch Name
id: branch
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/coverage-gather.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ jobs:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Build Spec
working-directory: ./tools
run: |-
mkdir -p ../build
mkdir -p ./build
npm install
npm run merge -- --source ../spec --output ../build/opensearch-openapi.yaml
npm run merge -- --source ./spec --output ./build/opensearch-openapi.yaml
- name: Build and Run Docker Container
run: |
docker build coverage --tag opensearch-with-api-plugin
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
uses: lycheeverse/lychee-action@v1
with:
fail: true
args: --base . --verbose --no-progress './**/*.yaml' './**/*.yml' './**/*.md' './**/*.json' './**/*.ts' --exclude-path ./tools/package-lock.json
args: --base . --verbose --no-progress './**/*.yaml' './**/*.yml' './**/*.md' './**/*.json' './**/*.ts' --exclude-path ./package-lock.json
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
node-version: 20.10.0
- run: npm install
- run: |
npm run lint:spec -- --source ../spec
npm run lint:spec -- --source ./spec
6 changes: 2 additions & 4 deletions _plugins/openapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ module OpenAPI
def self.generate(_site, _payload)
return if @generated

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

@generated = true
end
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tools/package.json → package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"author": "opensearch-project",
"license": "Apache-2.0",
"scripts": {
"merge": "ts-node merger/merge.ts",
"lint:spec": "ts-node linter/lint.ts",
"merge": "ts-node tools/merger/merge.ts",
"lint:spec": "ts-node tools/linter/lint.ts",
"lint": "eslint .",
"test": "jest"
},
Expand Down
2 changes: 1 addition & 1 deletion spec/_info.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$schema: ../json_schemas/_info.schema.yaml
$schema: ./json_schemas/_info.schema.yaml

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

/_opendistro/_alerting/destinations:
superseded_by: /_plugins/_alerting/destinations
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import InfoFile from '../../linter/components/InfoFile'
import InfoFile from '../../../tools/linter/components/InfoFile'

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

test('validate()', () => {
const root_folder = './test/linter/fixtures/inline_object_schema_validator'
const root_folder = './tests/tools/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'
import NamespacesFolder from '../../../tools/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('./tests/tools/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('./test/linter/fixtures/folder_validators/namespaces/invalid_folder')
const validator = new NamespacesFolder('./tests/tools/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 '../../linter/components/SchemasFolder'
import NamespacesFolder from '../../linter/components/NamespacesFolder'
import SchemaRefsValidator from '../../linter/SchemaRefsValidator'
import SchemasFolder from '../../../tools/linter/components/SchemasFolder'
import NamespacesFolder from '../../../tools/linter/components/NamespacesFolder'
import SchemaRefsValidator from '../../../tools/linter/SchemaRefsValidator'

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

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

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

test('validate()', () => {
const validator = new SupersededOperationsFile('./tests/tools/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]"
}
])
})
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import NamespaceFile from '../../../linter/components/NamespaceFile'
import NamespaceFile from '../../../../tools/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(`./tests/tools/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 '../../../linter/components/Operation'
import { type OperationSpec } from '../../../types'
import Operation from '../../../../tools/linter/components/Operation'
import { type OperationSpec } from '../../../../tools/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 '../../../linter/components/OperationGroup'
import OperationGroup from '../../../../tools/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 '../../../linter/components/Schema'
import Schema from '../../../../tools/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 '../../../linter/components/SchemaFile'
import SchemaFile from '../../../../tools/linter/components/SchemaFile'

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

interface MockedReturnedValues {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$schema: ../json_schemas/_superseded_operations.schema.yaml
$schema: ./json_schemas/_superseded_operations.schema.yaml

/hello/world:
superseded_by: /goodbye/world
Expand Down
4 changes: 4 additions & 0 deletions tests/tools/linter/fixtures/empty/_info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$schema: ./json_schemas/_info.schema.yaml

title: ''
version: ''
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$schema: ./json_schemas/_superseded_operations.schema.yaml
10 changes: 10 additions & 0 deletions tests/tools/merger/OpenApiMerger.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import OpenApiMerger from '../../../tools/merger/OpenApiMerger'
import fs from 'fs'

test('merge()', async () => {
const merger = new OpenApiMerger('./tests/tools/merger/fixtures/spec/')
merger.merge('./tests/tools/merger/opensearch-openapi.yaml')
expect(fs.readFileSync('./tests/tools/merger/fixtures/expected.yaml', 'utf8'))
.toEqual(fs.readFileSync('./tests/tools/merger/opensearch-openapi.yaml', 'utf8'))
fs.unlinkSync('./tests/tools/merger/opensearch-openapi.yaml')
})
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This folder contains tools for the repo:
## Setup

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

## Merger

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

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

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

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

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

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

Run `npm run lint:spec -- --help` for all options.
2 changes: 1 addition & 1 deletion tools/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
11 changes: 0 additions & 11 deletions tools/test/linter/SupersededOperationsFile.test.ts

This file was deleted.

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

This file was deleted.

This file was deleted.

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

This file was deleted.

File renamed without changes.

0 comments on commit 6348527

Please sign in to comment.