docusaurus-plugin-openapi-docs 0.0.0-beta.739 → 0.0.0-beta.741
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/lib/markdown/createSchema.js +26 -40
- package/lib/markdown/createSchema.test.js +76 -0
- package/lib/openapi/types.d.ts +1 -1
- package/lib/sidebars/index.js +3 -1
- package/package.json +2 -2
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +221 -0
- package/src/markdown/createSchema.test.ts +87 -0
- package/src/markdown/createSchema.ts +30 -46
- package/src/openapi/types.ts +1 -1
- package/src/sidebars/index.ts +4 -1
|
@@ -11,6 +11,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createNodes = exports.mergeAllOf = void 0;
|
|
13
13
|
const clsx_1 = __importDefault(require("clsx"));
|
|
14
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
14
15
|
const createArrayBracket_1 = require("./createArrayBracket");
|
|
15
16
|
const createDescription_1 = require("./createDescription");
|
|
16
17
|
const createDetails_1 = require("./createDetails");
|
|
@@ -141,70 +142,52 @@ function createProperties(schema) {
|
|
|
141
142
|
* For handling additionalProperties.
|
|
142
143
|
*/
|
|
143
144
|
function createAdditionalProperties(schema) {
|
|
144
|
-
var _a
|
|
145
|
+
var _a;
|
|
145
146
|
const additionalProperties = schema.additionalProperties;
|
|
146
|
-
|
|
147
|
+
if (!additionalProperties)
|
|
148
|
+
return [];
|
|
147
149
|
// Handle free-form objects
|
|
148
|
-
if (
|
|
150
|
+
if (additionalProperties === true || (0, isEmpty_1.default)(additionalProperties)) {
|
|
149
151
|
return (0, utils_1.create)("SchemaItem", {
|
|
150
152
|
name: "property name*",
|
|
151
153
|
required: false,
|
|
152
154
|
schemaName: "any",
|
|
153
|
-
qualifierMessage: (0, schema_1.getQualifierMessage)(schema
|
|
155
|
+
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
154
156
|
schema: schema,
|
|
155
157
|
collapsible: false,
|
|
156
158
|
discriminator: false,
|
|
157
159
|
});
|
|
158
160
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
// objects, arrays, complex schemas
|
|
162
|
+
if (additionalProperties.properties ||
|
|
163
|
+
additionalProperties.items ||
|
|
164
|
+
additionalProperties.allOf ||
|
|
165
|
+
additionalProperties.additionalProperties ||
|
|
166
|
+
additionalProperties.oneOf ||
|
|
167
|
+
additionalProperties.anyOf) {
|
|
166
168
|
const title = additionalProperties.title;
|
|
167
169
|
const schemaName = (0, schema_1.getSchemaName)(additionalProperties);
|
|
168
170
|
const required = (_a = schema.required) !== null && _a !== void 0 ? _a : false;
|
|
169
171
|
return createDetailsNode("property name*", title !== null && title !== void 0 ? title : schemaName, additionalProperties, required, schema.nullable);
|
|
170
172
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
if (additionalProperties !== undefined) {
|
|
178
|
-
const type = (_j = (_h = schema.additionalProperties) === null || _h === void 0 ? void 0 : _h.additionalProperties) === null || _j === void 0 ? void 0 : _j.type;
|
|
179
|
-
const schemaName = (0, schema_1.getSchemaName)((_k = schema.additionalProperties) === null || _k === void 0 ? void 0 : _k.additionalProperties);
|
|
180
|
-
return (0, utils_1.create)("SchemaItem", {
|
|
181
|
-
name: "property name*",
|
|
182
|
-
required: false,
|
|
183
|
-
schemaName: schemaName !== null && schemaName !== void 0 ? schemaName : type,
|
|
184
|
-
qualifierMessage: (_l = schema.additionalProperties) !== null && _l !== void 0 ? _l : (0, schema_1.getQualifierMessage)(schema.additionalProperties),
|
|
185
|
-
schema: schema,
|
|
186
|
-
collapsible: false,
|
|
187
|
-
discriminator: false,
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
const schemaName = (0, schema_1.getSchemaName)(schema.additionalProperties);
|
|
173
|
+
// primitive types
|
|
174
|
+
if (additionalProperties.type === "string" ||
|
|
175
|
+
additionalProperties.type === "boolean" ||
|
|
176
|
+
additionalProperties.type === "integer" ||
|
|
177
|
+
additionalProperties.type === "number") {
|
|
178
|
+
const schemaName = (0, schema_1.getSchemaName)(additionalProperties);
|
|
191
179
|
return (0, utils_1.create)("SchemaItem", {
|
|
192
180
|
name: "property name*",
|
|
193
181
|
required: false,
|
|
194
182
|
schemaName: schemaName,
|
|
195
183
|
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
196
|
-
schema:
|
|
184
|
+
schema: additionalProperties,
|
|
197
185
|
collapsible: false,
|
|
198
186
|
discriminator: false,
|
|
199
187
|
});
|
|
200
188
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
schema: val,
|
|
204
|
-
required: Array.isArray(schema.required)
|
|
205
|
-
? schema.required.includes(key)
|
|
206
|
-
: false,
|
|
207
|
-
}));
|
|
189
|
+
// unknown
|
|
190
|
+
return [];
|
|
208
191
|
}
|
|
209
192
|
/**
|
|
210
193
|
* For handling items.
|
|
@@ -593,7 +576,10 @@ function createNodes(schema, schemaType) {
|
|
|
593
576
|
}
|
|
594
577
|
if (schema.allOf !== undefined) {
|
|
595
578
|
const { mergedSchemas } = mergeAllOf(schema.allOf);
|
|
596
|
-
|
|
579
|
+
if (mergedSchemas.oneOf !== undefined ||
|
|
580
|
+
mergedSchemas.anyOf !== undefined) {
|
|
581
|
+
nodes.push(createAnyOneOf(mergedSchemas));
|
|
582
|
+
}
|
|
597
583
|
if (mergedSchemas.properties !== undefined) {
|
|
598
584
|
nodes.push(createProperties(mergedSchemas));
|
|
599
585
|
}
|
|
@@ -71,4 +71,80 @@ describe("createNodes", () => {
|
|
|
71
71
|
};
|
|
72
72
|
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "request").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
73
73
|
});
|
|
74
|
+
describe("additionalProperties", () => {
|
|
75
|
+
it.each([
|
|
76
|
+
[
|
|
77
|
+
{
|
|
78
|
+
allOf: [
|
|
79
|
+
{
|
|
80
|
+
oneOf: [
|
|
81
|
+
{
|
|
82
|
+
type: "object",
|
|
83
|
+
properties: {
|
|
84
|
+
type: {
|
|
85
|
+
type: "string",
|
|
86
|
+
enum: ["nose"],
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
required: ["type"],
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
type: "object",
|
|
93
|
+
properties: {
|
|
94
|
+
type: {
|
|
95
|
+
type: "string",
|
|
96
|
+
enum: ["mouth"],
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
required: ["type"],
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
type: "object",
|
|
103
|
+
properties: {
|
|
104
|
+
type: {
|
|
105
|
+
type: "string",
|
|
106
|
+
enum: ["eyes"],
|
|
107
|
+
},
|
|
108
|
+
default: {
|
|
109
|
+
type: "string",
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
required: ["type"],
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
type: "object",
|
|
118
|
+
properties: {
|
|
119
|
+
description: {
|
|
120
|
+
type: "string",
|
|
121
|
+
description: "Description of the body part.",
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
required: ["description"],
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
[
|
|
130
|
+
{
|
|
131
|
+
type: "array",
|
|
132
|
+
items: { type: "object", properties: { a: "string", b: "number" } },
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
[{ type: "string" }],
|
|
136
|
+
[{ type: "number" }],
|
|
137
|
+
[{ type: "integer" }],
|
|
138
|
+
[{ type: "boolean" }],
|
|
139
|
+
[false],
|
|
140
|
+
[true],
|
|
141
|
+
[{}],
|
|
142
|
+
])("should handle additionalProperties: %p", async (additionalProperties) => {
|
|
143
|
+
const schema = {
|
|
144
|
+
type: "object",
|
|
145
|
+
additionalProperties,
|
|
146
|
+
};
|
|
147
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "request").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
74
150
|
});
|
package/lib/openapi/types.d.ts
CHANGED
|
@@ -269,7 +269,7 @@ export type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf"
|
|
|
269
269
|
not?: SchemaObject;
|
|
270
270
|
items?: SchemaObject;
|
|
271
271
|
properties?: Map<SchemaObject>;
|
|
272
|
-
additionalProperties?:
|
|
272
|
+
additionalProperties?: boolean | SchemaObject;
|
|
273
273
|
nullable?: boolean;
|
|
274
274
|
discriminator?: DiscriminatorObject;
|
|
275
275
|
readOnly?: boolean;
|
package/lib/sidebars/index.js
CHANGED
|
@@ -55,7 +55,9 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
55
55
|
apiTags.push(tag.name);
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
|
-
|
|
58
|
+
if (sidebarOptions.groupPathsBy !== "tagGroup") {
|
|
59
|
+
apiTags = (0, uniq_1.default)(apiTags.concat(operationTags, schemaTags));
|
|
60
|
+
}
|
|
59
61
|
const basePath = docPath
|
|
60
62
|
? outputDir.split(docPath)[1].replace(/^\/+/g, "")
|
|
61
63
|
: outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
|
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-beta.
|
|
4
|
+
"version": "0.0.0-beta.741",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">=14"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "58863e27abae4f8e870ff050b3bcb276bda49fb6"
|
|
66
66
|
}
|
|
@@ -1,5 +1,226 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
+
exports[`createNodes additionalProperties should handle additionalProperties: {"allOf": [Array]} 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\\"}>property name*</strong>
|
|
10
|
+
<span className={\\"openapi-schema__name\\"}>object</span>
|
|
11
|
+
</span>
|
|
12
|
+
</summary>
|
|
13
|
+
<div style={{ marginLeft: \\"1rem\\" }}>
|
|
14
|
+
<div>
|
|
15
|
+
<span className={\\"badge badge--info\\"}>oneOf</span>
|
|
16
|
+
<SchemaTabs>
|
|
17
|
+
<TabItem label={\\"MOD1\\"} value={\\"0-item-properties\\"}>
|
|
18
|
+
<SchemaItem
|
|
19
|
+
collapsible={false}
|
|
20
|
+
name={\\"type\\"}
|
|
21
|
+
required={true}
|
|
22
|
+
schemaName={\\"string\\"}
|
|
23
|
+
qualifierMessage={\\"**Possible values:** [\`nose\`]\\"}
|
|
24
|
+
schema={{ type: \\"string\\", enum: [\\"nose\\"] }}
|
|
25
|
+
></SchemaItem>
|
|
26
|
+
</TabItem>
|
|
27
|
+
<TabItem label={\\"MOD2\\"} value={\\"1-item-properties\\"}>
|
|
28
|
+
<SchemaItem
|
|
29
|
+
collapsible={false}
|
|
30
|
+
name={\\"type\\"}
|
|
31
|
+
required={true}
|
|
32
|
+
schemaName={\\"string\\"}
|
|
33
|
+
qualifierMessage={\\"**Possible values:** [\`mouth\`]\\"}
|
|
34
|
+
schema={{ type: \\"string\\", enum: [\\"mouth\\"] }}
|
|
35
|
+
></SchemaItem>
|
|
36
|
+
</TabItem>
|
|
37
|
+
<TabItem label={\\"MOD3\\"} value={\\"2-item-properties\\"}>
|
|
38
|
+
<SchemaItem
|
|
39
|
+
collapsible={false}
|
|
40
|
+
name={\\"type\\"}
|
|
41
|
+
required={true}
|
|
42
|
+
schemaName={\\"string\\"}
|
|
43
|
+
qualifierMessage={\\"**Possible values:** [\`eyes\`]\\"}
|
|
44
|
+
schema={{ type: \\"string\\", enum: [\\"eyes\\"] }}
|
|
45
|
+
></SchemaItem>
|
|
46
|
+
<SchemaItem
|
|
47
|
+
collapsible={false}
|
|
48
|
+
name={\\"default\\"}
|
|
49
|
+
required={false}
|
|
50
|
+
schemaName={\\"string\\"}
|
|
51
|
+
qualifierMessage={undefined}
|
|
52
|
+
schema={{ type: \\"string\\" }}
|
|
53
|
+
></SchemaItem>
|
|
54
|
+
</TabItem>
|
|
55
|
+
</SchemaTabs>
|
|
56
|
+
</div>
|
|
57
|
+
<SchemaItem
|
|
58
|
+
collapsible={false}
|
|
59
|
+
name={\\"description\\"}
|
|
60
|
+
required={true}
|
|
61
|
+
schemaName={\\"string\\"}
|
|
62
|
+
qualifierMessage={undefined}
|
|
63
|
+
schema={{
|
|
64
|
+
type: \\"string\\",
|
|
65
|
+
description: \\"Description of the body part.\\",
|
|
66
|
+
}}
|
|
67
|
+
></SchemaItem>
|
|
68
|
+
</div>
|
|
69
|
+
</details>
|
|
70
|
+
</SchemaItem>;
|
|
71
|
+
",
|
|
72
|
+
]
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
exports[`createNodes additionalProperties should handle additionalProperties: {"items": [Object], "type": "array"} 1`] = `
|
|
76
|
+
Array [
|
|
77
|
+
"<SchemaItem collapsible={true} className={\\"schemaItem\\"}>
|
|
78
|
+
<details style={{}} className={\\"openapi-markdown__details\\"}>
|
|
79
|
+
<summary style={{}}>
|
|
80
|
+
<span className={\\"openapi-schema__container\\"}>
|
|
81
|
+
<strong className={\\"openapi-schema__property\\"}>property name*</strong>
|
|
82
|
+
<span className={\\"openapi-schema__name\\"}>object[]</span>
|
|
83
|
+
</span>
|
|
84
|
+
</summary>
|
|
85
|
+
<div style={{ marginLeft: \\"1rem\\" }}>
|
|
86
|
+
<li>
|
|
87
|
+
<div
|
|
88
|
+
style={{
|
|
89
|
+
fontSize: \\"var(--ifm-code-font-size)\\",
|
|
90
|
+
opacity: \\"0.6\\",
|
|
91
|
+
marginLeft: \\"-.5rem\\",
|
|
92
|
+
paddingBottom: \\".5rem\\",
|
|
93
|
+
}}
|
|
94
|
+
>
|
|
95
|
+
Array [
|
|
96
|
+
</div>
|
|
97
|
+
</li>
|
|
98
|
+
<SchemaItem
|
|
99
|
+
collapsible={false}
|
|
100
|
+
name={\\"a\\"}
|
|
101
|
+
required={false}
|
|
102
|
+
schemaName={\\"\\"}
|
|
103
|
+
qualifierMessage={undefined}
|
|
104
|
+
schema={\\"string\\"}
|
|
105
|
+
></SchemaItem>
|
|
106
|
+
<SchemaItem
|
|
107
|
+
collapsible={false}
|
|
108
|
+
name={\\"b\\"}
|
|
109
|
+
required={false}
|
|
110
|
+
schemaName={\\"\\"}
|
|
111
|
+
qualifierMessage={undefined}
|
|
112
|
+
schema={\\"number\\"}
|
|
113
|
+
></SchemaItem>
|
|
114
|
+
<li>
|
|
115
|
+
<div
|
|
116
|
+
style={{
|
|
117
|
+
fontSize: \\"var(--ifm-code-font-size)\\",
|
|
118
|
+
opacity: \\"0.6\\",
|
|
119
|
+
marginLeft: \\"-.5rem\\",
|
|
120
|
+
}}
|
|
121
|
+
>
|
|
122
|
+
]
|
|
123
|
+
</div>
|
|
124
|
+
</li>
|
|
125
|
+
</div>
|
|
126
|
+
</details>
|
|
127
|
+
</SchemaItem>;
|
|
128
|
+
",
|
|
129
|
+
]
|
|
130
|
+
`;
|
|
131
|
+
|
|
132
|
+
exports[`createNodes additionalProperties should handle additionalProperties: {"type": "boolean"} 1`] = `
|
|
133
|
+
Array [
|
|
134
|
+
"<SchemaItem
|
|
135
|
+
name={\\"property name*\\"}
|
|
136
|
+
required={false}
|
|
137
|
+
schemaName={\\"boolean\\"}
|
|
138
|
+
qualifierMessage={undefined}
|
|
139
|
+
schema={{ type: \\"boolean\\" }}
|
|
140
|
+
collapsible={false}
|
|
141
|
+
discriminator={false}
|
|
142
|
+
></SchemaItem>;
|
|
143
|
+
",
|
|
144
|
+
]
|
|
145
|
+
`;
|
|
146
|
+
|
|
147
|
+
exports[`createNodes additionalProperties should handle additionalProperties: {"type": "integer"} 1`] = `
|
|
148
|
+
Array [
|
|
149
|
+
"<SchemaItem
|
|
150
|
+
name={\\"property name*\\"}
|
|
151
|
+
required={false}
|
|
152
|
+
schemaName={\\"integer\\"}
|
|
153
|
+
qualifierMessage={undefined}
|
|
154
|
+
schema={{ type: \\"integer\\" }}
|
|
155
|
+
collapsible={false}
|
|
156
|
+
discriminator={false}
|
|
157
|
+
></SchemaItem>;
|
|
158
|
+
",
|
|
159
|
+
]
|
|
160
|
+
`;
|
|
161
|
+
|
|
162
|
+
exports[`createNodes additionalProperties should handle additionalProperties: {"type": "number"} 1`] = `
|
|
163
|
+
Array [
|
|
164
|
+
"<SchemaItem
|
|
165
|
+
name={\\"property name*\\"}
|
|
166
|
+
required={false}
|
|
167
|
+
schemaName={\\"number\\"}
|
|
168
|
+
qualifierMessage={undefined}
|
|
169
|
+
schema={{ type: \\"number\\" }}
|
|
170
|
+
collapsible={false}
|
|
171
|
+
discriminator={false}
|
|
172
|
+
></SchemaItem>;
|
|
173
|
+
",
|
|
174
|
+
]
|
|
175
|
+
`;
|
|
176
|
+
|
|
177
|
+
exports[`createNodes additionalProperties should handle additionalProperties: {"type": "string"} 1`] = `
|
|
178
|
+
Array [
|
|
179
|
+
"<SchemaItem
|
|
180
|
+
name={\\"property name*\\"}
|
|
181
|
+
required={false}
|
|
182
|
+
schemaName={\\"string\\"}
|
|
183
|
+
qualifierMessage={undefined}
|
|
184
|
+
schema={{ type: \\"string\\" }}
|
|
185
|
+
collapsible={false}
|
|
186
|
+
discriminator={false}
|
|
187
|
+
></SchemaItem>;
|
|
188
|
+
",
|
|
189
|
+
]
|
|
190
|
+
`;
|
|
191
|
+
|
|
192
|
+
exports[`createNodes additionalProperties should handle additionalProperties: {} 1`] = `
|
|
193
|
+
Array [
|
|
194
|
+
"<SchemaItem
|
|
195
|
+
name={\\"property name*\\"}
|
|
196
|
+
required={false}
|
|
197
|
+
schemaName={\\"any\\"}
|
|
198
|
+
qualifierMessage={undefined}
|
|
199
|
+
schema={{ type: \\"object\\", additionalProperties: {} }}
|
|
200
|
+
collapsible={false}
|
|
201
|
+
discriminator={false}
|
|
202
|
+
></SchemaItem>;
|
|
203
|
+
",
|
|
204
|
+
]
|
|
205
|
+
`;
|
|
206
|
+
|
|
207
|
+
exports[`createNodes additionalProperties should handle additionalProperties: false 1`] = `Array []`;
|
|
208
|
+
|
|
209
|
+
exports[`createNodes additionalProperties should handle additionalProperties: true 1`] = `
|
|
210
|
+
Array [
|
|
211
|
+
"<SchemaItem
|
|
212
|
+
name={\\"property name*\\"}
|
|
213
|
+
required={false}
|
|
214
|
+
schemaName={\\"any\\"}
|
|
215
|
+
qualifierMessage={undefined}
|
|
216
|
+
schema={{ type: \\"object\\", additionalProperties: true }}
|
|
217
|
+
collapsible={false}
|
|
218
|
+
discriminator={false}
|
|
219
|
+
></SchemaItem>;
|
|
220
|
+
",
|
|
221
|
+
]
|
|
222
|
+
`;
|
|
223
|
+
|
|
3
224
|
exports[`createNodes should create readable MODs for oneOf primitive properties 1`] = `
|
|
4
225
|
Array [
|
|
5
226
|
"<SchemaItem collapsible={true} className={\\"schemaItem\\"}>
|
|
@@ -56,4 +56,91 @@ describe("createNodes", () => {
|
|
|
56
56
|
)
|
|
57
57
|
).toMatchSnapshot();
|
|
58
58
|
});
|
|
59
|
+
|
|
60
|
+
describe("additionalProperties", () => {
|
|
61
|
+
it.each([
|
|
62
|
+
[
|
|
63
|
+
{
|
|
64
|
+
allOf: [
|
|
65
|
+
{
|
|
66
|
+
oneOf: [
|
|
67
|
+
{
|
|
68
|
+
type: "object",
|
|
69
|
+
properties: {
|
|
70
|
+
type: {
|
|
71
|
+
type: "string",
|
|
72
|
+
enum: ["nose"],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
required: ["type"],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
type: "object",
|
|
79
|
+
properties: {
|
|
80
|
+
type: {
|
|
81
|
+
type: "string",
|
|
82
|
+
enum: ["mouth"],
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
required: ["type"],
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
type: "object",
|
|
89
|
+
properties: {
|
|
90
|
+
type: {
|
|
91
|
+
type: "string",
|
|
92
|
+
enum: ["eyes"],
|
|
93
|
+
},
|
|
94
|
+
default: {
|
|
95
|
+
type: "string",
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
required: ["type"],
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
type: "object",
|
|
104
|
+
properties: {
|
|
105
|
+
description: {
|
|
106
|
+
type: "string",
|
|
107
|
+
description: "Description of the body part.",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
required: ["description"],
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
[
|
|
116
|
+
{
|
|
117
|
+
type: "array",
|
|
118
|
+
items: { type: "object", properties: { a: "string", b: "number" } },
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
[{ type: "string" }],
|
|
122
|
+
[{ type: "number" }],
|
|
123
|
+
[{ type: "integer" }],
|
|
124
|
+
[{ type: "boolean" }],
|
|
125
|
+
[false],
|
|
126
|
+
[true],
|
|
127
|
+
[{}],
|
|
128
|
+
] as [SchemaObject["additionalProperties"]][])(
|
|
129
|
+
"should handle additionalProperties: %p",
|
|
130
|
+
async (additionalProperties) => {
|
|
131
|
+
const schema: SchemaObject = {
|
|
132
|
+
type: "object",
|
|
133
|
+
additionalProperties,
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
expect(
|
|
137
|
+
await Promise.all(
|
|
138
|
+
createNodes(schema, "request").map(
|
|
139
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
140
|
+
)
|
|
141
|
+
)
|
|
142
|
+
).toMatchSnapshot();
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
});
|
|
59
146
|
});
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
8
|
import clsx from "clsx";
|
|
9
|
+
import isEmpty from "lodash/isEmpty";
|
|
9
10
|
|
|
10
11
|
import {
|
|
11
12
|
createClosingArrayBracket,
|
|
@@ -156,27 +157,29 @@ function createProperties(schema: SchemaObject) {
|
|
|
156
157
|
*/
|
|
157
158
|
function createAdditionalProperties(schema: SchemaObject) {
|
|
158
159
|
const additionalProperties = schema.additionalProperties;
|
|
159
|
-
|
|
160
|
+
if (!additionalProperties) return [];
|
|
161
|
+
|
|
160
162
|
// Handle free-form objects
|
|
161
|
-
if (
|
|
163
|
+
if (additionalProperties === true || isEmpty(additionalProperties)) {
|
|
162
164
|
return create("SchemaItem", {
|
|
163
165
|
name: "property name*",
|
|
164
166
|
required: false,
|
|
165
167
|
schemaName: "any",
|
|
166
|
-
qualifierMessage: getQualifierMessage(schema
|
|
168
|
+
qualifierMessage: getQualifierMessage(schema),
|
|
167
169
|
schema: schema,
|
|
168
170
|
collapsible: false,
|
|
169
171
|
discriminator: false,
|
|
170
172
|
});
|
|
171
173
|
}
|
|
174
|
+
|
|
175
|
+
// objects, arrays, complex schemas
|
|
172
176
|
if (
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
additionalProperties?.anyOf)
|
|
177
|
+
additionalProperties.properties ||
|
|
178
|
+
additionalProperties.items ||
|
|
179
|
+
additionalProperties.allOf ||
|
|
180
|
+
additionalProperties.additionalProperties ||
|
|
181
|
+
additionalProperties.oneOf ||
|
|
182
|
+
additionalProperties.anyOf
|
|
180
183
|
) {
|
|
181
184
|
const title = additionalProperties.title as string;
|
|
182
185
|
const schemaName = getSchemaName(additionalProperties);
|
|
@@ -190,52 +193,27 @@ function createAdditionalProperties(schema: SchemaObject) {
|
|
|
190
193
|
);
|
|
191
194
|
}
|
|
192
195
|
|
|
196
|
+
// primitive types
|
|
193
197
|
if (
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
(schema.additionalProperties?.type as string) === "number"
|
|
198
|
+
additionalProperties.type === "string" ||
|
|
199
|
+
additionalProperties.type === "boolean" ||
|
|
200
|
+
additionalProperties.type === "integer" ||
|
|
201
|
+
additionalProperties.type === "number"
|
|
199
202
|
) {
|
|
200
|
-
const
|
|
201
|
-
schema.additionalProperties?.additionalProperties;
|
|
202
|
-
if (additionalProperties !== undefined) {
|
|
203
|
-
const type = schema.additionalProperties?.additionalProperties?.type;
|
|
204
|
-
const schemaName = getSchemaName(
|
|
205
|
-
schema.additionalProperties?.additionalProperties!
|
|
206
|
-
);
|
|
207
|
-
return create("SchemaItem", {
|
|
208
|
-
name: "property name*",
|
|
209
|
-
required: false,
|
|
210
|
-
schemaName: schemaName ?? type,
|
|
211
|
-
qualifierMessage:
|
|
212
|
-
schema.additionalProperties ??
|
|
213
|
-
getQualifierMessage(schema.additionalProperties),
|
|
214
|
-
schema: schema,
|
|
215
|
-
collapsible: false,
|
|
216
|
-
discriminator: false,
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
const schemaName = getSchemaName(schema.additionalProperties!);
|
|
203
|
+
const schemaName = getSchemaName(additionalProperties);
|
|
220
204
|
return create("SchemaItem", {
|
|
221
205
|
name: "property name*",
|
|
222
206
|
required: false,
|
|
223
207
|
schemaName: schemaName,
|
|
224
208
|
qualifierMessage: getQualifierMessage(schema),
|
|
225
|
-
schema:
|
|
209
|
+
schema: additionalProperties,
|
|
226
210
|
collapsible: false,
|
|
227
211
|
discriminator: false,
|
|
228
212
|
});
|
|
229
213
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
schema: val,
|
|
234
|
-
required: Array.isArray(schema.required)
|
|
235
|
-
? schema.required.includes(key)
|
|
236
|
-
: false,
|
|
237
|
-
})
|
|
238
|
-
);
|
|
214
|
+
|
|
215
|
+
// unknown
|
|
216
|
+
return [];
|
|
239
217
|
}
|
|
240
218
|
|
|
241
219
|
/**
|
|
@@ -792,7 +770,13 @@ export function createNodes(
|
|
|
792
770
|
if (schema.allOf !== undefined) {
|
|
793
771
|
const { mergedSchemas } = mergeAllOf(schema.allOf);
|
|
794
772
|
|
|
795
|
-
|
|
773
|
+
if (
|
|
774
|
+
mergedSchemas.oneOf !== undefined ||
|
|
775
|
+
mergedSchemas.anyOf !== undefined
|
|
776
|
+
) {
|
|
777
|
+
nodes.push(createAnyOneOf(mergedSchemas));
|
|
778
|
+
}
|
|
779
|
+
|
|
796
780
|
if (mergedSchemas.properties !== undefined) {
|
|
797
781
|
nodes.push(createProperties(mergedSchemas));
|
|
798
782
|
}
|
package/src/openapi/types.ts
CHANGED
|
@@ -341,7 +341,7 @@ export type SchemaObject = Omit<
|
|
|
341
341
|
not?: SchemaObject;
|
|
342
342
|
items?: SchemaObject;
|
|
343
343
|
properties?: Map<SchemaObject>;
|
|
344
|
-
additionalProperties?:
|
|
344
|
+
additionalProperties?: boolean | SchemaObject;
|
|
345
345
|
|
|
346
346
|
// OpenAPI additions
|
|
347
347
|
nullable?: boolean;
|
package/src/sidebars/index.ts
CHANGED
|
@@ -93,7 +93,10 @@ function groupByTags(
|
|
|
93
93
|
apiTags.push(tag.name!);
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
|
-
|
|
96
|
+
|
|
97
|
+
if (sidebarOptions.groupPathsBy !== "tagGroup") {
|
|
98
|
+
apiTags = uniq(apiTags.concat(operationTags, schemaTags));
|
|
99
|
+
}
|
|
97
100
|
|
|
98
101
|
const basePath = docPath
|
|
99
102
|
? outputDir.split(docPath!)[1].replace(/^\/+/g, "")
|