docusaurus-plugin-openapi-docs 1.4.7 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/lib/index.js +6 -2
- package/lib/markdown/createRequestSchema.js +2 -0
- package/lib/markdown/createResponseSchema.js +2 -0
- package/lib/markdown/index.js +1 -1
- package/lib/openapi/createRequestExample.js +6 -4
- package/lib/openapi/createResponseExample.js +7 -4
- package/lib/openapi/openapi.d.ts +3 -3
- package/lib/openapi/openapi.js +9 -7
- package/lib/openapi/openapi.test.js +1 -1
- package/lib/options.js +1 -0
- package/lib/types.d.ts +1 -0
- package/package.json +2 -2
- package/src/index.ts +6 -1
- package/src/markdown/createRequestSchema.ts +2 -0
- package/src/markdown/createResponseSchema.ts +2 -0
- package/src/markdown/index.ts +1 -1
- package/src/openapi/createRequestExample.ts +10 -4
- package/src/openapi/createResponseExample.ts +13 -4
- package/src/openapi/openapi.test.ts +1 -2
- package/src/openapi/openapi.ts +13 -5
- package/src/options.ts +1 -0
- package/src/types.ts +1 -0
package/README.md
CHANGED
|
@@ -121,6 +121,7 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
|
|
|
121
121
|
| ---------------- | -------- | ------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
122
122
|
| `specPath` | `string` | `null` | Designated URL or path to the source of an OpenAPI specification file or directory of multiple OpenAPI specification files. |
|
|
123
123
|
| `ouputDir` | `string` | `null` | Desired output path for generated MDX files. |
|
|
124
|
+
| `proxy` | `string` | `null` | _Optional:_ Proxy URL to prepend to base URL when performing API requests from browser. |
|
|
124
125
|
| `template` | `string` | `null` | _Optional:_ Customize MDX content with a desired template. |
|
|
125
126
|
| `downloadUrl` | `string` | `null` | _Optional:_ Designated URL for downloading OpenAPI specification. (requires `info` section/doc) |
|
|
126
127
|
| `sidebarOptions` | `object` | `null` | _Optional:_ Set of options for sidebar configuration. See below for a list of supported options. |
|
package/lib/index.js
CHANGED
|
@@ -87,8 +87,8 @@ function pluginOpenAPIDocs(context, options) {
|
|
|
87
87
|
? specPath
|
|
88
88
|
: path_1.default.resolve(siteDir, specPath);
|
|
89
89
|
try {
|
|
90
|
-
const openapiFiles = await (0, openapi_1.readOpenapiFiles)(contentPath
|
|
91
|
-
const [loadedApi, tags] = await (0, openapi_1.processOpenapiFiles)(openapiFiles, sidebarOptions);
|
|
90
|
+
const openapiFiles = await (0, openapi_1.readOpenapiFiles)(contentPath);
|
|
91
|
+
const [loadedApi, tags] = await (0, openapi_1.processOpenapiFiles)(openapiFiles, options, sidebarOptions);
|
|
92
92
|
if (!fs_1.default.existsSync(outputDir)) {
|
|
93
93
|
try {
|
|
94
94
|
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
@@ -143,6 +143,10 @@ sidebar_class_name: "{{{api.method}}} api-method"
|
|
|
143
143
|
{{#infoPath}}
|
|
144
144
|
info_path: {{{infoPath}}}
|
|
145
145
|
{{/infoPath}}
|
|
146
|
+
custom_edit_url: null
|
|
147
|
+
{{#frontMatter.proxy}}
|
|
148
|
+
proxy: {{{frontMatter.proxy}}}
|
|
149
|
+
{{/frontMatter.proxy}}
|
|
146
150
|
---
|
|
147
151
|
|
|
148
152
|
{{{markdown}}}
|
|
@@ -480,6 +480,7 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
480
480
|
collapsible: false,
|
|
481
481
|
name,
|
|
482
482
|
required: Array.isArray(required) ? required.includes(name) : required,
|
|
483
|
+
deprecated: mergedSchemas.deprecated,
|
|
483
484
|
schemaDescription: mergedSchemas.description,
|
|
484
485
|
schemaName: schemaName,
|
|
485
486
|
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
@@ -507,6 +508,7 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
507
508
|
collapsible: false,
|
|
508
509
|
name,
|
|
509
510
|
required: Array.isArray(required) ? required.includes(name) : required,
|
|
511
|
+
deprecated: schema.deprecated,
|
|
510
512
|
schemaDescription: schema.description,
|
|
511
513
|
schemaName: schemaName,
|
|
512
514
|
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
@@ -479,6 +479,7 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
479
479
|
collapsible: false,
|
|
480
480
|
name,
|
|
481
481
|
required: false,
|
|
482
|
+
deprecated: mergedSchemas.deprecated,
|
|
482
483
|
schemaDescription: mergedSchemas.description,
|
|
483
484
|
schemaName: schemaName,
|
|
484
485
|
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
@@ -506,6 +507,7 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
506
507
|
collapsible: false,
|
|
507
508
|
name,
|
|
508
509
|
required: false,
|
|
510
|
+
deprecated: schema.deprecated,
|
|
509
511
|
schemaDescription: schema.description,
|
|
510
512
|
schemaName: schemaName,
|
|
511
513
|
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
package/lib/markdown/index.js
CHANGED
|
@@ -26,7 +26,7 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
|
|
|
26
26
|
`import MimeTabs from "@theme/MimeTabs";\n`,
|
|
27
27
|
`import ParamsItem from "@theme/ParamsItem";\n`,
|
|
28
28
|
`import ResponseSamples from "@theme/ResponseSamples";\n`,
|
|
29
|
-
`import SchemaItem from "@theme/SchemaItem"
|
|
29
|
+
`import SchemaItem from "@theme/SchemaItem";\n`,
|
|
30
30
|
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
31
31
|
`import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
|
|
32
32
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
@@ -76,7 +76,7 @@ const sampleRequestFromSchema = (schema = {}) => {
|
|
|
76
76
|
const { mergedSchemas } = (0, createRequestSchema_1.mergeAllOf)(allOf);
|
|
77
77
|
if (mergedSchemas.properties) {
|
|
78
78
|
for (const [key, value] of Object.entries(mergedSchemas.properties)) {
|
|
79
|
-
if (value.readOnly && value.readOnly === true) {
|
|
79
|
+
if ((value.readOnly && value.readOnly === true) || value.deprecated) {
|
|
80
80
|
delete mergedSchemas.properties[key];
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -99,14 +99,16 @@ const sampleRequestFromSchema = (schema = {}) => {
|
|
|
99
99
|
for (let [name, prop] of Object.entries(properties !== null && properties !== void 0 ? properties : {})) {
|
|
100
100
|
if (prop.properties) {
|
|
101
101
|
for (const [key, value] of Object.entries(prop.properties)) {
|
|
102
|
-
if (value.readOnly && value.readOnly === true)
|
|
102
|
+
if ((value.readOnly && value.readOnly === true) ||
|
|
103
|
+
value.deprecated) {
|
|
103
104
|
delete prop.properties[key];
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
if (prop.items && prop.items.properties) {
|
|
108
109
|
for (const [key, value] of Object.entries(prop.items.properties)) {
|
|
109
|
-
if (value.readOnly && value.readOnly === true)
|
|
110
|
+
if ((value.readOnly && value.readOnly === true) ||
|
|
111
|
+
value.deprecated) {
|
|
110
112
|
delete prop.items.properties[key];
|
|
111
113
|
}
|
|
112
114
|
}
|
|
@@ -137,7 +139,7 @@ const sampleRequestFromSchema = (schema = {}) => {
|
|
|
137
139
|
}
|
|
138
140
|
return normalizeArray(schema.enum)[0];
|
|
139
141
|
}
|
|
140
|
-
if (schema.readOnly && schema.readOnly === true) {
|
|
142
|
+
if ((schema.readOnly && schema.readOnly === true) || schema.deprecated) {
|
|
141
143
|
return undefined;
|
|
142
144
|
}
|
|
143
145
|
return primitive(schema);
|
|
@@ -68,7 +68,8 @@ const sampleResponseFromSchema = (schema = {}) => {
|
|
|
68
68
|
const { mergedSchemas } = (0, createResponseSchema_1.mergeAllOf)(allOf);
|
|
69
69
|
if (mergedSchemas.properties) {
|
|
70
70
|
for (const [key, value] of Object.entries(mergedSchemas.properties)) {
|
|
71
|
-
if (value.writeOnly && value.writeOnly === true)
|
|
71
|
+
if ((value.writeOnly && value.writeOnly === true) ||
|
|
72
|
+
value.deprecated) {
|
|
72
73
|
delete mergedSchemas.properties[key];
|
|
73
74
|
}
|
|
74
75
|
}
|
|
@@ -99,14 +100,16 @@ const sampleResponseFromSchema = (schema = {}) => {
|
|
|
99
100
|
for (let [name, prop] of Object.entries(properties !== null && properties !== void 0 ? properties : {})) {
|
|
100
101
|
if (prop.properties) {
|
|
101
102
|
for (const [key, value] of Object.entries(prop.properties)) {
|
|
102
|
-
if (value.writeOnly && value.writeOnly === true)
|
|
103
|
+
if ((value.writeOnly && value.writeOnly === true) ||
|
|
104
|
+
value.deprecated) {
|
|
103
105
|
delete prop.properties[key];
|
|
104
106
|
}
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
109
|
if (prop.items && prop.items.properties) {
|
|
108
110
|
for (const [key, value] of Object.entries(prop.items.properties)) {
|
|
109
|
-
if (value.writeOnly && value.writeOnly === true)
|
|
111
|
+
if ((value.writeOnly && value.writeOnly === true) ||
|
|
112
|
+
value.deprecated) {
|
|
110
113
|
delete prop.items.properties[key];
|
|
111
114
|
}
|
|
112
115
|
}
|
|
@@ -137,7 +140,7 @@ const sampleResponseFromSchema = (schema = {}) => {
|
|
|
137
140
|
}
|
|
138
141
|
return normalizeArray(schema.enum)[0];
|
|
139
142
|
}
|
|
140
|
-
if (schema.writeOnly && schema.writeOnly === true) {
|
|
143
|
+
if ((schema.writeOnly && schema.writeOnly === true) || schema.deprecated) {
|
|
141
144
|
return undefined;
|
|
142
145
|
}
|
|
143
146
|
return primitive(schema);
|
package/lib/openapi/openapi.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ interface OpenApiFiles {
|
|
|
5
5
|
sourceDirName: string;
|
|
6
6
|
data: OpenApiObject;
|
|
7
7
|
}
|
|
8
|
-
export declare function readOpenapiFiles(openapiPath: string
|
|
9
|
-
export declare function processOpenapiFiles(files: OpenApiFiles[], sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[][]]>;
|
|
10
|
-
export declare function processOpenapiFile(openapiData: OpenApiObject, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
|
|
8
|
+
export declare function readOpenapiFiles(openapiPath: string): Promise<OpenApiFiles[]>;
|
|
9
|
+
export declare function processOpenapiFiles(files: OpenApiFiles[], options: APIOptions, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[][]]>;
|
|
10
|
+
export declare function processOpenapiFile(openapiData: OpenApiObject, options: APIOptions, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
|
|
11
11
|
export declare function getTagDisplayName(tagName: string, tags: TagObject[]): string;
|
|
12
12
|
export {};
|
package/lib/openapi/openapi.js
CHANGED
|
@@ -60,11 +60,12 @@ async function createPostmanCollection(openapiData) {
|
|
|
60
60
|
}
|
|
61
61
|
return await jsonToCollection(data);
|
|
62
62
|
}
|
|
63
|
-
function createItems(openapiData, sidebarOptions) {
|
|
63
|
+
function createItems(openapiData, options, sidebarOptions) {
|
|
64
64
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
65
65
|
// TODO: Find a better way to handle this
|
|
66
66
|
let items = [];
|
|
67
|
-
const
|
|
67
|
+
const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
|
|
68
|
+
const infoId = (0, kebabCase_1.default)(infoIdSpaces);
|
|
68
69
|
if (openapiData.info.description) {
|
|
69
70
|
// Only create an info page if we have a description.
|
|
70
71
|
const infoDescription = (_a = openapiData.info) === null || _a === void 0 ? void 0 : _a.description;
|
|
@@ -171,6 +172,7 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
171
172
|
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
172
173
|
.replace(/\s+$/, "")
|
|
173
174
|
: "",
|
|
175
|
+
...((options === null || options === void 0 ? void 0 : options.proxy) && { proxy: options.proxy }),
|
|
174
176
|
},
|
|
175
177
|
api: {
|
|
176
178
|
...defaults,
|
|
@@ -248,7 +250,7 @@ function bindCollectionToApiItems(items, postmanCollection) {
|
|
|
248
250
|
}
|
|
249
251
|
});
|
|
250
252
|
}
|
|
251
|
-
async function readOpenapiFiles(openapiPath
|
|
253
|
+
async function readOpenapiFiles(openapiPath) {
|
|
252
254
|
if (!(0, index_1.isURL)(openapiPath)) {
|
|
253
255
|
const stat = await fs_extra_1.default.lstat(openapiPath);
|
|
254
256
|
if (stat.isDirectory()) {
|
|
@@ -281,10 +283,10 @@ async function readOpenapiFiles(openapiPath, options) {
|
|
|
281
283
|
];
|
|
282
284
|
}
|
|
283
285
|
exports.readOpenapiFiles = readOpenapiFiles;
|
|
284
|
-
async function processOpenapiFiles(files, sidebarOptions) {
|
|
286
|
+
async function processOpenapiFiles(files, options, sidebarOptions) {
|
|
285
287
|
const promises = files.map(async (file) => {
|
|
286
288
|
if (file.data !== undefined) {
|
|
287
|
-
const processedFile = await processOpenapiFile(file.data, sidebarOptions);
|
|
289
|
+
const processedFile = await processOpenapiFile(file.data, options, sidebarOptions);
|
|
288
290
|
const itemsObjectsArray = processedFile[0].map((item) => ({
|
|
289
291
|
...item,
|
|
290
292
|
}));
|
|
@@ -315,9 +317,9 @@ async function processOpenapiFiles(files, sidebarOptions) {
|
|
|
315
317
|
return [items, tags];
|
|
316
318
|
}
|
|
317
319
|
exports.processOpenapiFiles = processOpenapiFiles;
|
|
318
|
-
async function processOpenapiFile(openapiData, sidebarOptions) {
|
|
320
|
+
async function processOpenapiFile(openapiData, options, sidebarOptions) {
|
|
319
321
|
const postmanCollection = await createPostmanCollection(openapiData);
|
|
320
|
-
const items = createItems(openapiData, sidebarOptions);
|
|
322
|
+
const items = createItems(openapiData, options, sidebarOptions);
|
|
321
323
|
bindCollectionToApiItems(items, postmanCollection);
|
|
322
324
|
let tags = [];
|
|
323
325
|
if (openapiData.tags !== undefined) {
|
|
@@ -16,7 +16,7 @@ const _1 = require(".");
|
|
|
16
16
|
describe("openapi", () => {
|
|
17
17
|
describe("readOpenapiFiles", () => {
|
|
18
18
|
it("readOpenapiFiles", async () => {
|
|
19
|
-
const results = await (0, _1.readOpenapiFiles)((0, utils_1.posixPath)(path_1.default.join(__dirname, "__fixtures__/examples"))
|
|
19
|
+
const results = await (0, _1.readOpenapiFiles)((0, utils_1.posixPath)(path_1.default.join(__dirname, "__fixtures__/examples")));
|
|
20
20
|
const categoryMeta = results.find((x) => x.source.endsWith("_category_.json"));
|
|
21
21
|
expect(categoryMeta).toBeFalsy();
|
|
22
22
|
// console.log(results);
|
package/lib/options.js
CHANGED
|
@@ -21,6 +21,7 @@ exports.OptionsSchema = utils_validation_1.Joi.object({
|
|
|
21
21
|
config: utils_validation_1.Joi.object()
|
|
22
22
|
.pattern(/^/, utils_validation_1.Joi.object({
|
|
23
23
|
specPath: utils_validation_1.Joi.string().required(),
|
|
24
|
+
proxy: utils_validation_1.Joi.string(),
|
|
24
25
|
outputDir: utils_validation_1.Joi.string().required(),
|
|
25
26
|
template: utils_validation_1.Joi.string(),
|
|
26
27
|
downloadUrl: utils_validation_1.Joi.string(),
|
package/lib/types.d.ts
CHANGED
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": "1.
|
|
4
|
+
"version": "1.5.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"engines": {
|
|
69
69
|
"node": ">=14"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "7ed68875703f5481aaf58f936ce58feea36e6596"
|
|
72
72
|
}
|
package/src/index.ts
CHANGED
|
@@ -106,9 +106,10 @@ export default function pluginOpenAPIDocs(
|
|
|
106
106
|
: path.resolve(siteDir, specPath);
|
|
107
107
|
|
|
108
108
|
try {
|
|
109
|
-
const openapiFiles = await readOpenapiFiles(contentPath
|
|
109
|
+
const openapiFiles = await readOpenapiFiles(contentPath);
|
|
110
110
|
const [loadedApi, tags] = await processOpenapiFiles(
|
|
111
111
|
openapiFiles,
|
|
112
|
+
options,
|
|
112
113
|
sidebarOptions!
|
|
113
114
|
);
|
|
114
115
|
if (!fs.existsSync(outputDir)) {
|
|
@@ -182,6 +183,10 @@ sidebar_class_name: "{{{api.method}}} api-method"
|
|
|
182
183
|
{{#infoPath}}
|
|
183
184
|
info_path: {{{infoPath}}}
|
|
184
185
|
{{/infoPath}}
|
|
186
|
+
custom_edit_url: null
|
|
187
|
+
{{#frontMatter.proxy}}
|
|
188
|
+
proxy: {{{frontMatter.proxy}}}
|
|
189
|
+
{{/frontMatter.proxy}}
|
|
185
190
|
---
|
|
186
191
|
|
|
187
192
|
{{{markdown}}}
|
|
@@ -597,6 +597,7 @@ function createEdges({
|
|
|
597
597
|
collapsible: false,
|
|
598
598
|
name,
|
|
599
599
|
required: Array.isArray(required) ? required.includes(name) : required,
|
|
600
|
+
deprecated: mergedSchemas.deprecated,
|
|
600
601
|
schemaDescription: mergedSchemas.description,
|
|
601
602
|
schemaName: schemaName,
|
|
602
603
|
qualifierMessage: getQualifierMessage(schema),
|
|
@@ -630,6 +631,7 @@ function createEdges({
|
|
|
630
631
|
collapsible: false,
|
|
631
632
|
name,
|
|
632
633
|
required: Array.isArray(required) ? required.includes(name) : required,
|
|
634
|
+
deprecated: schema.deprecated,
|
|
633
635
|
schemaDescription: schema.description,
|
|
634
636
|
schemaName: schemaName,
|
|
635
637
|
qualifierMessage: getQualifierMessage(schema),
|
|
@@ -597,6 +597,7 @@ function createEdges({
|
|
|
597
597
|
collapsible: false,
|
|
598
598
|
name,
|
|
599
599
|
required: false,
|
|
600
|
+
deprecated: mergedSchemas.deprecated,
|
|
600
601
|
schemaDescription: mergedSchemas.description,
|
|
601
602
|
schemaName: schemaName,
|
|
602
603
|
qualifierMessage: getQualifierMessage(schema),
|
|
@@ -630,6 +631,7 @@ function createEdges({
|
|
|
630
631
|
collapsible: false,
|
|
631
632
|
name,
|
|
632
633
|
required: false,
|
|
634
|
+
deprecated: schema.deprecated,
|
|
633
635
|
schemaDescription: schema.description,
|
|
634
636
|
schemaName: schemaName,
|
|
635
637
|
qualifierMessage: getQualifierMessage(schema),
|
package/src/markdown/index.ts
CHANGED
|
@@ -53,7 +53,7 @@ export function createApiPageMD({
|
|
|
53
53
|
`import MimeTabs from "@theme/MimeTabs";\n`,
|
|
54
54
|
`import ParamsItem from "@theme/ParamsItem";\n`,
|
|
55
55
|
`import ResponseSamples from "@theme/ResponseSamples";\n`,
|
|
56
|
-
`import SchemaItem from "@theme/SchemaItem"
|
|
56
|
+
`import SchemaItem from "@theme/SchemaItem";\n`,
|
|
57
57
|
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
58
58
|
`import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
|
|
59
59
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
@@ -98,7 +98,7 @@ export const sampleRequestFromSchema = (schema: SchemaObject = {}): any => {
|
|
|
98
98
|
mergeAllOf(allOf);
|
|
99
99
|
if (mergedSchemas.properties) {
|
|
100
100
|
for (const [key, value] of Object.entries(mergedSchemas.properties)) {
|
|
101
|
-
if (value.readOnly && value.readOnly === true) {
|
|
101
|
+
if ((value.readOnly && value.readOnly === true) || value.deprecated) {
|
|
102
102
|
delete mergedSchemas.properties[key];
|
|
103
103
|
}
|
|
104
104
|
}
|
|
@@ -121,7 +121,10 @@ export const sampleRequestFromSchema = (schema: SchemaObject = {}): any => {
|
|
|
121
121
|
for (let [name, prop] of Object.entries(properties ?? {})) {
|
|
122
122
|
if (prop.properties) {
|
|
123
123
|
for (const [key, value] of Object.entries(prop.properties)) {
|
|
124
|
-
if (
|
|
124
|
+
if (
|
|
125
|
+
(value.readOnly && value.readOnly === true) ||
|
|
126
|
+
value.deprecated
|
|
127
|
+
) {
|
|
125
128
|
delete prop.properties[key];
|
|
126
129
|
}
|
|
127
130
|
}
|
|
@@ -129,7 +132,10 @@ export const sampleRequestFromSchema = (schema: SchemaObject = {}): any => {
|
|
|
129
132
|
|
|
130
133
|
if (prop.items && prop.items.properties) {
|
|
131
134
|
for (const [key, value] of Object.entries(prop.items.properties)) {
|
|
132
|
-
if (
|
|
135
|
+
if (
|
|
136
|
+
(value.readOnly && value.readOnly === true) ||
|
|
137
|
+
value.deprecated
|
|
138
|
+
) {
|
|
133
139
|
delete prop.items.properties[key];
|
|
134
140
|
}
|
|
135
141
|
}
|
|
@@ -168,7 +174,7 @@ export const sampleRequestFromSchema = (schema: SchemaObject = {}): any => {
|
|
|
168
174
|
return normalizeArray(schema.enum)[0];
|
|
169
175
|
}
|
|
170
176
|
|
|
171
|
-
if (schema.readOnly && schema.readOnly === true) {
|
|
177
|
+
if ((schema.readOnly && schema.readOnly === true) || schema.deprecated) {
|
|
172
178
|
return undefined;
|
|
173
179
|
}
|
|
174
180
|
|
|
@@ -88,7 +88,10 @@ export const sampleResponseFromSchema = (schema: SchemaObject = {}): any => {
|
|
|
88
88
|
mergeAllOf(allOf);
|
|
89
89
|
if (mergedSchemas.properties) {
|
|
90
90
|
for (const [key, value] of Object.entries(mergedSchemas.properties)) {
|
|
91
|
-
if (
|
|
91
|
+
if (
|
|
92
|
+
(value.writeOnly && value.writeOnly === true) ||
|
|
93
|
+
value.deprecated
|
|
94
|
+
) {
|
|
92
95
|
delete mergedSchemas.properties[key];
|
|
93
96
|
}
|
|
94
97
|
}
|
|
@@ -121,7 +124,10 @@ export const sampleResponseFromSchema = (schema: SchemaObject = {}): any => {
|
|
|
121
124
|
for (let [name, prop] of Object.entries(properties ?? {})) {
|
|
122
125
|
if (prop.properties) {
|
|
123
126
|
for (const [key, value] of Object.entries(prop.properties)) {
|
|
124
|
-
if (
|
|
127
|
+
if (
|
|
128
|
+
(value.writeOnly && value.writeOnly === true) ||
|
|
129
|
+
value.deprecated
|
|
130
|
+
) {
|
|
125
131
|
delete prop.properties[key];
|
|
126
132
|
}
|
|
127
133
|
}
|
|
@@ -129,7 +135,10 @@ export const sampleResponseFromSchema = (schema: SchemaObject = {}): any => {
|
|
|
129
135
|
|
|
130
136
|
if (prop.items && prop.items.properties) {
|
|
131
137
|
for (const [key, value] of Object.entries(prop.items.properties)) {
|
|
132
|
-
if (
|
|
138
|
+
if (
|
|
139
|
+
(value.writeOnly && value.writeOnly === true) ||
|
|
140
|
+
value.deprecated
|
|
141
|
+
) {
|
|
133
142
|
delete prop.items.properties[key];
|
|
134
143
|
}
|
|
135
144
|
}
|
|
@@ -168,7 +177,7 @@ export const sampleResponseFromSchema = (schema: SchemaObject = {}): any => {
|
|
|
168
177
|
return normalizeArray(schema.enum)[0];
|
|
169
178
|
}
|
|
170
179
|
|
|
171
|
-
if (schema.writeOnly && schema.writeOnly === true) {
|
|
180
|
+
if ((schema.writeOnly && schema.writeOnly === true) || schema.deprecated) {
|
|
172
181
|
return undefined;
|
|
173
182
|
}
|
|
174
183
|
|
|
@@ -17,8 +17,7 @@ describe("openapi", () => {
|
|
|
17
17
|
describe("readOpenapiFiles", () => {
|
|
18
18
|
it("readOpenapiFiles", async () => {
|
|
19
19
|
const results = await readOpenapiFiles(
|
|
20
|
-
posixPath(path.join(__dirname, "__fixtures__/examples"))
|
|
21
|
-
{ specPath: "./", outputDir: "./" }
|
|
20
|
+
posixPath(path.join(__dirname, "__fixtures__/examples"))
|
|
22
21
|
);
|
|
23
22
|
const categoryMeta = results.find((x) =>
|
|
24
23
|
x.source.endsWith("_category_.json")
|
package/src/openapi/openapi.ts
CHANGED
|
@@ -80,11 +80,13 @@ type PartialPage<T> = Omit<T, "permalink" | "source" | "sourceDirName">;
|
|
|
80
80
|
|
|
81
81
|
function createItems(
|
|
82
82
|
openapiData: OpenApiObject,
|
|
83
|
+
options: APIOptions,
|
|
83
84
|
sidebarOptions: SidebarOptions
|
|
84
85
|
): ApiMetadata[] {
|
|
85
86
|
// TODO: Find a better way to handle this
|
|
86
87
|
let items: PartialPage<ApiMetadata>[] = [];
|
|
87
|
-
const
|
|
88
|
+
const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
|
|
89
|
+
const infoId = kebabCase(infoIdSpaces);
|
|
88
90
|
|
|
89
91
|
if (openapiData.info.description) {
|
|
90
92
|
// Only create an info page if we have a description.
|
|
@@ -218,6 +220,7 @@ function createItems(
|
|
|
218
220
|
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
219
221
|
.replace(/\s+$/, "")
|
|
220
222
|
: "",
|
|
223
|
+
...(options?.proxy && { proxy: options.proxy }),
|
|
221
224
|
},
|
|
222
225
|
api: {
|
|
223
226
|
...defaults,
|
|
@@ -318,8 +321,7 @@ interface OpenApiFiles {
|
|
|
318
321
|
}
|
|
319
322
|
|
|
320
323
|
export async function readOpenapiFiles(
|
|
321
|
-
openapiPath: string
|
|
322
|
-
options: APIOptions
|
|
324
|
+
openapiPath: string
|
|
323
325
|
): Promise<OpenApiFiles[]> {
|
|
324
326
|
if (!isURL(openapiPath)) {
|
|
325
327
|
const stat = await fs.lstat(openapiPath);
|
|
@@ -361,11 +363,16 @@ export async function readOpenapiFiles(
|
|
|
361
363
|
|
|
362
364
|
export async function processOpenapiFiles(
|
|
363
365
|
files: OpenApiFiles[],
|
|
366
|
+
options: APIOptions,
|
|
364
367
|
sidebarOptions: SidebarOptions
|
|
365
368
|
): Promise<[ApiMetadata[], TagObject[][]]> {
|
|
366
369
|
const promises = files.map(async (file) => {
|
|
367
370
|
if (file.data !== undefined) {
|
|
368
|
-
const processedFile = await processOpenapiFile(
|
|
371
|
+
const processedFile = await processOpenapiFile(
|
|
372
|
+
file.data,
|
|
373
|
+
options,
|
|
374
|
+
sidebarOptions
|
|
375
|
+
);
|
|
369
376
|
const itemsObjectsArray = processedFile[0].map((item) => ({
|
|
370
377
|
...item,
|
|
371
378
|
}));
|
|
@@ -402,10 +409,11 @@ export async function processOpenapiFiles(
|
|
|
402
409
|
|
|
403
410
|
export async function processOpenapiFile(
|
|
404
411
|
openapiData: OpenApiObject,
|
|
412
|
+
options: APIOptions,
|
|
405
413
|
sidebarOptions: SidebarOptions
|
|
406
414
|
): Promise<[ApiMetadata[], TagObject[]]> {
|
|
407
415
|
const postmanCollection = await createPostmanCollection(openapiData);
|
|
408
|
-
const items = createItems(openapiData, sidebarOptions);
|
|
416
|
+
const items = createItems(openapiData, options, sidebarOptions);
|
|
409
417
|
|
|
410
418
|
bindCollectionToApiItems(items, postmanCollection);
|
|
411
419
|
|
package/src/options.ts
CHANGED