diff --git a/spec/opensearch-openapi.yaml b/spec/opensearch-openapi.yaml index aa652e149..dffbd314c 100644 --- a/spec/opensearch-openapi.yaml +++ b/spec/opensearch-openapi.yaml @@ -496,3 +496,47 @@ paths: $ref: 'namespaces/tasks.yaml#/paths/~1_tasks~1{task_id}' /_tasks/{task_id}/_cancel: $ref: 'namespaces/tasks.yaml#/paths/~1_tasks~1{task_id}~1_cancel' +components: + parameters: + _global::query.pretty: + x-global: true + name: pretty + in: query + description: Whether to pretty format the returned JSON response. + schema: + type: boolean + default: false + _global::query.human: + x-global: true + name: human + in: query + description: Whether to return human readable values for statistics. + schema: + type: boolean + default: true + _global::query.error_trace: + x-global: true + name: error_trace + in: query + description: Whether to include the stack trace of returned errors. + schema: + type: boolean + default: false + _global::query.source: + x-global: true + name: source + in: query + description: The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests. + schema: + type: string + _global::query.filter_path: + x-global: true + name: filter_path + in: query + description: Comma-separated list of filters used to reduce the response. + schema: + oneOf: + - type: string + - type: array + items: + type: string diff --git a/tools/merger/OpenApiMerger.ts b/tools/merger/OpenApiMerger.ts index 1ecda8929..2a075e1ed 100644 --- a/tools/merger/OpenApiMerger.ts +++ b/tools/merger/OpenApiMerger.ts @@ -17,14 +17,14 @@ export default class OpenApiMerger { this.root_folder = this.root_path.split('/').slice(0, -1).join('/'); this.spec = yaml.parse(fs.readFileSync(this.root_path, 'utf8')); this.spec.components = { - parameters: {}, + parameters: this.spec.components?.parameters || {}, requestBodies: {}, responses: {}, schemas: {}, }; } - merge(output_path: string | null): OpenAPIV3.Document { + merge(output_path?: string): OpenAPIV3.Document { this.#merge_namespaces(); this.#merge_schemas(); this.#sort_spec_keys(); diff --git a/tools/test/merger/OpenApiMerger.test.ts b/tools/test/merger/OpenApiMerger.test.ts new file mode 100644 index 000000000..32aec55e8 --- /dev/null +++ b/tools/test/merger/OpenApiMerger.test.ts @@ -0,0 +1,12 @@ +import OpenApiMerger from '../../merger/OpenApiMerger'; +import fs from 'fs'; +import yaml from 'yaml'; + + +test('merge()', async () => { + const merger = new OpenApiMerger('./test/merger/fixtures/spec/opensearch-openapi.yaml'); + 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'); +}); \ No newline at end of file diff --git a/tools/test/merger/fixtures/expected.yaml b/tools/test/merger/fixtures/expected.yaml new file mode 100644 index 000000000..c37945123 --- /dev/null +++ b/tools/test/merger/fixtures/expected.yaml @@ -0,0 +1,73 @@ +openapi: 3.1.0 +info: + title: OpenSearch API + description: OpenSearch API + version: 1.0.0 +paths: + /adopt/{animal}: + post: + parameters: + - $ref: '#/components/parameters/adopt::path.animal' + requestBody: + $ref: '#/components/requestBodies/adopt' + responses: + '200': + $ref: '#/components/responses/adopt@200' +components: + parameters: + _global::query.human: + x-global: true + name: human + in: query + description: Whether to return human readable values for statistics. + schema: + type: boolean + default: true + adopt::path.animal: + name: animal + in: path + schema: + $ref: '#/components/schemas/animals:Animal' + indices.create::path.index: + name: index + in: path + schema: + type: string + indices.create::query.pretty: + name: pretty + in: query + schema: + type: boolean + requestBodies: + adopt: {} + indices.create: {} + responses: + adopt@200: + description: '' + application/json: + schema: + type: object + indices.create@200: + description: '' + application/json: + schema: + type: object + schemas: + actions:Bark: + type: string + actions:Meow: + type: string + animals:Animal: + oneOf: + - $ref: '#/components/schemas/animals:Dog' + - $ref: '#/components/schemas/animals:Cat' + animals:Cat: + type: object + properties: + meow: + $ref: '#/components/schemas/actions:Meow' + animals:Dog: + type: object + properties: + bark: + $ref: '#/components/schemas/actions:Bark' diff --git a/tools/test/merger/fixtures/spec/namespaces/ignored.yaml b/tools/test/merger/fixtures/spec/namespaces/ignored.yaml new file mode 100644 index 000000000..f8a7688cd --- /dev/null +++ b/tools/test/merger/fixtures/spec/namespaces/ignored.yaml @@ -0,0 +1,35 @@ +openapi: 3.1.0 +info: + title: Ignored + version: 1.0.0 +paths: + '/{index}': + post: + parameters: + - $ref: '#/components/parameters/indices.create::path.index' + - $ref: '#/components/parameters/indices.create::query.pretty' + requestBody: + $ref: '#/components/requestBodies/indices.create' + responses: + '200': + $ref: '#/components/responses/indices.create@200' +components: + requestBodies: + indices.create: {} + parameters: + indices.create::path.index: + name: index + in: path + schema: + type: string + indices.create::query.pretty: + name: pretty + in: query + schema: + type: boolean + responses: + indices.create@200: + description: '' + application/json: + schema: + type: object \ No newline at end of file diff --git a/tools/test/merger/fixtures/spec/namespaces/shelter.yaml b/tools/test/merger/fixtures/spec/namespaces/shelter.yaml new file mode 100644 index 000000000..3d85cd359 --- /dev/null +++ b/tools/test/merger/fixtures/spec/namespaces/shelter.yaml @@ -0,0 +1,30 @@ +openapi: 3.1.0 +info: + title: OpenSearch API + description: OpenSearch API + version: 1.0.0 +paths: + '/adopt/{animal}': + post: + parameters: + - $ref: '#/components/parameters/adopt::path.animal' + requestBody: + $ref: '#/components/requestBodies/adopt' + responses: + '200': + $ref: '#/components/responses/adopt@200' +components: + requestBodies: + adopt: {} + parameters: + adopt::path.animal: + name: animal + in: path + schema: + $ref: '../schemas/animals.yaml#/components/schemas/Animal' + responses: + adopt@200: + description: '' + application/json: + schema: + type: object \ No newline at end of file diff --git a/tools/test/merger/fixtures/spec/opensearch-openapi.yaml b/tools/test/merger/fixtures/spec/opensearch-openapi.yaml new file mode 100644 index 000000000..1e9a06617 --- /dev/null +++ b/tools/test/merger/fixtures/spec/opensearch-openapi.yaml @@ -0,0 +1,18 @@ +openapi: 3.1.0 +info: + title: OpenSearch API + description: OpenSearch API + version: 1.0.0 +paths: + '/adopt/{animal}': + $ref: 'namespaces/shelter.yaml#/paths/~1adopt~1{animal}' +components: + parameters: + _global::query.human: + x-global: true + name: human + in: query + description: Whether to return human readable values for statistics. + schema: + type: boolean + default: true \ No newline at end of file diff --git a/tools/test/merger/fixtures/spec/schemas/actions.yaml b/tools/test/merger/fixtures/spec/schemas/actions.yaml new file mode 100644 index 000000000..89bec0877 --- /dev/null +++ b/tools/test/merger/fixtures/spec/schemas/actions.yaml @@ -0,0 +1,11 @@ +openapi: 3.1.0 +info: + title: OpenSearch API + description: OpenSearch API + version: 1.0.0 +components: + schemas: + Bark: + type: string + Meow: + type: string \ No newline at end of file diff --git a/tools/test/merger/fixtures/spec/schemas/animals.yaml b/tools/test/merger/fixtures/spec/schemas/animals.yaml new file mode 100644 index 000000000..bdb82a16f --- /dev/null +++ b/tools/test/merger/fixtures/spec/schemas/animals.yaml @@ -0,0 +1,21 @@ +openapi: 3.1.0 +info: + title: OpenSearch API + description: OpenSearch API + version: 1.0.0 +components: + schemas: + Animal: + oneOf: + - $ref: '#/components/schemas/Dog' + - $ref: '#/components/schemas/Cat' + Dog: + type: object + properties: + bark: + $ref: 'actions.yaml#/components/schemas/Bark' + Cat: + type: object + properties: + meow: + $ref: 'actions.yaml#/components/schemas/Meow' \ No newline at end of file