docusaurus-plugin-openapi-docs 2.2.0 → 2.2.2

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.
@@ -32,43 +32,261 @@ Object.defineProperty(exports, "__esModule", { value: true });
32
32
  const prettier = __importStar(require("prettier"));
33
33
  const createSchema_1 = require("./createSchema");
34
34
  describe("createNodes", () => {
35
- it("should create readable MODs for oneOf primitive properties", () => {
36
- const schema = {
37
- "x-tags": ["clown"],
38
- type: "object",
39
- properties: {
40
- oneOfProperty: {
41
- oneOf: [
42
- {
43
- type: "object",
44
- properties: {
45
- noseLength: {
46
- type: "number",
35
+ describe("oneOf", () => {
36
+ it("should create readable MODs for oneOf primitive properties", async () => {
37
+ const schema = {
38
+ "x-tags": ["clown"],
39
+ type: "object",
40
+ properties: {
41
+ oneOfProperty: {
42
+ oneOf: [
43
+ {
44
+ type: "object",
45
+ properties: {
46
+ noseLength: {
47
+ type: "number",
48
+ },
47
49
  },
50
+ required: ["noseLength"],
51
+ description: "Clown's nose length",
52
+ },
53
+ {
54
+ type: "array",
55
+ items: {
56
+ type: "string",
57
+ },
58
+ description: "Array of strings",
59
+ },
60
+ {
61
+ type: "boolean",
62
+ },
63
+ {
64
+ type: "number",
65
+ },
66
+ {
67
+ type: "string",
68
+ },
69
+ ],
70
+ },
71
+ },
72
+ };
73
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "request").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
74
+ });
75
+ });
76
+ describe("allOf", () => {
77
+ it("should render same-level properties with allOf", async () => {
78
+ const schema = {
79
+ allOf: [
80
+ {
81
+ type: "object",
82
+ properties: {
83
+ allOfProp1: {
84
+ type: "string",
85
+ },
86
+ allOfProp2: {
87
+ type: "string",
48
88
  },
49
- required: ["noseLength"],
50
- description: "Clown's nose length",
51
89
  },
52
- {
53
- type: "array",
54
- items: {
90
+ },
91
+ ],
92
+ properties: {
93
+ parentProp1: {
94
+ type: "string",
95
+ },
96
+ parentProp2: {
97
+ type: "string",
98
+ },
99
+ },
100
+ };
101
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
102
+ });
103
+ it("should correctly merge nested properties from multiple allOf schemas", async () => {
104
+ const schema = {
105
+ allOf: [
106
+ {
107
+ type: "object",
108
+ properties: {
109
+ outerProp1: {
110
+ type: "object",
111
+ properties: {
112
+ innerProp1: {
113
+ type: "string",
114
+ },
115
+ },
116
+ },
117
+ },
118
+ },
119
+ {
120
+ type: "object",
121
+ properties: {
122
+ outerProp2: {
123
+ type: "object",
124
+ properties: {
125
+ innerProp2: {
126
+ type: "number",
127
+ },
128
+ },
129
+ },
130
+ },
131
+ },
132
+ ],
133
+ };
134
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
135
+ });
136
+ it("should correctly handle shared required properties across allOf schemas", async () => {
137
+ const schema = {
138
+ allOf: [
139
+ {
140
+ type: "object",
141
+ properties: {
142
+ sharedProp: {
55
143
  type: "string",
56
144
  },
57
- description: "Array of strings",
58
145
  },
59
- {
60
- type: "boolean",
146
+ required: ["sharedProp"],
147
+ },
148
+ {
149
+ type: "object",
150
+ properties: {
151
+ anotherProp: {
152
+ type: "number",
153
+ },
61
154
  },
62
- {
63
- type: "number",
155
+ required: ["anotherProp"],
156
+ },
157
+ ],
158
+ };
159
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
160
+ });
161
+ // Could not resolve values for path:"properties.conflictingProp.type". They are probably incompatible. Values:
162
+ // "string"
163
+ // "number"
164
+ // eslint-disable-next-line jest/no-commented-out-tests
165
+ // it("should handle conflicting properties in allOf schemas", async () => {
166
+ // const schema: SchemaObject = {
167
+ // allOf: [
168
+ // {
169
+ // type: "object",
170
+ // properties: {
171
+ // conflictingProp: {
172
+ // type: "string",
173
+ // },
174
+ // },
175
+ // },
176
+ // {
177
+ // type: "object",
178
+ // properties: {
179
+ // conflictingProp: {
180
+ // type: "number",
181
+ // },
182
+ // },
183
+ // },
184
+ // ],
185
+ // };
186
+ // expect(
187
+ // await Promise.all(
188
+ // createNodes(schema, "response").map(
189
+ // async (md: any) => await prettier.format(md, { parser: "babel" })
190
+ // )
191
+ // )
192
+ // ).toMatchSnapshot();
193
+ // });
194
+ // Could not resolve values for path:"type". They are probably incompatible. Values:
195
+ // "object"
196
+ // "array"
197
+ // eslint-disable-next-line jest/no-commented-out-tests
198
+ // it("should handle mixed data types in allOf schemas", async () => {
199
+ // const schema: SchemaObject = {
200
+ // allOf: [
201
+ // {
202
+ // type: "object",
203
+ // properties: {
204
+ // mixedTypeProp1: {
205
+ // type: "string",
206
+ // },
207
+ // },
208
+ // },
209
+ // {
210
+ // type: "array",
211
+ // items: {
212
+ // type: "number",
213
+ // },
214
+ // },
215
+ // ],
216
+ // };
217
+ // expect(
218
+ // await Promise.all(
219
+ // createNodes(schema, "response").map(
220
+ // async (md: any) => await prettier.format(md, { parser: "babel" })
221
+ // )
222
+ // )
223
+ // ).toMatchSnapshot();
224
+ // });
225
+ it("should correctly deep merge properties in allOf schemas", async () => {
226
+ const schema = {
227
+ allOf: [
228
+ {
229
+ type: "object",
230
+ properties: {
231
+ deepProp: {
232
+ type: "object",
233
+ properties: {
234
+ innerProp1: {
235
+ type: "string",
236
+ },
237
+ },
238
+ },
64
239
  },
65
- {
66
- type: "string",
240
+ },
241
+ {
242
+ type: "object",
243
+ properties: {
244
+ deepProp: {
245
+ type: "object",
246
+ properties: {
247
+ innerProp2: {
248
+ type: "number",
249
+ },
250
+ },
251
+ },
67
252
  },
68
- ],
69
- },
70
- },
71
- };
72
- expect((0, createSchema_1.createNodes)(schema, "request").map((md) => prettier.format(md, { parser: "babel" }))).toMatchSnapshot();
253
+ },
254
+ ],
255
+ };
256
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
257
+ });
258
+ // eslint-disable-next-line jest/no-commented-out-tests
259
+ // it("should handle discriminator with allOf schemas", async () => {
260
+ // const schema: SchemaObject = {
261
+ // allOf: [
262
+ // {
263
+ // type: "object",
264
+ // discriminator: {
265
+ // propertyName: "type",
266
+ // },
267
+ // properties: {
268
+ // type: {
269
+ // type: "string",
270
+ // },
271
+ // },
272
+ // },
273
+ // {
274
+ // type: "object",
275
+ // properties: {
276
+ // specificProp: {
277
+ // type: "string",
278
+ // },
279
+ // },
280
+ // },
281
+ // ],
282
+ // };
283
+ // expect(
284
+ // await Promise.all(
285
+ // createNodes(schema, "response").map(
286
+ // async (md: any) => await prettier.format(md, { parser: "babel" })
287
+ // )
288
+ // )
289
+ // ).toMatchSnapshot();
290
+ // });
73
291
  });
74
292
  });
@@ -118,8 +118,9 @@ function createResponseExamples(responseExamples, mimeType) {
118
118
  value: `${exampleName}`,
119
119
  children: [
120
120
  (0, utils_2.guard)(exampleValue.summary, (summary) => [
121
- (0, utils_1.create)("Markdown", {
122
- children: ` ${summary}`,
121
+ (0, utils_1.create)("div", {
122
+ children: `${summary}`,
123
+ className: "openapi-example__summary",
123
124
  }),
124
125
  ]),
125
126
  (0, utils_1.create)("ResponseSamples", {
@@ -134,8 +135,9 @@ function createResponseExamples(responseExamples, mimeType) {
134
135
  value: `${exampleName}`,
135
136
  children: [
136
137
  (0, utils_2.guard)(exampleValue.summary, (summary) => [
137
- (0, utils_1.create)("Markdown", {
138
- children: ` ${summary}`,
138
+ (0, utils_1.create)("div", {
139
+ children: `${summary}`,
140
+ className: "openapi-example__summary",
139
141
  }),
140
142
  ]),
141
143
  (0, utils_1.create)("ResponseSamples", {
@@ -161,8 +163,9 @@ function createResponseExample(responseExample, mimeType) {
161
163
  value: `Example`,
162
164
  children: [
163
165
  (0, utils_2.guard)(responseExample.summary, (summary) => [
164
- (0, utils_1.create)("Markdown", {
165
- children: ` ${summary}`,
166
+ (0, utils_1.create)("div", {
167
+ children: `${summary}`,
168
+ className: "openapi-example__summary",
166
169
  }),
167
170
  ]),
168
171
  (0, utils_1.create)("ResponseSamples", {
@@ -177,8 +180,9 @@ function createResponseExample(responseExample, mimeType) {
177
180
  value: `Example`,
178
181
  children: [
179
182
  (0, utils_2.guard)(responseExample.summary, (summary) => [
180
- (0, utils_1.create)("Markdown", {
181
- children: ` ${summary}`,
183
+ (0, utils_1.create)("div", {
184
+ children: `${summary}`,
185
+ className: "openapi-example__summary",
182
186
  }),
183
187
  ]),
184
188
  (0, utils_1.create)("ResponseSamples", {
@@ -38,7 +38,7 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
38
38
  `import ResponseSamples from "@theme/ResponseSamples";\n`,
39
39
  `import SchemaItem from "@theme/SchemaItem";\n`,
40
40
  `import SchemaTabs from "@theme/SchemaTabs";\n`,
41
- `import Markdown from "@theme/Markdown";\n`,
41
+ `import Heading from "@theme/Heading";\n`,
42
42
  `import OperationTabs from "@theme/OperationTabs";\n`,
43
43
  `import TabItem from "@theme/TabItem";\n\n`,
44
44
  (0, createHeading_1.createHeading)(title.replace(utils_1.lessThan, "<").replace(utils_1.greaterThan, ">")),
@@ -17,8 +17,8 @@ const primitives = {
17
17
  string: {
18
18
  default: () => "string",
19
19
  email: () => "user@example.com",
20
- date: () => new Date().toISOString().substring(0, 10),
21
- "date-time": () => new Date().toISOString(),
20
+ date: () => "2024-07-29",
21
+ "date-time": () => "2024-07-29T15:51:28.071Z",
22
22
  uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
23
23
  hostname: () => "example.com",
24
24
  ipv4: () => "198.51.100.42",
@@ -17,8 +17,8 @@ const primitives = {
17
17
  string: {
18
18
  default: () => "string",
19
19
  email: () => "user@example.com",
20
- date: () => new Date().toISOString().substring(0, 10),
21
- "date-time": () => new Date().toISOString(),
20
+ date: () => "2024-07-29",
21
+ "date-time": () => "2024-07-29T15:51:28.071Z",
22
22
  uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
23
23
  hostname: () => "example.com",
24
24
  ipv4: () => "198.51.100.42",
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": "2.2.0",
4
+ "version": "2.2.2",
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": "060b5777c783abc23cd3744a6d43deb4df80cebd"
63
+ "gitHead": "297f91457e7742c5b5c334b975adf17e149f7f5c"
64
64
  }
package/src/index.ts CHANGED
@@ -536,6 +536,18 @@ custom_edit_url: null
536
536
  });
537
537
  }
538
538
 
539
+ if (!fs.existsSync(outputDir)) {
540
+ try {
541
+ fs.mkdirSync(outputDir, { recursive: true });
542
+ console.log(chalk.green(`Successfully created "${outputDir}"`));
543
+ } catch (err) {
544
+ console.error(
545
+ chalk.red(`Failed to create "${outputDir}"`),
546
+ chalk.yellow(err)
547
+ );
548
+ }
549
+ }
550
+
539
551
  const versionsJson = JSON.stringify(versionsArray, null, 2);
540
552
  try {
541
553
  fs.writeFileSync(`${outputDir}/versions.json`, versionsJson, "utf8");
@@ -1,6 +1,151 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`createNodes should create readable MODs for oneOf primitive properties 1`] = `
3
+ exports[`createNodes allOf should correctly deep merge properties in allOf schemas 1`] = `
4
+ Array [
5
+ "<SchemaItem collapsible={true} className={\\"schemaItem\\"}>
6
+ <details style={{}} className={\\"openapi-markdown__details\\"}>
7
+ <summary style={{}}>
8
+ <span className={\\"openapi-schema__container\\"}>
9
+ <strong className={\\"openapi-schema__property\\"}>deepProp</strong>
10
+ <span className={\\"openapi-schema__name\\"}> object</span>
11
+ </span>
12
+ </summary>
13
+ <div style={{ marginLeft: \\"1rem\\" }}>
14
+ <SchemaItem
15
+ collapsible={false}
16
+ name={\\"innerProp1\\"}
17
+ required={false}
18
+ schemaName={\\"string\\"}
19
+ qualifierMessage={undefined}
20
+ schema={{ type: \\"string\\" }}
21
+ ></SchemaItem>
22
+ <SchemaItem
23
+ collapsible={false}
24
+ name={\\"innerProp2\\"}
25
+ required={false}
26
+ schemaName={\\"number\\"}
27
+ qualifierMessage={undefined}
28
+ schema={{ type: \\"number\\" }}
29
+ ></SchemaItem>
30
+ </div>
31
+ </details>
32
+ </SchemaItem>;
33
+ ",
34
+ ]
35
+ `;
36
+
37
+ exports[`createNodes allOf should correctly handle shared required properties across allOf schemas 1`] = `
38
+ Array [
39
+ "<SchemaItem
40
+ collapsible={false}
41
+ name={\\"sharedProp\\"}
42
+ required={true}
43
+ schemaName={\\"string\\"}
44
+ qualifierMessage={undefined}
45
+ schema={{ type: \\"string\\" }}
46
+ ></SchemaItem>;
47
+ ",
48
+ "<SchemaItem
49
+ collapsible={false}
50
+ name={\\"anotherProp\\"}
51
+ required={true}
52
+ schemaName={\\"number\\"}
53
+ qualifierMessage={undefined}
54
+ schema={{ type: \\"number\\" }}
55
+ ></SchemaItem>;
56
+ ",
57
+ ]
58
+ `;
59
+
60
+ exports[`createNodes allOf should correctly merge nested properties from multiple allOf schemas 1`] = `
61
+ Array [
62
+ "<SchemaItem collapsible={true} className={\\"schemaItem\\"}>
63
+ <details style={{}} className={\\"openapi-markdown__details\\"}>
64
+ <summary style={{}}>
65
+ <span className={\\"openapi-schema__container\\"}>
66
+ <strong className={\\"openapi-schema__property\\"}>outerProp1</strong>
67
+ <span className={\\"openapi-schema__name\\"}> object</span>
68
+ </span>
69
+ </summary>
70
+ <div style={{ marginLeft: \\"1rem\\" }}>
71
+ <SchemaItem
72
+ collapsible={false}
73
+ name={\\"innerProp1\\"}
74
+ required={false}
75
+ schemaName={\\"string\\"}
76
+ qualifierMessage={undefined}
77
+ schema={{ type: \\"string\\" }}
78
+ ></SchemaItem>
79
+ </div>
80
+ </details>
81
+ </SchemaItem>;
82
+ ",
83
+ "<SchemaItem collapsible={true} className={\\"schemaItem\\"}>
84
+ <details style={{}} className={\\"openapi-markdown__details\\"}>
85
+ <summary style={{}}>
86
+ <span className={\\"openapi-schema__container\\"}>
87
+ <strong className={\\"openapi-schema__property\\"}>outerProp2</strong>
88
+ <span className={\\"openapi-schema__name\\"}> object</span>
89
+ </span>
90
+ </summary>
91
+ <div style={{ marginLeft: \\"1rem\\" }}>
92
+ <SchemaItem
93
+ collapsible={false}
94
+ name={\\"innerProp2\\"}
95
+ required={false}
96
+ schemaName={\\"number\\"}
97
+ qualifierMessage={undefined}
98
+ schema={{ type: \\"number\\" }}
99
+ ></SchemaItem>
100
+ </div>
101
+ </details>
102
+ </SchemaItem>;
103
+ ",
104
+ ]
105
+ `;
106
+
107
+ exports[`createNodes allOf should render same-level properties with allOf 1`] = `
108
+ Array [
109
+ "<SchemaItem
110
+ collapsible={false}
111
+ name={\\"parentProp1\\"}
112
+ required={false}
113
+ schemaName={\\"string\\"}
114
+ qualifierMessage={undefined}
115
+ schema={{ type: \\"string\\" }}
116
+ ></SchemaItem>;
117
+ ",
118
+ "<SchemaItem
119
+ collapsible={false}
120
+ name={\\"parentProp2\\"}
121
+ required={false}
122
+ schemaName={\\"string\\"}
123
+ qualifierMessage={undefined}
124
+ schema={{ type: \\"string\\" }}
125
+ ></SchemaItem>;
126
+ ",
127
+ "<SchemaItem
128
+ collapsible={false}
129
+ name={\\"allOfProp1\\"}
130
+ required={false}
131
+ schemaName={\\"string\\"}
132
+ qualifierMessage={undefined}
133
+ schema={{ type: \\"string\\" }}
134
+ ></SchemaItem>;
135
+ ",
136
+ "<SchemaItem
137
+ collapsible={false}
138
+ name={\\"allOfProp2\\"}
139
+ required={false}
140
+ schemaName={\\"string\\"}
141
+ qualifierMessage={undefined}
142
+ schema={{ type: \\"string\\" }}
143
+ ></SchemaItem>;
144
+ ",
145
+ ]
146
+ `;
147
+
148
+ exports[`createNodes oneOf should create readable MODs for oneOf primitive properties 1`] = `
4
149
  Array [
5
150
  "<SchemaItem collapsible={true} className={\\"schemaItem\\"}>
6
151
  <details style={{}} className={\\"openapi-markdown__details\\"}>