docusaurus-plugin-openapi-docs 1.0.0

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 (89) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +194 -0
  3. package/lib/index.d.ts +3 -0
  4. package/lib/index.js +194 -0
  5. package/lib/markdown/createDeprecationNotice.d.ts +6 -0
  6. package/lib/markdown/createDeprecationNotice.js +19 -0
  7. package/lib/markdown/createDescription.d.ts +1 -0
  8. package/lib/markdown/createDescription.js +16 -0
  9. package/lib/markdown/createDetails.d.ts +2 -0
  10. package/lib/markdown/createDetails.js +18 -0
  11. package/lib/markdown/createDetailsSummary.d.ts +2 -0
  12. package/lib/markdown/createDetailsSummary.js +18 -0
  13. package/lib/markdown/createFullWidthTable.d.ts +2 -0
  14. package/lib/markdown/createFullWidthTable.js +18 -0
  15. package/lib/markdown/createParamsDetails.d.ts +7 -0
  16. package/lib/markdown/createParamsDetails.js +44 -0
  17. package/lib/markdown/createParamsTable.d.ts +7 -0
  18. package/lib/markdown/createParamsTable.js +80 -0
  19. package/lib/markdown/createRequestBodyDetails.d.ts +6 -0
  20. package/lib/markdown/createRequestBodyDetails.js +14 -0
  21. package/lib/markdown/createRequestBodyTable.d.ts +6 -0
  22. package/lib/markdown/createRequestBodyTable.js +14 -0
  23. package/lib/markdown/createSchemaDetails.d.ts +14 -0
  24. package/lib/markdown/createSchemaDetails.js +241 -0
  25. package/lib/markdown/createSchemaTable.d.ts +14 -0
  26. package/lib/markdown/createSchemaTable.js +217 -0
  27. package/lib/markdown/createStatusCodes.d.ts +6 -0
  28. package/lib/markdown/createStatusCodes.js +47 -0
  29. package/lib/markdown/createVersionBadge.d.ts +1 -0
  30. package/lib/markdown/createVersionBadge.js +20 -0
  31. package/lib/markdown/index.d.ts +3 -0
  32. package/lib/markdown/index.js +43 -0
  33. package/lib/markdown/schema.d.ts +3 -0
  34. package/lib/markdown/schema.js +100 -0
  35. package/lib/markdown/schema.test.d.ts +1 -0
  36. package/lib/markdown/schema.test.js +171 -0
  37. package/lib/markdown/utils.d.ts +7 -0
  38. package/lib/markdown/utils.js +33 -0
  39. package/lib/openapi/createExample.d.ts +2 -0
  40. package/lib/openapi/createExample.js +113 -0
  41. package/lib/openapi/index.d.ts +1 -0
  42. package/lib/openapi/index.js +12 -0
  43. package/lib/openapi/openapi.d.ts +11 -0
  44. package/lib/openapi/openapi.js +233 -0
  45. package/lib/openapi/openapi.test.d.ts +1 -0
  46. package/lib/openapi/openapi.test.js +33 -0
  47. package/lib/openapi/types.d.ts +331 -0
  48. package/lib/openapi/types.js +8 -0
  49. package/lib/options.d.ts +4 -0
  50. package/lib/options.js +18 -0
  51. package/lib/sidebars/index.d.ts +3 -0
  52. package/lib/sidebars/index.js +89 -0
  53. package/lib/types.d.ts +68 -0
  54. package/lib/types.js +8 -0
  55. package/package.json +58 -0
  56. package/src/index.ts +244 -0
  57. package/src/markdown/createDeprecationNotice.ts +30 -0
  58. package/src/markdown/createDescription.ts +13 -0
  59. package/src/markdown/createDetails.ts +16 -0
  60. package/src/markdown/createDetailsSummary.ts +16 -0
  61. package/src/markdown/createFullWidthTable.ts +16 -0
  62. package/src/markdown/createParamsDetails.ts +53 -0
  63. package/src/markdown/createParamsTable.ts +102 -0
  64. package/src/markdown/createRequestBodyDetails.ts +17 -0
  65. package/src/markdown/createRequestBodyTable.ts +17 -0
  66. package/src/markdown/createSchemaDetails.ts +302 -0
  67. package/src/markdown/createSchemaTable.ts +275 -0
  68. package/src/markdown/createStatusCodes.ts +52 -0
  69. package/src/markdown/createVersionBadge.ts +18 -0
  70. package/src/markdown/index.ts +55 -0
  71. package/src/markdown/schema.test.ts +196 -0
  72. package/src/markdown/schema.ts +115 -0
  73. package/src/markdown/utils.ts +39 -0
  74. package/src/openapi/__fixtures__/examples/openapi.yaml +13 -0
  75. package/src/openapi/__fixtures__/examples/yogurtstore/_category_.json +4 -0
  76. package/src/openapi/__fixtures__/examples/yogurtstore/froyo.yaml +13 -0
  77. package/src/openapi/__fixtures__/examples/yogurtstore/nested/nested.yaml +13 -0
  78. package/src/openapi/createExample.ts +143 -0
  79. package/src/openapi/index.ts +8 -0
  80. package/src/openapi/openapi.test.ts +37 -0
  81. package/src/openapi/openapi.ts +293 -0
  82. package/src/openapi/types.ts +430 -0
  83. package/src/openapi-to-postmanv2.d.ts +10 -0
  84. package/src/options.ts +20 -0
  85. package/src/plugin-content-docs-types.d.ts +42 -0
  86. package/src/plugin-openapi.d.ts +87 -0
  87. package/src/sidebars/index.ts +121 -0
  88. package/src/types.ts +97 -0
  89. package/tsconfig.json +7 -0
