Skip to content

Commit

Permalink
Separated merger and tester fixtures, fixed leftoever nulls. (#559)
Browse files Browse the repository at this point in the history
* Separated merger and tester fixtures.

Signed-off-by: dblock <[email protected]>

* Fix: delete leftoever undefined array items.

Signed-off-by: dblock <[email protected]>

* Re-add x-version-added for geo types.

Signed-off-by: dblock <[email protected]>

---------

Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Sep 9, 2024
1 parent a768a73 commit 29185f4
Show file tree
Hide file tree
Showing 24 changed files with 305 additions and 12 deletions.
4 changes: 2 additions & 2 deletions spec/schemas/_common.mapping.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ components:
- recursive
- term
XyPointProperty:
# x-version-added: 2.4
x-version-added: '2.4'
allOf:
- $ref: '#/components/schemas/DocValuesPropertyBase'
- type: object
Expand All @@ -952,7 +952,7 @@ components:
required:
- type
XyShapeProperty:
# x-version-added: 2.4
x-version-added: '2.4'
allOf:
- $ref: '#/components/schemas/DocValuesPropertyBase'
- type: object
Expand Down
2 changes: 1 addition & 1 deletion spec/schemas/_common.query_dsl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2001,7 +2001,7 @@ components:
required:
- shape
XyShapeQuery:
x-version-added: 2.4
x-version-added: '2.4'
allOf:
- $ref: '#/components/schemas/QueryBase'
- type: object
Expand Down
2 changes: 1 addition & 1 deletion spec/schemas/_common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ components:
required:
- wkt
XyLocation:
x-version-added: 2.4
x-version-added: '2.4'
description: |-
A two-dimensional Cartesian point specified by x and y coordinates. It can be represented in various ways:
- as a `{x, y}` object
Expand Down
4 changes: 4 additions & 0 deletions tools/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ export function sort_array_by_keys (values: any[], priorities: string[] = []): s
export function delete_matching_keys(obj: any, condition: (obj: any) => boolean): void {
for (const key in obj) {
var item = obj[key]

if (_.isObject(item)) {
if (condition(item)) {
delete obj[key]
} else {
delete_matching_keys(item, condition)
if (_.isArray(item)) {
obj[key] = _.compact(item)
}
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions tools/tests/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,25 @@ describe('helpers', () => {
expect(obj).toStrictEqual({ foo: [{}] })
})
})

describe('an object with an array where some items are removed', () => {
var obj: object

beforeEach(() => {
obj = {
foo: [
{ value: 1 },
{ value: 1 },
{ value: 2 }
]
}
})

test('removes matching values', () => {
delete_matching_keys(obj, (_item: any) => _item.value == 1)
expect(obj).toStrictEqual({ foo: [{ value: 2 }] })
})
})
})

describe('find_refs', () => {
Expand Down
4 changes: 2 additions & 2 deletions tools/tests/merger/OpenApiMerger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('OpenApiMerger', () => {

describe('defaults', () => {
beforeEach(() => {
merger = new OpenApiMerger('./tools/tests/merger/fixtures/spec/')
merger = new OpenApiMerger('./tools/tests/merger/fixtures/specs/animals')
})

describe('merge()', () => {
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('OpenApiMerger', () => {

test('writes a spec', () => {
merger.write_to(filename)
expect(fs.readFileSync('./tools/tests/merger/fixtures/merger/expected.yaml', 'utf8'))
expect(fs.readFileSync('./tools/tests/merger/fixtures/merger/animals/expected.yaml', 'utf8'))
.toEqual(fs.readFileSync(filename, 'utf8'))
})
})
Expand Down
12 changes: 6 additions & 6 deletions tools/tests/merger/OpenApiVersionExtractor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import fs from 'fs'
import tmp from 'tmp'

describe('extract() from a merged API spec', () => {
const merger = new OpenApiMerger('tools/tests/tester/fixtures/specs/complete')
const merger = new OpenApiMerger('tools/tests/merger/fixtures/specs/opensearch')

describe('1.3', () => {
const extractor = new OpenApiVersionExtractor(merger.spec(), '1.3', 'ignore')
Expand All @@ -35,15 +35,15 @@ describe('extract() from a merged API spec', () => {

test('writes a spec', () => {
extractor.write_to(filename)
expect(fs.readFileSync('./tools/tests/merger/fixtures/extractor/expected_1.3.yaml', 'utf8'))
expect(fs.readFileSync('./tools/tests/merger/fixtures/extractor/opensearch/expected_1.3.yaml', 'utf8'))
.toEqual(fs.readFileSync(filename, 'utf8'))
})
})

test('has matching responses', () => {
const spec = extractor.extract()
expect(_.keys(spec.paths['/index']?.get?.responses)).toEqual([
'200', '201', '404', '500', '503', 'removed-2.0', 'added-1.3-removed-2.0', 'distributed-excluded-amazon-serverless'
'200', '201', '404', '500', '503', 'removed-2.0', 'removed-2.0-refs', 'added-1.3-removed-2.0', 'distributed-excluded-amazon-serverless'
])
})
})
Expand All @@ -54,7 +54,7 @@ describe('extract() from a merged API spec', () => {
test('has matching responses', () => {
const spec = extractor.extract()
expect(_.keys(spec.paths['/index']?.get?.responses)).toEqual([
'200', '201', '404', '500', '503', 'added-2.0', 'distributed-excluded-amazon-serverless'
'200', '201', '404', '500', '503', 'added-2.0', 'removed-2.0-refs', 'distributed-excluded-amazon-serverless'
])
})

Expand All @@ -74,7 +74,7 @@ describe('extract() from a merged API spec', () => {

test('writes a spec', () => {
extractor.write_to(filename)
expect(fs.readFileSync('./tools/tests/merger/fixtures/extractor/expected_2.0.yaml', 'utf8'))
expect(fs.readFileSync('./tools/tests/merger/fixtures/extractor/opensearch/expected_2.0.yaml', 'utf8'))
.toEqual(fs.readFileSync(filename, 'utf8'))
})
})
Expand All @@ -86,7 +86,7 @@ describe('extract() from a merged API spec', () => {
test('has matching responses', () => {
const spec = extractor.extract()
expect(_.keys(spec.paths['/index']?.get?.responses)).toEqual([
'200', '201', '404', '500', '503', 'added-2.0', 'added-2.1', 'distributed-excluded-amazon-serverless'
'200', '201', '404', '500', '503', 'added-2.0', 'removed-2.0-refs', 'added-2.1', 'distributed-excluded-amazon-serverless'
])
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ paths:
removed-2.0:
$ref: '#/components/responses/[email protected]'
x-version-removed: '2.0'
removed-2.0-refs:
$ref: '#/components/responses/[email protected]'
added-1.3-removed-2.0:
$ref: '#/components/responses/[email protected]'
distributed-excluded-amazon-serverless:
Expand Down Expand Up @@ -114,13 +116,21 @@ components:
description: Distributed in opensearch.org, AOS and AOSS.
[email protected]:
description: Removed in 2.0 via attribute next to ref.
[email protected]:
description: One of the ref values removed in 2.0.
schema:
oneOf:
- $ref: '#/components/schemas/_common:Type'
- $ref: '#/components/schemas/_common:OldId'
nodes.info@200:
description: All nodes.
content:
application/json:
schema:
type: object
schemas:
_common:OldId:
type: string
_common:Type:
type: string
x-version-removed: '2.0'
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ paths:
added-2.0:
$ref: '#/components/responses/[email protected]'
x-version-added: '2.0'
removed-2.0-refs:
$ref: '#/components/responses/[email protected]'
distributed-excluded-amazon-serverless:
$ref: '#/components/responses/info@distributed-all'
x-distributions-excluded:
Expand Down Expand Up @@ -150,6 +152,11 @@ components:
description: Added in 2.0 via attribute next to ref.
info@distributed-all:
description: Distributed in opensearch.org, AOS and AOSS.
[email protected]:
description: One of the ref values removed in 2.0.
schema:
oneOf:
- $ref: '#/components/schemas/_common:OldId'
nodes.info@200:
description: All nodes.
content:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
openapi: 3.1.0
info:
title: ''
version: ''
6 changes: 6 additions & 0 deletions tools/tests/merger/fixtures/specs/opensearch/_info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$schema: should-be-ignored

title: OpenSearch API
description: OpenSearch API
version: 1.0.0
x-api-version: 1.2.3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$schema: should-be-ignored
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
openapi: 3.1.0
info:
title: OpenSearch API
description: OpenSearch API
version: 1.0.0
paths:
/cluster_manager:
get:
operationId: cluster_manager.0
x-version-added: '2.0'
post:
operationId: cluster_manager.0
x-version-added: '2.0'
components:
requestBodies: []
parameters: []
responses: []
117 changes: 117 additions & 0 deletions tools/tests/merger/fixtures/specs/opensearch/namespaces/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
openapi: 3.1.0
info:
title: OpenSearch API
description: OpenSearch API
version: 1.0.0
paths:
/index:
get:
operationId: get.0
responses:
'200':
$ref: '#/components/responses/info@200'
'201':
$ref: '#/components/responses/info@201'
'404':
$ref: '#/components/responses/info@404'
added-2.0:
$ref: '#/components/responses/[email protected]'
x-version-added: '2.0'
removed-2.0:
$ref: '#/components/responses/[email protected]'
x-version-removed: '2.0'
removed-2.0-refs:
$ref: '#/components/responses/[email protected]'
added-1.3-removed-2.0:
$ref: '#/components/responses/[email protected]'
added-2.1:
$ref: '#/components/responses/[email protected]'
'500':
$ref: '#/components/responses/info@500'
'503':
$ref: '#/components/responses/info@503'
distributed-included-all:
$ref: '#/components/responses/info@distributed-all'
x-distributions-included:
- amazon-managed
- amazon-serverless
- opensearch.org
distributed-included-amazon-managed:
$ref: '#/components/responses/info@distributed-amazon-managed'
x-distributions-included:
- amazon-managed
distributed-excluded-amazon-serverless:
$ref: '#/components/responses/info@distributed-all'
x-distributions-excluded:
- amazon-serverless
components:
responses:
info@200:
content:
application/json:
schema:
type: object
properties:
_type:
$ref: '../schemas/_common.yaml#/components/schemas/Type'
tagline:
type: string
required:
- tagline
info@201:
content:
application/json:
schema:
type: object
properties:
tagline:
type: string
required:
- tagline
unevaluatedProperties: true
info@404:
content:
application/json:
schema:
type: object
properties:
tagline:
type: string
required:
- tagline
unevaluatedProperties:
type: object
[email protected]:
description: Added in 2.0 via attribute next to ref.
[email protected]:
description: Removed in 2.0 via attribute next to ref.
[email protected]:
description: One of the ref values removed in 2.0.
schema:
oneOf:
- $ref: '../schemas/_common.yaml#/components/schemas/Type'
- $ref: '../schemas/_common.yaml#/components/schemas/OldId'
[email protected]:
description: Added in 1.3, removed in 2.0 via attribute in response body.
x-version-added: '1.3'
x-version-removed: '2.0'
[email protected]:
description: Added in 2.1 via attribute in response body.
x-version-added: '2.1'
info@distributed-amazon-managed:
description: Distributed only in AOS.
info@distributed-all:
description: Distributed in opensearch.org, AOS and AOSS.
info@500:
content:
application/json:
schema:
type: object
properties:
tagline:
type: string
info@503:
content:
application/json:
schema:
type: object
Loading

0 comments on commit 29185f4

Please sign in to comment.