docusaurus-plugin-openapi-docs 0.0.0-421 → 0.0.0-422
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/createRequestBodyDetails.js +2 -2
- package/lib/markdown/createRequestSchema.d.ts +21 -0
- package/lib/markdown/{createSchemaDetails.js → createRequestSchema.js} +11 -5
- package/lib/markdown/{createSchemaDetails.d.ts → createResponseSchema.d.ts} +1 -1
- package/lib/markdown/createResponseSchema.js +680 -0
- package/lib/markdown/createStatusCodes.js +3 -3
- package/lib/openapi/createExample.js +27 -14
- package/lib/openapi/openapi.d.ts +1 -1
- package/lib/openapi/openapi.js +1 -1
- package/lib/sidebars/index.d.ts +1 -1
- package/lib/sidebars/index.js +1 -1
- package/package.json +2 -2
- package/src/markdown/createRequestBodyDetails.ts +2 -2
- package/src/markdown/{createSchemaDetails.ts → createRequestSchema.ts} +11 -5
- package/src/markdown/createResponseSchema.ts +850 -0
- package/src/markdown/createStatusCodes.ts +3 -3
- package/src/openapi/createExample.ts +31 -14
- package/src/openapi/openapi.ts +2 -2
- package/src/sidebars/index.ts +3 -3
|
@@ -10,7 +10,7 @@ exports.createStatusCodes = void 0;
|
|
|
10
10
|
const createDescription_1 = require("./createDescription");
|
|
11
11
|
const createDetails_1 = require("./createDetails");
|
|
12
12
|
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
13
|
-
const
|
|
13
|
+
const createResponseSchema_1 = require("./createResponseSchema");
|
|
14
14
|
const utils_1 = require("./utils");
|
|
15
15
|
const utils_2 = require("./utils");
|
|
16
16
|
function createResponseHeaders(responseHeaders) {
|
|
@@ -114,7 +114,7 @@ function createStatusCodes({ responses }) {
|
|
|
114
114
|
],
|
|
115
115
|
}),
|
|
116
116
|
(0, utils_1.create)("div", {
|
|
117
|
-
children: (0,
|
|
117
|
+
children: (0, createResponseSchema_1.createResponseSchema)({
|
|
118
118
|
title: "Schema",
|
|
119
119
|
body: {
|
|
120
120
|
content: responses[code].content,
|
|
@@ -140,7 +140,7 @@ function createStatusCodes({ responses }) {
|
|
|
140
140
|
],
|
|
141
141
|
})),
|
|
142
142
|
(0, utils_2.guard)(!responseExamples, () => (0, utils_1.create)("div", {
|
|
143
|
-
children: (0,
|
|
143
|
+
children: (0, createResponseSchema_1.createResponseSchema)({
|
|
144
144
|
title: "Schema",
|
|
145
145
|
body: {
|
|
146
146
|
content: responses[code].content,
|
|
@@ -11,11 +11,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.sampleFromSchema = void 0;
|
|
13
13
|
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
+
const createRequestSchema_1 = require("../markdown/createRequestSchema");
|
|
14
15
|
const primitives = {
|
|
15
16
|
string: {
|
|
16
17
|
default: () => "string",
|
|
17
18
|
email: () => "user@example.com",
|
|
18
19
|
date: () => new Date().toISOString().substring(0, 10),
|
|
20
|
+
"date-time": () => new Date().toISOString().substring(0, 10),
|
|
19
21
|
uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
|
20
22
|
hostname: () => "example.com",
|
|
21
23
|
ipv4: () => "198.51.100.42",
|
|
@@ -41,21 +43,15 @@ const sampleFromSchema = (schema = {}) => {
|
|
|
41
43
|
return example;
|
|
42
44
|
}
|
|
43
45
|
if (allOf) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
for (let item of allOf) {
|
|
51
|
-
if (item.properties) {
|
|
52
|
-
obj.properties = {
|
|
53
|
-
...obj.properties,
|
|
54
|
-
...item.properties,
|
|
55
|
-
};
|
|
46
|
+
const { mergedSchemas } = (0, createRequestSchema_1.mergeAllOf)(allOf);
|
|
47
|
+
if (mergedSchemas.properties) {
|
|
48
|
+
for (const [key, value] of Object.entries(mergedSchemas.properties)) {
|
|
49
|
+
if (value.readOnly && value.readOnly === true) {
|
|
50
|
+
delete mergedSchemas.properties[key];
|
|
51
|
+
}
|
|
56
52
|
}
|
|
57
53
|
}
|
|
58
|
-
return (0, exports.sampleFromSchema)(
|
|
54
|
+
return (0, exports.sampleFromSchema)(mergedSchemas);
|
|
59
55
|
}
|
|
60
56
|
if (!type) {
|
|
61
57
|
if (properties) {
|
|
@@ -71,6 +67,20 @@ const sampleFromSchema = (schema = {}) => {
|
|
|
71
67
|
if (type === "object") {
|
|
72
68
|
let obj = {};
|
|
73
69
|
for (let [name, prop] of Object.entries(properties !== null && properties !== void 0 ? properties : {})) {
|
|
70
|
+
if (prop.properties) {
|
|
71
|
+
for (const [key, value] of Object.entries(prop.properties)) {
|
|
72
|
+
if (value.readOnly && value.readOnly === true) {
|
|
73
|
+
delete prop.properties[key];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (prop.items && prop.items.properties) {
|
|
78
|
+
for (const [key, value] of Object.entries(prop.items.properties)) {
|
|
79
|
+
if (value.readOnly && value.readOnly === true) {
|
|
80
|
+
delete prop.items.properties[key];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
74
84
|
if (prop.deprecated) {
|
|
75
85
|
continue;
|
|
76
86
|
}
|
|
@@ -93,6 +103,9 @@ const sampleFromSchema = (schema = {}) => {
|
|
|
93
103
|
}
|
|
94
104
|
return normalizeArray(schema.enum)[0];
|
|
95
105
|
}
|
|
106
|
+
if (schema.readOnly && schema.readOnly === true) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
96
109
|
return primitive(schema);
|
|
97
110
|
}
|
|
98
111
|
catch (err) {
|
|
@@ -106,7 +119,7 @@ function primitive(schema = {}) {
|
|
|
106
119
|
if (type === undefined) {
|
|
107
120
|
return;
|
|
108
121
|
}
|
|
109
|
-
let fn = primitives[type].default;
|
|
122
|
+
let fn = schema.default ? () => schema.default : primitives[type].default;
|
|
110
123
|
if (format !== undefined) {
|
|
111
124
|
fn = primitives[type][format] || fn;
|
|
112
125
|
}
|
package/lib/openapi/openapi.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ interface OpenApiFiles {
|
|
|
6
6
|
data: OpenApiObject;
|
|
7
7
|
}
|
|
8
8
|
export declare function readOpenapiFiles(openapiPath: string, options: APIOptions): Promise<OpenApiFiles[]>;
|
|
9
|
-
export declare function processOpenapiFiles(files: OpenApiFiles[], sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
|
|
9
|
+
export declare function processOpenapiFiles(files: OpenApiFiles[], sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[][]]>;
|
|
10
10
|
export declare function processOpenapiFile(openapiData: OpenApiObject, 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
|
@@ -259,7 +259,7 @@ async function processOpenapiFiles(files, sidebarOptions) {
|
|
|
259
259
|
// Remove undefined tags due to transient parsing errors
|
|
260
260
|
return x !== undefined;
|
|
261
261
|
});
|
|
262
|
-
return [items, tags
|
|
262
|
+
return [items, tags];
|
|
263
263
|
}
|
|
264
264
|
exports.processOpenapiFiles = processOpenapiFiles;
|
|
265
265
|
async function processOpenapiFile(openapiData, sidebarOptions) {
|
package/lib/sidebars/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ProcessedSidebar } from "@docusaurus/plugin-content-docs/src/sidebars/types";
|
|
2
2
|
import { TagObject } from "../openapi/types";
|
|
3
3
|
import type { SidebarOptions, APIOptions, ApiMetadata } from "../types";
|
|
4
|
-
export default function generateSidebarSlice(sidebarOptions: SidebarOptions, options: APIOptions, api: ApiMetadata[], tags: TagObject[], docPath: string): ProcessedSidebar;
|
|
4
|
+
export default function generateSidebarSlice(sidebarOptions: SidebarOptions, options: APIOptions, api: ApiMetadata[], tags: TagObject[][], docPath: string): ProcessedSidebar;
|
package/lib/sidebars/index.js
CHANGED
|
@@ -38,7 +38,7 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
38
38
|
.filter((item) => !!item));
|
|
39
39
|
// Only include operation tags that are globally defined
|
|
40
40
|
const apiTags = [];
|
|
41
|
-
tags.forEach((tag) => {
|
|
41
|
+
tags.flat().forEach((tag) => {
|
|
42
42
|
if (operationTags.includes(tag.name)) {
|
|
43
43
|
apiTags.push(tag.name);
|
|
44
44
|
}
|
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-
|
|
4
|
+
"version": "0.0.0-422",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"engines": {
|
|
68
68
|
"node": ">=14"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "14d14041e6826bf3a0c6e851d3d8a2ac464811f4"
|
|
71
71
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
8
|
import { MediaTypeObject } from "../openapi/types";
|
|
9
|
-
import {
|
|
9
|
+
import { createRequestSchema } from "./createRequestSchema";
|
|
10
10
|
|
|
11
11
|
interface Props {
|
|
12
12
|
title: string;
|
|
@@ -20,5 +20,5 @@ interface Props {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function createRequestBodyDetails({ title, body }: Props): any {
|
|
23
|
-
return
|
|
23
|
+
return createRequestSchema({ title, body });
|
|
24
24
|
}
|
|
@@ -17,7 +17,7 @@ const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
|
|
|
17
17
|
/**
|
|
18
18
|
* Returns a merged representation of allOf array of schemas.
|
|
19
19
|
*/
|
|
20
|
-
function mergeAllOf(allOf: SchemaObject[]) {
|
|
20
|
+
export function mergeAllOf(allOf: SchemaObject[]) {
|
|
21
21
|
const mergedSchemas = jsonSchemaMergeAllOf(allOf, {
|
|
22
22
|
resolvers: {
|
|
23
23
|
readOnly: function () {
|
|
@@ -534,8 +534,6 @@ function createEdges({
|
|
|
534
534
|
}: EdgeProps): any {
|
|
535
535
|
const schemaName = getSchemaName(schema);
|
|
536
536
|
|
|
537
|
-
// if (name === "id") console.log(name, schema, required);
|
|
538
|
-
|
|
539
537
|
if (discriminator !== undefined && discriminator.propertyName === name) {
|
|
540
538
|
return createPropertyDiscriminator(
|
|
541
539
|
name,
|
|
@@ -578,6 +576,10 @@ function createEdges({
|
|
|
578
576
|
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
579
577
|
}
|
|
580
578
|
|
|
579
|
+
if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
|
|
580
|
+
return undefined;
|
|
581
|
+
}
|
|
582
|
+
|
|
581
583
|
return create("SchemaItem", {
|
|
582
584
|
collapsible: false,
|
|
583
585
|
name,
|
|
@@ -585,7 +587,7 @@ function createEdges({
|
|
|
585
587
|
schemaDescription: mergedSchemas.description,
|
|
586
588
|
schemaName: schemaName,
|
|
587
589
|
qualifierMessage: getQualifierMessage(schema),
|
|
588
|
-
defaultValue:
|
|
590
|
+
defaultValue: mergedSchemas.default,
|
|
589
591
|
});
|
|
590
592
|
}
|
|
591
593
|
|
|
@@ -602,6 +604,10 @@ function createEdges({
|
|
|
602
604
|
return createDetailsNode(name, schemaName, schema, required);
|
|
603
605
|
}
|
|
604
606
|
|
|
607
|
+
if (schema.readOnly && schema.readOnly === true) {
|
|
608
|
+
return undefined;
|
|
609
|
+
}
|
|
610
|
+
|
|
605
611
|
// primitives and array of non-objects
|
|
606
612
|
return create("SchemaItem", {
|
|
607
613
|
collapsible: false,
|
|
@@ -694,7 +700,7 @@ interface Props {
|
|
|
694
700
|
};
|
|
695
701
|
}
|
|
696
702
|
|
|
697
|
-
export function
|
|
703
|
+
export function createRequestSchema({ title, body, ...rest }: Props) {
|
|
698
704
|
if (
|
|
699
705
|
body === undefined ||
|
|
700
706
|
body.content === undefined ||
|