docusaurus-plugin-openapi-docs 1.0.5 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +6 -7
  2. package/lib/index.js +3 -3
  3. package/lib/markdown/createSchemaDetails.js +325 -132
  4. package/lib/markdown/index.js +1 -0
  5. package/lib/markdown/schema.js +25 -9
  6. package/lib/markdown/utils.d.ts +1 -1
  7. package/lib/markdown/utils.js +4 -1
  8. package/lib/openapi/openapi.d.ts +5 -5
  9. package/lib/openapi/openapi.js +27 -23
  10. package/lib/openapi/openapi.test.js +1 -1
  11. package/lib/openapi/types.d.ts +2 -1
  12. package/lib/openapi/utils/loadAndResolveSpec.d.ts +2 -0
  13. package/lib/openapi/utils/loadAndResolveSpec.js +112 -0
  14. package/lib/openapi/utils/services/OpenAPIParser.d.ts +52 -0
  15. package/lib/openapi/utils/services/OpenAPIParser.js +342 -0
  16. package/lib/openapi/utils/services/RedocNormalizedOptions.d.ts +100 -0
  17. package/lib/openapi/utils/services/RedocNormalizedOptions.js +170 -0
  18. package/lib/openapi/utils/types/index.d.ts +2 -0
  19. package/lib/openapi/utils/types/index.js +23 -0
  20. package/lib/openapi/utils/types/open-api.d.ts +305 -0
  21. package/lib/openapi/utils/types/open-api.js +8 -0
  22. package/lib/openapi/utils/utils/JsonPointer.d.ts +51 -0
  23. package/lib/openapi/utils/utils/JsonPointer.js +95 -0
  24. package/lib/openapi/utils/utils/helpers.d.ts +43 -0
  25. package/lib/openapi/utils/utils/helpers.js +230 -0
  26. package/lib/openapi/utils/utils/index.d.ts +3 -0
  27. package/lib/openapi/utils/utils/index.js +25 -0
  28. package/lib/openapi/utils/utils/openapi.d.ts +40 -0
  29. package/lib/openapi/utils/utils/openapi.js +605 -0
  30. package/lib/options.js +1 -1
  31. package/lib/sidebars/index.js +9 -5
  32. package/lib/types.d.ts +1 -1
  33. package/package.json +16 -11
  34. package/src/index.ts +3 -3
  35. package/src/markdown/createSchemaDetails.ts +405 -159
  36. package/src/markdown/index.ts +1 -0
  37. package/src/markdown/schema.ts +28 -8
  38. package/src/markdown/utils.ts +5 -2
  39. package/src/openapi/openapi.test.ts +1 -1
  40. package/src/openapi/openapi.ts +39 -29
  41. package/src/openapi/types.ts +2 -1
  42. package/src/openapi/utils/loadAndResolveSpec.ts +123 -0
  43. package/src/openapi/utils/services/OpenAPIParser.ts +433 -0
  44. package/src/openapi/utils/services/RedocNormalizedOptions.ts +330 -0
  45. package/src/openapi/utils/types/index.ts +10 -0
  46. package/src/openapi/utils/types/open-api.ts +303 -0
  47. package/src/openapi/utils/utils/JsonPointer.ts +99 -0
  48. package/src/openapi/utils/utils/helpers.ts +239 -0
  49. package/src/openapi/utils/utils/index.ts +11 -0
  50. package/src/openapi/utils/utils/openapi.ts +771 -0
  51. package/src/options.ts +1 -1
  52. package/src/sidebars/index.ts +11 -6
  53. package/src/types.ts +1 -1
  54. package/lib/openapi/utils/loadAndBundleSpec.d.ts +0 -3
  55. package/lib/openapi/utils/loadAndBundleSpec.js +0 -44
  56. package/src/openapi/utils/loadAndBundleSpec.ts +0 -62
