docusaurus-plugin-openapi-docs 0.0.0-361 → 0.0.0-366
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/index.js +5 -0
- package/lib/markdown/createAuthentication.d.ts +2 -0
- package/lib/markdown/createAuthentication.js +139 -0
- package/lib/markdown/index.d.ts +1 -1
- package/lib/markdown/index.js +5 -1
- package/lib/openapi/openapi.js +17 -16
- package/lib/openapi/openapi.test.js +0 -6
- package/lib/openapi/utils/loadAndBundleSpec.d.ts +3 -0
- package/lib/openapi/utils/loadAndBundleSpec.js +44 -0
- package/lib/openapi/utils/types.d.ts +306 -0
- package/lib/openapi/utils/types.js +8 -0
- package/lib/types.d.ts +5 -0
- package/package.json +10 -8
- package/src/index.ts +5 -0
- package/src/markdown/createAuthentication.ts +160 -0
- package/src/markdown/index.ts +10 -1
- package/src/openapi/openapi.test.ts +0 -6
- package/src/openapi/openapi.ts +9 -6
- package/src/openapi/utils/loadAndBundleSpec.ts +62 -0
- package/src/openapi/utils/types.ts +303 -0
- package/src/types.ts +5 -0
- package/src/openapi/__fixtures__/examples/yogurtstore/_category_.json +0 -4
- package/src/openapi/__fixtures__/examples/yogurtstore/froyo.yaml +0 -13
- package/src/openapi/__fixtures__/examples/yogurtstore/nested/nested.yaml +0 -13
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
// @ts-nocheck
|
|
9
|
+
|
|
10
|
+
import type { Source, Document } from "@redocly/openapi-core";
|
|
11
|
+
import { bundle } from "@redocly/openapi-core/lib/bundle";
|
|
12
|
+
import type { ResolvedConfig } from "@redocly/openapi-core/lib/config";
|
|
13
|
+
import { Config } from "@redocly/openapi-core/lib/config/config";
|
|
14
|
+
import { convertObj } from "swagger2openapi";
|
|
15
|
+
|
|
16
|
+
import { OpenAPISpec } from "./types";
|
|
17
|
+
|
|
18
|
+
export async function loadAndBundleSpec(
|
|
19
|
+
specUrlOrObject: object | string
|
|
20
|
+
): Promise<OpenAPISpec> {
|
|
21
|
+
const config = new Config({} as ResolvedConfig);
|
|
22
|
+
const bundleOpts = {
|
|
23
|
+
config,
|
|
24
|
+
base: process.cwd(),
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (typeof specUrlOrObject === "object" && specUrlOrObject !== null) {
|
|
28
|
+
bundleOpts["doc"] = {
|
|
29
|
+
source: { absoluteRef: "" } as Source,
|
|
30
|
+
parsed: specUrlOrObject,
|
|
31
|
+
} as Document;
|
|
32
|
+
} else {
|
|
33
|
+
bundleOpts["ref"] = specUrlOrObject;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Force dereference ?
|
|
37
|
+
// bundleOpts["dereference"] = true;
|
|
38
|
+
|
|
39
|
+
const {
|
|
40
|
+
bundle: { parsed },
|
|
41
|
+
} = await bundle(bundleOpts);
|
|
42
|
+
return parsed.swagger !== undefined ? convertSwagger2OpenAPI(parsed) : parsed;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function convertSwagger2OpenAPI(spec: any): Promise<OpenAPISpec> {
|
|
46
|
+
console.warn(
|
|
47
|
+
"[ReDoc Compatibility mode]: Converting OpenAPI 2.0 to OpenAPI 3.0"
|
|
48
|
+
);
|
|
49
|
+
return new Promise<OpenAPISpec>((resolve, reject) =>
|
|
50
|
+
convertObj(
|
|
51
|
+
spec,
|
|
52
|
+
{ patch: true, warnOnly: true, text: "{}", anchors: true },
|
|
53
|
+
(err, res) => {
|
|
54
|
+
// TODO: log any warnings
|
|
55
|
+
if (err) {
|
|
56
|
+
return reject(err);
|
|
57
|
+
}
|
|
58
|
+
resolve(res && (res.openapi as any));
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
@@ -0,0 +1,303 @@
|
|
|
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
|
+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
9
|
+
|
|
10
|
+
export interface OpenAPISpec {
|
|
11
|
+
openapi: string;
|
|
12
|
+
info: OpenAPIInfo;
|
|
13
|
+
servers?: OpenAPIServer[];
|
|
14
|
+
paths: OpenAPIPaths;
|
|
15
|
+
components?: OpenAPIComponents;
|
|
16
|
+
security?: OpenAPISecurityRequirement[];
|
|
17
|
+
tags?: OpenAPITag[];
|
|
18
|
+
externalDocs?: OpenAPIExternalDocumentation;
|
|
19
|
+
"x-webhooks"?: OpenAPIPaths;
|
|
20
|
+
webhooks?: OpenAPIPaths;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface OpenAPIInfo {
|
|
24
|
+
title: string;
|
|
25
|
+
version: string;
|
|
26
|
+
|
|
27
|
+
description?: string;
|
|
28
|
+
summary?: string;
|
|
29
|
+
termsOfService?: string;
|
|
30
|
+
contact?: OpenAPIContact;
|
|
31
|
+
license?: OpenAPILicense;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface OpenAPIServer {
|
|
35
|
+
url: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
variables?: { [name: string]: OpenAPIServerVariable };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface OpenAPIServerVariable {
|
|
41
|
+
enum?: string[];
|
|
42
|
+
default: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface OpenAPIPaths {
|
|
47
|
+
[path: string]: OpenAPIPath;
|
|
48
|
+
}
|
|
49
|
+
export interface OpenAPIRef {
|
|
50
|
+
$ref: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type Referenced<T> = OpenAPIRef | T;
|
|
54
|
+
|
|
55
|
+
export interface OpenAPIPath {
|
|
56
|
+
summary?: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
get?: OpenAPIOperation;
|
|
59
|
+
put?: OpenAPIOperation;
|
|
60
|
+
post?: OpenAPIOperation;
|
|
61
|
+
delete?: OpenAPIOperation;
|
|
62
|
+
options?: OpenAPIOperation;
|
|
63
|
+
head?: OpenAPIOperation;
|
|
64
|
+
patch?: OpenAPIOperation;
|
|
65
|
+
trace?: OpenAPIOperation;
|
|
66
|
+
servers?: OpenAPIServer[];
|
|
67
|
+
parameters?: Array<Referenced<OpenAPIParameter>>;
|
|
68
|
+
$ref?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface OpenAPIXCodeSample {
|
|
72
|
+
lang: string;
|
|
73
|
+
label?: string;
|
|
74
|
+
source: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface OpenAPIOperation {
|
|
78
|
+
tags?: string[];
|
|
79
|
+
summary?: string;
|
|
80
|
+
description?: string;
|
|
81
|
+
externalDocs?: OpenAPIExternalDocumentation;
|
|
82
|
+
operationId?: string;
|
|
83
|
+
parameters?: Array<Referenced<OpenAPIParameter>>;
|
|
84
|
+
requestBody?: Referenced<OpenAPIRequestBody>;
|
|
85
|
+
responses: OpenAPIResponses;
|
|
86
|
+
callbacks?: { [name: string]: Referenced<OpenAPICallback> };
|
|
87
|
+
deprecated?: boolean;
|
|
88
|
+
security?: OpenAPISecurityRequirement[];
|
|
89
|
+
servers?: OpenAPIServer[];
|
|
90
|
+
"x-codeSamples"?: OpenAPIXCodeSample[];
|
|
91
|
+
"x-code-samples"?: OpenAPIXCodeSample[]; // deprecated
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface OpenAPIParameter {
|
|
95
|
+
name: string;
|
|
96
|
+
in?: OpenAPIParameterLocation;
|
|
97
|
+
description?: string;
|
|
98
|
+
required?: boolean;
|
|
99
|
+
deprecated?: boolean;
|
|
100
|
+
allowEmptyValue?: boolean;
|
|
101
|
+
style?: OpenAPIParameterStyle;
|
|
102
|
+
explode?: boolean;
|
|
103
|
+
allowReserved?: boolean;
|
|
104
|
+
schema?: Referenced<OpenAPISchema>;
|
|
105
|
+
example?: any;
|
|
106
|
+
examples?: { [media: string]: Referenced<OpenAPIExample> };
|
|
107
|
+
content?: { [media: string]: OpenAPIMediaType };
|
|
108
|
+
encoding?: Record<string, OpenAPIEncoding>;
|
|
109
|
+
const?: any;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface OpenAPIExample {
|
|
113
|
+
value: any;
|
|
114
|
+
summary?: string;
|
|
115
|
+
description?: string;
|
|
116
|
+
externalValue?: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface OpenAPISchema {
|
|
120
|
+
$ref?: string;
|
|
121
|
+
type?: string | string[];
|
|
122
|
+
properties?: { [name: string]: OpenAPISchema };
|
|
123
|
+
patternProperties?: { [name: string]: OpenAPISchema };
|
|
124
|
+
additionalProperties?: boolean | OpenAPISchema;
|
|
125
|
+
unevaluatedProperties?: boolean | OpenAPISchema;
|
|
126
|
+
description?: string;
|
|
127
|
+
default?: any;
|
|
128
|
+
items?: OpenAPISchema | OpenAPISchema[] | boolean;
|
|
129
|
+
required?: string[];
|
|
130
|
+
readOnly?: boolean;
|
|
131
|
+
writeOnly?: boolean;
|
|
132
|
+
deprecated?: boolean;
|
|
133
|
+
format?: string;
|
|
134
|
+
externalDocs?: OpenAPIExternalDocumentation;
|
|
135
|
+
discriminator?: OpenAPIDiscriminator;
|
|
136
|
+
nullable?: boolean;
|
|
137
|
+
oneOf?: OpenAPISchema[];
|
|
138
|
+
anyOf?: OpenAPISchema[];
|
|
139
|
+
allOf?: OpenAPISchema[];
|
|
140
|
+
not?: OpenAPISchema;
|
|
141
|
+
|
|
142
|
+
title?: string;
|
|
143
|
+
multipleOf?: number;
|
|
144
|
+
maximum?: number;
|
|
145
|
+
exclusiveMaximum?: boolean | number;
|
|
146
|
+
minimum?: number;
|
|
147
|
+
exclusiveMinimum?: boolean | number;
|
|
148
|
+
maxLength?: number;
|
|
149
|
+
minLength?: number;
|
|
150
|
+
pattern?: string;
|
|
151
|
+
maxItems?: number;
|
|
152
|
+
minItems?: number;
|
|
153
|
+
uniqueItems?: boolean;
|
|
154
|
+
maxProperties?: number;
|
|
155
|
+
minProperties?: number;
|
|
156
|
+
enum?: any[];
|
|
157
|
+
example?: any;
|
|
158
|
+
|
|
159
|
+
if?: OpenAPISchema;
|
|
160
|
+
else?: OpenAPISchema;
|
|
161
|
+
then?: OpenAPISchema;
|
|
162
|
+
examples?: any[];
|
|
163
|
+
const?: string;
|
|
164
|
+
contentEncoding?: string;
|
|
165
|
+
contentMediaType?: string;
|
|
166
|
+
prefixItems?: OpenAPISchema[];
|
|
167
|
+
additionalItems?: OpenAPISchema | boolean;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface OpenAPIDiscriminator {
|
|
171
|
+
propertyName: string;
|
|
172
|
+
mapping?: { [name: string]: string };
|
|
173
|
+
"x-explicitMappingOnly"?: boolean;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface OpenAPIMediaType {
|
|
177
|
+
schema?: Referenced<OpenAPISchema>;
|
|
178
|
+
example?: any;
|
|
179
|
+
examples?: { [name: string]: Referenced<OpenAPIExample> };
|
|
180
|
+
encoding?: { [field: string]: OpenAPIEncoding };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface OpenAPIEncoding {
|
|
184
|
+
contentType: string;
|
|
185
|
+
headers?: { [name: string]: Referenced<OpenAPIHeader> };
|
|
186
|
+
style: OpenAPIParameterStyle;
|
|
187
|
+
explode: boolean;
|
|
188
|
+
allowReserved: boolean;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export type OpenAPIParameterLocation = "query" | "header" | "path" | "cookie";
|
|
192
|
+
export type OpenAPIParameterStyle =
|
|
193
|
+
| "matrix"
|
|
194
|
+
| "label"
|
|
195
|
+
| "form"
|
|
196
|
+
| "simple"
|
|
197
|
+
| "spaceDelimited"
|
|
198
|
+
| "pipeDelimited"
|
|
199
|
+
| "deepObject";
|
|
200
|
+
|
|
201
|
+
export interface OpenAPIRequestBody {
|
|
202
|
+
description?: string;
|
|
203
|
+
required?: boolean;
|
|
204
|
+
content: { [mime: string]: OpenAPIMediaType };
|
|
205
|
+
|
|
206
|
+
"x-examples"?: {
|
|
207
|
+
[mime: string]: { [name: string]: Referenced<OpenAPIExample> };
|
|
208
|
+
};
|
|
209
|
+
"x-example"?: { [mime: string]: any };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export interface OpenAPIResponses {
|
|
213
|
+
[code: string]: Referenced<OpenAPIResponse>;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface OpenAPIResponse
|
|
217
|
+
extends Pick<OpenAPIRequestBody, "description" | "x-examples" | "x-example"> {
|
|
218
|
+
headers?: { [name: string]: Referenced<OpenAPIHeader> };
|
|
219
|
+
links?: { [name: string]: Referenced<OpenAPILink> };
|
|
220
|
+
content?: { [mime: string]: OpenAPIMediaType };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export interface OpenAPILink {
|
|
224
|
+
$ref?: string;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export type OpenAPIHeader = Omit<OpenAPIParameter, "in" | "name">;
|
|
228
|
+
|
|
229
|
+
export interface OpenAPICallback {
|
|
230
|
+
[name: string]: OpenAPIPath;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export interface OpenAPIComponents {
|
|
234
|
+
schemas?: { [name: string]: Referenced<OpenAPISchema> };
|
|
235
|
+
responses?: { [name: string]: Referenced<OpenAPIResponse> };
|
|
236
|
+
parameters?: { [name: string]: Referenced<OpenAPIParameter> };
|
|
237
|
+
examples?: { [name: string]: Referenced<OpenAPIExample> };
|
|
238
|
+
requestBodies?: { [name: string]: Referenced<OpenAPIRequestBody> };
|
|
239
|
+
headers?: { [name: string]: Referenced<OpenAPIHeader> };
|
|
240
|
+
securitySchemes?: { [name: string]: Referenced<OpenAPISecurityScheme> };
|
|
241
|
+
links?: { [name: string]: Referenced<OpenAPILink> };
|
|
242
|
+
callbacks?: { [name: string]: Referenced<OpenAPICallback> };
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export interface OpenAPISecurityRequirement {
|
|
246
|
+
[name: string]: string[];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export interface OpenAPISecurityScheme {
|
|
250
|
+
type: "apiKey" | "http" | "oauth2" | "openIdConnect";
|
|
251
|
+
description?: string;
|
|
252
|
+
name?: string;
|
|
253
|
+
in?: "query" | "header" | "cookie";
|
|
254
|
+
scheme?: string;
|
|
255
|
+
bearerFormat: string;
|
|
256
|
+
flows: {
|
|
257
|
+
implicit?: {
|
|
258
|
+
refreshUrl?: string;
|
|
259
|
+
scopes: Record<string, string>;
|
|
260
|
+
authorizationUrl: string;
|
|
261
|
+
};
|
|
262
|
+
password?: {
|
|
263
|
+
refreshUrl?: string;
|
|
264
|
+
scopes: Record<string, string>;
|
|
265
|
+
tokenUrl: string;
|
|
266
|
+
};
|
|
267
|
+
clientCredentials?: {
|
|
268
|
+
refreshUrl?: string;
|
|
269
|
+
scopes: Record<string, string>;
|
|
270
|
+
tokenUrl: string;
|
|
271
|
+
};
|
|
272
|
+
authorizationCode?: {
|
|
273
|
+
refreshUrl?: string;
|
|
274
|
+
scopes: Record<string, string>;
|
|
275
|
+
tokenUrl: string;
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
openIdConnectUrl?: string;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface OpenAPITag {
|
|
282
|
+
name: string;
|
|
283
|
+
description?: string;
|
|
284
|
+
externalDocs?: OpenAPIExternalDocumentation;
|
|
285
|
+
"x-displayName"?: string;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export interface OpenAPIExternalDocumentation {
|
|
289
|
+
description?: string;
|
|
290
|
+
url: string;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export interface OpenAPIContact {
|
|
294
|
+
name?: string;
|
|
295
|
+
url?: string;
|
|
296
|
+
email?: string;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export interface OpenAPILicense {
|
|
300
|
+
name: string;
|
|
301
|
+
url?: string;
|
|
302
|
+
identifier?: string;
|
|
303
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -48,6 +48,8 @@ export interface ApiMetadataBase {
|
|
|
48
48
|
//
|
|
49
49
|
id: string; // TODO legacy versioned id => try to remove
|
|
50
50
|
unversionedId: string; // TODO new unversioned id => try to rename to "id"
|
|
51
|
+
infoId?: string;
|
|
52
|
+
infoPath?: string;
|
|
51
53
|
title: string;
|
|
52
54
|
description: string;
|
|
53
55
|
source: string; // @site aliased source => "@site/docs/folder/subFolder/subSubFolder/myDoc.md"
|
|
@@ -80,6 +82,9 @@ export interface InfoPageMetadata extends ApiMetadataBase {
|
|
|
80
82
|
type: "info";
|
|
81
83
|
info: ApiInfo;
|
|
82
84
|
markdown?: string;
|
|
85
|
+
securitySchemes?: {
|
|
86
|
+
[key: string]: SecuritySchemeObject;
|
|
87
|
+
};
|
|
83
88
|
}
|
|
84
89
|
|
|
85
90
|
export interface TagPageMetadata extends ApiMetadataBase {
|