-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathMergedOpenApiSpec.test.ts
64 lines (52 loc) · 2.23 KB
/
MergedOpenApiSpec.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
import { Logger } from 'Logger'
import _ from 'lodash'
import MergedOpenApiSpec from "tester/MergedOpenApiSpec"
describe('unevaluatedProperties', () => {
const spec = new MergedOpenApiSpec('tools/tests/tester/fixtures/specs/complete', '2.0', new Logger())
const responses: any = spec.spec().components?.responses
test('has an api version', () => {
expect(spec.api_version()).toEqual('1.2.3')
})
test('is added with required fields', () => {
const schema = responses['info@200'].content['application/json'].schema
expect(schema.unevaluatedProperties).toEqual({ not: true, errorMessage: 'property is not defined in the spec' })
})
test('is added when no required fields', () => {
const schema = responses['info@500'].content['application/json'].schema
expect(schema.unevaluatedProperties).toEqual({ not: true, errorMessage: 'property is not defined in the spec' })
})
test('is not added to empty object schema', () => {
const schema = responses['info@503'].content['application/json'].schema
expect(schema.unevaluatedProperties).toBeUndefined()
})
test('is not added when true', () => {
const schema = responses['info@201'].content['application/json'].schema
expect(schema.unevaluatedProperties).toEqual(true)
})
test('is not added when object', () => {
const schema = responses['info@404'].content['application/json'].schema
expect(schema.unevaluatedProperties).toEqual({ type: 'object' })
})
test('has matching 2.0 responses', () => {
expect(_.keys(spec.spec().paths['/index']?.get?.responses)).toEqual([
'200', '201', '404', '407', '500'
])
})
test('excludes schema added after 2.0', () => {
expect(spec.spec().paths['/index']?.get?.responses['405']).toBeUndefined()
})
test('excludes schema removed before 2.0', () => {
expect(spec.spec().paths['/index']?.get?.responses['406']).toBeUndefined()
})
test('excludes schema added/removed in the response type', () => {
expect(responses['info@407']).toBeUndefined()
})
})