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.
- package/LICENSE +21 -0
- package/README.md +194 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +194 -0
- package/lib/markdown/createDeprecationNotice.d.ts +6 -0
- package/lib/markdown/createDeprecationNotice.js +19 -0
- package/lib/markdown/createDescription.d.ts +1 -0
- package/lib/markdown/createDescription.js +16 -0
- package/lib/markdown/createDetails.d.ts +2 -0
- package/lib/markdown/createDetails.js +18 -0
- package/lib/markdown/createDetailsSummary.d.ts +2 -0
- package/lib/markdown/createDetailsSummary.js +18 -0
- package/lib/markdown/createFullWidthTable.d.ts +2 -0
- package/lib/markdown/createFullWidthTable.js +18 -0
- package/lib/markdown/createParamsDetails.d.ts +7 -0
- package/lib/markdown/createParamsDetails.js +44 -0
- package/lib/markdown/createParamsTable.d.ts +7 -0
- package/lib/markdown/createParamsTable.js +80 -0
- package/lib/markdown/createRequestBodyDetails.d.ts +6 -0
- package/lib/markdown/createRequestBodyDetails.js +14 -0
- package/lib/markdown/createRequestBodyTable.d.ts +6 -0
- package/lib/markdown/createRequestBodyTable.js +14 -0
- package/lib/markdown/createSchemaDetails.d.ts +14 -0
- package/lib/markdown/createSchemaDetails.js +241 -0
- package/lib/markdown/createSchemaTable.d.ts +14 -0
- package/lib/markdown/createSchemaTable.js +217 -0
- package/lib/markdown/createStatusCodes.d.ts +6 -0
- package/lib/markdown/createStatusCodes.js +47 -0
- package/lib/markdown/createVersionBadge.d.ts +1 -0
- package/lib/markdown/createVersionBadge.js +20 -0
- package/lib/markdown/index.d.ts +3 -0
- package/lib/markdown/index.js +43 -0
- package/lib/markdown/schema.d.ts +3 -0
- package/lib/markdown/schema.js +100 -0
- package/lib/markdown/schema.test.d.ts +1 -0
- package/lib/markdown/schema.test.js +171 -0
- package/lib/markdown/utils.d.ts +7 -0
- package/lib/markdown/utils.js +33 -0
- package/lib/openapi/createExample.d.ts +2 -0
- package/lib/openapi/createExample.js +113 -0
- package/lib/openapi/index.d.ts +1 -0
- package/lib/openapi/index.js +12 -0
- package/lib/openapi/openapi.d.ts +11 -0
- package/lib/openapi/openapi.js +233 -0
- package/lib/openapi/openapi.test.d.ts +1 -0
- package/lib/openapi/openapi.test.js +33 -0
- package/lib/openapi/types.d.ts +331 -0
- package/lib/openapi/types.js +8 -0
- package/lib/options.d.ts +4 -0
- package/lib/options.js +18 -0
- package/lib/sidebars/index.d.ts +3 -0
- package/lib/sidebars/index.js +89 -0
- package/lib/types.d.ts +68 -0
- package/lib/types.js +8 -0
- package/package.json +58 -0
- package/src/index.ts +244 -0
- package/src/markdown/createDeprecationNotice.ts +30 -0
- package/src/markdown/createDescription.ts +13 -0
- package/src/markdown/createDetails.ts +16 -0
- package/src/markdown/createDetailsSummary.ts +16 -0
- package/src/markdown/createFullWidthTable.ts +16 -0
- package/src/markdown/createParamsDetails.ts +53 -0
- package/src/markdown/createParamsTable.ts +102 -0
- package/src/markdown/createRequestBodyDetails.ts +17 -0
- package/src/markdown/createRequestBodyTable.ts +17 -0
- package/src/markdown/createSchemaDetails.ts +302 -0
- package/src/markdown/createSchemaTable.ts +275 -0
- package/src/markdown/createStatusCodes.ts +52 -0
- package/src/markdown/createVersionBadge.ts +18 -0
- package/src/markdown/index.ts +55 -0
- package/src/markdown/schema.test.ts +196 -0
- package/src/markdown/schema.ts +115 -0
- package/src/markdown/utils.ts +39 -0
- package/src/openapi/__fixtures__/examples/openapi.yaml +13 -0
- package/src/openapi/__fixtures__/examples/yogurtstore/_category_.json +4 -0
- package/src/openapi/__fixtures__/examples/yogurtstore/froyo.yaml +13 -0
- package/src/openapi/__fixtures__/examples/yogurtstore/nested/nested.yaml +13 -0
- package/src/openapi/createExample.ts +143 -0
- package/src/openapi/index.ts +8 -0
- package/src/openapi/openapi.test.ts +37 -0
- package/src/openapi/openapi.ts +293 -0
- package/src/openapi/types.ts +430 -0
- package/src/openapi-to-postmanv2.d.ts +10 -0
- package/src/options.ts +20 -0
- package/src/plugin-content-docs-types.d.ts +42 -0
- package/src/plugin-openapi.d.ts +87 -0
- package/src/sidebars/index.ts +121 -0
- package/src/types.ts +97 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,80 @@
|
|
|
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.createParamsTable = void 0;
|
|
10
|
+
const lodash_1 = require("lodash");
|
|
11
|
+
const createDescription_1 = require("./createDescription");
|
|
12
|
+
const createFullWidthTable_1 = require("./createFullWidthTable");
|
|
13
|
+
const schema_1 = require("./schema");
|
|
14
|
+
const utils_1 = require("./utils");
|
|
15
|
+
function createParamsTable({ parameters, type }) {
|
|
16
|
+
if (parameters === undefined) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
const params = parameters.filter((param) => (param === null || param === void 0 ? void 0 : param.in) === type);
|
|
20
|
+
if (params.length === 0) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return (0, createFullWidthTable_1.createFullWidthTable)({
|
|
24
|
+
children: [
|
|
25
|
+
(0, utils_1.create)("thead", {
|
|
26
|
+
children: (0, utils_1.create)("tr", {
|
|
27
|
+
children: (0, utils_1.create)("th", {
|
|
28
|
+
style: { textAlign: "left" },
|
|
29
|
+
children: `${type.charAt(0).toUpperCase() + type.slice(1)} Parameters`,
|
|
30
|
+
}),
|
|
31
|
+
}),
|
|
32
|
+
}),
|
|
33
|
+
(0, utils_1.create)("tbody", {
|
|
34
|
+
children: params.map((param) => (0, utils_1.create)("tr", {
|
|
35
|
+
children: (0, utils_1.create)("td", {
|
|
36
|
+
children: [
|
|
37
|
+
(0, utils_1.create)("code", { children: param.name }),
|
|
38
|
+
(0, utils_1.guard)(param.schema, (schema) => (0, utils_1.create)("span", {
|
|
39
|
+
style: { opacity: "0.6" },
|
|
40
|
+
children: ` ${(0, schema_1.getSchemaName)(schema)}`,
|
|
41
|
+
})),
|
|
42
|
+
(0, utils_1.guard)(param.required, () => [
|
|
43
|
+
(0, utils_1.create)("span", {
|
|
44
|
+
style: { opacity: "0.6" },
|
|
45
|
+
children: " — ",
|
|
46
|
+
}),
|
|
47
|
+
(0, utils_1.create)("strong", {
|
|
48
|
+
style: {
|
|
49
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
50
|
+
color: "var(--openapi-required)",
|
|
51
|
+
},
|
|
52
|
+
children: " REQUIRED",
|
|
53
|
+
}),
|
|
54
|
+
]),
|
|
55
|
+
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(param.schema), (message) => (0, utils_1.create)("div", {
|
|
56
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
57
|
+
children: (0, createDescription_1.createDescription)(message),
|
|
58
|
+
})),
|
|
59
|
+
(0, utils_1.guard)(param.description, (description) => (0, utils_1.create)("div", {
|
|
60
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
61
|
+
children: (0, createDescription_1.createDescription)(description),
|
|
62
|
+
})),
|
|
63
|
+
(0, utils_1.guard)(param.example, (example) => (0, utils_1.create)("div", {
|
|
64
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
65
|
+
children: (0, lodash_1.escape)(`Example: ${example}`),
|
|
66
|
+
})),
|
|
67
|
+
(0, utils_1.guard)(param.examples, (examples) => (0, utils_1.create)("div", {
|
|
68
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
69
|
+
children: Object.entries(examples).map(([k, v]) => (0, utils_1.create)("div", {
|
|
70
|
+
children: (0, lodash_1.escape)(`Example (${k}): ${v.value}`),
|
|
71
|
+
})),
|
|
72
|
+
})),
|
|
73
|
+
],
|
|
74
|
+
}),
|
|
75
|
+
})),
|
|
76
|
+
}),
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
exports.createParamsTable = createParamsTable;
|
|
@@ -0,0 +1,14 @@
|
|
|
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.createRequestBodyDetails = void 0;
|
|
10
|
+
const createSchemaDetails_1 = require("./createSchemaDetails");
|
|
11
|
+
function createRequestBodyDetails({ title, body }) {
|
|
12
|
+
return (0, createSchemaDetails_1.createSchemaDetails)({ title, body });
|
|
13
|
+
}
|
|
14
|
+
exports.createRequestBodyDetails = createRequestBodyDetails;
|
|
@@ -0,0 +1,14 @@
|
|
|
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.createRequestBodyTable = void 0;
|
|
10
|
+
const createSchemaTable_1 = require("./createSchemaTable");
|
|
11
|
+
function createRequestBodyTable({ title, body }) {
|
|
12
|
+
return (0, createSchemaTable_1.createSchemaTable)({ title, body });
|
|
13
|
+
}
|
|
14
|
+
exports.createRequestBodyTable = createRequestBodyTable;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MediaTypeObject } from "../openapi/types";
|
|
2
|
+
interface Props {
|
|
3
|
+
style?: any;
|
|
4
|
+
title: string;
|
|
5
|
+
body: {
|
|
6
|
+
content?: {
|
|
7
|
+
[key: string]: MediaTypeObject;
|
|
8
|
+
};
|
|
9
|
+
description?: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare function createSchemaDetails({ title, body, ...rest }: Props): string | undefined;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,241 @@
|
|
|
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.createSchemaDetails = void 0;
|
|
10
|
+
const createDescription_1 = require("./createDescription");
|
|
11
|
+
const createDetails_1 = require("./createDetails");
|
|
12
|
+
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
13
|
+
const schema_1 = require("./schema");
|
|
14
|
+
const utils_1 = require("./utils");
|
|
15
|
+
const mergeAllOf = require("json-schema-merge-allof");
|
|
16
|
+
function resolveAllOf(allOf) {
|
|
17
|
+
// Use external library to resolve and merge nested allOf schemas
|
|
18
|
+
let properties = {};
|
|
19
|
+
const mergedSchemas = mergeAllOf(allOf, {
|
|
20
|
+
resolvers: {
|
|
21
|
+
readOnly: function () {
|
|
22
|
+
return true;
|
|
23
|
+
},
|
|
24
|
+
example: function () {
|
|
25
|
+
return true;
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
if (mergedSchemas.properties) {
|
|
30
|
+
properties = mergedSchemas.properties;
|
|
31
|
+
}
|
|
32
|
+
const required = allOf.reduce((acc, cur) => {
|
|
33
|
+
if (Array.isArray(cur.required)) {
|
|
34
|
+
const next = [...acc, ...cur.required];
|
|
35
|
+
return next;
|
|
36
|
+
}
|
|
37
|
+
return acc;
|
|
38
|
+
}, []);
|
|
39
|
+
return { properties, required };
|
|
40
|
+
}
|
|
41
|
+
function createRow({ name, schema, required }) {
|
|
42
|
+
const schemaName = (0, schema_1.getSchemaName)(schema, true);
|
|
43
|
+
if (schemaName && (schemaName === "object" || schemaName === "object[]")) {
|
|
44
|
+
return (0, utils_1.create)("SchemaItem", {
|
|
45
|
+
collapsible: true,
|
|
46
|
+
className: "schemaItem",
|
|
47
|
+
children: [
|
|
48
|
+
(0, createDetails_1.createDetails)({
|
|
49
|
+
children: [
|
|
50
|
+
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
51
|
+
children: [
|
|
52
|
+
(0, utils_1.create)("strong", { children: name }),
|
|
53
|
+
(0, utils_1.create)("span", {
|
|
54
|
+
style: { opacity: "0.6" },
|
|
55
|
+
children: ` ${schemaName}`,
|
|
56
|
+
}),
|
|
57
|
+
(0, utils_1.guard)(required, () => [
|
|
58
|
+
(0, utils_1.create)("strong", {
|
|
59
|
+
style: {
|
|
60
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
61
|
+
color: "var(--openapi-required)",
|
|
62
|
+
},
|
|
63
|
+
children: " required",
|
|
64
|
+
}),
|
|
65
|
+
]),
|
|
66
|
+
],
|
|
67
|
+
}),
|
|
68
|
+
(0, utils_1.create)("div", {
|
|
69
|
+
style: { marginLeft: "1rem" },
|
|
70
|
+
children: [
|
|
71
|
+
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
|
|
72
|
+
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
73
|
+
children: (0, createDescription_1.createDescription)(message),
|
|
74
|
+
})),
|
|
75
|
+
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
76
|
+
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
77
|
+
children: (0, createDescription_1.createDescription)(description),
|
|
78
|
+
})),
|
|
79
|
+
createRows({ schema: schema }),
|
|
80
|
+
],
|
|
81
|
+
}),
|
|
82
|
+
],
|
|
83
|
+
}),
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return (0, utils_1.create)("SchemaItem", {
|
|
88
|
+
collapsible: false,
|
|
89
|
+
name,
|
|
90
|
+
required,
|
|
91
|
+
schemaDescription: schema.description,
|
|
92
|
+
schemaName: (0, schema_1.getSchemaName)(schema, true),
|
|
93
|
+
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function createRows({ schema }) {
|
|
97
|
+
// object
|
|
98
|
+
if (schema.properties !== undefined) {
|
|
99
|
+
return (0, utils_1.create)("ul", {
|
|
100
|
+
children: Object.entries(schema.properties).map(([key, val]) => createRow({
|
|
101
|
+
name: key,
|
|
102
|
+
schema: val,
|
|
103
|
+
required: Array.isArray(schema.required)
|
|
104
|
+
? schema.required.includes(key)
|
|
105
|
+
: false,
|
|
106
|
+
})),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
// TODO: This can be a bit complicated types can be missmatched and there can be nested allOfs which need to be resolved before merging properties
|
|
110
|
+
if (schema.allOf !== undefined) {
|
|
111
|
+
const { properties, required } = resolveAllOf(schema.allOf);
|
|
112
|
+
return (0, utils_1.create)("div", {
|
|
113
|
+
children: [
|
|
114
|
+
(0, utils_1.create)("span", {
|
|
115
|
+
className: "badge badge--info",
|
|
116
|
+
style: { marginBottom: "1rem" },
|
|
117
|
+
children: "allOf",
|
|
118
|
+
}),
|
|
119
|
+
(0, utils_1.create)("ul", {
|
|
120
|
+
className: "allOf",
|
|
121
|
+
children: Object.entries(properties).map(([key, val]) => createRow({
|
|
122
|
+
name: key,
|
|
123
|
+
schema: val,
|
|
124
|
+
required: Array.isArray(required)
|
|
125
|
+
? required.includes(key)
|
|
126
|
+
: false,
|
|
127
|
+
})),
|
|
128
|
+
}),
|
|
129
|
+
],
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
// array
|
|
133
|
+
if (schema.items !== undefined) {
|
|
134
|
+
return createRows({ schema: schema.items });
|
|
135
|
+
}
|
|
136
|
+
// primitive
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
function createRowsRoot({ schema }) {
|
|
140
|
+
// object
|
|
141
|
+
if (schema.properties !== undefined) {
|
|
142
|
+
return Object.entries(schema.properties).map(([key, val]) => createRow({
|
|
143
|
+
name: key,
|
|
144
|
+
schema: val,
|
|
145
|
+
required: Array.isArray(schema.required)
|
|
146
|
+
? schema.required.includes(key)
|
|
147
|
+
: false,
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
// TODO: This can be a bit complicated types can be missmatched and there can be nested allOfs which need to be resolved before merging properties
|
|
151
|
+
if (schema.allOf !== undefined) {
|
|
152
|
+
const { properties, required } = resolveAllOf(schema.allOf);
|
|
153
|
+
return Object.entries(properties).map(([key, val]) => createRow({
|
|
154
|
+
name: key,
|
|
155
|
+
schema: val,
|
|
156
|
+
required: Array.isArray(required) ? required.includes(key) : false,
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
// array
|
|
160
|
+
if (schema.items !== undefined) {
|
|
161
|
+
return (0, utils_1.create)("li", {
|
|
162
|
+
children: (0, utils_1.create)("div", {
|
|
163
|
+
children: [createRows({ schema: schema.items })],
|
|
164
|
+
}),
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
// primitive
|
|
168
|
+
return (0, utils_1.create)("li", {
|
|
169
|
+
children: (0, utils_1.create)("div", {
|
|
170
|
+
children: [
|
|
171
|
+
(0, utils_1.create)("span", {
|
|
172
|
+
style: { opacity: "0.6" },
|
|
173
|
+
children: ` ${schema.type}`,
|
|
174
|
+
}),
|
|
175
|
+
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
|
|
176
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
177
|
+
children: (0, createDescription_1.createDescription)(message),
|
|
178
|
+
})),
|
|
179
|
+
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
180
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
181
|
+
children: (0, createDescription_1.createDescription)(description),
|
|
182
|
+
})),
|
|
183
|
+
],
|
|
184
|
+
}),
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
function createSchemaDetails({ title, body, ...rest }) {
|
|
188
|
+
if (body === undefined || body.content === undefined) {
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
// TODO:
|
|
192
|
+
// NOTE: We just pick a random content-type.
|
|
193
|
+
// How common is it to have multiple?
|
|
194
|
+
const randomFirstKey = Object.keys(body.content)[0];
|
|
195
|
+
const firstBody = body.content[randomFirstKey].schema;
|
|
196
|
+
if (firstBody === undefined) {
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
// we don't show the table if there is no properties to show
|
|
200
|
+
if (firstBody.properties !== undefined) {
|
|
201
|
+
if (Object.keys(firstBody.properties).length === 0) {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return (0, createDetails_1.createDetails)({
|
|
206
|
+
...rest,
|
|
207
|
+
children: [
|
|
208
|
+
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
209
|
+
style: { textAlign: "left" },
|
|
210
|
+
children: [
|
|
211
|
+
(0, utils_1.create)("strong", { children: `${title}` }),
|
|
212
|
+
(0, utils_1.guard)(body.required, () => [
|
|
213
|
+
(0, utils_1.create)("strong", {
|
|
214
|
+
style: {
|
|
215
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
216
|
+
color: "var(--openapi-required)",
|
|
217
|
+
},
|
|
218
|
+
children: " required",
|
|
219
|
+
}),
|
|
220
|
+
]),
|
|
221
|
+
],
|
|
222
|
+
}),
|
|
223
|
+
(0, utils_1.create)("div", {
|
|
224
|
+
style: { textAlign: "left", marginLeft: "1rem" },
|
|
225
|
+
children: [
|
|
226
|
+
(0, utils_1.guard)(body.description, () => [
|
|
227
|
+
(0, utils_1.create)("div", {
|
|
228
|
+
style: { marginTop: "1rem", marginBottom: "1rem" },
|
|
229
|
+
children: (0, createDescription_1.createDescription)(body.description),
|
|
230
|
+
}),
|
|
231
|
+
]),
|
|
232
|
+
],
|
|
233
|
+
}),
|
|
234
|
+
(0, utils_1.create)("ul", {
|
|
235
|
+
style: { marginLeft: "1rem" },
|
|
236
|
+
children: createRowsRoot({ schema: firstBody }),
|
|
237
|
+
}),
|
|
238
|
+
],
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
exports.createSchemaDetails = createSchemaDetails;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MediaTypeObject } from "../openapi/types";
|
|
2
|
+
interface Props {
|
|
3
|
+
style?: any;
|
|
4
|
+
title: string;
|
|
5
|
+
body: {
|
|
6
|
+
content?: {
|
|
7
|
+
[key: string]: MediaTypeObject;
|
|
8
|
+
};
|
|
9
|
+
description?: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare function createSchemaTable({ title, body, ...rest }: Props): string | undefined;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,217 @@
|
|
|
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.createSchemaTable = void 0;
|
|
10
|
+
const createDescription_1 = require("./createDescription");
|
|
11
|
+
const createFullWidthTable_1 = require("./createFullWidthTable");
|
|
12
|
+
const schema_1 = require("./schema");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
function resolveAllOf(allOf) {
|
|
15
|
+
// TODO: naive implementation (only supports objects, no directly nested allOf)
|
|
16
|
+
const properties = allOf.reduce((acc, cur) => {
|
|
17
|
+
if (cur.properties !== undefined) {
|
|
18
|
+
const next = { ...acc, ...cur.properties };
|
|
19
|
+
return next;
|
|
20
|
+
}
|
|
21
|
+
return acc;
|
|
22
|
+
}, {});
|
|
23
|
+
const required = allOf.reduce((acc, cur) => {
|
|
24
|
+
if (Array.isArray(cur.required)) {
|
|
25
|
+
const next = [...acc, ...cur.required];
|
|
26
|
+
return next;
|
|
27
|
+
}
|
|
28
|
+
return acc;
|
|
29
|
+
}, []);
|
|
30
|
+
return { properties, required };
|
|
31
|
+
}
|
|
32
|
+
function createRow({ name, schema, required }) {
|
|
33
|
+
return (0, utils_1.create)("tr", {
|
|
34
|
+
children: (0, utils_1.create)("td", {
|
|
35
|
+
children: [
|
|
36
|
+
(0, utils_1.create)("code", { children: name }),
|
|
37
|
+
(0, utils_1.create)("span", {
|
|
38
|
+
style: { opacity: "0.6" },
|
|
39
|
+
children: ` ${(0, schema_1.getSchemaName)(schema, true)}`,
|
|
40
|
+
}),
|
|
41
|
+
(0, utils_1.guard)(required, () => [
|
|
42
|
+
(0, utils_1.create)("span", {
|
|
43
|
+
style: { opacity: "0.6" },
|
|
44
|
+
children: " — ",
|
|
45
|
+
}),
|
|
46
|
+
(0, utils_1.create)("strong", {
|
|
47
|
+
style: {
|
|
48
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
49
|
+
color: "var(--openapi-required)",
|
|
50
|
+
},
|
|
51
|
+
children: " REQUIRED",
|
|
52
|
+
}),
|
|
53
|
+
]),
|
|
54
|
+
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
|
|
55
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
56
|
+
children: (0, createDescription_1.createDescription)(message),
|
|
57
|
+
})),
|
|
58
|
+
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
59
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
60
|
+
children: (0, createDescription_1.createDescription)(description),
|
|
61
|
+
})),
|
|
62
|
+
createRows({ schema: schema }),
|
|
63
|
+
],
|
|
64
|
+
}),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function createRows({ schema }) {
|
|
68
|
+
// object
|
|
69
|
+
if (schema.properties !== undefined) {
|
|
70
|
+
return (0, createFullWidthTable_1.createFullWidthTable)({
|
|
71
|
+
style: {
|
|
72
|
+
marginTop: "var(--ifm-table-cell-padding)",
|
|
73
|
+
marginBottom: "0px",
|
|
74
|
+
},
|
|
75
|
+
children: (0, utils_1.create)("tbody", {
|
|
76
|
+
children: Object.entries(schema.properties).map(([key, val]) => createRow({
|
|
77
|
+
name: key,
|
|
78
|
+
schema: val,
|
|
79
|
+
required: Array.isArray(schema.required)
|
|
80
|
+
? schema.required.includes(key)
|
|
81
|
+
: false,
|
|
82
|
+
})),
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// TODO: This can be a bit complicated types can be missmatched and there can be nested allOfs which need to be resolved before merging properties
|
|
87
|
+
if (schema.allOf !== undefined) {
|
|
88
|
+
const { properties, required } = resolveAllOf(schema.allOf);
|
|
89
|
+
return (0, createFullWidthTable_1.createFullWidthTable)({
|
|
90
|
+
style: {
|
|
91
|
+
marginTop: "var(--ifm-table-cell-padding)",
|
|
92
|
+
marginBottom: "0px",
|
|
93
|
+
},
|
|
94
|
+
children: (0, utils_1.create)("tbody", {
|
|
95
|
+
children: Object.entries(properties).map(([key, val]) => createRow({
|
|
96
|
+
name: key,
|
|
97
|
+
schema: val,
|
|
98
|
+
required: Array.isArray(required) ? required.includes(key) : false,
|
|
99
|
+
})),
|
|
100
|
+
}),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// array
|
|
104
|
+
if (schema.items !== undefined) {
|
|
105
|
+
return createRows({ schema: schema.items });
|
|
106
|
+
}
|
|
107
|
+
// primitive
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
function createRowsRoot({ schema }) {
|
|
111
|
+
// object
|
|
112
|
+
if (schema.properties !== undefined) {
|
|
113
|
+
return Object.entries(schema.properties).map(([key, val]) => createRow({
|
|
114
|
+
name: key,
|
|
115
|
+
schema: val,
|
|
116
|
+
required: Array.isArray(schema.required)
|
|
117
|
+
? schema.required.includes(key)
|
|
118
|
+
: false,
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
// TODO: This can be a bit complicated types can be missmatched and there can be nested allOfs which need to be resolved before merging properties
|
|
122
|
+
if (schema.allOf !== undefined) {
|
|
123
|
+
const { properties, required } = resolveAllOf(schema.allOf);
|
|
124
|
+
return Object.entries(properties).map(([key, val]) => createRow({
|
|
125
|
+
name: key,
|
|
126
|
+
schema: val,
|
|
127
|
+
required: Array.isArray(required) ? required.includes(key) : false,
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
// array
|
|
131
|
+
if (schema.items !== undefined) {
|
|
132
|
+
return (0, utils_1.create)("tr", {
|
|
133
|
+
children: (0, utils_1.create)("td", {
|
|
134
|
+
children: [
|
|
135
|
+
(0, utils_1.create)("span", {
|
|
136
|
+
style: { opacity: "0.6" },
|
|
137
|
+
children: ` ${(0, schema_1.getSchemaName)(schema, true)}`,
|
|
138
|
+
}),
|
|
139
|
+
createRows({ schema: schema.items }),
|
|
140
|
+
],
|
|
141
|
+
}),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
// primitive
|
|
145
|
+
return (0, utils_1.create)("tr", {
|
|
146
|
+
children: (0, utils_1.create)("td", {
|
|
147
|
+
children: [
|
|
148
|
+
(0, utils_1.create)("span", {
|
|
149
|
+
style: { opacity: "0.6" },
|
|
150
|
+
children: ` ${schema.type}`,
|
|
151
|
+
}),
|
|
152
|
+
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
|
|
153
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
154
|
+
children: (0, createDescription_1.createDescription)(message),
|
|
155
|
+
})),
|
|
156
|
+
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
157
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
158
|
+
children: (0, createDescription_1.createDescription)(description),
|
|
159
|
+
})),
|
|
160
|
+
],
|
|
161
|
+
}),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function createSchemaTable({ title, body, ...rest }) {
|
|
165
|
+
if (body === undefined || body.content === undefined) {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
// TODO:
|
|
169
|
+
// NOTE: We just pick a random content-type.
|
|
170
|
+
// How common is it to have multiple?
|
|
171
|
+
const randomFirstKey = Object.keys(body.content)[0];
|
|
172
|
+
const firstBody = body.content[randomFirstKey].schema;
|
|
173
|
+
if (firstBody === undefined) {
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
// we don't show the table if there is no properties to show
|
|
177
|
+
if (firstBody.properties !== undefined) {
|
|
178
|
+
if (Object.keys(firstBody.properties).length === 0) {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return (0, createFullWidthTable_1.createFullWidthTable)({
|
|
183
|
+
...rest,
|
|
184
|
+
children: [
|
|
185
|
+
(0, utils_1.create)("thead", {
|
|
186
|
+
children: (0, utils_1.create)("tr", {
|
|
187
|
+
children: (0, utils_1.create)("th", {
|
|
188
|
+
style: { textAlign: "left" },
|
|
189
|
+
children: [
|
|
190
|
+
`${title} `,
|
|
191
|
+
(0, utils_1.guard)(body.required, () => [
|
|
192
|
+
(0, utils_1.create)("span", {
|
|
193
|
+
style: { opacity: "0.6" },
|
|
194
|
+
children: " — ",
|
|
195
|
+
}),
|
|
196
|
+
(0, utils_1.create)("strong", {
|
|
197
|
+
style: {
|
|
198
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
199
|
+
color: "var(--openapi-required)",
|
|
200
|
+
},
|
|
201
|
+
children: " REQUIRED",
|
|
202
|
+
}),
|
|
203
|
+
]),
|
|
204
|
+
(0, utils_1.create)("div", {
|
|
205
|
+
children: (0, createDescription_1.createDescription)(body.description),
|
|
206
|
+
}),
|
|
207
|
+
],
|
|
208
|
+
}),
|
|
209
|
+
}),
|
|
210
|
+
}),
|
|
211
|
+
(0, utils_1.create)("tbody", {
|
|
212
|
+
children: createRowsRoot({ schema: firstBody }),
|
|
213
|
+
}),
|
|
214
|
+
],
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
exports.createSchemaTable = createSchemaTable;
|
|
@@ -0,0 +1,47 @@
|
|
|
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.createStatusCodes = void 0;
|
|
10
|
+
const createDescription_1 = require("./createDescription");
|
|
11
|
+
const createSchemaDetails_1 = require("./createSchemaDetails");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
function createStatusCodes({ responses }) {
|
|
14
|
+
if (responses === undefined) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
const codes = Object.keys(responses);
|
|
18
|
+
if (codes.length === 0) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return (0, utils_1.create)("div", {
|
|
22
|
+
children: [
|
|
23
|
+
(0, utils_1.create)("Tabs", {
|
|
24
|
+
children: codes.map((code) => {
|
|
25
|
+
return (0, utils_1.create)("TabItem", {
|
|
26
|
+
label: code,
|
|
27
|
+
value: code,
|
|
28
|
+
children: [
|
|
29
|
+
(0, utils_1.create)("div", {
|
|
30
|
+
children: (0, createDescription_1.createDescription)(responses[code].description),
|
|
31
|
+
}),
|
|
32
|
+
(0, utils_1.create)("div", {
|
|
33
|
+
children: (0, createSchemaDetails_1.createSchemaDetails)({
|
|
34
|
+
title: "Schema",
|
|
35
|
+
body: {
|
|
36
|
+
content: responses[code].content,
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
}),
|
|
43
|
+
}),
|
|
44
|
+
],
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.createStatusCodes = createStatusCodes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createVersionBadge(version: string | undefined): string;
|