docusaurus-plugin-openapi-docs 0.0.0-1000
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/LICENSE +21 -0
- package/README.md +361 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +709 -0
- package/lib/markdown/createArrayBracket.d.ts +2 -0
- package/lib/markdown/createArrayBracket.js +36 -0
- package/lib/markdown/createAuthentication.d.ts +2 -0
- package/lib/markdown/createAuthentication.js +171 -0
- package/lib/markdown/createAuthorization.d.ts +1 -0
- package/lib/markdown/createAuthorization.js +15 -0
- package/lib/markdown/createCallbackMethodEndpoint.d.ts +1 -0
- package/lib/markdown/createCallbackMethodEndpoint.js +20 -0
- package/lib/markdown/createCallbacks.d.ts +6 -0
- package/lib/markdown/createCallbacks.js +77 -0
- package/lib/markdown/createContactInfo.d.ts +2 -0
- package/lib/markdown/createContactInfo.js +39 -0
- package/lib/markdown/createDeprecationNotice.d.ts +6 -0
- package/lib/markdown/createDeprecationNotice.js +20 -0
- package/lib/markdown/createDescription.d.ts +1 -0
- package/lib/markdown/createDescription.js +13 -0
- package/lib/markdown/createDetails.d.ts +2 -0
- package/lib/markdown/createDetails.js +17 -0
- package/lib/markdown/createDetailsSummary.d.ts +2 -0
- package/lib/markdown/createDetailsSummary.js +17 -0
- package/lib/markdown/createDownload.d.ts +1 -0
- package/lib/markdown/createDownload.js +16 -0
- package/lib/markdown/createHeading.d.ts +1 -0
- package/lib/markdown/createHeading.js +20 -0
- package/lib/markdown/createLicense.d.ts +2 -0
- package/lib/markdown/createLicense.js +32 -0
- package/lib/markdown/createLogo.d.ts +2 -0
- package/lib/markdown/createLogo.js +18 -0
- package/lib/markdown/createMethodEndpoint.d.ts +1 -0
- package/lib/markdown/createMethodEndpoint.js +20 -0
- package/lib/markdown/createParamsDetails.d.ts +6 -0
- package/lib/markdown/createParamsDetails.js +18 -0
- package/lib/markdown/createRequestBodyDetails.d.ts +13 -0
- package/lib/markdown/createRequestBodyDetails.js +13 -0
- package/lib/markdown/createRequestHeader.d.ts +1 -0
- package/lib/markdown/createRequestHeader.js +21 -0
- package/lib/markdown/createRequestSchema.d.ts +14 -0
- package/lib/markdown/createRequestSchema.js +20 -0
- package/lib/markdown/createResponseSchema.d.ts +14 -0
- package/lib/markdown/createResponseSchema.js +20 -0
- package/lib/markdown/createSchema.d.ts +9 -0
- package/lib/markdown/createSchema.js +668 -0
- package/lib/markdown/createSchema.test.d.ts +1 -0
- package/lib/markdown/createSchema.test.js +913 -0
- package/lib/markdown/createStatusCodes.d.ts +9 -0
- package/lib/markdown/createStatusCodes.js +63 -0
- package/lib/markdown/createTermsOfService.d.ts +1 -0
- package/lib/markdown/createTermsOfService.js +31 -0
- package/lib/markdown/createVendorExtensions.d.ts +1 -0
- package/lib/markdown/createVendorExtensions.js +24 -0
- package/lib/markdown/createVersionBadge.d.ts +1 -0
- package/lib/markdown/createVersionBadge.js +19 -0
- package/lib/markdown/index.d.ts +5 -0
- package/lib/markdown/index.js +92 -0
- package/lib/markdown/schema.d.ts +3 -0
- package/lib/markdown/schema.js +154 -0
- package/lib/markdown/schema.test.d.ts +1 -0
- package/lib/markdown/schema.test.js +181 -0
- package/lib/markdown/utils.d.ts +20 -0
- package/lib/markdown/utils.js +68 -0
- package/lib/openapi/createRequestExample.d.ts +2 -0
- package/lib/openapi/createRequestExample.js +191 -0
- package/lib/openapi/createResponseExample.d.ts +2 -0
- package/lib/openapi/createResponseExample.js +192 -0
- package/lib/openapi/index.d.ts +1 -0
- package/lib/openapi/index.js +12 -0
- package/lib/openapi/openapi.d.ts +12 -0
- package/lib/openapi/openapi.js +544 -0
- package/lib/openapi/openapi.test.d.ts +1 -0
- package/lib/openapi/openapi.test.js +33 -0
- package/lib/openapi/types.d.ts +354 -0
- package/lib/openapi/types.js +8 -0
- package/lib/openapi/utils/loadAndResolveSpec.d.ts +2 -0
- package/lib/openapi/utils/loadAndResolveSpec.js +153 -0
- package/lib/openapi/utils/services/OpenAPIParser.d.ts +52 -0
- package/lib/openapi/utils/services/OpenAPIParser.js +343 -0
- package/lib/openapi/utils/services/RedocNormalizedOptions.d.ts +100 -0
- package/lib/openapi/utils/services/RedocNormalizedOptions.js +170 -0
- package/lib/openapi/utils/types/index.d.ts +2 -0
- package/lib/openapi/utils/types/index.js +23 -0
- package/lib/openapi/utils/types/open-api.d.ts +305 -0
- package/lib/openapi/utils/types/open-api.js +8 -0
- package/lib/openapi/utils/types.d.ts +306 -0
- package/lib/openapi/utils/types.js +8 -0
- package/lib/openapi/utils/utils/JsonPointer.d.ts +51 -0
- package/lib/openapi/utils/utils/JsonPointer.js +95 -0
- package/lib/openapi/utils/utils/helpers.d.ts +43 -0
- package/lib/openapi/utils/utils/helpers.js +230 -0
- package/lib/openapi/utils/utils/index.d.ts +3 -0
- package/lib/openapi/utils/utils/index.js +25 -0
- package/lib/openapi/utils/utils/openapi.d.ts +40 -0
- package/lib/openapi/utils/utils/openapi.js +605 -0
- package/lib/options.d.ts +2 -0
- package/lib/options.js +69 -0
- package/lib/sidebars/index.d.ts +4 -0
- package/lib/sidebars/index.js +226 -0
- package/lib/sidebars/utils.d.ts +2 -0
- package/lib/sidebars/utils.js +30 -0
- package/lib/types.d.ts +135 -0
- package/lib/types.js +8 -0
- package/package.json +69 -0
- package/src/index.ts +945 -0
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +1605 -0
- package/src/markdown/createArrayBracket.ts +35 -0
- package/src/markdown/createAuthentication.ts +201 -0
- package/src/markdown/createAuthorization.ts +13 -0
- package/src/markdown/createCallbackMethodEndpoint.ts +19 -0
- package/src/markdown/createCallbacks.ts +101 -0
- package/src/markdown/createContactInfo.ts +41 -0
- package/src/markdown/createDeprecationNotice.ts +31 -0
- package/src/markdown/createDescription.ts +12 -0
- package/src/markdown/createDetails.ts +16 -0
- package/src/markdown/createDetailsSummary.ts +16 -0
- package/src/markdown/createDownload.ts +15 -0
- package/src/markdown/createHeading.ts +23 -0
- package/src/markdown/createLicense.ts +34 -0
- package/src/markdown/createLogo.ts +21 -0
- package/src/markdown/createMethodEndpoint.ts +19 -0
- package/src/markdown/createParamsDetails.ts +22 -0
- package/src/markdown/createRequestBodyDetails.ts +24 -0
- package/src/markdown/createRequestHeader.ts +24 -0
- package/src/markdown/createRequestSchema.ts +32 -0
- package/src/markdown/createResponseSchema.ts +32 -0
- package/src/markdown/createSchema.test.ts +1075 -0
- package/src/markdown/createSchema.ts +862 -0
- package/src/markdown/createStatusCodes.ts +63 -0
- package/src/markdown/createTermsOfService.ts +30 -0
- package/src/markdown/createVendorExtensions.ts +22 -0
- package/src/markdown/createVersionBadge.ts +22 -0
- package/src/markdown/index.ts +144 -0
- package/src/markdown/schema.test.ts +208 -0
- package/src/markdown/schema.ts +185 -0
- package/src/markdown/utils.ts +89 -0
- package/src/openapi/__fixtures__/examples/openapi.yaml +49 -0
- package/src/openapi/createRequestExample.ts +235 -0
- package/src/openapi/createResponseExample.ts +238 -0
- package/src/openapi/index.ts +8 -0
- package/src/openapi/openapi.test.ts +40 -0
- package/src/openapi/openapi.ts +697 -0
- package/src/openapi/types.ts +455 -0
- package/src/openapi/utils/loadAndResolveSpec.ts +171 -0
- package/src/openapi/utils/services/OpenAPIParser.ts +434 -0
- package/src/openapi/utils/services/RedocNormalizedOptions.ts +330 -0
- package/src/openapi/utils/types/index.ts +10 -0
- package/src/openapi/utils/types/open-api.ts +303 -0
- package/src/openapi/utils/types.ts +303 -0
- package/src/openapi/utils/utils/JsonPointer.ts +99 -0
- package/src/openapi/utils/utils/helpers.ts +239 -0
- package/src/openapi/utils/utils/index.ts +11 -0
- package/src/openapi/utils/utils/openapi.ts +771 -0
- package/src/openapi-to-postmanv2.d.ts +10 -0
- package/src/options.ts +77 -0
- package/src/plugin-content-docs-types.d.ts +42 -0
- package/src/plugin-openapi.d.ts +87 -0
- package/src/postman-collection.d.ts +10 -0
- package/src/sidebars/index.ts +322 -0
- package/src/sidebars/utils.ts +29 -0
- package/src/types.ts +176 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import type { JSONSchema4, JSONSchema6, JSONSchema7 } from "json-schema";
|
|
2
|
+
interface Map<T> {
|
|
3
|
+
[key: string]: T;
|
|
4
|
+
}
|
|
5
|
+
export interface OpenApiObject {
|
|
6
|
+
openapi: string;
|
|
7
|
+
info: InfoObject;
|
|
8
|
+
servers?: ServerObject[];
|
|
9
|
+
paths: PathsObject;
|
|
10
|
+
components?: ComponentsObject;
|
|
11
|
+
security?: SecurityRequirementObject[];
|
|
12
|
+
tags?: TagObject[];
|
|
13
|
+
externalDocs?: ExternalDocumentationObject;
|
|
14
|
+
swagger?: string;
|
|
15
|
+
webhooks?: PathsObject;
|
|
16
|
+
"x-webhooks"?: PathsObject;
|
|
17
|
+
"x-tagGroups"?: TagGroupObject[];
|
|
18
|
+
}
|
|
19
|
+
export interface OpenApiObjectWithRef {
|
|
20
|
+
openapi: string;
|
|
21
|
+
info: InfoObject;
|
|
22
|
+
servers?: ServerObject[];
|
|
23
|
+
paths: PathsObjectWithRef;
|
|
24
|
+
components?: ComponentsObjectWithRef;
|
|
25
|
+
security?: SecurityRequirementObject[];
|
|
26
|
+
tags?: TagObject[];
|
|
27
|
+
externalDocs?: ExternalDocumentationObject;
|
|
28
|
+
}
|
|
29
|
+
export interface InfoObject {
|
|
30
|
+
title: string;
|
|
31
|
+
description?: string;
|
|
32
|
+
termsOfService?: string;
|
|
33
|
+
contact?: ContactObject;
|
|
34
|
+
license?: LicenseObject;
|
|
35
|
+
version: string;
|
|
36
|
+
tags?: TagObject[];
|
|
37
|
+
"x-logo"?: LogoObject;
|
|
38
|
+
"x-dark-logo"?: LogoObject;
|
|
39
|
+
logo?: LogoObject;
|
|
40
|
+
darkLogo?: LogoObject;
|
|
41
|
+
}
|
|
42
|
+
export interface LogoObject {
|
|
43
|
+
url?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface ContactObject {
|
|
46
|
+
name?: string;
|
|
47
|
+
url?: string;
|
|
48
|
+
email?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface LicenseObject {
|
|
51
|
+
name: string;
|
|
52
|
+
url?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface ServerObject {
|
|
55
|
+
url: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
variables?: Map<ServerVariable>;
|
|
58
|
+
}
|
|
59
|
+
export interface ServerVariable {
|
|
60
|
+
enum?: string[];
|
|
61
|
+
default: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface ComponentsObject {
|
|
65
|
+
schemas?: Map<SchemaObject>;
|
|
66
|
+
responses?: Map<ResponseObject>;
|
|
67
|
+
parameters?: Map<ParameterObject>;
|
|
68
|
+
examples?: Map<ExampleObject>;
|
|
69
|
+
requestBodies?: Map<RequestBodyObject>;
|
|
70
|
+
headers?: Map<HeaderObject>;
|
|
71
|
+
securitySchemes?: Map<SecuritySchemeObject>;
|
|
72
|
+
links?: Map<LinkObject>;
|
|
73
|
+
callbacks?: Map<CallbackObject>;
|
|
74
|
+
}
|
|
75
|
+
export interface ComponentsObjectWithRef {
|
|
76
|
+
schemas?: Map<SchemaObjectWithRef | ReferenceObject>;
|
|
77
|
+
responses?: Map<ResponseObjectWithRef | ReferenceObject>;
|
|
78
|
+
parameters?: Map<ParameterObjectWithRef | ReferenceObject>;
|
|
79
|
+
examples?: Map<ExampleObject | ReferenceObject>;
|
|
80
|
+
requestBodies?: Map<RequestBodyObjectWithRef | ReferenceObject>;
|
|
81
|
+
headers?: Map<HeaderObjectWithRef | ReferenceObject>;
|
|
82
|
+
securitySchemes?: Map<SecuritySchemeObject | ReferenceObject>;
|
|
83
|
+
links?: Map<LinkObject | ReferenceObject>;
|
|
84
|
+
callbacks?: Map<CallbackObjectWithRef | ReferenceObject>;
|
|
85
|
+
}
|
|
86
|
+
export type PathsObject = Map<PathItemObject>;
|
|
87
|
+
export type PathsObjectWithRef = Map<PathItemObjectWithRef>;
|
|
88
|
+
export interface PathItemObject {
|
|
89
|
+
$ref?: string;
|
|
90
|
+
summary?: string;
|
|
91
|
+
description?: string;
|
|
92
|
+
get?: OperationObject;
|
|
93
|
+
put?: OperationObject;
|
|
94
|
+
post?: OperationObject;
|
|
95
|
+
delete?: OperationObject;
|
|
96
|
+
options?: OperationObject;
|
|
97
|
+
head?: OperationObject;
|
|
98
|
+
patch?: OperationObject;
|
|
99
|
+
trace?: OperationObject;
|
|
100
|
+
servers?: ServerObject[];
|
|
101
|
+
parameters?: ParameterObject[];
|
|
102
|
+
}
|
|
103
|
+
export interface PathItemObjectWithRef {
|
|
104
|
+
$ref?: string;
|
|
105
|
+
summary?: string;
|
|
106
|
+
description?: string;
|
|
107
|
+
get?: OperationObjectWithRef;
|
|
108
|
+
put?: OperationObjectWithRef;
|
|
109
|
+
post?: OperationObjectWithRef;
|
|
110
|
+
delete?: OperationObjectWithRef;
|
|
111
|
+
options?: OperationObjectWithRef;
|
|
112
|
+
head?: OperationObjectWithRef;
|
|
113
|
+
patch?: OperationObjectWithRef;
|
|
114
|
+
trace?: OperationObjectWithRef;
|
|
115
|
+
servers?: ServerObject[];
|
|
116
|
+
parameters?: (ParameterObjectWithRef | ReferenceObject)[];
|
|
117
|
+
}
|
|
118
|
+
export interface OperationObject {
|
|
119
|
+
tags?: string[];
|
|
120
|
+
summary?: string;
|
|
121
|
+
description?: string;
|
|
122
|
+
externalDocs?: ExternalDocumentationObject;
|
|
123
|
+
operationId?: string;
|
|
124
|
+
parameters?: ParameterObject[];
|
|
125
|
+
requestBody?: RequestBodyObject;
|
|
126
|
+
responses: ResponsesObject;
|
|
127
|
+
callbacks?: Map<CallbackObject>;
|
|
128
|
+
deprecated?: boolean;
|
|
129
|
+
security?: SecurityRequirementObject[];
|
|
130
|
+
servers?: ServerObject[];
|
|
131
|
+
"x-deprecated-description"?: string;
|
|
132
|
+
}
|
|
133
|
+
export interface OperationObjectWithRef {
|
|
134
|
+
tags?: string[];
|
|
135
|
+
summary?: string;
|
|
136
|
+
description?: string;
|
|
137
|
+
externalDocs?: ExternalDocumentationObject;
|
|
138
|
+
operationId?: string;
|
|
139
|
+
parameters?: (ParameterObjectWithRef | ReferenceObject)[];
|
|
140
|
+
requestBody?: RequestBodyObjectWithRef | ReferenceObject;
|
|
141
|
+
responses: ResponsesObjectWithRef;
|
|
142
|
+
callbacks?: Map<CallbackObjectWithRef | ReferenceObject>;
|
|
143
|
+
deprecated?: boolean;
|
|
144
|
+
security?: SecurityRequirementObject[];
|
|
145
|
+
servers?: ServerObject[];
|
|
146
|
+
"x-deprecated-description"?: string;
|
|
147
|
+
}
|
|
148
|
+
export interface ExternalDocumentationObject {
|
|
149
|
+
description?: string;
|
|
150
|
+
url: string;
|
|
151
|
+
}
|
|
152
|
+
export interface ParameterObject {
|
|
153
|
+
name: string;
|
|
154
|
+
in: "query" | "header" | "path" | "cookie";
|
|
155
|
+
description?: string;
|
|
156
|
+
required?: boolean;
|
|
157
|
+
deprecated?: boolean;
|
|
158
|
+
allowEmptyValue?: boolean;
|
|
159
|
+
style?: string;
|
|
160
|
+
explode?: string;
|
|
161
|
+
allowReserved?: boolean;
|
|
162
|
+
schema?: SchemaObject;
|
|
163
|
+
example?: any;
|
|
164
|
+
examples?: Map<ExampleObject>;
|
|
165
|
+
content?: Map<MediaTypeObject>;
|
|
166
|
+
param?: Object;
|
|
167
|
+
"x-enumDescriptions"?: Record<string, string>;
|
|
168
|
+
}
|
|
169
|
+
export interface ParameterObjectWithRef {
|
|
170
|
+
name: string;
|
|
171
|
+
in: string;
|
|
172
|
+
description?: string;
|
|
173
|
+
required?: boolean;
|
|
174
|
+
deprecated?: boolean;
|
|
175
|
+
allowEmptyValue?: boolean;
|
|
176
|
+
style?: string;
|
|
177
|
+
explode?: string;
|
|
178
|
+
allowReserved?: boolean;
|
|
179
|
+
schema?: SchemaObjectWithRef | ReferenceObject;
|
|
180
|
+
example?: any;
|
|
181
|
+
examples?: Map<ExampleObject | ReferenceObject>;
|
|
182
|
+
content?: Map<MediaTypeObjectWithRef>;
|
|
183
|
+
}
|
|
184
|
+
export interface RequestBodyObject {
|
|
185
|
+
description?: string;
|
|
186
|
+
content: Map<MediaTypeObject>;
|
|
187
|
+
required?: boolean;
|
|
188
|
+
}
|
|
189
|
+
export interface RequestBodyObjectWithRef {
|
|
190
|
+
description?: string;
|
|
191
|
+
content: Map<MediaTypeObjectWithRef>;
|
|
192
|
+
required?: boolean;
|
|
193
|
+
}
|
|
194
|
+
export interface MediaTypeObject {
|
|
195
|
+
schema?: SchemaObject;
|
|
196
|
+
example?: any;
|
|
197
|
+
examples?: Map<ExampleObject>;
|
|
198
|
+
encoding?: Map<EncodingObject>;
|
|
199
|
+
type?: any;
|
|
200
|
+
}
|
|
201
|
+
export interface MediaTypeObjectWithRef {
|
|
202
|
+
schema?: SchemaObjectWithRef | ReferenceObject;
|
|
203
|
+
example?: any;
|
|
204
|
+
examples?: Map<ExampleObject | ReferenceObject>;
|
|
205
|
+
encoding?: Map<EncodingObjectWithRef>;
|
|
206
|
+
}
|
|
207
|
+
export interface EncodingObject {
|
|
208
|
+
contentType?: string;
|
|
209
|
+
headers?: Map<HeaderObject>;
|
|
210
|
+
style?: string;
|
|
211
|
+
explode?: boolean;
|
|
212
|
+
allowReserved?: boolean;
|
|
213
|
+
}
|
|
214
|
+
export interface EncodingObjectWithRef {
|
|
215
|
+
contentType?: string;
|
|
216
|
+
headers?: Map<HeaderObjectWithRef | ReferenceObject>;
|
|
217
|
+
style?: string;
|
|
218
|
+
explode?: boolean;
|
|
219
|
+
allowReserved?: boolean;
|
|
220
|
+
}
|
|
221
|
+
export type ResponsesObject = Map<ResponseObject>;
|
|
222
|
+
export type ResponsesObjectWithRef = Map<ResponseObjectWithRef | ReferenceObject>;
|
|
223
|
+
export interface ResponseObject {
|
|
224
|
+
description: string;
|
|
225
|
+
headers?: Map<HeaderObject>;
|
|
226
|
+
content?: Map<MediaTypeObject>;
|
|
227
|
+
links?: Map<LinkObject>;
|
|
228
|
+
}
|
|
229
|
+
export interface ResponseObjectWithRef {
|
|
230
|
+
description: string;
|
|
231
|
+
headers?: Map<HeaderObjectWithRef | ReferenceObject>;
|
|
232
|
+
content?: Map<MediaTypeObjectWithRef>;
|
|
233
|
+
links?: Map<LinkObject | ReferenceObject>;
|
|
234
|
+
}
|
|
235
|
+
export type CallbackObject = Map<PathItemObject>;
|
|
236
|
+
export type CallbackObjectWithRef = Map<PathItemObjectWithRef>;
|
|
237
|
+
export interface ExampleObject {
|
|
238
|
+
summary?: string;
|
|
239
|
+
description?: string;
|
|
240
|
+
value?: any;
|
|
241
|
+
externalValue?: string;
|
|
242
|
+
}
|
|
243
|
+
export interface LinkObject {
|
|
244
|
+
operationRef?: string;
|
|
245
|
+
operationId?: string;
|
|
246
|
+
parameters?: Map<any>;
|
|
247
|
+
requestBody?: any;
|
|
248
|
+
description?: string;
|
|
249
|
+
server?: ServerObject;
|
|
250
|
+
}
|
|
251
|
+
export type HeaderObject = Omit<ParameterObject, "name" | "in">;
|
|
252
|
+
export type HeaderObjectWithRef = Omit<ParameterObjectWithRef, "name" | "in">;
|
|
253
|
+
export interface TagObject {
|
|
254
|
+
name?: string;
|
|
255
|
+
description?: string;
|
|
256
|
+
externalDocs?: ExternalDocumentationObject;
|
|
257
|
+
"x-displayName"?: string;
|
|
258
|
+
}
|
|
259
|
+
export interface TagGroupObject {
|
|
260
|
+
name: string;
|
|
261
|
+
tags: string[];
|
|
262
|
+
}
|
|
263
|
+
export interface ReferenceObject {
|
|
264
|
+
$ref: string;
|
|
265
|
+
}
|
|
266
|
+
export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
|
|
267
|
+
export type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
|
|
268
|
+
type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
|
|
269
|
+
allOf?: SchemaObject[];
|
|
270
|
+
oneOf?: SchemaObject[];
|
|
271
|
+
anyOf?: SchemaObject[];
|
|
272
|
+
not?: SchemaObject;
|
|
273
|
+
items?: SchemaObject;
|
|
274
|
+
properties?: Map<SchemaObject>;
|
|
275
|
+
additionalProperties?: boolean | SchemaObject;
|
|
276
|
+
nullable?: boolean;
|
|
277
|
+
discriminator?: DiscriminatorObject;
|
|
278
|
+
readOnly?: boolean;
|
|
279
|
+
writeOnly?: boolean;
|
|
280
|
+
xml?: XMLObject;
|
|
281
|
+
externalDocs?: ExternalDocumentationObject;
|
|
282
|
+
example?: any;
|
|
283
|
+
deprecated?: boolean;
|
|
284
|
+
"x-tags"?: string[];
|
|
285
|
+
"x-enumDescriptions"?: Record<string, string>;
|
|
286
|
+
};
|
|
287
|
+
export type SchemaObjectWithRef = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
|
|
288
|
+
type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
|
|
289
|
+
allOf?: (SchemaObject | ReferenceObject)[];
|
|
290
|
+
oneOf?: (SchemaObject | ReferenceObject)[];
|
|
291
|
+
anyOf?: (SchemaObject | ReferenceObject)[];
|
|
292
|
+
not?: SchemaObject | ReferenceObject;
|
|
293
|
+
items?: SchemaObject | ReferenceObject;
|
|
294
|
+
properties?: Map<SchemaObject | ReferenceObject>;
|
|
295
|
+
additionalProperties?: boolean | SchemaObject | ReferenceObject;
|
|
296
|
+
nullable?: boolean;
|
|
297
|
+
discriminator?: DiscriminatorObject;
|
|
298
|
+
readOnly?: boolean;
|
|
299
|
+
writeOnly?: boolean;
|
|
300
|
+
xml?: XMLObject;
|
|
301
|
+
externalDocs?: ExternalDocumentationObject;
|
|
302
|
+
example?: any;
|
|
303
|
+
deprecated?: boolean;
|
|
304
|
+
};
|
|
305
|
+
export interface DiscriminatorObject {
|
|
306
|
+
propertyName: string;
|
|
307
|
+
mapping?: Map<string>;
|
|
308
|
+
}
|
|
309
|
+
export interface XMLObject {
|
|
310
|
+
name?: string;
|
|
311
|
+
namespace?: string;
|
|
312
|
+
prefix?: string;
|
|
313
|
+
attribute?: boolean;
|
|
314
|
+
wrapped?: boolean;
|
|
315
|
+
}
|
|
316
|
+
export type SecuritySchemeObject = ApiKeySecuritySchemeObject | HttpSecuritySchemeObject | Oauth2SecuritySchemeObject | OpenIdConnectSecuritySchemeObject;
|
|
317
|
+
export interface ApiKeySecuritySchemeObject {
|
|
318
|
+
type: "apiKey";
|
|
319
|
+
description?: string;
|
|
320
|
+
name: string;
|
|
321
|
+
in: "query" | "header" | "cookie";
|
|
322
|
+
}
|
|
323
|
+
export interface HttpSecuritySchemeObject {
|
|
324
|
+
type: "http";
|
|
325
|
+
description?: string;
|
|
326
|
+
scheme: string;
|
|
327
|
+
bearerFormat?: string;
|
|
328
|
+
name?: string;
|
|
329
|
+
in?: string;
|
|
330
|
+
}
|
|
331
|
+
export interface Oauth2SecuritySchemeObject {
|
|
332
|
+
type: "oauth2";
|
|
333
|
+
description?: string;
|
|
334
|
+
flows: OAuthFlowsObject;
|
|
335
|
+
}
|
|
336
|
+
export interface OpenIdConnectSecuritySchemeObject {
|
|
337
|
+
type: "openIdConnect";
|
|
338
|
+
description?: string;
|
|
339
|
+
openIdConnectUrl: string;
|
|
340
|
+
}
|
|
341
|
+
export interface OAuthFlowsObject {
|
|
342
|
+
implicit?: OAuthFlowObject;
|
|
343
|
+
password?: OAuthFlowObject;
|
|
344
|
+
clientCredentials?: OAuthFlowObject;
|
|
345
|
+
authorizationCode?: OAuthFlowObject;
|
|
346
|
+
}
|
|
347
|
+
export interface OAuthFlowObject {
|
|
348
|
+
authorizationUrl?: string;
|
|
349
|
+
tokenUrl?: string;
|
|
350
|
+
refreshUrl?: string;
|
|
351
|
+
scopes: Map<string>;
|
|
352
|
+
}
|
|
353
|
+
export type SecurityRequirementObject = Map<string[]>;
|
|
354
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.convertSwagger2OpenAPI = convertSwagger2OpenAPI;
|
|
13
|
+
exports.loadAndResolveSpec = loadAndResolveSpec;
|
|
14
|
+
const json_schema_ref_parser_1 = __importDefault(require("@apidevtools/json-schema-ref-parser"));
|
|
15
|
+
const openapi_core_1 = require("@redocly/openapi-core");
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
const swagger2openapi_1 = require("swagger2openapi");
|
|
19
|
+
const OpenAPIParser_1 = require("./services/OpenAPIParser");
|
|
20
|
+
function serializer(replacer, cycleReplacer) {
|
|
21
|
+
var stack = [], keys = [];
|
|
22
|
+
if (cycleReplacer === undefined)
|
|
23
|
+
cycleReplacer = function (key, value) {
|
|
24
|
+
if (stack[0] === value)
|
|
25
|
+
return "circular()";
|
|
26
|
+
return value.title ? `circular(${value.title})` : "circular()";
|
|
27
|
+
};
|
|
28
|
+
return function (key, value) {
|
|
29
|
+
// Resolve discriminator ref pointers
|
|
30
|
+
if ((value === null || value === void 0 ? void 0 : value.discriminator) !== undefined) {
|
|
31
|
+
const parser = new OpenAPIParser_1.OpenAPIParser(stack[0]);
|
|
32
|
+
if (value.discriminator.mapping &&
|
|
33
|
+
typeof value.discriminator.mapping === "object") {
|
|
34
|
+
for (let [k, v] of Object.entries(value.discriminator.mapping)) {
|
|
35
|
+
const discriminator = k;
|
|
36
|
+
if (typeof v === "string" && v.charAt(0) === "#") {
|
|
37
|
+
const ref = v;
|
|
38
|
+
const resolvedRef = parser.byRef(ref);
|
|
39
|
+
value.discriminator.mapping[discriminator] = resolvedRef;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (stack.length > 0) {
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
var thisPos = stack.indexOf(this);
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
|
|
49
|
+
~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
if (~stack.indexOf(value))
|
|
52
|
+
value = cycleReplacer.call(this, key, value);
|
|
53
|
+
}
|
|
54
|
+
else
|
|
55
|
+
stack.push(value);
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
return replacer === undefined ? value : replacer.call(this, key, value);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function convertSwagger2OpenAPI(spec) {
|
|
61
|
+
console.warn("[ReDoc Compatibility mode]: Converting OpenAPI 2.0 to OpenAPI 3.0");
|
|
62
|
+
return new Promise((resolve, reject) => (0, swagger2openapi_1.convertObj)(spec, {
|
|
63
|
+
patch: true,
|
|
64
|
+
warnOnly: true,
|
|
65
|
+
text: "{}",
|
|
66
|
+
anchors: true,
|
|
67
|
+
resolveInternal: true,
|
|
68
|
+
}, (err, res) => {
|
|
69
|
+
// TODO: log any warnings
|
|
70
|
+
if (err) {
|
|
71
|
+
return reject(err);
|
|
72
|
+
}
|
|
73
|
+
resolve(res && res.openapi);
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
async function resolveJsonRefs(specUrlOrObject) {
|
|
77
|
+
try {
|
|
78
|
+
let schema = await json_schema_ref_parser_1.default.dereference(specUrlOrObject, {
|
|
79
|
+
continueOnError: true,
|
|
80
|
+
resolve: {
|
|
81
|
+
file: true,
|
|
82
|
+
external: true,
|
|
83
|
+
http: {
|
|
84
|
+
timeout: 15000, // 15 sec timeout
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
dereference: {
|
|
88
|
+
circular: true,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
return schema;
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
let errorMsg = "";
|
|
95
|
+
if (err.errors[0] !== undefined) {
|
|
96
|
+
const error = err.errors[0];
|
|
97
|
+
errorMsg = `Error: [${error.message}] with footprint [${error.footprint}]`;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
errorMsg = err;
|
|
101
|
+
}
|
|
102
|
+
console.error(chalk_1.default.yellow(errorMsg));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function loadAndResolveSpec(specUrlOrObject) {
|
|
107
|
+
const config = new openapi_core_1.Config({});
|
|
108
|
+
const bundleOpts = {
|
|
109
|
+
config,
|
|
110
|
+
base: process.cwd(),
|
|
111
|
+
};
|
|
112
|
+
if (typeof specUrlOrObject === "object" && specUrlOrObject !== null) {
|
|
113
|
+
bundleOpts["doc"] = {
|
|
114
|
+
source: { absoluteRef: "" },
|
|
115
|
+
parsed: specUrlOrObject,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
bundleOpts["ref"] = specUrlOrObject;
|
|
120
|
+
}
|
|
121
|
+
// Force dereference ?
|
|
122
|
+
// bundleOpts["dereference"] = true;
|
|
123
|
+
const { bundle: { parsed }, } = await (0, openapi_core_1.bundle)(bundleOpts);
|
|
124
|
+
//Pre-processing before resolving JSON refs
|
|
125
|
+
if (parsed.components) {
|
|
126
|
+
for (let [component, type] of Object.entries(parsed.components)) {
|
|
127
|
+
if (component === "schemas") {
|
|
128
|
+
for (let [schemaKey, schemaValue] of Object.entries(type)) {
|
|
129
|
+
const title = schemaValue["title"];
|
|
130
|
+
if (!title) {
|
|
131
|
+
schemaValue.title = schemaKey;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const resolved = await resolveJsonRefs(parsed);
|
|
138
|
+
// Force serialization and replace circular $ref pointers
|
|
139
|
+
// @ts-ignore
|
|
140
|
+
const serialized = JSON.stringify(resolved, serializer());
|
|
141
|
+
let decycled;
|
|
142
|
+
try {
|
|
143
|
+
decycled = JSON.parse(serialized);
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
console.error(chalk_1.default.yellow(err));
|
|
147
|
+
}
|
|
148
|
+
return decycled !== undefined && typeof decycled === "object"
|
|
149
|
+
? decycled.swagger !== undefined
|
|
150
|
+
? convertSwagger2OpenAPI(decycled)
|
|
151
|
+
: decycled
|
|
152
|
+
: resolved;
|
|
153
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { OpenAPIRef, OpenAPISchema, OpenAPISpec, Referenced } from "../types";
|
|
2
|
+
export type MergedOpenAPISchema = OpenAPISchema & {
|
|
3
|
+
parentRefs?: string[];
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Loads and keeps spec. Provides raw spec operations
|
|
7
|
+
*/
|
|
8
|
+
export declare class OpenAPIParser {
|
|
9
|
+
private options;
|
|
10
|
+
specUrl?: string;
|
|
11
|
+
spec: OpenAPISpec;
|
|
12
|
+
private _refCounter;
|
|
13
|
+
private allowMergeRefs;
|
|
14
|
+
constructor(spec: OpenAPISpec, specUrl?: string, options?: {});
|
|
15
|
+
validate(spec: any): void;
|
|
16
|
+
/**
|
|
17
|
+
* get spec part by JsonPointer ($ref)
|
|
18
|
+
*/
|
|
19
|
+
byRef: <T extends unknown = any>(ref: string) => T | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* checks if the object is OpenAPI reference (contains $ref property)
|
|
22
|
+
*/
|
|
23
|
+
isRef(obj: any): obj is OpenAPIRef;
|
|
24
|
+
/**
|
|
25
|
+
* resets visited endpoints. should be run after
|
|
26
|
+
*/
|
|
27
|
+
resetVisited(): void;
|
|
28
|
+
exitRef<T>(ref: Referenced<T>): void;
|
|
29
|
+
/**
|
|
30
|
+
* Resolve given reference object or return as is if it is not a reference
|
|
31
|
+
* @param obj object to dereference
|
|
32
|
+
* @param forceCircular whether to dereference even if it is circular ref
|
|
33
|
+
*/
|
|
34
|
+
deref<T extends object>(obj: OpenAPIRef | T, forceCircular?: boolean, mergeAsAllOf?: boolean): T;
|
|
35
|
+
shallowDeref<T extends unknown>(obj: OpenAPIRef | T): T;
|
|
36
|
+
mergeRefs(ref: any, resolved: any, mergeAsAllOf: boolean): any;
|
|
37
|
+
/**
|
|
38
|
+
* Merge allOf constraints.
|
|
39
|
+
* @param schema schema with allOF
|
|
40
|
+
* @param $ref pointer of the schema
|
|
41
|
+
* @param forceCircular whether to dereference children even if it is a circular ref
|
|
42
|
+
*/
|
|
43
|
+
mergeAllOf(schema: OpenAPISchema, $ref?: string, forceCircular?: boolean, used$Refs?: Set<string>): MergedOpenAPISchema;
|
|
44
|
+
/**
|
|
45
|
+
* Find all derived definitions among #/components/schemas from any of $refs
|
|
46
|
+
* returns map of definition pointer to definition name
|
|
47
|
+
* @param $refs array of references to find derived from
|
|
48
|
+
*/
|
|
49
|
+
findDerived($refs: string[]): Record<string, string[] | string>;
|
|
50
|
+
exitParents(shema: MergedOpenAPISchema): void;
|
|
51
|
+
private hoistOneOfs;
|
|
52
|
+
}
|