@@ -0,0 +1,342 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.OpenAPIParser = void 0;
10
+ const helpers_1 = require("../utils/helpers");
11
+ const JsonPointer_1 = require("../utils/JsonPointer");
12
+ const openapi_1 = require("../utils/openapi");
13
+ const RedocNormalizedOptions_1 = require("./RedocNormalizedOptions");
14
+ /**
15
+ * Helper class to keep track of visited references to avoid
16
+ * endless recursion because of circular refs
17
+ */
18
+ class RefCounter {
19
+ constructor() {
20
+ this._counter = {};
21
+ }
22
+ reset() {
23
+ this._counter = {};
24
+ }
25
+ visit(ref) {
26
+ this._counter[ref] = this._counter[ref] ? this._counter[ref] + 1 : 1;
27
+ }
28
+ exit(ref) {
29
+ this._counter[ref] = this._counter[ref] && this._counter[ref] - 1;
30
+ }
31
+ visited(ref) {
32
+ return !!this._counter[ref];
33
+ }
34
+ }
35
+ /**
36
+ * Loads and keeps spec. Provides raw spec operations
37
+ */
38
+ class OpenAPIParser {
39
+ constructor(spec, specUrl, options = new RedocNormalizedOptions_1.RedocNormalizedOptions()) {
40
+ this.options = options;
41
+ this._refCounter = new RefCounter();
42
+ this.allowMergeRefs = false;
43
+ /**
44
+ * get spec part by JsonPointer ($ref)
45
+ */
46
+ this.byRef = (ref) => {
47
+ let res;
48
+ if (!this.spec) {
49
+ return;
50
+ }
51
+ if (ref.charAt(0) !== "#") {
52
+ ref = "#" + ref;
53
+ }
54
+ ref = decodeURIComponent(ref);
55
+ try {
56
+ res = JsonPointer_1.JsonPointer.get(this.spec, ref);
57
+ }
58
+ catch (e) {
59
+ // do nothing
60
+ }
61
+ return res || {};
62
+ };
63
+ this.validate(spec);
64
+ this.spec = spec;
65
+ this.allowMergeRefs = spec.openapi.startsWith("3.1");
66
+ const href = undefined;
67
+ if (typeof specUrl === "string") {
68
+ this.specUrl = new URL(specUrl, href).href;
69
+ }
70
+ }
71
+ validate(spec) {
72
+ if (spec.openapi === undefined) {
73
+ throw new Error("Document must be valid OpenAPI 3.0.0 definition");
74
+ }
75
+ }
76
+ /**
77
+ * checks if the object is OpenAPI reference (contains $ref property)
78
+ */
79
+ isRef(obj) {
80
+ if (!obj) {
81
+ return false;
82
+ }
83
+ return obj.$ref !== undefined && obj.$ref !== null;
84
+ }
85
+ /**
86
+ * resets visited endpoints. should be run after
87
+ */
88
+ resetVisited() {
89
+ if (process.env.NODE_ENV !== "production") {
90
+ // check in dev mode
91
+ for (const k in this._refCounter._counter) {
92
+ if (this._refCounter._counter[k] > 0) {
93
+ console.warn("Not exited reference: " + k);
94
+ }
95
+ }
96
+ }
97
+ this._refCounter = new RefCounter();
98
+ }
99
+ exitRef(ref) {
100
+ if (!this.isRef(ref)) {
101
+ return;
102
+ }
103
+ this._refCounter.exit(ref.$ref);
104
+ }
105
+ /**
106
+ * Resolve given reference object or return as is if it is not a reference
107
+ * @param obj object to dereference
108
+ * @param forceCircular whether to dereference even if it is circular ref
109
+ */
110
+ deref(obj, forceCircular = false, mergeAsAllOf = false) {
111
+ if (this.isRef(obj)) {
112
+ const schemaName = (0, openapi_1.getDefinitionName)(obj.$ref);
113
+ if (schemaName && this.options.ignoreNamedSchemas.has(schemaName)) {
114
+ return { type: "object", title: schemaName };
115
+ }
116
+ const resolved = this.byRef(obj.$ref);
117
+ const visited = this._refCounter.visited(obj.$ref);
118
+ this._refCounter.visit(obj.$ref);
119
+ if (visited && !forceCircular) {
120
+ // circular reference detected
121
+ // tslint:disable-next-line
122
+ return Object.assign({}, resolved, { "x-circular-ref": true });
123
+ }
124
+ // deref again in case one more $ref is here
125
+ let result = resolved;
126
+ if (this.isRef(resolved)) {
127
+ result = this.deref(resolved, false, mergeAsAllOf);
128
+ this.exitRef(resolved);
129
+ }
130
+ return this.allowMergeRefs
131
+ ? this.mergeRefs(obj, resolved, mergeAsAllOf)
132
+ : result;
133
+ }
134
+ return obj;
135
+ }
136
+ shallowDeref(obj) {
137
+ if (this.isRef(obj)) {
138
+ const schemaName = (0, openapi_1.getDefinitionName)(obj.$ref);
139
+ if (schemaName && this.options.ignoreNamedSchemas.has(schemaName)) {
140
+ return { type: "object", title: schemaName };
141
+ }
142
+ const resolved = this.byRef(obj.$ref);
143
+ return this.allowMergeRefs
144
+ ? this.mergeRefs(obj, resolved, false)
145
+ : resolved;
146
+ }
147
+ return obj;
148
+ }
149
+ mergeRefs(ref, resolved, mergeAsAllOf) {
150
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
151
+ const { $ref, ...rest } = ref;
152
+ const keys = Object.keys(rest);
153
+ if (keys.length === 0) {
154
+ if (this.isRef(resolved)) {
155
+ return this.shallowDeref(resolved);
156
+ }
157
+ return resolved;
158
+ }
159
+ if (mergeAsAllOf &&
160
+ keys.some((k) => k !== "description" && k !== "title" && k !== "externalDocs")) {
161
+ return {
162
+ allOf: [rest, resolved],
163
+ };
164
+ }
165
+ else {
166
+ // small optimization
167
+ return {
168
+ ...resolved,
169
+ ...rest,
170
+ };
171
+ }
172
+ }
173
+ /**
174
+ * Merge allOf constraints.
175
+ * @param schema schema with allOF
176
+ * @param $ref pointer of the schema
177
+ * @param forceCircular whether to dereference children even if it is a circular ref
178
+ */
179
+ mergeAllOf(schema, $ref, forceCircular = false, used$Refs = new Set()) {
180
+ if ($ref) {
181
+ used$Refs.add($ref);
182
+ }
183
+ schema = this.hoistOneOfs(schema);
184
+ if (schema.allOf === undefined) {
185
+ return schema;
186
+ }
187
+ let receiver = {
188
+ ...schema,
189
+ allOf: undefined,
190
+ parentRefs: [],
191
+ title: schema.title || (0, openapi_1.getDefinitionName)($ref),
192
+ };
193
+ // avoid mutating inner objects
194
+ if (receiver.properties !== undefined &&
195
+ typeof receiver.properties === "object") {
196
+ receiver.properties = { ...receiver.properties };
197
+ }
198
+ if (receiver.items !== undefined && typeof receiver.items === "object") {
199
+ receiver.items = { ...receiver.items };
200
+ }
201
+ const allOfSchemas = schema.allOf
202
+ .map((subSchema) => {
203
+ if (subSchema && subSchema.$ref && used$Refs.has(subSchema.$ref)) {
204
+ return undefined;
205
+ }
206
+ const resolved = this.deref(subSchema, forceCircular, true);
207
+ const subRef = subSchema.$ref || undefined;
208
+ const subMerged = this.mergeAllOf(resolved, subRef, forceCircular, used$Refs);
209
+ receiver.parentRefs.push(...(subMerged.parentRefs || []));
210
+ return {
211
+ $ref: subRef,
212
+ schema: subMerged,
213
+ };
214
+ })
215
+ .filter((child) => child !== undefined);
216
+ for (const { $ref: subSchemaRef, schema: subSchema } of allOfSchemas) {
217
+ const { type, enum: enumProperty, properties, items, required, oneOf, anyOf, title, ...otherConstraints } = subSchema;
218
+ if (receiver.type !== type &&
219
+ receiver.type !== undefined &&
220
+ type !== undefined) {
221
+ console.warn(`Incompatible types in allOf at "${$ref}": "${receiver.type}" and "${type}"`);
222
+ }
223
+ if (type !== undefined) {
224
+ if (Array.isArray(type) && Array.isArray(receiver.type)) {
225
+ receiver.type = [...type, ...receiver.type];
226
+ }
227
+ else {
228
+ receiver.type = type;
229
+ }
230
+ }
231
+ if (enumProperty !== undefined) {
232
+ if (Array.isArray(enumProperty) && Array.isArray(receiver.enum)) {
233
+ receiver.enum = [...enumProperty, ...receiver.enum];
234
+ }
235
+ else {
236
+ receiver.enum = enumProperty;
237
+ }
238
+ }
239
+ if (properties !== undefined) {
240
+ receiver.properties = receiver.properties || {};
241
+ for (const prop in properties) {
242
+ if (!receiver.properties[prop]) {
243
+ receiver.properties[prop] = properties[prop];
244
+ }
245
+ else {
246
+ // merge inner properties
247
+ const mergedProp = this.mergeAllOf({ allOf: [receiver.properties[prop], properties[prop]] }, $ref + "/properties/" + prop);
248
+ receiver.properties[prop] = mergedProp;
249
+ this.exitParents(mergedProp); // every prop resolution should have separate recursive stack
250
+ }
251
+ }
252
+ }
253
+ if (items !== undefined) {
254
+ const receiverItems = (0, helpers_1.isBoolean)(receiver.items)
255
+ ? { items: receiver.items }
256
+ : receiver.items
257
+ ? Object.assign({}, receiver.items)
258
+ : {};
259
+ const subSchemaItems = (0, helpers_1.isBoolean)(items)
260
+ ? { items }
261
+ : Object.assign({}, items);
262
+ // merge inner properties
263
+ receiver.items = this.mergeAllOf({ allOf: [receiverItems, subSchemaItems] }, $ref + "/items");
264
+ }
265
+ if (required !== undefined) {
266
+ receiver.required = (receiver.required || []).concat(required);
267
+ }
268
+ if (oneOf !== undefined) {
269
+ receiver.oneOf = oneOf;
270
+ }
271
+ if (anyOf !== undefined) {
272
+ receiver.anyOf = anyOf;
273
+ }
274
+ // merge rest of constraints
275
+ // TODO: do more intelligent merge
276
+ receiver = {
277
+ ...receiver,
278
+ title: receiver.title || title,
279
+ ...otherConstraints,
280
+ };
281
+ if (subSchemaRef) {
282
+ receiver.parentRefs.push(subSchemaRef);
283
+ if (receiver.title === undefined && (0, openapi_1.isNamedDefinition)(subSchemaRef)) {
284
+ // this is not so correct behaviour. commented out for now
285
+ // ref: https://github.com/Redocly/redoc/issues/601
286
+ // receiver.title = JsonPointer.baseName(subSchemaRef);
287
+ }
288
+ }
289
+ }
290
+ return receiver;
291
+ }
292
+ /**
293
+ * Find all derived definitions among #/components/schemas from any of $refs
294
+ * returns map of definition pointer to definition name
295
+ * @param $refs array of references to find derived from
296
+ */
297
+ findDerived($refs) {
298
+ const res = {};
299
+ const schemas = (this.spec.components && this.spec.components.schemas) || {};
300
+ for (const defName in schemas) {
301
+ const def = this.deref(schemas[defName]);
302
+ if (def.allOf !== undefined &&
303
+ def.allOf.find((obj) => obj.$ref !== undefined && $refs.indexOf(obj.$ref) > -1)) {
304
+ res["#/components/schemas/" + defName] = [
305
+ def["x-discriminator-value"] || defName,
306
+ ];
307
+ }
308
+ }
309
+ return res;
310
+ }
311
+ exitParents(shema) {
312
+ for (const parent$ref of shema.parentRefs || []) {
313
+ this.exitRef({ $ref: parent$ref });
314
+ }
315
+ }
316
+ hoistOneOfs(schema) {
317
+ if (schema.allOf === undefined) {
318
+ return schema;
319
+ }
320
+ const allOf = schema.allOf;
321
+ for (let i = 0; i < allOf.length; i++) {
322
+ const sub = allOf[i];
323
+ if ((0, helpers_1.isArray)(sub.oneOf)) {
324
+ const beforeAllOf = allOf.slice(0, i);
325
+ const afterAllOf = allOf.slice(i + 1);
326
+ return {
327
+ oneOf: sub.oneOf.map((part) => {
328
+ const merged = this.mergeAllOf({
329
+ allOf: [...beforeAllOf, part, ...afterAllOf],
330
+ });
331
+ // each oneOf should be independent so exiting all the parent refs
332
+ // otherwise it will cause false-positive recursive detection
333
+ this.exitParents(merged);
334
+ return merged;
335
+ }),
336
+ };
337
+ }
338
+ }
339
+ return schema;
340
+ }
341
+ }
342
+ exports.OpenAPIParser = OpenAPIParser;
@@ -0,0 +1,100 @@
1
+ export declare enum SideNavStyleEnum {
2
+ SummaryOnly = "summary-only",
3
+ PathOnly = "path-only",
4
+ IdOnly = "id-only"
5
+ }
6
+ export interface RedocRawOptions {
7
+ scrollYOffset?: number | string | (() => number);
8
+ hideHostname?: boolean | string;
9
+ expandResponses?: string | "all";
10
+ requiredPropsFirst?: boolean | string;
11
+ sortPropsAlphabetically?: boolean | string;
12
+ sortEnumValuesAlphabetically?: boolean | string;
13
+ sortOperationsAlphabetically?: boolean | string;
14
+ sortTagsAlphabetically?: boolean | string;
15
+ nativeScrollbars?: boolean | string;
16
+ pathInMiddlePanel?: boolean | string;
17
+ untrustedSpec?: boolean | string;
18
+ hideLoading?: boolean | string;
19
+ hideDownloadButton?: boolean | string;
20
+ downloadFileName?: string;
21
+ downloadDefinitionUrl?: string;
22
+ disableSearch?: boolean | string;
23
+ onlyRequiredInSamples?: boolean | string;
24
+ showExtensions?: boolean | string | string[];
25
+ sideNavStyle?: SideNavStyleEnum;
26
+ hideSingleRequestSampleTab?: boolean | string;
27
+ menuToggle?: boolean | string;
28
+ jsonSampleExpandLevel?: number | string | "all";
29
+ hideSchemaTitles?: boolean | string;
30
+ simpleOneOfTypeLabel?: boolean | string;
31
+ payloadSampleIdx?: number;
32
+ expandSingleSchemaField?: boolean | string;
33
+ schemaExpansionLevel?: number | string | "all";
34
+ showObjectSchemaExamples?: boolean | string;
35
+ showSecuritySchemeType?: boolean;
36
+ hideSecuritySection?: boolean;
37
+ unstable_ignoreMimeParameters?: boolean;
38
+ enumSkipQuotes?: boolean | string;
39
+ expandDefaultServerVariables?: boolean;
40
+ maxDisplayedEnumValues?: number;
41
+ ignoreNamedSchemas?: string[] | string;
42
+ hideSchemaPattern?: boolean;
43
+ generatedPayloadSamplesMaxDepth?: number;
44
+ nonce?: string;
45
+ hideFab?: boolean;
46
+ minCharacterLengthToInitSearch?: number;
47
+ showWebhookVerb?: boolean;
48
+ }
49
+ export declare function argValueToBoolean(val?: string | boolean, defaultValue?: boolean): boolean;
50
+ export declare class RedocNormalizedOptions {
51
+ static normalizeExpandResponses(value: RedocRawOptions["expandResponses"]): {};
52
+ static normalizeHideHostname(value: RedocRawOptions["hideHostname"]): boolean;
53
+ static normalizeShowExtensions(value: RedocRawOptions["showExtensions"]): string[] | boolean;
54
+ static normalizeSideNavStyle(value: RedocRawOptions["sideNavStyle"]): SideNavStyleEnum;
55
+ static normalizePayloadSampleIdx(value: RedocRawOptions["payloadSampleIdx"]): number;
56
+ private static normalizeJsonSampleExpandLevel;
57
+ private static normalizeGeneratedPayloadSamplesMaxDepth;
58
+ hideHostname: boolean;
59
+ expandResponses: {
60
+ [code: string]: boolean;
61
+ } | "all";
62
+ requiredPropsFirst: boolean;
63
+ sortPropsAlphabetically: boolean;
64
+ sortEnumValuesAlphabetically: boolean;
65
+ sortOperationsAlphabetically: boolean;
66
+ sortTagsAlphabetically: boolean;
67
+ nativeScrollbars: boolean;
68
+ pathInMiddlePanel: boolean;
69
+ untrustedSpec: boolean;
70
+ hideDownloadButton: boolean;
71
+ downloadFileName?: string;
72
+ downloadDefinitionUrl?: string;
73
+ disableSearch: boolean;
74
+ onlyRequiredInSamples: boolean;
75
+ showExtensions: boolean | string[];
76
+ sideNavStyle: SideNavStyleEnum;
77
+ hideSingleRequestSampleTab: boolean;
78
+ menuToggle: boolean;
79
+ jsonSampleExpandLevel: number;
80
+ enumSkipQuotes: boolean;
81
+ hideSchemaTitles: boolean;
82
+ simpleOneOfTypeLabel: boolean;
83
+ payloadSampleIdx: number;
84
+ expandSingleSchemaField: boolean;
85
+ schemaExpansionLevel: number;
86
+ showObjectSchemaExamples: boolean;
87
+ showSecuritySchemeType?: boolean;
88
+ hideSecuritySection?: boolean;
89
+ unstable_ignoreMimeParameters: boolean;
90
+ expandDefaultServerVariables: boolean;
91
+ maxDisplayedEnumValues?: number;
92
+ ignoreNamedSchemas: Set<string>;
93
+ hideSchemaPattern: boolean;
94
+ generatedPayloadSamplesMaxDepth: number;
95
+ hideFab: boolean;
96
+ minCharacterLengthToInitSearch: number;
97
+ showWebhookVerb: boolean;
98
+ nonce?: string;
99
+ constructor(raw: RedocRawOptions, defaults?: RedocRawOptions);
100
+ }
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.RedocNormalizedOptions = exports.argValueToBoolean = exports.SideNavStyleEnum = void 0;
10
+ // @ts-nocheck
11
+ const helpers_1 = require("../utils/helpers");
12
+ var SideNavStyleEnum;
13
+ (function (SideNavStyleEnum) {
14
+ SideNavStyleEnum["SummaryOnly"] = "summary-only";
15
+ SideNavStyleEnum["PathOnly"] = "path-only";
16
+ SideNavStyleEnum["IdOnly"] = "id-only";
17
+ })(SideNavStyleEnum = exports.SideNavStyleEnum || (exports.SideNavStyleEnum = {}));
18
+ function argValueToBoolean(val, defaultValue) {
19
+ if (val === undefined) {
20
+ return defaultValue || false;
21
+ }
22
+ if (typeof val === "string") {
23
+ return val !== "false";
24
+ }
25
+ return val;
26
+ }
27
+ exports.argValueToBoolean = argValueToBoolean;
28
+ function argValueToNumber(value) {
29
+ if (typeof value === "string") {
30
+ return parseInt(value, 10);
31
+ }
32
+ if (typeof value === "number") {
33
+ return value;
34
+ }
35
+ }
36
+ function argValueToExpandLevel(value, defaultValue = 0) {
37
+ if (value === "all")
38
+ return Infinity;
39
+ return argValueToNumber(value) || defaultValue;
40
+ }
41
+ class RedocNormalizedOptions {
42
+ constructor(raw, defaults = {}) {
43
+ var _a;
44
+ raw = { ...defaults, ...raw };
45
+ this.hideHostname = RedocNormalizedOptions.normalizeHideHostname(raw.hideHostname);
46
+ this.expandResponses = RedocNormalizedOptions.normalizeExpandResponses(raw.expandResponses);
47
+ this.requiredPropsFirst = argValueToBoolean(raw.requiredPropsFirst);
48
+ this.sortPropsAlphabetically = argValueToBoolean(raw.sortPropsAlphabetically);
49
+ this.sortEnumValuesAlphabetically = argValueToBoolean(raw.sortEnumValuesAlphabetically);
50
+ this.sortOperationsAlphabetically = argValueToBoolean(raw.sortOperationsAlphabetically);
51
+ this.sortTagsAlphabetically = argValueToBoolean(raw.sortTagsAlphabetically);
52
+ this.nativeScrollbars = argValueToBoolean(raw.nativeScrollbars);
53
+ this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel);
54
+ this.untrustedSpec = argValueToBoolean(raw.untrustedSpec);
55
+ this.hideDownloadButton = argValueToBoolean(raw.hideDownloadButton);
56
+ this.downloadFileName = raw.downloadFileName;
57
+ this.downloadDefinitionUrl = raw.downloadDefinitionUrl;
58
+ this.disableSearch = argValueToBoolean(raw.disableSearch);
59
+ this.onlyRequiredInSamples = argValueToBoolean(raw.onlyRequiredInSamples);
60
+ this.showExtensions = RedocNormalizedOptions.normalizeShowExtensions(raw.showExtensions);
61
+ this.sideNavStyle = RedocNormalizedOptions.normalizeSideNavStyle(raw.sideNavStyle);
62
+ this.hideSingleRequestSampleTab = argValueToBoolean(raw.hideSingleRequestSampleTab);
63
+ this.menuToggle = argValueToBoolean(raw.menuToggle, true);
64
+ this.jsonSampleExpandLevel =
65
+ RedocNormalizedOptions.normalizeJsonSampleExpandLevel(raw.jsonSampleExpandLevel);
66
+ this.enumSkipQuotes = argValueToBoolean(raw.enumSkipQuotes);
67
+ this.hideSchemaTitles = argValueToBoolean(raw.hideSchemaTitles);
68
+ this.simpleOneOfTypeLabel = argValueToBoolean(raw.simpleOneOfTypeLabel);
69
+ this.payloadSampleIdx = RedocNormalizedOptions.normalizePayloadSampleIdx(raw.payloadSampleIdx);
70
+ this.expandSingleSchemaField = argValueToBoolean(raw.expandSingleSchemaField);
71
+ this.schemaExpansionLevel = argValueToExpandLevel(raw.schemaExpansionLevel);
72
+ this.showObjectSchemaExamples = argValueToBoolean(raw.showObjectSchemaExamples);
73
+ this.showSecuritySchemeType = argValueToBoolean(raw.showSecuritySchemeType);
74
+ this.hideSecuritySection = argValueToBoolean(raw.hideSecuritySection);
75
+ this.unstable_ignoreMimeParameters = argValueToBoolean(raw.unstable_ignoreMimeParameters);
76
+ this.expandDefaultServerVariables = argValueToBoolean(raw.expandDefaultServerVariables);
77
+ this.maxDisplayedEnumValues = argValueToNumber(raw.maxDisplayedEnumValues);
78
+ const ignoreNamedSchemas = (0, helpers_1.isArray)(raw.ignoreNamedSchemas)
79
+ ? raw.ignoreNamedSchemas
80
+ : (_a = raw.ignoreNamedSchemas) === null || _a === void 0 ? void 0 : _a.split(",").map((s) => s.trim());
81
+ this.ignoreNamedSchemas = new Set(ignoreNamedSchemas);
82
+ this.hideSchemaPattern = argValueToBoolean(raw.hideSchemaPattern);
83
+ this.generatedPayloadSamplesMaxDepth =
84
+ RedocNormalizedOptions.normalizeGeneratedPayloadSamplesMaxDepth(raw.generatedPayloadSamplesMaxDepth);
85
+ this.nonce = raw.nonce;
86
+ this.hideFab = argValueToBoolean(raw.hideFab);
87
+ this.minCharacterLengthToInitSearch =
88
+ argValueToNumber(raw.minCharacterLengthToInitSearch) || 3;
89
+ this.showWebhookVerb = argValueToBoolean(raw.showWebhookVerb);
90
+ }
91
+ static normalizeExpandResponses(value) {
92
+ if (value === "all") {
93
+ return "all";
94
+ }
95
+ if (typeof value === "string") {
96
+ const res = {};
97
+ value.split(",").forEach((code) => {
98
+ res[code.trim()] = true;
99
+ });
100
+ return res;
101
+ }
102
+ else if (value !== undefined) {
103
+ console.warn(`expandResponses must be a string but received value "${value}" of type ${typeof value}`);
104
+ }
105
+ return {};
106
+ }
107
+ static normalizeHideHostname(value) {
108
+ return !!value;
109
+ }
110
+ static normalizeShowExtensions(value) {
111
+ if (typeof value === "undefined") {
112
+ return false;
113
+ }
114
+ if (value === "") {
115
+ return true;
116
+ }
117
+ if (typeof value !== "string") {
118
+ return value;
119
+ }
120
+ switch (value) {
121
+ case "true":
122
+ return true;
123
+ case "false":
124
+ return false;
125
+ default:
126
+ return value.split(",").map((ext) => ext.trim());
127
+ }
128
+ }
129
+ static normalizeSideNavStyle(value) {
130
+ const defaultValue = SideNavStyleEnum.SummaryOnly;
131
+ if (typeof value !== "string") {
132
+ return defaultValue;
133
+ }
134
+ switch (value) {
135
+ case defaultValue:
136
+ return value;
137
+ case SideNavStyleEnum.PathOnly:
138
+ return SideNavStyleEnum.PathOnly;
139
+ case SideNavStyleEnum.IdOnly:
140
+ return SideNavStyleEnum.IdOnly;
141
+ default:
142
+ return defaultValue;
143
+ }
144
+ }
145
+ static normalizePayloadSampleIdx(value) {
146
+ if (typeof value === "number") {
147
+ return Math.max(0, value); // always greater or equal than 0
148
+ }
149
+ if (typeof value === "string") {
150
+ return isFinite(value) ? parseInt(value, 10) : 0;
151
+ }
152
+ return 0;
153
+ }
154
+ static normalizeJsonSampleExpandLevel(level) {
155
+ if (level === "all") {
156
+ return +Infinity;
157
+ }
158
+ if (!isNaN(Number(level))) {
159
+ return Math.ceil(Number(level));
160
+ }
161
+ return 2;
162
+ }
163
+ static normalizeGeneratedPayloadSamplesMaxDepth(value) {
164
+ if (!isNaN(Number(value))) {
165
+ return Math.max(0, Number(value));
166
+ }
167
+ return 10;
168
+ }
169
+ }
170
+ exports.RedocNormalizedOptions = RedocNormalizedOptions;
@@ -0,0 +1,2 @@
1
+ export * from "./open-api";
2
+ export declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ __exportStar(require("./open-api"), exports);