docusaurus-theme-openapi-docs 0.0.0-1250 → 0.0.0-1252
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.
|
@@ -83,6 +83,51 @@ const TabItem_1 = __importDefault(require("@theme/TabItem"));
|
|
|
83
83
|
const translationIds_1 = require("@theme/translationIds");
|
|
84
84
|
const clsx_1 = __importDefault(require("clsx"));
|
|
85
85
|
const slice_1 = require("./slice");
|
|
86
|
+
// Pretty-print a JSON string by re-indenting structural tokens only.
|
|
87
|
+
// Numbers pass through verbatim, so values beyond Number.MAX_SAFE_INTEGER
|
|
88
|
+
// (e.g. 19-digit IDs) keep their exact digits. Issue #1208.
|
|
89
|
+
function prettyPrintJson(raw, indent = 2) {
|
|
90
|
+
const pad = " ".repeat(indent);
|
|
91
|
+
let out = "";
|
|
92
|
+
let depth = 0;
|
|
93
|
+
let inString = false;
|
|
94
|
+
let escape = false;
|
|
95
|
+
for (let i = 0; i < raw.length; i++) {
|
|
96
|
+
const ch = raw[i];
|
|
97
|
+
if (inString) {
|
|
98
|
+
out += ch;
|
|
99
|
+
if (escape) escape = false;
|
|
100
|
+
else if (ch === "\\") escape = true;
|
|
101
|
+
else if (ch === '"') inString = false;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (ch === " " || ch === "\t" || ch === "\n" || ch === "\r") continue;
|
|
105
|
+
if (ch === '"') {
|
|
106
|
+
out += ch;
|
|
107
|
+
inString = true;
|
|
108
|
+
} else if (ch === "{" || ch === "[") {
|
|
109
|
+
let j = i + 1;
|
|
110
|
+
while (j < raw.length && /\s/.test(raw[j])) j++;
|
|
111
|
+
if (raw[j] === "}" || raw[j] === "]") {
|
|
112
|
+
out += ch + raw[j];
|
|
113
|
+
i = j;
|
|
114
|
+
} else {
|
|
115
|
+
depth++;
|
|
116
|
+
out += ch + "\n" + pad.repeat(depth);
|
|
117
|
+
}
|
|
118
|
+
} else if (ch === "}" || ch === "]") {
|
|
119
|
+
depth--;
|
|
120
|
+
out += "\n" + pad.repeat(depth) + ch;
|
|
121
|
+
} else if (ch === ",") {
|
|
122
|
+
out += ",\n" + pad.repeat(depth);
|
|
123
|
+
} else if (ch === ":") {
|
|
124
|
+
out += ": ";
|
|
125
|
+
} else {
|
|
126
|
+
out += ch;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
86
131
|
// TODO: We probably shouldn't attempt to format XML...
|
|
87
132
|
function formatXml(xml) {
|
|
88
133
|
const tab = " ";
|
|
@@ -130,7 +175,8 @@ function Response({ item }) {
|
|
|
130
175
|
let prettyResponse = response;
|
|
131
176
|
if (prettyResponse) {
|
|
132
177
|
try {
|
|
133
|
-
|
|
178
|
+
JSON.parse(response);
|
|
179
|
+
prettyResponse = prettyPrintJson(response);
|
|
134
180
|
} catch {
|
|
135
181
|
if (response.startsWith("<")) {
|
|
136
182
|
prettyResponse = formatXml(response);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-theme-openapi-docs",
|
|
3
3
|
"description": "OpenAPI theme for Docusaurus.",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-1252",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@types/postman-collection": "^3.5.11",
|
|
39
39
|
"@types/react-modal": "^3.16.3",
|
|
40
40
|
"concurrently": "^9.2.0",
|
|
41
|
-
"docusaurus-plugin-openapi-docs": "0.0.0-
|
|
41
|
+
"docusaurus-plugin-openapi-docs": "0.0.0-1252",
|
|
42
42
|
"docusaurus-plugin-sass": "^0.2.6",
|
|
43
43
|
"eslint-plugin-prettier": "^5.5.1"
|
|
44
44
|
},
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"engines": {
|
|
83
83
|
"node": ">=14"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "16f7e4f6cd11d8117634f036ff4e6c8636d5d53c"
|
|
86
86
|
}
|
|
@@ -22,6 +22,57 @@ import type { ThemeConfig } from "docusaurus-theme-openapi-docs/src/types";
|
|
|
22
22
|
|
|
23
23
|
import { clearResponse, clearCode, clearHeaders } from "./slice";
|
|
24
24
|
|
|
25
|
+
// Pretty-print a JSON string by re-indenting structural tokens only.
|
|
26
|
+
// Numbers pass through verbatim, so values beyond Number.MAX_SAFE_INTEGER
|
|
27
|
+
// (e.g. 19-digit IDs) keep their exact digits. Issue #1208.
|
|
28
|
+
function prettyPrintJson(raw: string, indent = 2): string {
|
|
29
|
+
const pad = " ".repeat(indent);
|
|
30
|
+
let out = "";
|
|
31
|
+
let depth = 0;
|
|
32
|
+
let inString = false;
|
|
33
|
+
let escape = false;
|
|
34
|
+
|
|
35
|
+
for (let i = 0; i < raw.length; i++) {
|
|
36
|
+
const ch = raw[i];
|
|
37
|
+
|
|
38
|
+
if (inString) {
|
|
39
|
+
out += ch;
|
|
40
|
+
if (escape) escape = false;
|
|
41
|
+
else if (ch === "\\") escape = true;
|
|
42
|
+
else if (ch === '"') inString = false;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (ch === " " || ch === "\t" || ch === "\n" || ch === "\r") continue;
|
|
47
|
+
|
|
48
|
+
if (ch === '"') {
|
|
49
|
+
out += ch;
|
|
50
|
+
inString = true;
|
|
51
|
+
} else if (ch === "{" || ch === "[") {
|
|
52
|
+
let j = i + 1;
|
|
53
|
+
while (j < raw.length && /\s/.test(raw[j])) j++;
|
|
54
|
+
if (raw[j] === "}" || raw[j] === "]") {
|
|
55
|
+
out += ch + raw[j];
|
|
56
|
+
i = j;
|
|
57
|
+
} else {
|
|
58
|
+
depth++;
|
|
59
|
+
out += ch + "\n" + pad.repeat(depth);
|
|
60
|
+
}
|
|
61
|
+
} else if (ch === "}" || ch === "]") {
|
|
62
|
+
depth--;
|
|
63
|
+
out += "\n" + pad.repeat(depth) + ch;
|
|
64
|
+
} else if (ch === ",") {
|
|
65
|
+
out += ",\n" + pad.repeat(depth);
|
|
66
|
+
} else if (ch === ":") {
|
|
67
|
+
out += ": ";
|
|
68
|
+
} else {
|
|
69
|
+
out += ch;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
|
|
25
76
|
// TODO: We probably shouldn't attempt to format XML...
|
|
26
77
|
function formatXml(xml: string) {
|
|
27
78
|
const tab = " ";
|
|
@@ -70,7 +121,8 @@ function Response({ item }: { item: ApiItem }) {
|
|
|
70
121
|
|
|
71
122
|
if (prettyResponse) {
|
|
72
123
|
try {
|
|
73
|
-
|
|
124
|
+
JSON.parse(response);
|
|
125
|
+
prettyResponse = prettyPrintJson(response);
|
|
74
126
|
} catch {
|
|
75
127
|
if (response.startsWith("<")) {
|
|
76
128
|
prettyResponse = formatXml(response);
|