docusaurus-plugin-openapi-docs 0.0.0-350 → 0.0.0-351

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.
@@ -0,0 +1,2 @@
1
+ import { ContactObject } from "../openapi/types";
2
+ export declare function createContactInfo(contact: ContactObject): string;
@@ -0,0 +1,49 @@
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.createContactInfo = void 0;
10
+ const utils_1 = require("./utils");
11
+ function createContactInfo(contact) {
12
+ if (!contact)
13
+ return "";
14
+ const { name, url, email } = contact;
15
+ return (0, utils_1.create)("div", {
16
+ style: {
17
+ display: "flex",
18
+ flexDirection: "column",
19
+ marginBottom: "var(--ifm-paragraph-margin-bottom)",
20
+ },
21
+ children: [
22
+ (0, utils_1.create)("h3", {
23
+ style: {
24
+ marginBottom: "0.25rem",
25
+ },
26
+ children: "Contact",
27
+ }),
28
+ (0, utils_1.create)("span", {
29
+ children: [
30
+ `${name}: `,
31
+ (0, utils_1.create)("a", {
32
+ href: `mailto:${email}`,
33
+ children: `${email}`,
34
+ }),
35
+ ],
36
+ }),
37
+ (0, utils_1.create)("span", {
38
+ children: [
39
+ "URL: ",
40
+ (0, utils_1.create)("a", {
41
+ href: `${url}`,
42
+ children: `${url}`,
43
+ }),
44
+ ],
45
+ }),
46
+ ],
47
+ });
48
+ }
49
+ exports.createContactInfo = createContactInfo;
@@ -0,0 +1,2 @@
1
+ import { LicenseObject } from "../openapi/types";
2
+ export declare function createLicense(license: LicenseObject): 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.createLicense = void 0;
10
+ const utils_1 = require("./utils");
11
+ function createLicense(license) {
12
+ if (!license)
13
+ return "";
14
+ const { name, url } = license;
15
+ return (0, utils_1.create)("div", {
16
+ style: {
17
+ marginBottom: "var(--ifm-paragraph-margin-bottom)",
18
+ },
19
+ children: [
20
+ (0, utils_1.create)("h3", {
21
+ style: {
22
+ marginBottom: "0.25rem",
23
+ },
24
+ children: "License",
25
+ }),
26
+ (0, utils_1.create)("a", {
27
+ href: url,
28
+ children: name,
29
+ }),
30
+ ],
31
+ });
32
+ }
33
+ exports.createLicense = createLicense;
@@ -0,0 +1 @@
1
+ export declare function createTermsOfService(termsOfService: string | undefined): string;
@@ -0,0 +1,32 @@
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.createTermsOfService = void 0;
10
+ const utils_1 = require("./utils");
11
+ function createTermsOfService(termsOfService) {
12
+ if (!createTermsOfService)
13
+ return "";
14
+ return (0, utils_1.create)("div", {
15
+ style: {
16
+ marginBottom: "var(--ifm-paragraph-margin-bottom)",
17
+ },
18
+ children: [
19
+ (0, utils_1.create)("h3", {
20
+ style: {
21
+ marginBottom: "0.25rem",
22
+ },
23
+ children: "Terms of Service",
24
+ }),
25
+ (0, utils_1.create)("a", {
26
+ href: `${termsOfService}`,
27
+ children: termsOfService,
28
+ }),
29
+ ],
30
+ });
31
+ }
32
+ exports.createTermsOfService = createTermsOfService;
@@ -1,3 +1,3 @@
1
1
  import { ApiPageMetadata, InfoPageMetadata } from "../types";
2
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;
3
+ export declare function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService }, }: InfoPageMetadata): string;
@@ -8,11 +8,14 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.createInfoPageMD = exports.createApiPageMD = void 0;
10
10
  const lodash_1 = require("lodash");
11
+ const createContactInfo_1 = require("./createContactInfo");
11
12
  const createDeprecationNotice_1 = require("./createDeprecationNotice");
12
13
  const createDescription_1 = require("./createDescription");
14
+ const createLicense_1 = require("./createLicense");
13
15
  const createParamsDetails_1 = require("./createParamsDetails");
14
16
  const createRequestBodyDetails_1 = require("./createRequestBodyDetails");
15
17
  const createStatusCodes_1 = require("./createStatusCodes");
18
+ const createTermsOfService_1 = require("./createTermsOfService");
16
19
  const createVersionBadge_1 = require("./createVersionBadge");
17
20
  const utils_1 = require("./utils");
18
21
  function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, parameters, requestBody, responses, }, }) {
@@ -33,11 +36,14 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
33
36
  ]);
