docusaurus-plugin-openapi-docs 4.3.7 → 4.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 +32 -27
- package/lib/index.js +11 -6
- package/lib/markdown/createAuthentication.js +4 -2
- package/lib/markdown/schema.js +3 -0
- package/lib/openapi/createRequestExample.js +2 -179
- package/lib/openapi/createResponseExample.js +2 -180
- package/lib/openapi/createSchemaExample.d.ts +7 -0
- package/lib/openapi/createSchemaExample.js +231 -0
- package/lib/openapi/openapi.js +51 -2
- package/lib/openapi/types.d.ts +57 -59
- package/lib/openapi/utils/services/OpenAPIParser.d.ts +1 -1
- package/lib/openapi/utils/types.d.ts +1 -0
- package/lib/options.js +3 -0
- package/lib/types.d.ts +4 -1
- package/package.json +2 -2
- package/src/index.ts +13 -5
- package/src/markdown/createAuthentication.ts +12 -4
- package/src/markdown/schema.ts +3 -0
- package/src/openapi/createRequestExample.ts +2 -224
- package/src/openapi/createResponseExample.ts +2 -227
- package/src/openapi/createSchemaExample.ts +292 -0
- package/src/openapi/openapi.ts +19 -2
- package/src/openapi/types.ts +62 -59
- package/src/openapi/utils/types.ts +1 -0
- package/src/options.ts +3 -0
- package/src/plugin-openapi.d.ts +3 -2
- package/src/types.ts +5 -1
- package/src/postman-collection.d.ts +0 -10
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import chalk from "chalk";
|
|
9
|
+
import merge from "lodash/merge";
|
|
10
|
+
|
|
11
|
+
import { SchemaObject } from "./types";
|
|
12
|
+
import { mergeAllOf } from "../markdown/createSchema";
|
|
13
|
+
|
|
14
|
+
interface OASTypeToTypeMap {
|
|
15
|
+
string: string;
|
|
16
|
+
number: number;
|
|
17
|
+
integer: number;
|
|
18
|
+
boolean: boolean;
|
|
19
|
+
object: any;
|
|
20
|
+
array: any[];
|
|
21
|
+
null: string | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type Primitives = {
|
|
25
|
+
[OASType in keyof OASTypeToTypeMap]: {
|
|
26
|
+
[format: string]: (schema: SchemaObject) => OASTypeToTypeMap[OASType];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const primitives: Primitives = {
|
|
31
|
+
string: {
|
|
32
|
+
default: () => "string",
|
|
33
|
+
email: () => "user@example.com",
|
|
34
|
+
date: () => "2024-07-29",
|
|
35
|
+
"date-time": () => "2024-07-29T15:51:28.071Z",
|
|
36
|
+
uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
|
37
|
+
hostname: () => "example.com",
|
|
38
|
+
ipv4: () => "198.51.100.42",
|
|
39
|
+
ipv6: () => "2001:0db8:5b96:0000:0000:426f:8e17:642a",
|
|
40
|
+
},
|
|
41
|
+
number: {
|
|
42
|
+
default: () => 0,
|
|
43
|
+
float: () => 0.0,
|
|
44
|
+
},
|
|
45
|
+
integer: {
|
|
46
|
+
default: () => 0,
|
|
47
|
+
},
|
|
48
|
+
boolean: {
|
|
49
|
+
default: (schema) =>
|
|
50
|
+
typeof schema.default === "boolean" ? schema.default : true,
|
|
51
|
+
},
|
|
52
|
+
object: {},
|
|
53
|
+
array: {},
|
|
54
|
+
null: {
|
|
55
|
+
default: () => "null",
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
type ExampleType = "request" | "response";
|
|
60
|
+
|
|
61
|
+
interface ExampleContext {
|
|
62
|
+
type: ExampleType;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function shouldExcludeProperty(
|
|
66
|
+
prop: SchemaObject,
|
|
67
|
+
context: ExampleContext
|
|
68
|
+
): boolean {
|
|
69
|
+
if (prop.deprecated) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (context.type === "request") {
|
|
74
|
+
return prop.readOnly === true;
|
|
75
|
+
} else {
|
|
76
|
+
return prop.writeOnly === true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function sampleFromProp(
|
|
81
|
+
name: string,
|
|
82
|
+
prop: any,
|
|
83
|
+
obj: any,
|
|
84
|
+
context: ExampleContext
|
|
85
|
+
): any {
|
|
86
|
+
// Handle resolved circular props
|
|
87
|
+
if (typeof prop === "object" && Object.keys(prop).length === 0) {
|
|
88
|
+
obj[name] = prop;
|
|
89
|
+
return obj;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// TODO: handle discriminators
|
|
93
|
+
|
|
94
|
+
if (prop.oneOf) {
|
|
95
|
+
obj[name] = sampleFromSchema(prop.oneOf[0], context);
|
|
96
|
+
} else if (prop.anyOf) {
|
|
97
|
+
obj[name] = sampleFromSchema(prop.anyOf[0], context);
|
|
98
|
+
} else if (prop.allOf) {
|
|
99
|
+
const mergedSchemas = mergeAllOf(prop) as SchemaObject;
|
|
100
|
+
sampleFromProp(name, mergedSchemas, obj, context);
|
|
101
|
+
} else {
|
|
102
|
+
obj[name] = sampleFromSchema(prop, context);
|
|
103
|
+
}
|
|
104
|
+
return obj;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const sampleFromSchema = (
|
|
108
|
+
schema: SchemaObject = {},
|
|
109
|
+
context: ExampleContext
|
|
110
|
+
): any => {
|
|
111
|
+
try {
|
|
112
|
+
// deep copy schema before processing
|
|
113
|
+
let schemaCopy = JSON.parse(JSON.stringify(schema));
|
|
114
|
+
let { type, example, allOf, properties, items, oneOf, anyOf } = schemaCopy;
|
|
115
|
+
|
|
116
|
+
if (example !== undefined) {
|
|
117
|
+
return example;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (oneOf) {
|
|
121
|
+
if (properties) {
|
|
122
|
+
const combinedSchemas = merge(schemaCopy, oneOf[0]);
|
|
123
|
+
delete combinedSchemas.oneOf;
|
|
124
|
+
return sampleFromSchema(combinedSchemas, context);
|
|
125
|
+
}
|
|
126
|
+
// Just go with first schema
|
|
127
|
+
return sampleFromSchema(oneOf[0], context);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (anyOf) {
|
|
131
|
+
if (properties) {
|
|
132
|
+
const combinedSchemas = merge(schemaCopy, anyOf[0]);
|
|
133
|
+
delete combinedSchemas.anyOf;
|
|
134
|
+
return sampleFromSchema(combinedSchemas, context);
|
|
135
|
+
}
|
|
136
|
+
// Just go with first schema
|
|
137
|
+
return sampleFromSchema(anyOf[0], context);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (allOf) {
|
|
141
|
+
const mergedSchemas = mergeAllOf(schemaCopy) as SchemaObject;
|
|
142
|
+
if (mergedSchemas.properties) {
|
|
143
|
+
for (const [key, value] of Object.entries(mergedSchemas.properties)) {
|
|
144
|
+
if (shouldExcludeProperty(value, context)) {
|
|
145
|
+
delete mergedSchemas.properties[key];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (properties) {
|
|
150
|
+
const combinedSchemas = merge(schemaCopy, mergedSchemas);
|
|
151
|
+
delete combinedSchemas.allOf;
|
|
152
|
+
return sampleFromSchema(combinedSchemas, context);
|
|
153
|
+
}
|
|
154
|
+
return sampleFromSchema(mergedSchemas, context);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (!type) {
|
|
158
|
+
if (properties) {
|
|
159
|
+
type = "object";
|
|
160
|
+
} else if (items) {
|
|
161
|
+
type = "array";
|
|
162
|
+
} else {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (type === "object") {
|
|
168
|
+
let obj: any = {};
|
|
169
|
+
for (let [name, prop] of Object.entries(properties ?? {}) as any) {
|
|
170
|
+
if (prop.properties) {
|
|
171
|
+
for (const [key, value] of Object.entries(prop.properties) as any) {
|
|
172
|
+
if (shouldExcludeProperty(value, context)) {
|
|
173
|
+
delete prop.properties[key];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (prop.items && prop.items.properties) {
|
|
179
|
+
for (const [key, value] of Object.entries(
|
|
180
|
+
prop.items.properties
|
|
181
|
+
) as any) {
|
|
182
|
+
if (shouldExcludeProperty(value, context)) {
|
|
183
|
+
delete prop.items.properties[key];
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (shouldExcludeProperty(prop, context)) {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Resolve schema from prop recursively
|
|
193
|
+
obj = sampleFromProp(name, prop, obj, context);
|
|
194
|
+
}
|
|
195
|
+
return obj;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (type === "array") {
|
|
199
|
+
if (Array.isArray(items?.anyOf)) {
|
|
200
|
+
return processArrayItems(items, "anyOf", context);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (Array.isArray(items?.oneOf)) {
|
|
204
|
+
return processArrayItems(items, "oneOf", context);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return normalizeArray(sampleFromSchema(items, context));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (schemaCopy.enum) {
|
|
211
|
+
if (schemaCopy.default) {
|
|
212
|
+
return schemaCopy.default;
|
|
213
|
+
}
|
|
214
|
+
return normalizeArray(schemaCopy.enum)[0];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (shouldExcludeProperty(schemaCopy, context)) {
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return primitive(schemaCopy);
|
|
222
|
+
} catch (err) {
|
|
223
|
+
console.error(
|
|
224
|
+
chalk.yellow("WARNING: failed to create example from schema object:", err)
|
|
225
|
+
);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
function primitive(schema: SchemaObject = {}) {
|
|
231
|
+
let { type, format } = schema;
|
|
232
|
+
|
|
233
|
+
if (type === undefined) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// If type is an array, use the first type
|
|
238
|
+
if (Array.isArray(type)) {
|
|
239
|
+
type = type[0];
|
|
240
|
+
if (type === undefined) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Use schema default if available, otherwise use type default
|
|
246
|
+
if (schema.default !== undefined) {
|
|
247
|
+
return schema.default;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const typeConfig = primitives[type];
|
|
251
|
+
if (typeConfig) {
|
|
252
|
+
if (format !== undefined && typeConfig[format] !== undefined) {
|
|
253
|
+
return typeConfig[format](schema);
|
|
254
|
+
}
|
|
255
|
+
if (typeConfig.default !== undefined) {
|
|
256
|
+
return typeConfig.default(schema);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return "Unknown Type: " + schema.type;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function normalizeArray(arr: any) {
|
|
264
|
+
if (Array.isArray(arr)) {
|
|
265
|
+
return arr;
|
|
266
|
+
}
|
|
267
|
+
return [arr];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function processArrayItems(
|
|
271
|
+
items: SchemaObject,
|
|
272
|
+
schemaType: "anyOf" | "oneOf",
|
|
273
|
+
context: ExampleContext
|
|
274
|
+
): any[] {
|
|
275
|
+
const itemsArray = items[schemaType] as SchemaObject[];
|
|
276
|
+
return itemsArray.map((item: SchemaObject) => {
|
|
277
|
+
// If items has properties, merge them with each item
|
|
278
|
+
if (items.properties) {
|
|
279
|
+
const combinedSchema = {
|
|
280
|
+
...item,
|
|
281
|
+
properties: {
|
|
282
|
+
...items.properties, // Common properties from parent
|
|
283
|
+
...item.properties, // Specific properties from this anyOf/oneOf item
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
// Remove anyOf/oneOf to prevent infinite recursion when calling sampleFromSchema
|
|
287
|
+
delete combinedSchema[schemaType];
|
|
288
|
+
return sampleFromSchema(combinedSchema, context);
|
|
289
|
+
}
|
|
290
|
+
return sampleFromSchema(item, context);
|
|
291
|
+
});
|
|
292
|
+
}
|
package/src/openapi/openapi.ts
CHANGED
|
@@ -15,8 +15,8 @@ import kebabCase from "lodash/kebabCase";
|
|
|
15
15
|
import unionBy from "lodash/unionBy";
|
|
16
16
|
import uniq from "lodash/uniq";
|
|
17
17
|
import Converter from "openapi-to-postmanv2";
|
|
18
|
-
import Collection from "postman-collection";
|
|
19
|
-
import sdk from "postman-collection";
|
|
18
|
+
import { Collection } from "postman-collection";
|
|
19
|
+
import * as sdk from "postman-collection";
|
|
20
20
|
|
|
21
21
|
import { sampleRequestFromSchema } from "./createRequestExample";
|
|
22
22
|
import { OpenApiObject, TagGroupObject, TagObject } from "./types";
|
|
@@ -263,6 +263,7 @@ function createItems(
|
|
|
263
263
|
jsonRequestBodyExample,
|
|
264
264
|
info: openapiData.info,
|
|
265
265
|
},
|
|
266
|
+
position: operationObject["x-position"] as number | undefined,
|
|
266
267
|
};
|
|
267
268
|
|
|
268
269
|
items.push(apiPage);
|
|
@@ -509,6 +510,22 @@ function createItems(
|
|
|
509
510
|
});
|
|
510
511
|
}
|
|
511
512
|
|
|
513
|
+
items.sort((a, b) => {
|
|
514
|
+
// Items with position come first, sorted by position
|
|
515
|
+
if (a.position !== undefined && b.position !== undefined) {
|
|
516
|
+
return a.position - b.position;
|
|
517
|
+
}
|
|
518
|
+
// Items with position come before items without position
|
|
519
|
+
if (a.position !== undefined) {
|
|
520
|
+
return -1;
|
|
521
|
+
}
|
|
522
|
+
if (b.position !== undefined) {
|
|
523
|
+
return 1;
|
|
524
|
+
}
|
|
525
|
+
// If neither has position, maintain original order
|
|
526
|
+
return 0;
|
|
527
|
+
});
|
|
528
|
+
|
|
512
529
|
return items as ApiMetadata[];
|
|
513
530
|
}
|
|
514
531
|
|
package/src/openapi/types.ts
CHANGED
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import type {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
import type {
|
|
9
|
+
JSONSchema4,
|
|
10
|
+
JSONSchema6,
|
|
11
|
+
JSONSchema7,
|
|
12
|
+
JSONSchema7TypeName,
|
|
13
|
+
} from "json-schema";
|
|
13
14
|
|
|
14
15
|
export interface OpenApiObject {
|
|
15
16
|
openapi: string;
|
|
@@ -69,7 +70,7 @@ export interface LicenseObject {
|
|
|
69
70
|
export interface ServerObject {
|
|
70
71
|
url: string;
|
|
71
72
|
description?: string;
|
|
72
|
-
variables?:
|
|
73
|
+
variables?: Record<string, ServerVariable>;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
export interface ServerVariable {
|
|
@@ -79,32 +80,32 @@ export interface ServerVariable {
|
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
export interface ComponentsObject {
|
|
82
|
-
schemas?:
|
|
83
|
-
responses?:
|
|
84
|
-
parameters?:
|
|
85
|
-
examples?:
|
|
86
|
-
requestBodies?:
|
|
87
|
-
headers?:
|
|
88
|
-
securitySchemes?:
|
|
89
|
-
links?:
|
|
90
|
-
callbacks?:
|
|
83
|
+
schemas?: Record<string, SchemaObject>;
|
|
84
|
+
responses?: Record<string, ResponseObject>;
|
|
85
|
+
parameters?: Record<string, ParameterObject>;
|
|
86
|
+
examples?: Record<string, ExampleObject>;
|
|
87
|
+
requestBodies?: Record<string, RequestBodyObject>;
|
|
88
|
+
headers?: Record<string, HeaderObject>;
|
|
89
|
+
securitySchemes?: Record<string, SecuritySchemeObject>;
|
|
90
|
+
links?: Record<string, LinkObject>;
|
|
91
|
+
callbacks?: Record<string, CallbackObject>;
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
export interface ComponentsObjectWithRef {
|
|
94
|
-
schemas?:
|
|
95
|
-
responses?:
|
|
96
|
-
parameters?:
|
|
97
|
-
examples?:
|
|
98
|
-
requestBodies?:
|
|
99
|
-
headers?:
|
|
100
|
-
securitySchemes?:
|
|
101
|
-
links?:
|
|
102
|
-
callbacks?:
|
|
95
|
+
schemas?: Record<string, SchemaObjectWithRef | ReferenceObject>;
|
|
96
|
+
responses?: Record<string, ResponseObjectWithRef | ReferenceObject>;
|
|
97
|
+
parameters?: Record<string, ParameterObjectWithRef | ReferenceObject>;
|
|
98
|
+
examples?: Record<string, ExampleObject | ReferenceObject>;
|
|
99
|
+
requestBodies?: Record<string, RequestBodyObjectWithRef | ReferenceObject>;
|
|
100
|
+
headers?: Record<string, HeaderObjectWithRef | ReferenceObject>;
|
|
101
|
+
securitySchemes?: Record<string, SecuritySchemeObject | ReferenceObject>;
|
|
102
|
+
links?: Record<string, LinkObject | ReferenceObject>;
|
|
103
|
+
callbacks?: Record<string, CallbackObjectWithRef | ReferenceObject>;
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
export type PathsObject =
|
|
106
|
+
export type PathsObject = Record<string, PathItemObject>;
|
|
106
107
|
|
|
107
|
-
export type PathsObjectWithRef =
|
|
108
|
+
export type PathsObjectWithRef = Record<string, PathItemObjectWithRef>;
|
|
108
109
|
|
|
109
110
|
export interface PathItemObject {
|
|
110
111
|
$ref?: string;
|
|
@@ -147,12 +148,12 @@ export interface OperationObject {
|
|
|
147
148
|
parameters?: ParameterObject[];
|
|
148
149
|
requestBody?: RequestBodyObject;
|
|
149
150
|
responses: ResponsesObject;
|
|
150
|
-
callbacks?:
|
|
151
|
+
callbacks?: Record<string, CallbackObject>;
|
|
151
152
|
deprecated?: boolean;
|
|
152
153
|
security?: SecurityRequirementObject[];
|
|
153
154
|
servers?: ServerObject[];
|
|
154
|
-
|
|
155
155
|
// extensions
|
|
156
|
+
"x-position"?: number;
|
|
156
157
|
"x-deprecated-description"?: string;
|
|
157
158
|
}
|
|
158
159
|
|
|
@@ -165,7 +166,7 @@ export interface OperationObjectWithRef {
|
|
|
165
166
|
parameters?: (ParameterObjectWithRef | ReferenceObject)[];
|
|
166
167
|
requestBody?: RequestBodyObjectWithRef | ReferenceObject;
|
|
167
168
|
responses: ResponsesObjectWithRef;
|
|
168
|
-
callbacks?:
|
|
169
|
+
callbacks?: Record<string, CallbackObjectWithRef | ReferenceObject>;
|
|
169
170
|
deprecated?: boolean;
|
|
170
171
|
security?: SecurityRequirementObject[];
|
|
171
172
|
servers?: ServerObject[];
|
|
@@ -192,9 +193,9 @@ export interface ParameterObject {
|
|
|
192
193
|
allowReserved?: boolean;
|
|
193
194
|
schema?: SchemaObject;
|
|
194
195
|
example?: any;
|
|
195
|
-
examples?:
|
|
196
|
+
examples?: Record<string, ExampleObject>;
|
|
196
197
|
//
|
|
197
|
-
content?:
|
|
198
|
+
content?: Record<string, MediaTypeObject>;
|
|
198
199
|
param?: Object;
|
|
199
200
|
// ignoring stylings: matrix, label, form, simple, spaceDelimited,
|
|
200
201
|
// pipeDelimited and deepObject
|
|
@@ -214,43 +215,43 @@ export interface ParameterObjectWithRef {
|
|
|
214
215
|
allowReserved?: boolean;
|
|
215
216
|
schema?: SchemaObjectWithRef | ReferenceObject;
|
|
216
217
|
example?: any;
|
|
217
|
-
examples?:
|
|
218
|
+
examples?: Record<string, ExampleObject | ReferenceObject>;
|
|
218
219
|
//
|
|
219
|
-
content?:
|
|
220
|
+
content?: Record<string, MediaTypeObjectWithRef>;
|
|
220
221
|
// ignoring stylings: matrix, label, form, simple, spaceDelimited,
|
|
221
222
|
// pipeDelimited and deepObject
|
|
222
223
|
}
|
|
223
224
|
|
|
224
225
|
export interface RequestBodyObject {
|
|
225
226
|
description?: string;
|
|
226
|
-
content:
|
|
227
|
+
content: Record<string, MediaTypeObject>;
|
|
227
228
|
required?: boolean;
|
|
228
229
|
}
|
|
229
230
|
|
|
230
231
|
export interface RequestBodyObjectWithRef {
|
|
231
232
|
description?: string;
|
|
232
|
-
content:
|
|
233
|
+
content: Record<string, MediaTypeObjectWithRef>;
|
|
233
234
|
required?: boolean;
|
|
234
235
|
}
|
|
235
236
|
|
|
236
237
|
export interface MediaTypeObject {
|
|
237
238
|
schema?: SchemaObject;
|
|
238
239
|
example?: any;
|
|
239
|
-
examples?:
|
|
240
|
-
encoding?:
|
|
240
|
+
examples?: Record<string, ExampleObject>;
|
|
241
|
+
encoding?: Record<string, EncodingObject>;
|
|
241
242
|
type?: any;
|
|
242
243
|
}
|
|
243
244
|
|
|
244
245
|
export interface MediaTypeObjectWithRef {
|
|
245
246
|
schema?: SchemaObjectWithRef | ReferenceObject;
|
|
246
247
|
example?: any;
|
|
247
|
-
examples?:
|
|
248
|
-
encoding?:
|
|
248
|
+
examples?: Record<string, ExampleObject | ReferenceObject>;
|
|
249
|
+
encoding?: Record<string, EncodingObjectWithRef>;
|
|
249
250
|
}
|
|
250
251
|
|
|
251
252
|
export interface EncodingObject {
|
|
252
253
|
contentType?: string;
|
|
253
|
-
headers?:
|
|
254
|
+
headers?: Record<string, HeaderObject>;
|
|
254
255
|
style?: string;
|
|
255
256
|
explode?: boolean;
|
|
256
257
|
allowReserved?: boolean;
|
|
@@ -258,35 +259,36 @@ export interface EncodingObject {
|
|
|
258
259
|
|
|
259
260
|
export interface EncodingObjectWithRef {
|
|
260
261
|
contentType?: string;
|
|
261
|
-
headers?:
|
|
262
|
+
headers?: Record<string, HeaderObjectWithRef | ReferenceObject>;
|
|
262
263
|
style?: string;
|
|
263
264
|
explode?: boolean;
|
|
264
265
|
allowReserved?: boolean;
|
|
265
266
|
}
|
|
266
267
|
|
|
267
|
-
export type ResponsesObject =
|
|
268
|
+
export type ResponsesObject = Record<string, ResponseObject>;
|
|
268
269
|
|
|
269
|
-
export type ResponsesObjectWithRef =
|
|
270
|
+
export type ResponsesObjectWithRef = Record<
|
|
271
|
+
string,
|
|
270
272
|
ResponseObjectWithRef | ReferenceObject
|
|
271
273
|
>;
|
|
272
274
|
|
|
273
275
|
export interface ResponseObject {
|
|
274
276
|
description: string;
|
|
275
|
-
headers?:
|
|
276
|
-
content?:
|
|
277
|
-
links?:
|
|
277
|
+
headers?: Record<string, HeaderObject>;
|
|
278
|
+
content?: Record<string, MediaTypeObject>;
|
|
279
|
+
links?: Record<string, LinkObject>;
|
|
278
280
|
}
|
|
279
281
|
|
|
280
282
|
export interface ResponseObjectWithRef {
|
|
281
283
|
description: string;
|
|
282
|
-
headers?:
|
|
283
|
-
content?:
|
|
284
|
-
links?:
|
|
284
|
+
headers?: Record<string, HeaderObjectWithRef | ReferenceObject>;
|
|
285
|
+
content?: Record<string, MediaTypeObjectWithRef>;
|
|
286
|
+
links?: Record<string, LinkObject | ReferenceObject>;
|
|
285
287
|
}
|
|
286
288
|
|
|
287
|
-
export type CallbackObject =
|
|
289
|
+
export type CallbackObject = Record<string, PathItemObject>;
|
|
288
290
|
|
|
289
|
-
export type CallbackObjectWithRef =
|
|
291
|
+
export type CallbackObjectWithRef = Record<string, PathItemObjectWithRef>;
|
|
290
292
|
|
|
291
293
|
export interface ExampleObject {
|
|
292
294
|
summary?: string;
|
|
@@ -298,7 +300,7 @@ export interface ExampleObject {
|
|
|
298
300
|
export interface LinkObject {
|
|
299
301
|
operationRef?: string;
|
|
300
302
|
operationId?: string;
|
|
301
|
-
parameters?:
|
|
303
|
+
parameters?: Record<string, any>;
|
|
302
304
|
requestBody?: any;
|
|
303
305
|
description?: string;
|
|
304
306
|
server?: ServerObject;
|
|
@@ -325,6 +327,7 @@ export interface ReferenceObject {
|
|
|
325
327
|
}
|
|
326
328
|
|
|
327
329
|
export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
|
|
330
|
+
export type SchemaType = JSONSchema7TypeName;
|
|
328
331
|
export type SchemaObject = Omit<
|
|
329
332
|
JSONSchema,
|
|
330
333
|
| "type"
|
|
@@ -337,13 +340,13 @@ export type SchemaObject = Omit<
|
|
|
337
340
|
| "additionalProperties"
|
|
338
341
|
> & {
|
|
339
342
|
// OpenAPI specific overrides
|
|
340
|
-
type?:
|
|
343
|
+
type?: SchemaType;
|
|
341
344
|
allOf?: SchemaObject[];
|
|
342
345
|
oneOf?: SchemaObject[];
|
|
343
346
|
anyOf?: SchemaObject[];
|
|
344
347
|
not?: SchemaObject;
|
|
345
348
|
items?: SchemaObject;
|
|
346
|
-
properties?:
|
|
349
|
+
properties?: Record<string, SchemaObject>;
|
|
347
350
|
additionalProperties?: boolean | SchemaObject;
|
|
348
351
|
|
|
349
352
|
// OpenAPI additions
|
|
@@ -371,13 +374,13 @@ export type SchemaObjectWithRef = Omit<
|
|
|
371
374
|
| "additionalProperties"
|
|
372
375
|
> & {
|
|
373
376
|
// OpenAPI specific overrides
|
|
374
|
-
type?:
|
|
377
|
+
type?: SchemaType;
|
|
375
378
|
allOf?: (SchemaObject | ReferenceObject)[];
|
|
376
379
|
oneOf?: (SchemaObject | ReferenceObject)[];
|
|
377
380
|
anyOf?: (SchemaObject | ReferenceObject)[];
|
|
378
381
|
not?: SchemaObject | ReferenceObject;
|
|
379
382
|
items?: SchemaObject | ReferenceObject;
|
|
380
|
-
properties?:
|
|
383
|
+
properties?: Record<string, SchemaObject | ReferenceObject>;
|
|
381
384
|
additionalProperties?: boolean | SchemaObject | ReferenceObject;
|
|
382
385
|
|
|
383
386
|
// OpenAPI additions
|
|
@@ -393,7 +396,7 @@ export type SchemaObjectWithRef = Omit<
|
|
|
393
396
|
|
|
394
397
|
export interface DiscriminatorObject {
|
|
395
398
|
propertyName: string;
|
|
396
|
-
mapping?:
|
|
399
|
+
mapping?: Record<string, string>;
|
|
397
400
|
}
|
|
398
401
|
|
|
399
402
|
export interface XMLObject {
|
|
@@ -449,7 +452,7 @@ export interface OAuthFlowObject {
|
|
|
449
452
|
authorizationUrl?: string; // required for some
|
|
450
453
|
tokenUrl?: string; // required for some
|
|
451
454
|
refreshUrl?: string;
|
|
452
|
-
scopes:
|
|
455
|
+
scopes: Record<string, string>;
|
|
453
456
|
}
|
|
454
457
|
|
|
455
|
-
export type SecurityRequirementObject =
|
|
458
|
+
export type SecurityRequirementObject = Record<string, string[]>;
|
package/src/options.ts
CHANGED
|
@@ -39,6 +39,9 @@ export const OptionsSchema = Joi.object({
|
|
|
39
39
|
proxy: Joi.string(),
|
|
40
40
|
outputDir: Joi.string().required(),
|
|
41
41
|
template: Joi.string(),
|
|
42
|
+
infoTemplate: Joi.string(),
|
|
43
|
+
tagTemplate: Joi.string(),
|
|
44
|
+
schemaTemplate: Joi.string(),
|
|
42
45
|
downloadUrl: Joi.string(),
|
|
43
46
|
hideSendButton: Joi.boolean(),
|
|
44
47
|
showExtensions: Joi.boolean(),
|
package/src/plugin-openapi.d.ts
CHANGED
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
+
import type { TOCItem } from "@docusaurus/mdx-loader";
|
|
9
|
+
import type { VersionBanner } from "@docusaurus/plugin-content-docs";
|
|
8
10
|
import type { FrontMatter as DocsFrontMatter } from "@docusaurus/types";
|
|
9
11
|
import type { Props as DocsProps } from "@docusaurus/types";
|
|
10
12
|
|
|
11
|
-
// TODO: figure out how to import this
|
|
12
13
|
declare module "docusaurus-plugin-openapi-docs" {
|
|
13
14
|
import type { PropSidebars } from "@docusaurus/plugin-content-docs-types";
|
|
14
15
|
|
|
@@ -77,7 +78,7 @@ declare module "@theme/ApiItem" {
|
|
|
77
78
|
readonly frontMatter: FrontMatter;
|
|
78
79
|
readonly metadata: Metadata;
|
|
79
80
|
readonly contentTitle: string | undefined;
|
|
80
|
-
readonly toc:
|
|
81
|
+
readonly toc: readonly TOCItem[] | undefined;
|
|
81
82
|
(): JSX.Element;
|
|
82
83
|
};
|
|
83
84
|
}
|
package/src/types.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
8
|
import { SidebarItemDoc } from "@docusaurus/plugin-content-docs/src/sidebars/types";
|
|
9
|
-
import
|
|
9
|
+
import Request from "postman-collection";
|
|
10
10
|
|
|
11
11
|
import {
|
|
12
12
|
InfoObject,
|
|
@@ -35,6 +35,9 @@ export interface APIOptions {
|
|
|
35
35
|
specPath: string;
|
|
36
36
|
outputDir: string;
|
|
37
37
|
template?: string;
|
|
38
|
+
infoTemplate?: string;
|
|
39
|
+
tagTemplate?: string;
|
|
40
|
+
schemaTemplate?: string;
|
|
38
41
|
downloadUrl?: string;
|
|
39
42
|
hideSendButton?: boolean;
|
|
40
43
|
showExtensions?: boolean;
|
|
@@ -115,6 +118,7 @@ export interface ApiMetadataBase {
|
|
|
115
118
|
frontMatter: Record<string, unknown>;
|
|
116
119
|
method?: string;
|
|
117
120
|
path?: string;
|
|
121
|
+
position?: number;
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
export interface ApiPageMetadata extends ApiMetadataBase {
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/* ============================================================================
|
|
2
|
-
* Copyright (c) Palo Alto Networks
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
* ========================================================================== */
|
|
7
|
-
|
|
8
|
-
declare module "postman-collection" {
|
|
9
|
-
export default any;
|
|
10
|
-
}
|