-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
36 lines (32 loc) · 921 Bytes
/
index.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
/*
* @japa/openapi-assertions
*
* (c) Japa.dev
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { Assert } from '@japa/assert'
import type { PluginFn } from '@japa/runner/types'
import type { PluginConfig } from './src/types.js'
import { OpenApiAssertions } from './src/openapi_assertions.js'
declare module '@japa/assert' {
export interface Assert {
isValidApiResponse: (response: any) => void
}
}
/**
* Plugin for "@japa/runner"
*/
export function openapi(options: PluginConfig): PluginFn {
OpenApiAssertions.registerSpecs(options.schemas, {
exportCoverage: options.exportCoverage,
reportCoverage: options.reportCoverage,
})
return function () {
Assert.macro('isValidApiResponse', (response) =>
new OpenApiAssertions().isValidResponse(response)
)
}
}
export { OpenApiAssertions }