34
37
  }
35
38
  exports.createApiPageMD = createApiPageMD;
36
- function createInfoPageMD({ info: { title, version, description }, }) {
39
+ function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService }, }) {
37
40
  return (0, utils_1.render)([
38
41
  (0, createVersionBadge_1.createVersionBadge)(version),
39
42
  `# ${(0, lodash_1.escape)(title)}\n\n`,
40
43
  (0, createDescription_1.createDescription)(description),
44
+ (0, createContactInfo_1.createContactInfo)(contact),
45
+ (0, createTermsOfService_1.createTermsOfService)(termsOfService),
46
+ (0, createLicense_1.createLicense)(license),
41
47
  ]);
42
48
  }
43
49
  exports.createInfoPageMD = createInfoPageMD;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-openapi-docs",
3
3
  "description": "OpenAPI plugin for Docusaurus.",
4
- "version": "0.0.0-350",
4
+ "version": "0.0.0-351",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -60,5 +60,5 @@
60
60
  "engines": {
61
61
  "node": ">=14"
62
62
  },
63
- "gitHead": "c66039acf120aeef0024c18d5ca0d842f38b32a6"
63
+ "gitHead": "475483bcb20b232da5c12ee23c48855dd32ba0d8"
64
64
  }
@@ -0,0 +1,48 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+
8
+ import { ContactObject } from "../openapi/types";
9
+ import { create } from "./utils";
10
+
11
+ export function createContactInfo(contact: ContactObject) {
12
+ if (!contact) return "";
13
+ const { name, url, email } = contact;
14
+
15
+ return create("div", {
16
+ style: {
17
+ display: "flex",
18
+ flexDirection: "column",
19
+ marginBottom: "var(--ifm-paragraph-margin-bottom)",
20
+ },
21
+ children: [
22
+ create("h3", {
23
+ style: {
24
+ marginBottom: "0.25rem",
25
+ },
26
+ children: "Contact",
27
+ }),
28
+ create("span", {
29
+ children: [
30
+ `${name}: `,
31
+ create("a", {
32
+ href: `mailto:${email}`,
33
+ children: `${email}`,
34
+ }),
35
+ ],
36
+ }),
37
+ create("span", {
38
+ children: [
39
+ "URL: ",
40
+ create("a", {
41
+ href: `${url}`,
42
+ children: `${url}`,
43
+ }),
44
+ ],
45
+ }),
46
+ ],
47
+ });
48
+ }
@@ -0,0 +1,32 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+
8
+ import { LicenseObject } from "../openapi/types";
9
+ import { create } from "./utils";
10
+
11
+ export function createLicense(license: LicenseObject) {
12
+ if (!license) return "";
13
+ const { name, url } = license;
14
+
15
+ return create("div", {
16
+ style: {
17
+ marginBottom: "var(--ifm-paragraph-margin-bottom)",
18
+ },
19
+ children: [
20
+ create("h3", {
21
+ style: {
22
+ marginBottom: "0.25rem",
23
+ },
24
+ children: "License",
25
+ }),
26
+ create("a", {
27
+ href: url,
28
+ children: name,
29
+ }),
30
+ ],
31
+ });
32
+ }
@@ -0,0 +1,30 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+
8
+ import { create } from "./utils";
9
+
10
+ export function createTermsOfService(termsOfService: string | undefined) {
11
+ if (!createTermsOfService) return "";
12
+
13
+ return create("div", {
14
+ style: {
15
+ marginBottom: "var(--ifm-paragraph-margin-bottom)",
16
+ },
17
+ children: [
18
+ create("h3", {
19
+ style: {
20
+ marginBottom: "0.25rem",
21
+ },
22
+ children: "Terms of Service",
23
+ }),
24
+ create("a", {
25
+ href: `${termsOfService}`,
26
+ children: termsOfService,
27
+ }),
28
+ ],
29
+ });
30
+ }
@@ -7,12 +7,16 @@
7
7
 
8
8
  import { escape } from "lodash";
9
9
 
10
+ import { ContactObject, LicenseObject } from "../openapi/types";
10
11
  import { ApiPageMetadata, InfoPageMetadata } from "../types";
12
+ import { createContactInfo } from "./createContactInfo";
11
13
  import { createDeprecationNotice } from "./createDeprecationNotice";
12
14
  import { createDescription } from "./createDescription";
15
+ import { createLicense } from "./createLicense";
13
16
  import { createParamsDetails } from "./createParamsDetails";
14
17
  import { createRequestBodyDetails } from "./createRequestBodyDetails";
