docusaurus-theme-openapi-docs 0.0.0-1079 → 0.0.0-1080

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.
@@ -37,6 +37,9 @@ function prettyName(schema, circular) {
37
37
  return schema.xml?.name ?? schema.type;
38
38
  // return schema.type;
39
39
  }
40
+ if (Array.isArray(schema.type)) {
41
+ return schema.type.join(" | ");
42
+ }
40
43
  return schema.title ?? schema.type;
41
44
  }
42
45
  function getSchemaName(schema, circular) {
@@ -0,0 +1,11 @@
1
+ .openapi-examples {
2
+ > .openapi-tabs__schema-container {
3
+ margin: 0.4rem;
4
+
5
+ @layer docusaurus.infima {
6
+ > .margin-top--md {
7
+ margin: 0.2rem !important;
8
+ }
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,24 @@
1
+ import React from "react";
2
+ import { ExampleObject } from "@theme/ParamsItem";
3
+ type ExampleType = string;
4
+ type ExamplesType = Record<string, ExampleObject> | string[];
5
+ /**
6
+ * Example Component Props
7
+ */
8
+ type ExampleProps = {
9
+ example?: ExampleType;
10
+ examples?: ExamplesType;
11
+ };
12
+ /**
13
+ * Example Component
14
+ */
15
+ export declare const Example: ({ example, examples }: ExampleProps) => React.JSX.Element | undefined;
16
+ /**
17
+ * Render string examples
18
+ *
19
+ * @param examples
20
+ * @returns
21
+ */
22
+ export declare function renderStringArrayExamples(examples: string[]): React.JSX.Element | undefined;
23
+ export declare const renderExamplesRecord: (examples: Record<string, ExampleObject>) => React.JSX.Element | undefined;
24
+ export {};
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
8
+ var __importDefault =
9
+ (this && this.__importDefault) ||
10
+ function (mod) {
11
+ return mod && mod.__esModule ? mod : { default: mod };
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.renderExamplesRecord = exports.Example = void 0;
15
+ exports.renderStringArrayExamples = renderStringArrayExamples;
16
+ const react_1 = __importDefault(require("react"));
17
+ const Translate_1 = require("@docusaurus/Translate");
18
+ const SchemaTabs_1 = __importDefault(require("@theme/SchemaTabs"));
19
+ const TabItem_1 = __importDefault(require("@theme/TabItem"));
20
+ const translationIds_1 = require("@theme/translationIds");
21
+ const EXAMPLE_CLASS_NAME = "openapi-example";
22
+ const EXAMPLES_CLASS_NAME = "openapi-examples";
23
+ /**
24
+ * Example Component
25
+ */
26
+ const Example = ({ example, examples }) => {
27
+ if (example !== undefined) {
28
+ return renderExample(example);
29
+ }
30
+ if (examples !== undefined) {
31
+ return renderExamples(examples);
32
+ }
33
+ return undefined;
34
+ };
35
+ exports.Example = Example;
36
+ /**
37
+ * Format example value
38
+ *
39
+ * @param example
40
+ * @returns
41
+ */
42
+ const formatExample = (example) => {
43
+ if (typeof example === "object" && example !== null) {
44
+ return JSON.stringify(example);
45
+ }
46
+ return String(example);
47
+ };
48
+ const renderExample = (example) => {
49
+ return react_1.default.createElement(
50
+ "div",
51
+ { className: EXAMPLE_CLASS_NAME },
52
+ react_1.default.createElement(
53
+ "strong",
54
+ null,
55
+ (0, Translate_1.translate)({
56
+ id: translationIds_1.OPENAPI_SCHEMA_ITEM.EXAMPLE,
57
+ message: "Example:",
58
+ }),
59
+ " "
60
+ ),
61
+ react_1.default.createElement(
62
+ "span",
63
+ null,
64
+ react_1.default.createElement("code", null, formatExample(example))
65
+ )
66
+ );
67
+ };
68
+ const renderExamples = (examples) => {
69
+ if (Array.isArray(examples)) {
70
+ return renderStringArrayExamples(examples);
71
+ }
72
+ return (0, exports.renderExamplesRecord)(examples);
73
+ };
74
+ /**
75
+ * Render string examples
76
+ *
77
+ * @param examples
78
+ * @returns
79
+ */
80
+ function renderStringArrayExamples(examples) {
81
+ if (examples.length === 0) {
82
+ return undefined;
83
+ }
84
+ // If there's only one example, display it without tabs
85
+ if (examples.length === 1) {
86
+ return renderExample(examples[0]);
87
+ }
88
+ // Multiple examples - use tabs
89
+ const exampleEntries = examples.reduce(
90
+ (acc, example, index) => ({
91
+ ...acc,
92
+ [`Example ${index + 1}`]: {
93
+ value: example,
94
+ },
95
+ }),
96
+ {}
97
+ );
98
+ return (0, exports.renderExamplesRecord)(exampleEntries);
99
+ }
100
+ const renderExamplesRecord = (examples) => {
101
+ const exampleEntries = Object.entries(examples);
102
+ // If there's only one example, display it without tabs
103
+ if (exampleEntries.length === 1) {
104
+ const firstExample = exampleEntries[0][1];
105
+ if (!firstExample) {
106
+ return undefined;
107
+ }
108
+ return renderExample(firstExample.value);
109
+ }
110
+ return react_1.default.createElement(
111
+ "div",
112
+ { className: EXAMPLES_CLASS_NAME },
113
+ react_1.default.createElement(
114
+ "strong",
115
+ null,
116
+ (0, Translate_1.translate)({
117
+ id: translationIds_1.OPENAPI_SCHEMA_ITEM.EXAMPLES,
118
+ message: "Examples:",
119
+ })
120
+ ),
121
+ react_1.default.createElement(
122
+ SchemaTabs_1.default,
123
+ null,
124
+ exampleEntries.map(([exampleName, exampleProperties]) =>
125
+ renderExampleObject(exampleName, exampleProperties)
126
+ )
127
+ )
128
+ );
129
+ };
130
+ exports.renderExamplesRecord = renderExamplesRecord;
131
+ /**
132
+ * Render example object
133
+ *
134
+ * @param exampleName
135
+ * @param exampleProperties
136
+ * @returns
137
+ */
138
+ const renderExampleObject = (exampleName, exampleProperties) => {
139
+ return (
140
+ // @ts-ignore
141
+ react_1.default.createElement(
142
+ TabItem_1.default,
143
+ { value: exampleName, label: exampleName },
144
+ exampleProperties.summary &&
145
+ react_1.default.createElement("p", null, exampleProperties.summary),
146
+ exampleProperties.description &&
147
+ react_1.default.createElement(
148
+ "p",
149
+ null,
150
+ react_1.default.createElement(
151
+ "strong",
152
+ null,
153
+ (0, Translate_1.translate)({
154
+ id: translationIds_1.OPENAPI_SCHEMA_ITEM.DESCRIPTION,
155
+ message: "Description:",
156
+ }),
157
+ " "
158
+ ),
159
+ react_1.default.createElement(
160
+ "span",
161
+ null,
162
+ exampleProperties.description
163
+ )
164
+ ),
165
+ exampleProperties.value !== undefined
166
+ ? renderExample(exampleProperties.value)
167
+ : undefined
168
+ )
169
+ );
170
+ };
@@ -10,7 +10,7 @@ export interface Props {
10
10
  param: {
11
11
  description: string;
12
12
  example: any;
13
- examples: Record<string, ExampleObject>;
13
+ examples: Record<string, ExampleObject> | undefined;
14
14
  name: string;
15
15
  required: boolean;
16
16
  deprecated: boolean;
@@ -13,12 +13,11 @@ var __importDefault =
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  const react_1 = __importDefault(require("react"));
15
15
  const Translate_1 = require("@docusaurus/Translate");
16
+ const Example_1 = require("@theme/Example");
16
17
  const Markdown_1 = __importDefault(require("@theme/Markdown"));
17
- const SchemaTabs_1 = __importDefault(require("@theme/SchemaTabs"));
18
- const TabItem_1 = __importDefault(require("@theme/TabItem"));
19
18
  /* eslint-disable import/no-extraneous-dependencies*/
20
- const clsx_1 = __importDefault(require("clsx"));
21
19
  const translationIds_1 = require("@theme/translationIds");
20
+ const clsx_1 = __importDefault(require("clsx"));
22
21
  const schema_1 = require("../../markdown/schema");
23
22
  const utils_1 = require("../../markdown/utils");
24
23
  const getEnumDescriptionMarkdown = (enumDescriptions) => {
@@ -43,17 +42,11 @@ ${enumDescriptions
43
42
  return "";
44
43
  };
45
44
  function ParamsItem({ param, ...rest }) {
46
- const {
47
- description,
48
- example,
49
- examples,
50
- name,
51
- required,
52
- deprecated,
53
- enumDescriptions,
54
- } = param;
45
+ const { description, name, required, deprecated, enumDescriptions } = param;
55
46
  let schema = param.schema;
56
47
  let defaultValue;
48
+ let examples = param.examples ?? schema?.examples;
49
+ let example = param.example ?? schema?.example;
57
50
  if (!schema) {
58
51
  schema = { type: "any" };
59
52
  }
@@ -160,93 +153,6 @@ function ParamsItem({ param, ...rest }) {
160
153
  }
161
154
  return undefined;
162
155
  }
163
- const renderExample = (0, utils_1.guard)(
164
- (0, utils_1.toString)(example),
165
- (example) =>
166
- react_1.default.createElement(
167
- "div",
168
- null,
169
- react_1.default.createElement(
170
- "strong",
171
- null,
172
- (0, Translate_1.translate)({
173
- id: translationIds_1.OPENAPI_SCHEMA_ITEM.EXAMPLE,
174
- message: "Example:",
175
- }),
176
- " "
177
- ),
178
- example
179
- )
180
- );
181
- const renderExamples = (0, utils_1.guard)(examples, (examples) => {
182
- const exampleEntries = Object.entries(examples);
183
- return react_1.default.createElement(
184
- react_1.default.Fragment,
185
- null,
186
- react_1.default.createElement(
187
- "strong",
188
- null,
189
- (0, Translate_1.translate)({
190
- id: translationIds_1.OPENAPI_SCHEMA_ITEM.EXAMPLES,
191
- message: "Examples:",
192
- })
193
- ),
194
- react_1.default.createElement(
195
- SchemaTabs_1.default,
196
- null,
197
- exampleEntries.map(([exampleName, exampleProperties]) =>
198
- // @ts-ignore
199
- react_1.default.createElement(
200
- TabItem_1.default,
201
- { value: exampleName, label: exampleName },
202
- exampleProperties.summary &&
203
- react_1.default.createElement(
204
- "p",
205
- null,
206
- exampleProperties.summary
207
- ),
208
- exampleProperties.description &&
209
- react_1.default.createElement(
210
- "p",
211
- null,
212
- react_1.default.createElement(
213
- "strong",
214
- null,
215
- (0, Translate_1.translate)({
216
- id: translationIds_1.OPENAPI_SCHEMA_ITEM.DESCRIPTION,
217
- message: "Description:",
218
- }),
219
- " "
220
- ),
221
- react_1.default.createElement(
222
- "span",
223
- null,
224
- exampleProperties.description
225
- )
226
- ),
227
- react_1.default.createElement(
228
- "p",
229
- null,
230
- react_1.default.createElement(
231
- "strong",
232
- null,
233
- (0, Translate_1.translate)({
234
- id: translationIds_1.OPENAPI_SCHEMA_ITEM.EXAMPLE,
235
- message: "Example:",
236
- }),
237
- " "
238
- ),
239
- react_1.default.createElement(
240
- "code",
241
- null,
242
- exampleProperties.value
243
- )
244
- )
245
- )
246
- )
247
- )
248
- );
249
- });
250
156
  return react_1.default.createElement(
251
157
  "div",
252
158
  { className: "openapi-params__list-item" },
@@ -274,8 +180,8 @@ function ParamsItem({ param, ...rest }) {
274
180
  renderDescription,
275
181
  renderEnumDescriptions,
276
182
  renderDefaultValue(),
277
- renderExample,
278
- renderExamples
183
+ react_1.default.createElement(Example_1.Example, { example: example }),
184
+ react_1.default.createElement(Example_1.Example, { examples: examples })
279
185
  );
280
186
  }
281
187
  exports.default = ParamsItem;
@@ -12,9 +12,8 @@ var __importDefault =
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  const react_1 = __importDefault(require("react"));
15
- const Translate_1 = require("@docusaurus/Translate");
16
- const translationIds_1 = require("@theme/translationIds");
17
15
  const BrowserOnly_1 = __importDefault(require("@docusaurus/BrowserOnly"));
16
+ const Translate_1 = require("@docusaurus/Translate");
18
17
  const Details_1 = __importDefault(require("@theme/Details"));
19
18
  const Markdown_1 = __importDefault(require("@theme/Markdown"));
20
19
  const MimeTabs_1 = __importDefault(require("@theme/MimeTabs")); // Assume these components exist
@@ -23,6 +22,7 @@ const Schema_1 = __importDefault(require("@theme/Schema"));
23
22
  const SchemaTabs_1 = __importDefault(require("@theme/SchemaTabs"));
24
23
  const SkeletonLoader_1 = __importDefault(require("@theme/SkeletonLoader"));
25
24
  const TabItem_1 = __importDefault(require("@theme/TabItem"));
25
+ const translationIds_1 = require("@theme/translationIds");
26
26
  const ResponseSchemaComponent = ({ title, body, style }) => {
27
27
  if (
28
28
  body === undefined ||
@@ -39,109 +39,118 @@ const ResponseSchemaComponent = ({ title, body, style }) => {
39
39
  MimeTabs_1.default,
40
40
  { className: "openapi-tabs__mime", schemaType: "response" },
41
41
  mimeTypes.map((mimeType) => {
42
- const responseExamples = body.content[mimeType].examples;
43
- const responseExample = body.content[mimeType].example;
44
- const firstBody =
45
- body.content[mimeType].schema ?? body.content[mimeType];
42
+ const mediaTypeObject = body.content?.[mimeType];
43
+ const responseExamples = mediaTypeObject?.examples;
44
+ const responseExample = mediaTypeObject?.example;
45
+ const firstBody = mediaTypeObject?.schema;
46
46
  if (
47
- firstBody === undefined &&
48
- responseExample === undefined &&
49
- responseExamples === undefined
47
+ !firstBody ||
48
+ (firstBody.properties &&
49
+ Object.keys(firstBody.properties).length === 0)
50
50
  ) {
51
- return undefined;
52
- }
53
- if (firstBody) {
54
51
  return (
55
52
  // @ts-ignore
56
53
  react_1.default.createElement(
57
54
  TabItem_1.default,
58
55
  { key: mimeType, label: mimeType, value: mimeType },
59
56
  react_1.default.createElement(
60
- SchemaTabs_1.default,
61
- { className: "openapi-tabs__schema" },
57
+ "div",
58
+ null,
59
+ (0, Translate_1.translate)({
60
+ id: translationIds_1.OPENAPI_SCHEMA.NO_SCHEMA,
61
+ message: "No schema",
62
+ })
63
+ )
64
+ )
65
+ );
66
+ }
67
+ return (
68
+ // @ts-ignore
69
+ react_1.default.createElement(
70
+ TabItem_1.default,
71
+ { key: mimeType, label: mimeType, value: mimeType },
72
+ react_1.default.createElement(
73
+ SchemaTabs_1.default,
74
+ { className: "openapi-tabs__schema" },
75
+ react_1.default.createElement(
76
+ TabItem_1.default,
77
+ { key: title, label: title, value: title },
62
78
  react_1.default.createElement(
63
- TabItem_1.default,
64
- { key: title, label: title, value: title },
65
- react_1.default.createElement(
66
- Details_1.default,
67
- {
68
- className: "openapi-markdown__details response",
69
- "data-collapsed": false,
70
- open: true,
71
- style: style,
72
- summary: react_1.default.createElement(
73
- react_1.default.Fragment,
79
+ Details_1.default,
80
+ {
81
+ className: "openapi-markdown__details response",
82
+ "data-collapsed": false,
83
+ open: true,
84
+ style: style,
85
+ summary: react_1.default.createElement(
86
+ react_1.default.Fragment,
87
+ null,
88
+ react_1.default.createElement(
89
+ "summary",
74
90
  null,
75
91
  react_1.default.createElement(
76
- "summary",
77
- null,
78
- react_1.default.createElement(
79
- "strong",
80
- {
81
- className:
82
- "openapi-markdown__details-summary-response",
83
- },
84
- title,
85
- body.required === true &&
86
- react_1.default.createElement(
87
- "span",
88
- { className: "openapi-schema__required" },
89
- (0, Translate_1.translate)({
90
- id: translationIds_1.OPENAPI_SCHEMA_ITEM
91
- .REQUIRED,
92
- message: "required",
93
- })
94
- )
95
- )
96
- )
97
- ),
98
- },
99
- react_1.default.createElement(
100
- "div",
101
- { style: { textAlign: "left", marginLeft: "1rem" } },
102
- body.description &&
103
- react_1.default.createElement(
104
- "div",
92
+ "strong",
105
93
  {
106
- style: { marginTop: "1rem", marginBottom: "1rem" },
94
+ className:
95
+ "openapi-markdown__details-summary-response",
107
96
  },
108
- react_1.default.createElement(
109
- Markdown_1.default,
110
- null,
111
- body.description
112
- )
97
+ title,
98
+ body.required === true &&
99
+ react_1.default.createElement(
100
+ "span",
101
+ { className: "openapi-schema__required" },
102
+ (0, Translate_1.translate)({
103
+ id: translationIds_1.OPENAPI_SCHEMA_ITEM
104
+ .REQUIRED,
105
+ message: "required",
106
+ })
107
+ )
113
108
  )
109
+ )
114
110
  ),
115
- react_1.default.createElement(
116
- "ul",
117
- { style: { marginLeft: "1rem" } },
118
- react_1.default.createElement(Schema_1.default, {
119
- schema: firstBody,
120
- schemaType: "response",
121
- })
122
- )
111
+ },
112
+ react_1.default.createElement(
113
+ "div",
114
+ { style: { textAlign: "left", marginLeft: "1rem" } },
115
+ body.description &&
116
+ react_1.default.createElement(
117
+ "div",
118
+ { style: { marginTop: "1rem", marginBottom: "1rem" } },
119
+ react_1.default.createElement(
120
+ Markdown_1.default,
121
+ null,
122
+ body.description
123
+ )
124
+ )
125
+ ),
126
+ react_1.default.createElement(
127
+ "ul",
128
+ { style: { marginLeft: "1rem" } },
129
+ react_1.default.createElement(Schema_1.default, {
130
+ schema: firstBody,
131
+ schemaType: "response",
132
+ })
123
133
  )
124
- ),
125
- firstBody &&
126
- (0, ResponseExamples_1.ExampleFromSchema)({
127
- schema: firstBody,
128
- mimeType: mimeType,
129
- }),
130
- responseExamples &&
131
- (0, ResponseExamples_1.ResponseExamples)({
132
- responseExamples,
133
- mimeType,
134
- }),
135
- responseExample &&
136
- (0, ResponseExamples_1.ResponseExample)({
137
- responseExample,
138
- mimeType,
139
- })
140
- )
134
+ )
135
+ ),
136
+ firstBody &&
137
+ (0, ResponseExamples_1.ExampleFromSchema)({
138
+ schema: firstBody,
139
+ mimeType: mimeType,
140
+ }),
141
+ responseExamples &&
142
+ (0, ResponseExamples_1.ResponseExamples)({
143
+ responseExamples,
144
+ mimeType,
145
+ }),
146
+ responseExample &&
147
+ (0, ResponseExamples_1.ResponseExample)({
148
+ responseExample,
149
+ mimeType,
150
+ })
141
151
  )
142
- );
143
- }
144
- return undefined;
152
+ )
153
+ );
145
154
  })
146
155
  );
147
156
  }
@@ -13,10 +13,11 @@ var __importDefault =
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.default = SchemaItem;
15
15
  const react_1 = __importDefault(require("react"));
16
- const Markdown_1 = __importDefault(require("@theme/Markdown"));
17
- const clsx_1 = __importDefault(require("clsx"));
18
16
  const Translate_1 = require("@docusaurus/Translate");
17
+ const Example_1 = require("@theme/Example");
18
+ const Markdown_1 = __importDefault(require("@theme/Markdown"));
19
19
  const translationIds_1 = require("@theme/translationIds");
20
+ const clsx_1 = __importDefault(require("clsx"));
20
21
  const utils_1 = require("../../markdown/utils");
21
22
  const transformEnumDescriptions = (enumDescriptions) => {
22
23
  if (enumDescriptions) {
@@ -59,6 +60,7 @@ function SchemaItem(props) {
59
60
  let schemaDescription;
60
61
  let defaultValue;
61
62
  let example;
63
+ let examples;
62
64
  let nullable;
63
65
  let enumDescriptions = [];
64
66
  let constValue;
@@ -68,6 +70,7 @@ function SchemaItem(props) {
68
70
  enumDescriptions = transformEnumDescriptions(schema["x-enumDescriptions"]);
69
71
  defaultValue = schema.default;
70
72
  example = schema.example;
73
+ examples = schema.examples;
71
74
  nullable =
72
75
  schema.nullable ||
73
76
  (Array.isArray(schema.type) && schema.type.includes("null")); // support JSON Schema nullable
@@ -180,49 +183,6 @@ function SchemaItem(props) {
180
183
  }
181
184
  return undefined;
182
185
  }
183
- function renderExample() {
184
- if (example !== undefined) {
185
- if (typeof example === "string") {
186
- return react_1.default.createElement(
187
- "div",
188
- null,
189
- react_1.default.createElement(
190
- "strong",
191
- null,
192
- (0, Translate_1.translate)({
193
- id: translationIds_1.OPENAPI_SCHEMA_ITEM.EXAMPLE,
194
- message: "Example:",
195
- }),
196
- " "
197
- ),
198
- react_1.default.createElement(
199
- "span",
200
- null,
201
- react_1.default.createElement("code", null, example)
202
- )
203
- );
204
- }
205
- return react_1.default.createElement(
206
- "div",
207
- null,
208
- react_1.default.createElement(
209
- "strong",
210
- null,
211
- (0, Translate_1.translate)({
212
- id: translationIds_1.OPENAPI_SCHEMA_ITEM.EXAMPLE,
213
- message: "Example:",
214
- }),
215
- " "
216
- ),
217
- react_1.default.createElement(
218
- "span",
219
- null,
220
- react_1.default.createElement("code", null, JSON.stringify(example))
221
- )
222
- );
223
- }
224
- return undefined;
225
- }
226
186
  function renderConstValue() {
227
187
  if (constValue !== undefined) {
228
188
  if (typeof constValue === "string") {
@@ -303,7 +263,8 @@ function SchemaItem(props) {
303
263
  renderQualifierMessage,
304
264
  renderConstValue(),
305
265
  renderDefaultValue(),
306
- renderExample(),
266
+ react_1.default.createElement(Example_1.Example, { example: example }),
267
+ react_1.default.createElement(Example_1.Example, { examples: examples }),
307
268
  collapsibleSchemaContent ?? collapsibleSchemaContent
308
269
  );
309
270
  return react_1.default.createElement(
@@ -41,6 +41,8 @@
41
41
  @use "./CodeSamples/CodeSamples";
42
42
  /* Markdown Styling */
43
43
  @use "./Markdown/Details/Details";
44
+ /* Example Styling */
45
+ @use "./Example/Example";
44
46
 
45
47
  :root {
46
48
  --openapi-required: var(--ifm-color-danger);