/
index.ts
210 lines (200 loc) · 7.14 KB
/
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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import { identity } from 'ramda';
import { RefElement } from 'minim';
import type Parser from '../parse/parsers/Parser';
import type Resolver from '../resolve/resolvers/Resolver';
import type ResolveStrategy from '../resolve/strategies/ResolveStrategy';
import type DereferenceStrategy from '../dereference/strategies/DereferenceStrategy';
import type ReferenceSet from '../ReferenceSet';
import type BundleStrategy from '../bundle/strategies/BundleStrategy';
interface ReferenceParseOptions {
mediaType: string;
parsers: Array<Parser>;
parserOpts: Record<string, any>;
}
interface ReferenceResolveOptions {
baseURI: string;
resolvers: Array<Resolver>;
resolverOpts: Record<string, any>;
strategies: Array<ResolveStrategy>;
strategyOpts: Record<string, any>;
internal: boolean;
external: boolean;
maxDepth: number;
}
interface ReferenceDereferenceOptions {
strategies: Array<DereferenceStrategy>;
strategyOpts: Record<string, any>;
refSet: null | ReferenceSet;
maxDepth: number;
circular: 'ignore' | 'replace' | 'error';
circularReplacer: (ref: RefElement) => unknown;
immutable: boolean;
}
interface ReferenceBundleOptions {
strategies: Array<BundleStrategy>;
refSet: null | ReferenceSet;
maxDepth: number;
}
export interface ReferenceOptions {
readonly parse: ReferenceParseOptions;
readonly resolve: ReferenceResolveOptions;
readonly dereference: ReferenceDereferenceOptions;
readonly bundle: ReferenceBundleOptions;
}
const defaultOptions: ReferenceOptions = {
parse: {
/**
* This is media type that will be used to parse the input.
*/
mediaType: 'text/plain',
/**
* Determines how different types of files will be parsed.
*
* You can add additional parsers of your own, replace an existing one with
* your own implementation, or remove any resolver by removing it from the list.
* It's recommended to keep the order of parser from most specific ones to most generic ones.
*/
parsers: [],
/**
* These options are merged with parser plugin instance before the plugin is run.
*/
parserOpts: {},
},
resolve: {
/**
* baseURI serves as a base for all relative URL found in ApiDOM references.
*/
baseURI: '',
/**
* Determines how References will be resolved.
*
* You can add additional resolvers of your own, replace an existing one with
* your own implementation, or remove any resolver by removing it from the list.
*/
resolvers: [],
/**
* These options are merged with resolver plugin instance before the plugin is run.
*/
resolverOpts: {},
/**
* Determines strategies how References are identified and processed by resolvers.
* Strategy is determined by media type.
*
* You can add additional resolver strategies of your own, replace an existing one with
* your own implementation, or remove any resolve strategy by removing it from the list.
*/
strategies: [],
/**
* These options are available in resolver strategy `canResolve` and `resolve` methods.
*/
strategyOpts: {},
/**
* Determines whether internal references will be resolved.
* Internal references will simply be ignored.
*/
internal: true,
/**
* Determines whether external references will be resolved.
* If this option is disabled, then none of above resolvers will be called.
* Instead, external references will simply be ignored.
*/
external: true,
/**
* Determines the maximum depth of resolve algorithms.
* By default, there is no limit.
*
* This option tracks the depth of the file tree not the depth of the dereference path.
*
* It can be set to any positive integer number or zero (0).
*
* The resolver should throw MaximumResolverDepthError if resolution depth
* is exceeded by this option.
*/
maxDepth: +Infinity,
},
dereference: {
/**
* Determines strategies how ApiDOM is dereferenced.
* Strategy is determined by media type or by inspecting ApiDOM to be dereferenced.
*
* You can add additional dereference strategies of your own, replace an existing one with
* your own implementation, or remove any dereference strategy by removing it from the list.
*/
strategies: [],
/**
* These options are available in dereference strategy `canDereference` and `dereference` methods.
*/
strategyOpts: {},
/**
* This option accepts an instance of pre-computed ReferenceSet.
* If provided it will speed up the dereferencing significantly as the external
* resolution doesn't need to happen anymore.
*/
refSet: null,
/**
* Determines the maximum depth of dereferencing.
* By default, there is no limit.
*
* The maxDepth represents a number of references that needed to be followed
* before the eventual value was reached.
*
* It can be set to any positive integer number or zero (0).
*
* The dereferencing should throw MaximumDereferenceDepthError if dereferencing depth
* is exceeded by this option.
*/
maxDepth: +Infinity,
/**
* Determines how circular references are handled.
*
* "ignore" - circular reference are allowed
* "replace" - circular references are not allowed and are translated to RefElement
* "error" - circular references are not allowed and will throw an error
*/
circular: 'ignore',
/**
* This function is used to replace circular references when `circular` option is set to "replace".
* By default, it's an identity function. It means that circular references are replaced with RefElement.
*/
circularReplacer: identity,
/**
* Determines whether the dereferencing process will be immutable.
* By default, the dereferencing process is immutable, which means that the original
* ApiDOM passed to the dereference process is NOT modified.
*
* true - the dereferencing process will be immutable (deep cloning of ApiDOM is involved)
* false - the dereferencing process will be mutable
*/
immutable: true,
},
bundle: {
/**
* Determines strategies how ApiDOM is bundled.
* Strategy is determined by media type or by inspecting ApiDOM to be bundled.
*
* You can add additional bundle strategies of your own, replace an existing one with
* your own implementation, or remove any bundle strategy by removing it from the list.
*/
strategies: [],
/**
* This option accepts an instance of pre-computed ReferenceSet.
* If provided it will speed up the bundling significantly as the external
* resolution doesn't need to happen anymore.
*/
refSet: null,
/**
* Determines the maximum depth of bundling.
* By default, there is no limit.
*
* The maxDepth represents a number of references that needed to be followed
* before the eventual value was reached.
*
* It can be set to any positive integer number or zero (0).
*
* The bundling should throw MaximumBundleDepthError if bundling depth
* is exceeded by this option.
*/
maxDepth: +Infinity,
},
};
export default defaultOptions;