forked from openapi-ts/openapi-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-helpers.ts
57 lines (55 loc) · 1.43 KB
/
test-helpers.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
import { createConfig } from "@redocly/openapi-core";
import { resolveRef } from "../src/lib/utils.js";
import type { GlobalContext, TransformNodeOptions } from "../src/types.js";
/** Default options for all transform* functions */
export const DEFAULT_CTX: GlobalContext = {
additionalProperties: false,
alphabetize: false,
arrayLength: false,
defaultNonNullable: true,
discriminators: {
objects: {},
refsHandled: [],
},
emptyObjectsUnknown: false,
enum: false,
enumValues: false,
dedupeEnums: false,
excludeDeprecated: false,
exportType: false,
immutable: false,
injectFooter: [],
pathParamsAsTypes: false,
postTransform: undefined,
propertiesRequiredByDefault: false,
redoc: await createConfig({}, { extends: ["minimal"] }),
resolve($ref) {
return resolveRef({}, $ref, { silent: false });
},
silent: true,
transform: undefined,
};
/** Generic test case */
export type TestCase<T = any, O = TransformNodeOptions> = [
string,
{
/**
* The OpenAPI schema. * Typing as `any` is good because it lets us test
* any invalid or unexpected formats without fighting with TypeScript.
*/
given: T;
/**
* The expected TypeScript output. Be mindful of indentation and
* parentheses!
*/
want: string | URL;
/**
* Transform options.
*/
options?: O;
/**
* Options for Vitest
*/
ci?: { timeout?: number; skipIf?: boolean };
},
];