15
18
  import { createStatusCodes } from "./createStatusCodes";
19
+ import { createTermsOfService } from "./createTermsOfService";
16
20
  import { createVersionBadge } from "./createVersionBadge";
17
21
  import { render } from "./utils";
18
22
 
@@ -45,11 +49,14 @@ export function createApiPageMD({
45
49
  }
46
50
 
47
51
  export function createInfoPageMD({
48
- info: { title, version, description },
52
+ info: { title, version, description, contact, license, termsOfService },
49
53
  }: InfoPageMetadata) {
50
54
  return render([
51
55
  createVersionBadge(version),
52
56
  `# ${escape(title)}\n\n`,
53
57
  createDescription(description),
58
+ createContactInfo(contact as ContactObject),
59
+ createTermsOfService(termsOfService),
60
+ createLicense(license as LicenseObject),
54
61
  ]);
55
62
  }
@@ -1,2 +0,0 @@
1
- import { Props } from "./utils";
2
- export declare function createFullWidthTable({ children, style, ...rest }: Props): string;
@@ -1,18 +0,0 @@
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.createFullWidthTable = void 0;
10
- const utils_1 = require("./utils");
11
- function createFullWidthTable({ children, style, ...rest }) {
12
- return (0, utils_1.create)("table", {
13
- style: { display: "table", width: "100%", ...style },
14
- ...rest,
15
- children,
16
- });
17
- }
18
- exports.createFullWidthTable = createFullWidthTable;
@@ -1,7 +0,0 @@
1
- import { ApiItem } from "../types";
2
- interface Props {
3
- parameters: ApiItem["parameters"];
4
- type: "path" | "query" | "header" | "cookie";
5
- }
6
- export declare function createParamsTable({ parameters, type }: Props): string | undefined;
7
- export {};
@@ -1,80 +0,0 @@
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;
@@ -1,6 +0,0 @@
1
- interface Props {
2
- title: string;
3
- body: any;
4
- }
5
- export declare function createRequestBodyTable({ title, body }: Props): string | undefined;
6
- export {};
@@ -1,14 +0,0 @@
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;
@@ -1,14 +0,0 @@
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 {};
@@ -1,217 +0,0 @@
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;
@@ -1,16 +0,0 @@
1
- /* ============================================================================
2
- * Copyright (c) Palo Alto Networks
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- * ========================================================================== */
7
-
8
- import { create, Props } from "./utils";
9
-
10
- export function createFullWidthTable({ children, style, ...rest }: Props) {
11
- return create("table", {
12
- style: { display: "table", width: "100%", ...style },
13
- ...rest,
14
- children,
15
- });
16
- }
@@ -1,102 +0,0 @@
1
- /* ============================================================================
2
- * Copyright (c) Palo Alto Networks
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- * ========================================================================== */
7
-
8
- import { escape } from "lodash";
9
-
10
- import { ApiItem } from "../types";
11
- import { createDescription } from "./createDescription";
12
- import { createFullWidthTable } from "./createFullWidthTable";
13
- import { getQualifierMessage, getSchemaName } from "./schema";
14
- import { create, guard } from "./utils";
15
-
16
- interface Props {
17
- parameters: ApiItem["parameters"];
18
- type: "path" | "query" | "header" | "cookie";
19
- }
20
-
21
- export function createParamsTable({ parameters, type }: Props) {
22
- if (parameters === undefined) {
23
- return undefined;
24
- }
25
- const params = parameters.filter((param) => param?.in === type);
26
- if (params.length === 0) {
27
- return undefined;
28
- }
29
-
30
- return createFullWidthTable({
31
- children: [
32
- create("thead", {
33
- children: create("tr", {
34
- children: create("th", {
35
- style: { textAlign: "left" },
36
- children: `${
37
- type.charAt(0).toUpperCase() + type.slice(1)
38
- } Parameters`,
39
- }),
40
- }),
41
- }),
42
- create("tbody", {
43
- children: params.map((param) =>
44
- create("tr", {
45
- children: create("td", {
46
- children: [
47
- create("code", { children: param.name }),
48
- guard(param.schema, (schema) =>
49
- create("span", {
50
- style: { opacity: "0.6" },
51
- children: ` ${getSchemaName(schema)}`,
52
- })
53
- ),
54
- guard(param.required, () => [
55
- create("span", {
56
- style: { opacity: "0.6" },
57
- children: " — ",
58
- }),
59
- create("strong", {
60
- style: {
61
- fontSize: "var(--ifm-code-font-size)",
62
- color: "var(--openapi-required)",
63
- },
64
- children: " REQUIRED",
65
- }),
66
- ]),
67
- guard(getQualifierMessage(param.schema), (message) =>
68
- create("div", {
69
- style: { marginTop: "var(--ifm-table-cell-padding)" },
70
- children: createDescription(message),
71
- })
72
- ),
73
- guard(param.description, (description) =>
74
- create("div", {
75
- style: { marginTop: "var(--ifm-table-cell-padding)" },
76
- children: createDescription(description),
77
- })
78
- ),
79
- guard(param.example, (example) =>
80
- create("div", {
81
- style: { marginTop: "var(--ifm-table-cell-padding)" },
82
- children: escape(`Example: ${example}`),
83
- })
84
- ),
85
- guard(param.examples, (examples) =>
86
- create("div", {
87
- style: { marginTop: "var(--ifm-table-cell-padding)" },
88
- children: Object.entries(examples).map(([k, v]) =>
89
- create("div", {
90
- children: escape(`Example (${k}): ${v.value}`),
91
- })
92
- ),
93
- })
94
- ),
95
- ],
96
- }),
97
- })
98
- ),
99
- }),
100
- ],
101
- });
102
- }
@@ -1,17 +0,0 @@
1
- /* ============================================================================
2
- * Copyright (c) Palo Alto Networks
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- * ========================================================================== */
7
-
8
- import { createSchemaTable } from "./createSchemaTable";
9
-
10
- interface Props {
11
- title: string;
12
- body: any;
13
- }
14
-
15
- export function createRequestBodyTable({ title, body }: Props) {
16
- return createSchemaTable({ title, body });
17
- }
@@ -1,275 +0,0 @@
1
- /* ============================================================================
2
- * Copyright (c) Palo Alto Networks
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- * ========================================================================== */
7
-
8
- import { MediaTypeObject, SchemaObject } from "../openapi/types";
9
- import { createDescription } from "./createDescription";
10
- import { createFullWidthTable } from "./createFullWidthTable";
11
- import { getQualifierMessage, getSchemaName } from "./schema";
12
- import { create, guard } from "./utils";
13
-
14
- function resolveAllOf(allOf: SchemaObject[]) {
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
-
24
- const required = allOf.reduce((acc, cur) => {
25
- if (Array.isArray(cur.required)) {
26
- const next = [...acc, ...cur.required];
27
- return next;
28
- }
29
- return acc;
30
- }, [] as string[]);
31
-
32
- return { properties, required };
33
- }
34
-
35
- interface RowProps {
36
- name: string;
37
- schema: SchemaObject;
38
- required: boolean;
39
- }
40
-
41
- function createRow({ name, schema, required }: RowProps) {
42
- return create("tr", {
43
- children: create("td", {
44
- children: [
45
- create("code", { children: name }),
46
- create("span", {
47
- style: { opacity: "0.6" },
48
- children: ` ${getSchemaName(schema, true)}`,
49
- }),
50
- guard(required, () => [
51
- create("span", {
52
- style: { opacity: "0.6" },
53
- children: " — ",
54
- }),
55
- create("strong", {
56
- style: {
57
- fontSize: "var(--ifm-code-font-size)",
58
- color: "var(--openapi-required)",
59
- },
60
- children: " REQUIRED",
61
- }),
62
- ]),
63
- guard(getQualifierMessage(schema), (message) =>
64
- create("div", {
65
- style: { marginTop: "var(--ifm-table-cell-padding)" },
66
- children: createDescription(message),
67
- })
68
- ),
69
- guard(schema.description, (description) =>
70
- create("div", {
71
- style: { marginTop: "var(--ifm-table-cell-padding)" },
72
- children: createDescription(description),
73
- })
74
- ),
75
- createRows({ schema: schema }),
76
- ],
77
- }),
78
- });
79
- }
80
-
81
- interface RowsProps {
82
- schema: SchemaObject;
83
- }
84
-
85
- function createRows({ schema }: RowsProps): string | undefined {
86
- // object
87
- if (schema.properties !== undefined) {
88
- return createFullWidthTable({
89
- style: {
90
- marginTop: "var(--ifm-table-cell-padding)",
91
- marginBottom: "0px",
92
- },
93
- children: create("tbody", {
94
- children: Object.entries(schema.properties).map(([key, val]) =>
95
- createRow({
96
- name: key,
97
- schema: val,
98
- required: Array.isArray(schema.required)
99
- ? schema.required.includes(key)
100
- : false,
101
- })
102
- ),
103
- }),
104
- });
105
- }
106
-
107
- // 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
108
- if (schema.allOf !== undefined) {
109
- const { properties, required } = resolveAllOf(schema.allOf);
110
- return createFullWidthTable({
111
- style: {
112
- marginTop: "var(--ifm-table-cell-padding)",
113
- marginBottom: "0px",
114
- },
115
- children: create("tbody", {
116
- children: Object.entries(properties).map(([key, val]) =>
117
- createRow({
118
- name: key,
119
- schema: val,
120
- required: Array.isArray(required) ? required.includes(key) : false,
121
- })
122
- ),
123
- }),
124
- });
125
- }
126
-
127
- // array
128
- if (schema.items !== undefined) {
129
- return createRows({ schema: schema.items });
130
- }
131
-
132
- // primitive
133
- return undefined;
134
- }
135
-
136
- interface RowsRootProps {
137
- schema: SchemaObject;
138
- }
139
-
140
- function createRowsRoot({ schema }: RowsRootProps) {
141
- // object
142
- if (schema.properties !== undefined) {
143
- return Object.entries(schema.properties).map(([key, val]) =>
144
- createRow({
145
- name: key,
146
- schema: val,
147
- required: Array.isArray(schema.required)
148
- ? schema.required.includes(key)
149
- : false,
150
- })
151
- );
152
- }
153
-
154
- // 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
155
- if (schema.allOf !== undefined) {
156
- const { properties, required } = resolveAllOf(schema.allOf);
157
- return Object.entries(properties).map(([key, val]) =>
158
- createRow({
159
- name: key,
160
- schema: val,
161
- required: Array.isArray(required) ? required.includes(key) : false,
162
- })
163
- );
164
- }
165
-
166
- // array
167
- if (schema.items !== undefined) {
168
- return create("tr", {
169
- children: create("td", {
170
- children: [
171
- create("span", {
172
- style: { opacity: "0.6" },
173
- children: ` ${getSchemaName(schema, true)}`,
174
- }),
175
- createRows({ schema: schema.items }),
176
- ],
177
- }),
178
- });
179
- }
180
-
181
- // primitive
182
- return create("tr", {
183
- children: create("td", {
184
- children: [
185
- create("span", {
186
- style: { opacity: "0.6" },
187
- children: ` ${schema.type}`,
188
- }),
189
- guard(getQualifierMessage(schema), (message) =>
190
- create("div", {
191
- style: { marginTop: "var(--ifm-table-cell-padding)" },
192
- children: createDescription(message),
193
- })
194
- ),
195
- guard(schema.description, (description) =>
196
- create("div", {
197
- style: { marginTop: "var(--ifm-table-cell-padding)" },
198
- children: createDescription(description),
199
- })
200
- ),
201
- ],
202
- }),
203
- });
204
- }
205
-
206
- interface Props {
207
- style?: any;
208
- title: string;
209
- body: {
210
- content?: {
211
- [key: string]: MediaTypeObject;
212
- };
213
- description?: string;
214
- required?: boolean;
215
- };
216
- }
217
-
218
- export function createSchemaTable({ title, body, ...rest }: Props) {
219
- if (body === undefined || body.content === undefined) {
220
- return undefined;
221
- }
222
-
223
- // TODO:
224
- // NOTE: We just pick a random content-type.
225
- // How common is it to have multiple?
226
- const randomFirstKey = Object.keys(body.content)[0];
227
-
228
- const firstBody = body.content[randomFirstKey].schema;
229
-
230
- if (firstBody === undefined) {
231
- return undefined;
232
- }
233
-
234
- // we don't show the table if there is no properties to show
235
- if (firstBody.properties !== undefined) {
236
- if (Object.keys(firstBody.properties).length === 0) {
237
- return undefined;
238
- }
239
- }
240
-
241
- return createFullWidthTable({
242
- ...rest,
243
- children: [
244
- create("thead", {
245
- children: create("tr", {
246
- children: create("th", {
247
- style: { textAlign: "left" },
248
- children: [
249
- `${title} `,
250
- guard(body.required, () => [
251
- create("span", {
252
- style: { opacity: "0.6" },
253
- children: " — ",
254
- }),
255
- create("strong", {
256
- style: {
257
- fontSize: "var(--ifm-code-font-size)",
258
- color: "var(--openapi-required)",
259
- },
260
- children: " REQUIRED",
261
- }),
262
- ]),
263
- create("div", {
264
- children: createDescription(body.description),
265
- }),
266
- ],
267
- }),
268
- }),
269
- }),
270
- create("tbody", {
271
- children: createRowsRoot({ schema: firstBody }),
272
- }),
273
- ],
274
- });
275
- }