@@ -0,0 +1,20 @@
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.createVersionBadge = void 0;
10
+ const utils_1 = require("./utils");
11
+ function createVersionBadge(version) {
12
+ return (0, utils_1.guard)(version, (version) => [
13
+ (0, utils_1.create)("span", {
14
+ className: "theme-doc-version-badge badge badge--secondary",
15
+ children: `Version: ${escape(version)}`,
16
+ }),
17
+ `\n\n`,
18
+ ]);
19
+ }
20
+ exports.createVersionBadge = createVersionBadge;
@@ -0,0 +1,3 @@
1
+ import { ApiPageMetadata, InfoPageMetadata } from "../types";
2
+ export declare function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, parameters, requestBody, responses, }, }: ApiPageMetadata): string;
3
+ export declare function createInfoPageMD({ info: { title, version, description }, }: InfoPageMetadata): string;
@@ -0,0 +1,43 @@
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.createInfoPageMD = exports.createApiPageMD = void 0;
10
+ const lodash_1 = require("lodash");
11
+ const createDeprecationNotice_1 = require("./createDeprecationNotice");
12
+ const createDescription_1 = require("./createDescription");
13
+ const createParamsDetails_1 = require("./createParamsDetails");
14
+ const createRequestBodyDetails_1 = require("./createRequestBodyDetails");
15
+ const createStatusCodes_1 = require("./createStatusCodes");
16
+ const createVersionBadge_1 = require("./createVersionBadge");
17
+ const utils_1 = require("./utils");
18
+ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, parameters, requestBody, responses, }, }) {
19
+ return (0, utils_1.render)([
20
+ `import ParamsItem from "@theme/ParamsItem";\n`,
21
+ `import SchemaItem from "@theme/SchemaItem"\n`,
22
+ `import Tabs from "@theme/Tabs";\n`,
23
+ `import TabItem from "@theme/TabItem";\n\n`,
24
+ `## ${(0, lodash_1.escape)(title)}\n\n`,
25
+ (0, createDeprecationNotice_1.createDeprecationNotice)({ deprecated, description: deprecatedDescription }),
26
+ (0, createDescription_1.createDescription)((0, lodash_1.escape)(description)),
27
+ (0, createParamsDetails_1.createParamsDetails)({ parameters, type: "path" }),
28
+ (0, createParamsDetails_1.createParamsDetails)({ parameters, type: "query" }),
29
+ (0, createParamsDetails_1.createParamsDetails)({ parameters, type: "header" }),
30
+ (0, createParamsDetails_1.createParamsDetails)({ parameters, type: "cookie" }),
31
+ (0, createRequestBodyDetails_1.createRequestBodyDetails)({ title: "Request Body", body: requestBody }),
32
+ (0, createStatusCodes_1.createStatusCodes)({ responses }),
33
+ ]);
34
+ }
35
+ exports.createApiPageMD = createApiPageMD;
36
+ function createInfoPageMD({ info: { title, version, description }, }) {
37
+ return (0, utils_1.render)([
38
+ (0, createVersionBadge_1.createVersionBadge)(version),
39
+ `# ${(0, lodash_1.escape)(title)}\n\n`,
40
+ (0, createDescription_1.createDescription)(description),
41
+ ]);
42
+ }
43
+ exports.createInfoPageMD = createInfoPageMD;
@@ -0,0 +1,3 @@
1
+ import { SchemaObject } from "../openapi/types";
2
+ export declare function getSchemaName(schema: SchemaObject, circular?: boolean): string;
3
+ export declare function getQualifierMessage(schema?: SchemaObject): string | undefined;
@@ -0,0 +1,100 @@
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.getQualifierMessage = exports.getSchemaName = void 0;
10
+ function prettyName(schema, circular) {
11
+ var _a, _b, _c;
12
+ if (schema.$ref) {
13
+ return schema.$ref.replace("#/components/schemas/", "") + circular
14
+ ? " (circular)"
15
+ : "";
16
+ }
17
+ if (schema.format) {
18
+ return schema.format;
19
+ }
20
+ if (schema.allOf) {
21
+ return "object";
22
+ }
23
+ if (schema.type === "object") {
24
+ return (_b = (_a = schema.xml) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : schema.type;
25
+ }
26
+ return (_c = schema.title) !== null && _c !== void 0 ? _c : schema.type;
27
+ }
28
+ function getSchemaName(schema, circular) {
29
+ var _a;
30
+ if (schema.items) {
31
+ return prettyName(schema.items, circular) + "[]";
32
+ }
33
+ return (_a = prettyName(schema, circular)) !== null && _a !== void 0 ? _a : "";
34
+ }
35
+ exports.getSchemaName = getSchemaName;
36
+ function getQualifierMessage(schema) {
37
+ // TODO:
38
+ // - maxItems
39
+ // - minItems
40
+ // - uniqueItems
41
+ // - maxProperties
42
+ // - minProperties
43
+ // - multipleOf
44
+ if (!schema) {
45
+ return undefined;
46
+ }
47
+ if (schema.items) {
48
+ return getQualifierMessage(schema.items);
49
+ }
50
+ let message = "**Possible values:** ";
51
+ let qualifierGroups = [];
52
+ if (schema.minLength || schema.maxLength) {
53
+ let lengthQualifier = "";
54
+ if (schema.minLength) {
55
+ lengthQualifier += `${schema.minLength} ≤ `;
56
+ }
57
+ lengthQualifier += "length";
58
+ if (schema.maxLength) {
59
+ lengthQualifier += ` ≤ ${schema.maxLength}`;
60
+ }
61
+ qualifierGroups.push(lengthQualifier);
62
+ }
63
+ if (schema.minimum ||
64
+ schema.maximum ||
65
+ typeof schema.exclusiveMinimum === "number" ||
66
+ typeof schema.exclusiveMaximum === "number") {
67
+ let minmaxQualifier = "";
68
+ if (typeof schema.exclusiveMinimum === "number") {
69
+ minmaxQualifier += `${schema.exclusiveMinimum} < `;
70
+ }
71
+ else if (schema.minimum && !schema.exclusiveMinimum) {
72
+ minmaxQualifier += `${schema.minimum} ≤ `;
73
+ }
74
+ else if (schema.minimum && schema.exclusiveMinimum === true) {
75
+ minmaxQualifier += `${schema.minimum} < `;
76
+ }
77
+ minmaxQualifier += "value";
78
+ if (typeof schema.exclusiveMaximum === "number") {
79
+ minmaxQualifier += ` < ${schema.exclusiveMaximum}`;
80
+ }
81
+ else if (schema.maximum && !schema.exclusiveMaximum) {
82
+ minmaxQualifier += ` ≤ ${schema.maximum}`;
83
+ }
84
+ else if (schema.maximum && schema.exclusiveMaximum === true) {
85
+ minmaxQualifier += ` < ${schema.maximum}`;
86
+ }
87
+ qualifierGroups.push(minmaxQualifier);
88
+ }
89
+ if (schema.pattern) {
90
+ qualifierGroups.push(`Value must match regular expression \`${schema.pattern}\``);
91
+ }
92
+ if (schema.enum) {
93
+ qualifierGroups.push(`[${schema.enum.map((e) => `\`${e}\``).join(", ")}]`);
94
+ }
95
+ if (qualifierGroups.length === 0) {
96
+ return undefined;
97
+ }
98
+ return message + qualifierGroups.join(", ");
99
+ }
100
+ exports.getQualifierMessage = getQualifierMessage;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,171 @@
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
+ const schema_1 = require("./schema");
10
+ describe("getQualifierMessage", () => {
11
+ it("should render nothing", () => {
12
+ const actual = (0, schema_1.getQualifierMessage)({});
13
+ expect(actual).toBeUndefined();
14
+ });
15
+ //
16
+ // minLength + maxLength
17
+ //
18
+ it("should render minLength", () => {
19
+ const expected = "**Possible values:** 1 ≤ length";
20
+ const actual = (0, schema_1.getQualifierMessage)({ minLength: 1 });
21
+ expect(actual).toBe(expected);
22
+ });
23
+ it("should render maxLength", () => {
24
+ const expected = "**Possible values:** length ≤ 40";
25
+ const actual = (0, schema_1.getQualifierMessage)({ maxLength: 40 });
26
+ expect(actual).toBe(expected);
27
+ });
28
+ it("should render minLength and maxLength", () => {
29
+ const expected = "**Possible values:** 1 ≤ length ≤ 40";
30
+ const actual = (0, schema_1.getQualifierMessage)({ minLength: 1, maxLength: 40 });
31
+ expect(actual).toBe(expected);
32
+ });
33
+ //
34
+ // pattern
35
+ //
36
+ it("should render pattern", () => {
37
+ const expected = "**Possible values:** Value must match regular expression `^[a-zA-Z0-9_-]*$`";
38
+ const actual = (0, schema_1.getQualifierMessage)({ pattern: "^[a-zA-Z0-9_-]*$" });
39
+ expect(actual).toBe(expected);
40
+ });
41
+ it("should render multiple string qualifiers", () => {
42
+ const expected = "**Possible values:** 1 ≤ length ≤ 40, Value must match regular expression `^[a-zA-Z0-9_-]*$`";
43
+ const actual = (0, schema_1.getQualifierMessage)({
44
+ minLength: 1,
45
+ maxLength: 40,
46
+ pattern: "^[a-zA-Z0-9_-]*$",
47
+ });
48
+ expect(actual).toBe(expected);
49
+ });
50
+ //
51
+ // enum
52
+ //
53
+ it("should render enum", () => {
54
+ const expected = "**Possible values:** [`cat`, `dog`, `mouse`]";
55
+ const actual = (0, schema_1.getQualifierMessage)({ enum: ["cat", "dog", "mouse"] });
56
+ expect(actual).toBe(expected);
57
+ });
58
+ //
59
+ // minimum + maximum + exclusiveMinimum + exclusiveMaximum
60
+ //
61
+ it("should render minimum", () => {
62
+ const expected = "**Possible values:** 1 ≤ value";
63
+ const actual = (0, schema_1.getQualifierMessage)({ minimum: 1 });
64
+ expect(actual).toBe(expected);
65
+ });
66
+ it("should render maximum", () => {
67
+ const expected = "**Possible values:** value ≤ 40";
68
+ const actual = (0, schema_1.getQualifierMessage)({ maximum: 40 });
69
+ expect(actual).toBe(expected);
70
+ });
71
+ it("should render numeric exclusiveMinimum", () => {
72
+ const expected = "**Possible values:** 1 < value";
73
+ const actual = (0, schema_1.getQualifierMessage)({ exclusiveMinimum: 1 });
74
+ expect(actual).toBe(expected);
75
+ });
76
+ it("should render numeric exclusiveMaximum", () => {
77
+ const expected = "**Possible values:** value < 40";
78
+ const actual = (0, schema_1.getQualifierMessage)({ exclusiveMaximum: 40 });
79
+ expect(actual).toBe(expected);
80
+ });
81
+ it("should render boolean exclusiveMinimum", () => {
82
+ const expected = "**Possible values:** 1 < value";
83
+ const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, exclusiveMinimum: true });
84
+ expect(actual).toBe(expected);
85
+ });
86
+ it("should render boolean exclusiveMaximum", () => {
87
+ const expected = "**Possible values:** value < 40";
88
+ const actual = (0, schema_1.getQualifierMessage)({ maximum: 40, exclusiveMaximum: true });
89
+ expect(actual).toBe(expected);
90
+ });
91
+ it("should render minimum when exclusiveMinimum is false", () => {
92
+ const expected = "**Possible values:** 1 ≤ value";
93
+ const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, exclusiveMinimum: false });
94
+ expect(actual).toBe(expected);
95
+ });
96
+ it("should render maximum when exclusiveMaximum is false", () => {
97
+ const expected = "**Possible values:** value ≤ 40";
98
+ const actual = (0, schema_1.getQualifierMessage)({
99
+ maximum: 40,
100
+ exclusiveMaximum: false,
101
+ });
102
+ expect(actual).toBe(expected);
103
+ });
104
+ it("should render minimum and maximum", () => {
105
+ const expected = "**Possible values:** 1 ≤ value ≤ 40";
106
+ const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, maximum: 40 });
107
+ expect(actual).toBe(expected);
108
+ });
109
+ it("should render boolean exclusiveMinimum and maximum", () => {
110
+ const expected = "**Possible values:** 1 < value ≤ 40";
111
+ const actual = (0, schema_1.getQualifierMessage)({
112
+ minimum: 1,
113
+ maximum: 40,
114
+ exclusiveMinimum: true,
115
+ });
116
+ expect(actual).toBe(expected);
117
+ });
118
+ it("should render minimum and boolean exclusiveMaximum", () => {
119
+ const expected = "**Possible values:** 1 ≤ value < 40";
120
+ const actual = (0, schema_1.getQualifierMessage)({
121
+ minimum: 1,
122
+ maximum: 40,
123
+ exclusiveMaximum: true,
124
+ });
125
+ expect(actual).toBe(expected);
126
+ });
127
+ it("should render numeric exclusiveMinimum and maximum", () => {
128
+ const expected = "**Possible values:** 1 < value ≤ 40";
129
+ const actual = (0, schema_1.getQualifierMessage)({
130
+ exclusiveMinimum: 1,
131
+ maximum: 40,
132
+ });
133
+ expect(actual).toBe(expected);
134
+ });
135
+ it("should render minimum and numeric exclusiveMaximum", () => {
136
+ const expected = "**Possible values:** 1 ≤ value < 40";
137
+ const actual = (0, schema_1.getQualifierMessage)({
138
+ minimum: 1,
139
+ exclusiveMaximum: 40,
140
+ });
141
+ expect(actual).toBe(expected);
142
+ });
143
+ it("should render numeric exclusiveMinimum and boolean exclusiveMaximum", () => {
144
+ const expected = "**Possible values:** 1 < value < 40";
145
+ const actual = (0, schema_1.getQualifierMessage)({
146
+ exclusiveMinimum: 1,
147
+ maximum: 40,
148
+ exclusiveMaximum: true,
149
+ });
150
+ expect(actual).toBe(expected);
151
+ });
152
+ it("should render nothing with empty boolean exclusiveMinimum", () => {
153
+ const actual = (0, schema_1.getQualifierMessage)({
154
+ exclusiveMinimum: true,
155
+ });
156
+ expect(actual).toBeUndefined();
157
+ });
158
+ it("should render nothing with empty boolean exclusiveMaximum", () => {
159
+ const actual = (0, schema_1.getQualifierMessage)({
160
+ exclusiveMaximum: true,
161
+ });
162
+ expect(actual).toBeUndefined();
163
+ });
164
+ it("should render nothing with empty boolean exclusiveMinimum and exclusiveMaximum", () => {
165
+ const actual = (0, schema_1.getQualifierMessage)({
166
+ exclusiveMinimum: true,
167
+ exclusiveMaximum: true,
168
+ });
169
+ expect(actual).toBeUndefined();
170
+ });
171
+ });
@@ -0,0 +1,7 @@
1
+ export declare type Children = string | undefined | (string | undefined)[];
2
+ export declare type Props = Record<string, any> & {
3
+ children?: Children;
4
+ };
5
+ export declare function create(tag: string, props: Props): string;
6
+ export declare function guard<T>(value: T | undefined, cb: (value: T) => Children): string;
7
+ export declare function render(children: Children): string;
@@ -0,0 +1,33 @@
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.render = exports.guard = exports.create = void 0;
10
+ function create(tag, props) {
11
+ const { children, ...rest } = props;
12
+ let propString = "";
13
+ for (const [key, value] of Object.entries(rest)) {
14
+ propString += ` ${key}={${JSON.stringify(value)}}`;
15
+ }
16
+ return `<${tag}${propString}>${render(children)}</${tag}>`;
17
+ }
18
+ exports.create = create;
19
+ function guard(value, cb) {
20
+ if (value) {
21
+ const children = cb(value);
22
+ return render(children);
23
+ }
24
+ return "";
25
+ }
26
+ exports.guard = guard;
27
+ function render(children) {
28
+ if (Array.isArray(children)) {
29
+ return children.filter((c) => c !== undefined).join("");
30
+ }
31
+ return children !== null && children !== void 0 ? children : "";
32
+ }
33
+ exports.render = render;
@@ -0,0 +1,2 @@
1
+ import { SchemaObject } from "./types";
2
+ export declare const sampleFromSchema: (schema?: SchemaObject) => any;
@@ -0,0 +1,113 @@
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.sampleFromSchema = void 0;
10
+ const primitives = {
11
+ string: {
12
+ default: () => "string",
13
+ email: () => "user@example.com",
14
+ date: () => new Date().toISOString().substring(0, 10),
15
+ uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
16
+ hostname: () => "example.com",
17
+ ipv4: () => "198.51.100.42",
18
+ ipv6: () => "2001:0db8:5b96:0000:0000:426f:8e17:642a",
19
+ },
20
+ number: {
21
+ default: () => 0,
22
+ float: () => 0.0,
23
+ },
24
+ integer: {
25
+ default: () => 0,
26
+ },
27
+ boolean: {
28
+ default: (schema) => typeof schema.default === "boolean" ? schema.default : true,
29
+ },
30
+ object: {},
31
+ array: {},
32
+ };
33
+ const sampleFromSchema = (schema = {}) => {
34
+ let { type, example, allOf, properties, items } = schema;
35
+ if (example !== undefined) {
36
+ return example;
37
+ }
38
+ if (allOf) {
39
+ // TODO: We are just assuming it will always be an object for now
40
+ let obj = {
41
+ type: "object",
42
+ properties: {},
43
+ required: [], // NOTE: We shouldn't need to worry about required
44
+ };
45
+ for (let item of allOf) {
46
+ if (item.properties) {
47
+ obj.properties = {
48
+ ...obj.properties,
49
+ ...item.properties,
50
+ };
51
+ }
52
+ }
53
+ return (0, exports.sampleFromSchema)(obj);
54
+ }
55
+ if (!type) {
56
+ if (properties) {
57
+ type = "object";
58
+ }
59
+ else if (items) {
60
+ type = "array";
61
+ }
62
+ else {
63
+ return;
64
+ }
65
+ }
66
+ if (type === "object") {
67
+ let obj = {};
68
+ for (let [name, prop] of Object.entries(properties !== null && properties !== void 0 ? properties : {})) {
69
+ if (prop.deprecated) {
70
+ continue;
71
+ }
72
+ obj[name] = (0, exports.sampleFromSchema)(prop);
73
+ }
74
+ return obj;
75
+ }
76
+ if (type === "array") {
77
+ if (Array.isArray(items === null || items === void 0 ? void 0 : items.anyOf)) {
78
+ return items === null || items === void 0 ? void 0 : items.anyOf.map((item) => (0, exports.sampleFromSchema)(item));
79
+ }
80
+ if (Array.isArray(items === null || items === void 0 ? void 0 : items.oneOf)) {
81
+ return items === null || items === void 0 ? void 0 : items.oneOf.map((item) => (0, exports.sampleFromSchema)(item));
82
+ }
83
+ return [(0, exports.sampleFromSchema)(items)];
84
+ }
85
+ if (schema.enum) {
86
+ if (schema.default) {
87
+ return schema.default;
88
+ }
89
+ return normalizeArray(schema.enum)[0];
90
+ }
91
+ return primitive(schema);
92
+ };
93
+ exports.sampleFromSchema = sampleFromSchema;
94
+ function primitive(schema = {}) {
95
+ let { type, format } = schema;
96
+ if (type === undefined) {
97
+ return;
98
+ }
99
+ let fn = primitives[type].default;
100
+ if (format !== undefined) {
101
+ fn = primitives[type][format] || fn;
102
+ }
103
+ if (fn) {
104
+ return fn(schema);
105
+ }
106
+ return "Unknown Type: " + schema.type;
107
+ }
108
+ function normalizeArray(arr) {
109
+ if (Array.isArray(arr)) {
110
+ return arr;
111
+ }
112
+ return [arr];
113
+ }
@@ -0,0 +1 @@
1
+ export { readOpenapiFiles, processOpenapiFiles } from "./openapi";
@@ -0,0 +1,12 @@
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.processOpenapiFiles = exports.readOpenapiFiles = void 0;
10
+ var openapi_1 = require("./openapi");
11
+ Object.defineProperty(exports, "readOpenapiFiles", { enumerable: true, get: function () { return openapi_1.readOpenapiFiles; } });
12
+ Object.defineProperty(exports, "processOpenapiFiles", { enumerable: true, get: function () { return openapi_1.processOpenapiFiles; } });
@@ -0,0 +1,11 @@
1
+ import { ApiMetadata } from "../types";
2
+ import { OpenApiObjectWithRef } from "./types";
3
+ interface OpenApiFiles {
4
+ source: string;
5
+ sourceDirName: string;
6
+ data: OpenApiObjectWithRef;
7
+ }
8
+ export declare function readOpenapiFiles(openapiPath: string, _options: {}): Promise<OpenApiFiles[]>;
9
+ export declare function processOpenapiFiles(files: OpenApiFiles[]): Promise<ApiMetadata[]>;
10
+ export declare function processOpenapiFile(openapiDataWithRefs: OpenApiObjectWithRef): Promise<ApiMetadata[]>;
11
+ export {};