@visulima/jsdoc-open-api 1.3.9 → 1.3.11
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/CHANGELOG.md +28 -0
- package/bin/index.js +4 -7
- package/dist/chunk-D7VYGB4A.js +33 -0
- package/dist/chunk-D7VYGB4A.js.map +1 -0
- package/dist/chunk-LJ3K3FMO.js +58 -0
- package/dist/chunk-LJ3K3FMO.js.map +1 -0
- package/dist/chunk-NLSOZGMI.mjs +50 -0
- package/dist/chunk-NLSOZGMI.mjs.map +1 -0
- package/dist/chunk-WHYPHVY6.mjs +19 -0
- package/dist/chunk-WHYPHVY6.mjs.map +1 -0
- package/dist/cli/commander/index.d.mts +7 -0
- package/dist/cli/commander/index.d.ts +2 -2
- package/dist/cli/commander/index.js +5 -5
- package/dist/cli/commander/index.js.map +1 -1
- package/dist/cli/commander/index.mjs +4 -4
- package/dist/cli/commander/index.mjs.map +1 -1
- package/dist/cli/index.d.mts +10 -0
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +4 -4
- package/dist/cli/index.mjs +2 -2
- package/dist/index.d.mts +291 -0
- package/dist/index.d.ts +97 -109
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +40 -42
- package/dist/chunk-I7ZHNMGN.js +0 -33
- package/dist/chunk-I7ZHNMGN.js.map +0 -1
- package/dist/chunk-KUMMB3O5.mjs +0 -50
- package/dist/chunk-KUMMB3O5.mjs.map +0 -1
- package/dist/chunk-SMHWGAPA.mjs +0 -19
- package/dist/chunk-SMHWGAPA.mjs.map +0 -1
- package/dist/chunk-TDDRTX7G.js +0 -58
- package/dist/chunk-TDDRTX7G.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Compiler } from 'webpack';
|
|
2
2
|
|
|
3
3
|
interface BaseDefinition {
|
|
4
|
-
|
|
4
|
+
components?: ComponentsObject;
|
|
5
|
+
externalDocs?: ExternalDocumentationObject;
|
|
5
6
|
info: InfoObject;
|
|
6
|
-
|
|
7
|
+
openapi: string;
|
|
7
8
|
paths?: PathsObject;
|
|
8
|
-
components?: ComponentsObject;
|
|
9
9
|
security?: SecurityRequirementObject[];
|
|
10
|
+
servers?: ServerObject[];
|
|
10
11
|
tags?: TagObject[];
|
|
11
|
-
externalDocs?: ExternalDocumentationObject;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
interface OpenApiObject extends BaseDefinition {
|
|
@@ -16,18 +16,18 @@ interface OpenApiObject extends BaseDefinition {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
interface InfoObject {
|
|
19
|
-
title: string;
|
|
20
|
-
version: string;
|
|
21
|
-
description?: string;
|
|
22
|
-
termsOfService?: string;
|
|
23
19
|
contact?: ContactObject;
|
|
20
|
+
description?: string;
|
|
24
21
|
license?: LicenseObject;
|
|
22
|
+
termsOfService?: string;
|
|
23
|
+
title: string;
|
|
24
|
+
version: string;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
interface ContactObject {
|
|
28
|
+
email?: string;
|
|
28
29
|
name?: string;
|
|
29
30
|
url?: string;
|
|
30
|
-
email?: string;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
interface LicenseObject {
|
|
@@ -36,87 +36,85 @@ interface LicenseObject {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
interface ServerObject {
|
|
39
|
-
url: string;
|
|
40
39
|
description?: string;
|
|
40
|
+
url: string;
|
|
41
41
|
variables?: Map<ServerVariable>;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
interface ServerVariable {
|
|
45
45
|
default: string;
|
|
46
|
-
enum?: string[];
|
|
47
46
|
description?: string;
|
|
47
|
+
enum?: string[];
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
interface ComponentsObject {
|
|
51
|
-
|
|
52
|
-
responses?: Map<ReferenceObject | ResponseObject>;
|
|
53
|
-
parameters?: Map<ParameterObject | ReferenceObject>;
|
|
51
|
+
callbacks?: Map<CallbackObject | ReferenceObject>;
|
|
54
52
|
examples?: Map<ExampleObject | ReferenceObject>;
|
|
55
|
-
requestBodies?: Map<ReferenceObject | RequestBodyObject>;
|
|
56
53
|
headers?: Map<HeaderObject | ReferenceObject>;
|
|
54
|
+
links?: Map<LinkObject | ReferenceObject>;
|
|
55
|
+
parameters?: Map<ParameterObject | ReferenceObject>;
|
|
56
|
+
requestBodies?: Map<ReferenceObject | RequestBodyObject>;
|
|
57
|
+
responses?: Map<ReferenceObject | ResponseObject>;
|
|
58
|
+
schemas?: Map<ReferenceObject | SchemaObject>;
|
|
57
59
|
securitySchemes?: Map<
|
|
58
|
-
|
|
60
|
+
ApiKeySecuritySchemeObject | HttpSecuritySchemeObject | Oauth2SecuritySchemeObject | OpenIdConnectSecuritySchemeObject | ReferenceObject
|
|
59
61
|
>;
|
|
60
|
-
links?: Map<LinkObject | ReferenceObject>;
|
|
61
|
-
callbacks?: Map<CallbackObject | ReferenceObject>;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
[path: string]: PathItemObject;
|
|
66
|
-
}
|
|
64
|
+
type PathsObject = Record<string, PathItemObject>;
|
|
67
65
|
|
|
68
66
|
interface PathItemObject {
|
|
69
67
|
$ref?: string;
|
|
70
|
-
|
|
68
|
+
delete?: OperationObject;
|
|
71
69
|
description?: string;
|
|
72
70
|
get?: OperationObject;
|
|
73
|
-
put?: OperationObject;
|
|
74
|
-
post?: OperationObject;
|
|
75
|
-
delete?: OperationObject;
|
|
76
|
-
options?: OperationObject;
|
|
77
71
|
head?: OperationObject;
|
|
72
|
+
options?: OperationObject;
|
|
73
|
+
parameters?: (ParameterObject | ReferenceObject)[];
|
|
78
74
|
patch?: OperationObject;
|
|
79
|
-
|
|
75
|
+
post?: OperationObject;
|
|
76
|
+
put?: OperationObject;
|
|
80
77
|
servers?: ServerObject[];
|
|
81
|
-
|
|
78
|
+
summary?: string;
|
|
79
|
+
trace?: OperationObject;
|
|
82
80
|
}
|
|
83
81
|
|
|
84
82
|
interface OperationObject {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
summary?: string;
|
|
83
|
+
callbacks?: Map<CallbackObject | ReferenceObject>;
|
|
84
|
+
deprecated?: boolean;
|
|
88
85
|
description?: string;
|
|
89
86
|
externalDocs?: ExternalDocumentationObject;
|
|
90
87
|
operationId?: string;
|
|
91
88
|
parameters?: (ParameterObject | ReferenceObject)[];
|
|
92
89
|
requestBody?: ReferenceObject | RequestBodyObject;
|
|
93
|
-
|
|
94
|
-
deprecated?: boolean;
|
|
90
|
+
responses: ResponsesObject;
|
|
95
91
|
security?: SecurityRequirementObject[];
|
|
96
92
|
servers?: ServerObject[];
|
|
93
|
+
summary?: string;
|
|
94
|
+
tags?: string[];
|
|
97
95
|
}
|
|
98
96
|
|
|
99
97
|
interface ExternalDocumentationObject {
|
|
100
|
-
url: string;
|
|
101
98
|
description?: string;
|
|
99
|
+
url: string;
|
|
102
100
|
}
|
|
103
101
|
|
|
104
102
|
interface ParameterObject {
|
|
105
|
-
name: string;
|
|
106
|
-
in: string;
|
|
107
|
-
description?: string;
|
|
108
|
-
required?: boolean;
|
|
109
|
-
deprecated?: boolean;
|
|
110
103
|
allowEmptyValue?: boolean;
|
|
111
|
-
//
|
|
112
|
-
style?: string;
|
|
113
|
-
explode?: string;
|
|
114
104
|
allowReserved?: boolean;
|
|
115
|
-
|
|
105
|
+
//
|
|
106
|
+
content?: Map<MediaTypeObject>;
|
|
107
|
+
deprecated?: boolean;
|
|
108
|
+
description?: string;
|
|
116
109
|
example?: any;
|
|
117
110
|
examples?: Map<ExampleObject | ReferenceObject>;
|
|
111
|
+
explode?: string;
|
|
112
|
+
in: string;
|
|
113
|
+
name: string;
|
|
114
|
+
required?: boolean;
|
|
115
|
+
schema?: ReferenceObject | SchemaObject;
|
|
118
116
|
//
|
|
119
|
-
|
|
117
|
+
style?: string;
|
|
120
118
|
// ignoring stylings: matrix, label, form, simple, spaceDelimited,
|
|
121
119
|
// pipeDelimited and deepObject
|
|
122
120
|
}
|
|
@@ -128,73 +126,69 @@ interface RequestBodyObject {
|
|
|
128
126
|
}
|
|
129
127
|
|
|
130
128
|
interface MediaTypeObject {
|
|
131
|
-
|
|
129
|
+
encoding?: Map<EncodingObject>;
|
|
132
130
|
example?: any;
|
|
133
131
|
examples?: Map<ExampleObject | ReferenceObject>;
|
|
134
|
-
|
|
132
|
+
schema?: ReferenceObject | SchemaObject;
|
|
135
133
|
}
|
|
136
134
|
|
|
137
135
|
interface EncodingObject {
|
|
136
|
+
allowReserved?: boolean;
|
|
138
137
|
contentType?: string;
|
|
138
|
+
explode?: boolean;
|
|
139
139
|
headers?: Map<HeaderObject | ReferenceObject>;
|
|
140
140
|
style?: string;
|
|
141
|
-
explode?: boolean;
|
|
142
|
-
allowReserved?: boolean;
|
|
143
141
|
}
|
|
144
142
|
|
|
145
|
-
|
|
146
|
-
[code: string]: ReferenceObject | ResponseObject;
|
|
147
|
-
}
|
|
143
|
+
type ResponsesObject = Record<string, ReferenceObject | ResponseObject>;
|
|
148
144
|
|
|
149
145
|
interface ResponseObject {
|
|
146
|
+
content?: Map<MediaTypeObject>;
|
|
150
147
|
description: string;
|
|
151
148
|
headers?: Map<HeaderObject | ReferenceObject>;
|
|
152
|
-
content?: Map<MediaTypeObject>;
|
|
153
149
|
links?: Map<LinkObject | ReferenceObject>;
|
|
154
150
|
}
|
|
155
151
|
|
|
156
|
-
|
|
157
|
-
[expression: string]: PathItemObject;
|
|
158
|
-
}
|
|
152
|
+
type CallbackObject = Record<string, PathItemObject>;
|
|
159
153
|
|
|
160
154
|
interface ExampleObject {
|
|
161
|
-
summary?: string;
|
|
162
155
|
description?: string;
|
|
163
|
-
value?: any;
|
|
164
156
|
externalValue?: string;
|
|
157
|
+
summary?: string;
|
|
158
|
+
value?: any;
|
|
165
159
|
}
|
|
166
160
|
|
|
167
161
|
interface LinkObject {
|
|
168
|
-
|
|
162
|
+
description?: string;
|
|
169
163
|
operationId?: string;
|
|
164
|
+
operationRef?: string;
|
|
170
165
|
parameters?: Map<any>;
|
|
171
166
|
requestBody?: any;
|
|
172
|
-
description?: string;
|
|
173
167
|
server?: ServerObject;
|
|
174
168
|
}
|
|
175
169
|
|
|
176
170
|
interface HeaderObject {
|
|
177
|
-
description?: string;
|
|
178
|
-
required?: boolean;
|
|
179
|
-
deprecated?: boolean;
|
|
180
171
|
allowEmptyValue?: boolean;
|
|
181
|
-
//
|
|
182
|
-
style?: string;
|
|
183
|
-
explode?: string;
|
|
184
172
|
allowReserved?: boolean;
|
|
185
|
-
|
|
173
|
+
//
|
|
174
|
+
content?: Map<MediaTypeObject>;
|
|
175
|
+
deprecated?: boolean;
|
|
176
|
+
description?: string;
|
|
186
177
|
example?: any;
|
|
187
178
|
examples?: Map<ExampleObject | ReferenceObject>;
|
|
179
|
+
explode?: string;
|
|
180
|
+
required?: boolean;
|
|
181
|
+
schema?: ReferenceObject | SchemaObject;
|
|
188
182
|
//
|
|
189
|
-
|
|
183
|
+
style?: string;
|
|
190
184
|
// ignoring stylings: matrix, label, form, simple, spaceDelimited,
|
|
191
185
|
// pipeDelimited and deepObject
|
|
192
186
|
}
|
|
193
187
|
|
|
194
188
|
interface TagObject {
|
|
195
|
-
name: string;
|
|
196
189
|
description?: string;
|
|
197
190
|
externalDocs?: ExternalDocumentationObject;
|
|
191
|
+
name: string;
|
|
198
192
|
}
|
|
199
193
|
|
|
200
194
|
interface ReferenceObject {
|
|
@@ -202,102 +196,96 @@ interface ReferenceObject {
|
|
|
202
196
|
}
|
|
203
197
|
|
|
204
198
|
// TODO: this could be expanded on.
|
|
205
|
-
|
|
206
|
-
[key: string]: any;
|
|
207
|
-
}
|
|
199
|
+
type SchemaObject = Record<string, any>;
|
|
208
200
|
|
|
209
201
|
interface ApiKeySecuritySchemeObject {
|
|
210
|
-
type: string;
|
|
211
202
|
description?: string;
|
|
212
|
-
name: string;
|
|
213
203
|
in: string;
|
|
204
|
+
name: string;
|
|
205
|
+
type: string;
|
|
214
206
|
}
|
|
215
207
|
|
|
216
208
|
interface HttpSecuritySchemeObject {
|
|
217
|
-
|
|
209
|
+
bearerFormat?: string;
|
|
218
210
|
description?: string;
|
|
219
211
|
scheme: string;
|
|
220
|
-
|
|
212
|
+
type: string;
|
|
221
213
|
}
|
|
222
214
|
|
|
223
215
|
interface Oauth2SecuritySchemeObject {
|
|
224
|
-
type: string;
|
|
225
216
|
description?: string;
|
|
226
217
|
flows: OAuthFlowsObject;
|
|
218
|
+
type: string;
|
|
227
219
|
}
|
|
228
220
|
|
|
229
221
|
interface OpenIdConnectSecuritySchemeObject {
|
|
230
|
-
type: string;
|
|
231
222
|
description?: string;
|
|
232
223
|
openIdConnectUrl: string;
|
|
224
|
+
type: string;
|
|
233
225
|
}
|
|
234
226
|
|
|
235
227
|
interface OAuthFlowsObject {
|
|
228
|
+
authorizationCode?: OAuthFlowObject;
|
|
229
|
+
clientCredentials?: OAuthFlowObject;
|
|
236
230
|
implicit?: OAuthFlowObject;
|
|
237
231
|
password?: OAuthFlowObject;
|
|
238
|
-
clientCredentials?: OAuthFlowObject;
|
|
239
|
-
authorizationCode?: OAuthFlowObject;
|
|
240
232
|
}
|
|
241
233
|
|
|
242
234
|
interface OAuthFlowObject {
|
|
243
235
|
authorizationUrl?: string; // required for some?
|
|
244
|
-
tokenUrl?: string; // required for some?
|
|
245
236
|
refreshUrl: string;
|
|
246
237
|
scopes: Map<string>;
|
|
238
|
+
tokenUrl?: string; // required for some?
|
|
247
239
|
}
|
|
248
240
|
|
|
249
|
-
|
|
250
|
-
[name: string]: string[];
|
|
251
|
-
}
|
|
241
|
+
type SecurityRequirementObject = Record<string, string[]>;
|
|
252
242
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
243
|
+
type Map<T> = Record<string, T>;
|
|
244
|
+
|
|
245
|
+
declare const commentsToOpenApi$1: (fileContents: string, verbose?: boolean) => {
|
|
246
|
+
loc: number;
|
|
247
|
+
spec: OpenApiObject;
|
|
248
|
+
}[];
|
|
249
|
+
|
|
250
|
+
declare const parseFile: (file: string, commentsToOpenApi: (fileContent: string, verbose?: boolean) => {
|
|
251
|
+
loc: number;
|
|
252
|
+
spec: OpenApiObject;
|
|
253
|
+
}[], verbose?: boolean) => {
|
|
254
|
+
loc: number;
|
|
255
|
+
spec: OpenApiObject;
|
|
256
|
+
}[];
|
|
256
257
|
|
|
257
258
|
declare class SpecBuilder implements OpenApiObject {
|
|
258
|
-
|
|
259
|
+
components?: ComponentsObject;
|
|
260
|
+
externalDocs?: ExternalDocumentationObject;
|
|
259
261
|
info: InfoObject;
|
|
260
|
-
|
|
262
|
+
openapi: string;
|
|
261
263
|
paths: PathsObject;
|
|
262
|
-
components?: ComponentsObject;
|
|
263
264
|
security?: SecurityRequirementObject[];
|
|
265
|
+
servers?: ServerObject[];
|
|
264
266
|
tags?: TagObject[];
|
|
265
|
-
externalDocs?: ExternalDocumentationObject;
|
|
266
267
|
constructor(baseDefinition: BaseDefinition);
|
|
267
268
|
addData(parsedFile: OpenApiObject[]): void;
|
|
268
269
|
}
|
|
269
270
|
|
|
270
|
-
declare const
|
|
271
|
-
spec: OpenApiObject;
|
|
271
|
+
declare const commentsToOpenApi: (fileContents: string, verbose?: boolean) => {
|
|
272
272
|
loc: number;
|
|
273
|
-
}[], verbose?: boolean) => {
|
|
274
273
|
spec: OpenApiObject;
|
|
275
|
-
loc: number;
|
|
276
274
|
}[];
|
|
277
275
|
|
|
278
|
-
declare
|
|
276
|
+
declare const yamlLoc: (string: string) => number;
|
|
279
277
|
|
|
280
278
|
declare class SwaggerCompilerPlugin {
|
|
281
|
-
private readonly
|
|
279
|
+
private readonly assetsPath;
|
|
280
|
+
private readonly ignore;
|
|
282
281
|
private readonly sources;
|
|
282
|
+
private readonly swaggerDefinition;
|
|
283
283
|
private readonly verbose;
|
|
284
|
-
private readonly ignore;
|
|
285
|
-
private readonly assetsPath;
|
|
286
284
|
constructor(assetsPath: string, sources: string[], swaggerDefinition: BaseDefinition, options: {
|
|
287
|
-
verbose?: boolean;
|
|
288
285
|
ignore?: ReadonlyArray<string> | string;
|
|
286
|
+
verbose?: boolean;
|
|
289
287
|
});
|
|
290
288
|
apply(compiler: Compiler): void;
|
|
291
289
|
}
|
|
292
290
|
|
|
293
|
-
declare const commentsToOpenApi$1: (fileContents: string, verbose?: boolean) => {
|
|
294
|
-
spec: OpenApiObject;
|
|
295
|
-
loc: number;
|
|
296
|
-
}[];
|
|
297
|
-
|
|
298
|
-
declare const commentsToOpenApi: (fileContents: string, verbose?: boolean) => {
|
|
299
|
-
spec: OpenApiObject;
|
|
300
|
-
loc: number;
|
|
301
|
-
}[];
|
|
302
|
-
|
|
303
291
|
export { BaseDefinition, OpenApiObject, SpecBuilder, SwaggerCompilerPlugin, commentsToOpenApi$1 as jsDocumentCommentsToOpenApi, parseFile, commentsToOpenApi as swaggerJsDocumentCommentsToOpenApi, yamlLoc };
|
package/dist/index.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkD7VYGB4A_js = require('./chunk-D7VYGB4A.js');
|
|
4
4
|
var readdir = require('@visulima/readdir');
|
|
5
5
|
var fs = require('fs');
|
|
6
6
|
var path = require('path');
|
|
7
7
|
var process = require('process');
|
|
8
8
|
|
|
9
|
-
var O=["coverage/**",".github/**","packages/*/test{,s}/**","**/*.d.ts","test{,s}/**","test{,-*}.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}","**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}","**/__tests__/**","**/{ava,babel,nyc}.config.{js,cjs,mjs}","**/jest.config.{js,cjs,mjs,ts}","**/{karma,rollup,webpack}.config.js","**/.{eslint,mocha}rc.{js,cjs}","**/.{travis,yarnrc}.yml","**/{docker-compose,docker}.yml","**/.yamllint.{yaml,yml}","**/node_modules/**","**/pnpm-lock.yaml","**/pnpm-workspace.yaml","**/{package,package-lock}.json","**/yarn.lock","**/package.json5","**/.next/**"],b=t=>{t&&(console.error(t),process.exit(1));},d=class{constructor(r,u,i,e){this.assetsPath=r,this.swaggerDefinition=i,this.sources=u,this.verbose=e.verbose??!1,this.ignore=e.ignore??[];}apply(r){r.hooks.make.tapAsync("SwaggerCompilerPlugin",async(u,i)=>{console.log("Build paused, switching to swagger build");let e=new
|
|
9
|
+
var O=["coverage/**",".github/**","packages/*/test{,s}/**","**/*.d.ts","test{,s}/**","test{,-*}.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}","**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}","**/__tests__/**","**/{ava,babel,nyc}.config.{js,cjs,mjs}","**/jest.config.{js,cjs,mjs,ts}","**/{karma,rollup,webpack}.config.js","**/.{eslint,mocha}rc.{js,cjs}","**/.{travis,yarnrc}.yml","**/{docker-compose,docker}.yml","**/.yamllint.{yaml,yml}","**/node_modules/**","**/pnpm-lock.yaml","**/pnpm-workspace.yaml","**/{package,package-lock}.json","**/yarn.lock","**/package.json5","**/.next/**"],b=t=>{t&&(console.error(t),process.exit(1));},d=class{constructor(r,u,i,e){this.assetsPath=r,this.swaggerDefinition=i,this.sources=u,this.verbose=e.verbose??!1,this.ignore=e.ignore??[];}apply(r){r.hooks.make.tapAsync("SwaggerCompilerPlugin",async(u,i)=>{console.log("Build paused, switching to swagger build");let e=new chunkD7VYGB4A_js.d(this.swaggerDefinition);for await(let s of this.sources){let a=await readdir.collect(s,{extensions:[".js",".cjs",".mjs",".ts",".tsx",".jsx",".yaml",".yml"],includeDirs:!1,minimatchOptions:{match:{debug:this.verbose,matchBase:!0},skip:{debug:this.verbose,matchBase:!0}},skip:[...this.ignore,...O]});this.verbose&&(console.log(`Found ${a.length} files in ${s}`),console.log(a)),a.forEach(n=>{this.verbose&&console.log(`Parsing file ${n}`);try{let l=chunkD7VYGB4A_js.c(n,chunkD7VYGB4A_js.a,this.verbose);e.addData(l.map(c=>c.spec));let j=chunkD7VYGB4A_js.c(n,chunkD7VYGB4A_js.e,this.verbose);e.addData(j.map(c=>c.spec));}catch(l){console.error(l),process.exit(1);}});}try{this.verbose&&(console.log("Validating swagger spec"),console.log(JSON.stringify(e,null,2))),await chunkD7VYGB4A_js.f(JSON.parse(JSON.stringify(e)));}catch(s){console.error(s.toJSON()),process.exit(1);}let{assetsPath:y}=this;fs.mkdir(path.dirname(y),{recursive:!0},s=>{s&&b(s),fs.writeFile(y,JSON.stringify(e,null,2),b);}),this.verbose&&console.log(`Written swagger spec to "${this.assetsPath}" file`),console.log("switching back to normal build"),i();});}},B=d;
|
|
10
10
|
|
|
11
11
|
Object.defineProperty(exports, 'SpecBuilder', {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkD7VYGB4A_js.d; }
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(exports, 'jsDocumentCommentsToOpenApi', {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
17
|
+
get: function () { return chunkD7VYGB4A_js.a; }
|
|
18
18
|
});
|
|
19
19
|
Object.defineProperty(exports, 'parseFile', {
|
|
20
20
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
21
|
+
get: function () { return chunkD7VYGB4A_js.c; }
|
|
22
22
|
});
|
|
23
23
|
Object.defineProperty(exports, 'swaggerJsDocumentCommentsToOpenApi', {
|
|
24
24
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
25
|
+
get: function () { return chunkD7VYGB4A_js.e; }
|
|
26
26
|
});
|
|
27
27
|
Object.defineProperty(exports, 'yamlLoc', {
|
|
28
28
|
enumerable: true,
|
|
29
|
-
get: function () { return
|
|
29
|
+
get: function () { return chunkD7VYGB4A_js.b; }
|
|
30
30
|
});
|
|
31
31
|
exports.SwaggerCompilerPlugin = B;
|
|
32
32
|
//# sourceMappingURL=out.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/webpack/swagger-compiler-plugin.ts"],"names":["collect","mkdir","writeFile","dirname","exit","exclude","errorHandler","error","SwaggerCompilerPlugin","assetsPath","sources","swaggerDefinition","options","compiler","_","callback","spec","spec_builder_default","dir","files","file","parsedJsDocumentFile","parse_file_default","comments_to_open_api_default","item","parsedSwaggerJsDocumentFile","validate_default","swagger_compiler_plugin_default"],"mappings":"2EAAA,OAAS,WAAAA,MAAe,oBACxB,OAAS,SAAAC,EAAO,aAAAC,MAAiB,KACjC,OAAS,WAAAC,MAAe,OACxB,OAAS,QAAAC,MAAY,UAWrB,IAAMC,EAAU,CACZ,cACA,aACA,yBACA,YACA,cACA,6CACA,iDACA,kBACA,yCACA,iCACA,sCACA,gCACA,0BACA,iCACA,0BACA,qBACA,oBACA,yBACA,iCACA,eACA,mBACA,aACJ,EAEMC,EAAgBC,GAAe,CAC7BA,
|
|
1
|
+
{"version":3,"sources":["../src/webpack/swagger-compiler-plugin.ts"],"names":["collect","mkdir","writeFile","dirname","exit","exclude","errorHandler","error","SwaggerCompilerPlugin","assetsPath","sources","swaggerDefinition","options","compiler","_","callback","spec","spec_builder_default","dir","files","file","parsedJsDocumentFile","parse_file_default","comments_to_open_api_default","item","parsedSwaggerJsDocumentFile","validate_default","swagger_compiler_plugin_default"],"mappings":"2EAAA,OAAS,WAAAA,MAAe,oBACxB,OAAS,SAAAC,EAAO,aAAAC,MAAiB,KACjC,OAAS,WAAAC,MAAe,OACxB,OAAS,QAAAC,MAAY,UAWrB,IAAMC,EAAU,CACZ,cACA,aACA,yBACA,YACA,cACA,6CACA,iDACA,kBACA,yCACA,iCACA,sCACA,gCACA,0BACA,iCACA,0BACA,qBACA,oBACA,yBACA,iCACA,eACA,mBACA,aACJ,EAEMC,EAAgBC,GAAe,CAC7BA,IACA,QAAQ,MAAMA,CAAK,EACnBH,EAAK,CAAC,EAEd,EAEMI,EAAN,KAA4B,CAWjB,YACHC,EACAC,EACAC,EACAC,EAIF,CACE,KAAK,WAAaH,EAClB,KAAK,kBAAoBE,EACzB,KAAK,QAAUD,EACf,KAAK,QAAUE,EAAQ,SAAW,GAClC,KAAK,OAASA,EAAQ,QAAU,CAAC,CACrC,CAEO,MAAMC,EAA0B,CAEnCA,EAAS,MAAM,KAAK,SAAS,wBAAyB,MAAOC,EAAGC,IAA0C,CACtG,QAAQ,IAAI,0CAA0C,EAEtD,IAAMC,EAAO,IAAIC,EAAY,KAAK,iBAAiB,EAGnD,cAAiBC,KAAO,KAAK,QAAS,CAClC,IAAMC,EAAQ,MAAMnB,EAAQkB,EAAK,CAC7B,WAAY,CAAC,MAAO,OAAQ,OAAQ,MAAO,OAAQ,OAAQ,QAAS,MAAM,EAC1E,YAAa,GACb,iBAAkB,CACd,MAAO,CACH,MAAO,KAAK,QACZ,UAAW,EACf,EACA,KAAM,CACF,MAAO,KAAK,QACZ,UAAW,EACf,CACJ,EACA,KAAM,CAAC,GAAG,KAAK,OAAQ,GAAGb,CAAO,CACrC,CAAC,EAEG,KAAK,UACL,QAAQ,IAAI,SAASc,EAAM,MAAM,aAAaD,CAAG,EAAE,EAEnD,QAAQ,IAAIC,CAAK,GAGrBA,EAAM,QAASC,GAAS,CAChB,KAAK,SACL,QAAQ,IAAI,gBAAgBA,CAAI,EAAE,EAGtC,GAAI,CACA,IAAMC,EAAuBC,EAAUF,EAAMG,EAA6B,KAAK,OAAO,EAEtFP,EAAK,QAAQK,EAAqB,IAAKG,GAASA,EAAK,IAAI,CAAC,EAE1D,IAAMC,EAA8BH,EAAUF,EAAMG,EAAoC,KAAK,OAAO,EAEpGP,EAAK,QAAQS,EAA4B,IAAKD,GAASA,EAAK,IAAI,CAAC,CACrE,OAASjB,EAAO,CACZ,QAAQ,MAAMA,CAAK,EACnBH,EAAK,CAAC,CACV,CACJ,CAAC,CACL,CAEA,GAAI,CACI,KAAK,UACL,QAAQ,IAAI,yBAAyB,EAErC,QAAQ,IAAI,KAAK,UAAUY,EAAM,KAAM,CAAC,CAAC,GAG7C,MAAMU,EAAS,KAAK,MAAM,KAAK,UAAUV,CAAI,CAAC,CAAC,CACnD,OAAST,EAAY,CACjB,QAAQ,MAAMA,EAAM,OAAO,CAAC,EAC5BH,EAAK,CAAC,CACV,CAEA,GAAM,CAAE,WAAAK,CAAW,EAAI,KAGvBR,EAAME,EAAQM,CAAU,EAAG,CAAE,UAAW,EAAK,EAAIF,GAAU,CACnDA,GACAD,EAAaC,CAAK,EAItBL,EAAUO,EAAY,KAAK,UAAUO,EAAM,KAAM,CAAC,EAAGV,CAAY,CACrE,CAAC,EAEG,KAAK,SACL,QAAQ,IAAI,4BAA4B,KAAK,UAAU,QAAQ,EAGnE,QAAQ,IAAI,gCAAgC,EAE5CS,EAAS,CACb,CAAC,CACL,CACJ,EAEOY,EAAQnB","sourcesContent":["import { collect } from \"@visulima/readdir\";\nimport { mkdir, writeFile } from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport { exit } from \"node:process\";\n\nimport type { Compiler } from \"webpack\";\n\nimport type { BaseDefinition } from \"../exported.d\";\nimport jsDocumentCommentsToOpenApi from \"../jsdoc/comments-to-open-api\";\nimport parseFile from \"../parse-file\";\nimport SpecBuilder from \"../spec-builder\";\nimport swaggerJsDocumentCommentsToOpenApi from \"../swagger-jsdoc/comments-to-open-api\";\nimport validate from \"../validate\";\n\nconst exclude = [\n \"coverage/**\",\n \".github/**\",\n \"packages/*/test{,s}/**\",\n \"**/*.d.ts\",\n \"test{,s}/**\",\n \"test{,-*}.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}\",\n \"**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}\",\n \"**/__tests__/**\",\n \"**/{ava,babel,nyc}.config.{js,cjs,mjs}\",\n \"**/jest.config.{js,cjs,mjs,ts}\",\n \"**/{karma,rollup,webpack}.config.js\",\n \"**/.{eslint,mocha}rc.{js,cjs}\",\n \"**/.{travis,yarnrc}.yml\",\n \"**/{docker-compose,docker}.yml\",\n \"**/.yamllint.{yaml,yml}\",\n \"**/node_modules/**\",\n \"**/pnpm-lock.yaml\",\n \"**/pnpm-workspace.yaml\",\n \"**/{package,package-lock}.json\",\n \"**/yarn.lock\",\n \"**/package.json5\",\n \"**/.next/**\",\n];\n\nconst errorHandler = (error: any) => {\n if (error) {\n console.error(error);\n exit(1);\n }\n};\n\nclass SwaggerCompilerPlugin {\n private readonly assetsPath: string;\n\n private readonly ignore: ReadonlyArray<string> | string;\n\n private readonly sources: string[];\n\n private readonly swaggerDefinition: BaseDefinition;\n\n private readonly verbose: boolean;\n\n public constructor(\n assetsPath: string,\n sources: string[],\n swaggerDefinition: BaseDefinition,\n options: {\n ignore?: ReadonlyArray<string> | string;\n verbose?: boolean;\n },\n ) {\n this.assetsPath = assetsPath;\n this.swaggerDefinition = swaggerDefinition;\n this.sources = sources;\n this.verbose = options.verbose ?? false;\n this.ignore = options.ignore ?? [];\n }\n\n public apply(compiler: Compiler): void {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n compiler.hooks.make.tapAsync(\"SwaggerCompilerPlugin\", async (_, callback: VoidFunction): Promise<void> => {\n console.log(\"Build paused, switching to swagger build\");\n\n const spec = new SpecBuilder(this.swaggerDefinition);\n\n // eslint-disable-next-line no-restricted-syntax,unicorn/prevent-abbreviations\n for await (const dir of this.sources) {\n const files = await collect(dir, {\n extensions: [\".js\", \".cjs\", \".mjs\", \".ts\", \".tsx\", \".jsx\", \".yaml\", \".yml\"],\n includeDirs: false,\n minimatchOptions: {\n match: {\n debug: this.verbose,\n matchBase: true,\n },\n skip: {\n debug: this.verbose,\n matchBase: true,\n },\n },\n skip: [...this.ignore, ...exclude],\n });\n\n if (this.verbose) {\n console.log(`Found ${files.length} files in ${dir}`);\n\n console.log(files);\n }\n\n files.forEach((file) => {\n if (this.verbose) {\n console.log(`Parsing file ${file}`);\n }\n\n try {\n const parsedJsDocumentFile = parseFile(file, jsDocumentCommentsToOpenApi, this.verbose);\n\n spec.addData(parsedJsDocumentFile.map((item) => item.spec));\n\n const parsedSwaggerJsDocumentFile = parseFile(file, swaggerJsDocumentCommentsToOpenApi, this.verbose);\n\n spec.addData(parsedSwaggerJsDocumentFile.map((item) => item.spec));\n } catch (error) {\n console.error(error);\n exit(1);\n }\n });\n }\n\n try {\n if (this.verbose) {\n console.log(\"Validating swagger spec\");\n\n console.log(JSON.stringify(spec, null, 2));\n }\n\n await validate(JSON.parse(JSON.stringify(spec)));\n } catch (error: any) {\n console.error(error.toJSON());\n exit(1);\n }\n\n const { assetsPath } = this;\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n mkdir(dirname(assetsPath), { recursive: true }, (error) => {\n if (error) {\n errorHandler(error);\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n writeFile(assetsPath, JSON.stringify(spec, null, 2), errorHandler);\n });\n\n if (this.verbose) {\n console.log(`Written swagger spec to \"${this.assetsPath}\" file`);\n }\n\n console.log(\"switching back to normal build\");\n\n callback();\n });\n }\n}\n\nexport default SwaggerCompilerPlugin;\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { d as d$1, c, a, e, f } from './chunk-WHYPHVY6.mjs';
|
|
2
|
+
export { d as SpecBuilder, a as jsDocumentCommentsToOpenApi, c as parseFile, e as swaggerJsDocumentCommentsToOpenApi, b as yamlLoc } from './chunk-WHYPHVY6.mjs';
|
|
3
3
|
import { collect } from '@visulima/readdir';
|
|
4
4
|
import { mkdir, writeFile } from 'fs';
|
|
5
5
|
import { dirname } from 'path';
|
|
6
6
|
import { exit } from 'process';
|
|
7
7
|
|
|
8
|
-
var O=["coverage/**",".github/**","packages/*/test{,s}/**","**/*.d.ts","test{,s}/**","test{,-*}.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}","**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}","**/__tests__/**","**/{ava,babel,nyc}.config.{js,cjs,mjs}","**/jest.config.{js,cjs,mjs,ts}","**/{karma,rollup,webpack}.config.js","**/.{eslint,mocha}rc.{js,cjs}","**/.{travis,yarnrc}.yml","**/{docker-compose,docker}.yml","**/.yamllint.{yaml,yml}","**/node_modules/**","**/pnpm-lock.yaml","**/pnpm-workspace.yaml","**/{package,package-lock}.json","**/yarn.lock","**/package.json5","**/.next/**"],b=t=>{t&&(console.error(t),exit(1));},d=class{constructor(r,u,i,e){this.assetsPath=r,this.swaggerDefinition=i,this.sources=u,this.verbose=e.verbose??!1,this.ignore=e.ignore??[];}apply(r){r.hooks.make.tapAsync("SwaggerCompilerPlugin",async(u,i)=>{console.log("Build paused, switching to swagger build");let e$1=new
|
|
8
|
+
var O=["coverage/**",".github/**","packages/*/test{,s}/**","**/*.d.ts","test{,s}/**","test{,-*}.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}","**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}","**/__tests__/**","**/{ava,babel,nyc}.config.{js,cjs,mjs}","**/jest.config.{js,cjs,mjs,ts}","**/{karma,rollup,webpack}.config.js","**/.{eslint,mocha}rc.{js,cjs}","**/.{travis,yarnrc}.yml","**/{docker-compose,docker}.yml","**/.yamllint.{yaml,yml}","**/node_modules/**","**/pnpm-lock.yaml","**/pnpm-workspace.yaml","**/{package,package-lock}.json","**/yarn.lock","**/package.json5","**/.next/**"],b=t=>{t&&(console.error(t),exit(1));},d=class{constructor(r,u,i,e){this.assetsPath=r,this.swaggerDefinition=i,this.sources=u,this.verbose=e.verbose??!1,this.ignore=e.ignore??[];}apply(r){r.hooks.make.tapAsync("SwaggerCompilerPlugin",async(u,i)=>{console.log("Build paused, switching to swagger build");let e$1=new d$1(this.swaggerDefinition);for await(let s of this.sources){let a$1=await collect(s,{extensions:[".js",".cjs",".mjs",".ts",".tsx",".jsx",".yaml",".yml"],includeDirs:!1,minimatchOptions:{match:{debug:this.verbose,matchBase:!0},skip:{debug:this.verbose,matchBase:!0}},skip:[...this.ignore,...O]});this.verbose&&(console.log(`Found ${a$1.length} files in ${s}`),console.log(a$1)),a$1.forEach(n=>{this.verbose&&console.log(`Parsing file ${n}`);try{let l=c(n,a,this.verbose);e$1.addData(l.map(c=>c.spec));let j=c(n,e,this.verbose);e$1.addData(j.map(c=>c.spec));}catch(l){console.error(l),exit(1);}});}try{this.verbose&&(console.log("Validating swagger spec"),console.log(JSON.stringify(e$1,null,2))),await f(JSON.parse(JSON.stringify(e$1)));}catch(s){console.error(s.toJSON()),exit(1);}let{assetsPath:y}=this;mkdir(dirname(y),{recursive:!0},s=>{s&&b(s),writeFile(y,JSON.stringify(e$1,null,2),b);}),this.verbose&&console.log(`Written swagger spec to "${this.assetsPath}" file`),console.log("switching back to normal build"),i();});}},B=d;
|
|
9
9
|
|
|
10
10
|
export { B as SwaggerCompilerPlugin };
|
|
11
11
|
//# sourceMappingURL=out.js.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/webpack/swagger-compiler-plugin.ts"],"names":["collect","mkdir","writeFile","dirname","exit","exclude","errorHandler","error","SwaggerCompilerPlugin","assetsPath","sources","swaggerDefinition","options","compiler","_","callback","spec","spec_builder_default","dir","files","file","parsedJsDocumentFile","parse_file_default","comments_to_open_api_default","item","parsedSwaggerJsDocumentFile","validate_default","swagger_compiler_plugin_default"],"mappings":"4EAAA,OAAS,WAAAA,MAAe,oBACxB,OAAS,SAAAC,EAAO,aAAAC,MAAiB,KACjC,OAAS,WAAAC,MAAe,OACxB,OAAS,QAAAC,MAAY,UAWrB,IAAMC,EAAU,CACZ,cACA,aACA,yBACA,YACA,cACA,6CACA,iDACA,kBACA,yCACA,iCACA,sCACA,gCACA,0BACA,iCACA,0BACA,qBACA,oBACA,yBACA,iCACA,eACA,mBACA,aACJ,EAEMC,EAAgBC,GAAe,CAC7BA,
|
|
1
|
+
{"version":3,"sources":["../src/webpack/swagger-compiler-plugin.ts"],"names":["collect","mkdir","writeFile","dirname","exit","exclude","errorHandler","error","SwaggerCompilerPlugin","assetsPath","sources","swaggerDefinition","options","compiler","_","callback","spec","spec_builder_default","dir","files","file","parsedJsDocumentFile","parse_file_default","comments_to_open_api_default","item","parsedSwaggerJsDocumentFile","validate_default","swagger_compiler_plugin_default"],"mappings":"4EAAA,OAAS,WAAAA,MAAe,oBACxB,OAAS,SAAAC,EAAO,aAAAC,MAAiB,KACjC,OAAS,WAAAC,MAAe,OACxB,OAAS,QAAAC,MAAY,UAWrB,IAAMC,EAAU,CACZ,cACA,aACA,yBACA,YACA,cACA,6CACA,iDACA,kBACA,yCACA,iCACA,sCACA,gCACA,0BACA,iCACA,0BACA,qBACA,oBACA,yBACA,iCACA,eACA,mBACA,aACJ,EAEMC,EAAgBC,GAAe,CAC7BA,IACA,QAAQ,MAAMA,CAAK,EACnBH,EAAK,CAAC,EAEd,EAEMI,EAAN,KAA4B,CAWjB,YACHC,EACAC,EACAC,EACAC,EAIF,CACE,KAAK,WAAaH,EAClB,KAAK,kBAAoBE,EACzB,KAAK,QAAUD,EACf,KAAK,QAAUE,EAAQ,SAAW,GAClC,KAAK,OAASA,EAAQ,QAAU,CAAC,CACrC,CAEO,MAAMC,EAA0B,CAEnCA,EAAS,MAAM,KAAK,SAAS,wBAAyB,MAAOC,EAAGC,IAA0C,CACtG,QAAQ,IAAI,0CAA0C,EAEtD,IAAMC,EAAO,IAAIC,EAAY,KAAK,iBAAiB,EAGnD,cAAiBC,KAAO,KAAK,QAAS,CAClC,IAAMC,EAAQ,MAAMnB,EAAQkB,EAAK,CAC7B,WAAY,CAAC,MAAO,OAAQ,OAAQ,MAAO,OAAQ,OAAQ,QAAS,MAAM,EAC1E,YAAa,GACb,iBAAkB,CACd,MAAO,CACH,MAAO,KAAK,QACZ,UAAW,EACf,EACA,KAAM,CACF,MAAO,KAAK,QACZ,UAAW,EACf,CACJ,EACA,KAAM,CAAC,GAAG,KAAK,OAAQ,GAAGb,CAAO,CACrC,CAAC,EAEG,KAAK,UACL,QAAQ,IAAI,SAASc,EAAM,MAAM,aAAaD,CAAG,EAAE,EAEnD,QAAQ,IAAIC,CAAK,GAGrBA,EAAM,QAASC,GAAS,CAChB,KAAK,SACL,QAAQ,IAAI,gBAAgBA,CAAI,EAAE,EAGtC,GAAI,CACA,IAAMC,EAAuBC,EAAUF,EAAMG,EAA6B,KAAK,OAAO,EAEtFP,EAAK,QAAQK,EAAqB,IAAKG,GAASA,EAAK,IAAI,CAAC,EAE1D,IAAMC,EAA8BH,EAAUF,EAAMG,EAAoC,KAAK,OAAO,EAEpGP,EAAK,QAAQS,EAA4B,IAAKD,GAASA,EAAK,IAAI,CAAC,CACrE,OAASjB,EAAO,CACZ,QAAQ,MAAMA,CAAK,EACnBH,EAAK,CAAC,CACV,CACJ,CAAC,CACL,CAEA,GAAI,CACI,KAAK,UACL,QAAQ,IAAI,yBAAyB,EAErC,QAAQ,IAAI,KAAK,UAAUY,EAAM,KAAM,CAAC,CAAC,GAG7C,MAAMU,EAAS,KAAK,MAAM,KAAK,UAAUV,CAAI,CAAC,CAAC,CACnD,OAAST,EAAY,CACjB,QAAQ,MAAMA,EAAM,OAAO,CAAC,EAC5BH,EAAK,CAAC,CACV,CAEA,GAAM,CAAE,WAAAK,CAAW,EAAI,KAGvBR,EAAME,EAAQM,CAAU,EAAG,CAAE,UAAW,EAAK,EAAIF,GAAU,CACnDA,GACAD,EAAaC,CAAK,EAItBL,EAAUO,EAAY,KAAK,UAAUO,EAAM,KAAM,CAAC,EAAGV,CAAY,CACrE,CAAC,EAEG,KAAK,SACL,QAAQ,IAAI,4BAA4B,KAAK,UAAU,QAAQ,EAGnE,QAAQ,IAAI,gCAAgC,EAE5CS,EAAS,CACb,CAAC,CACL,CACJ,EAEOY,EAAQnB","sourcesContent":["import { collect } from \"@visulima/readdir\";\nimport { mkdir, writeFile } from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport { exit } from \"node:process\";\n\nimport type { Compiler } from \"webpack\";\n\nimport type { BaseDefinition } from \"../exported.d\";\nimport jsDocumentCommentsToOpenApi from \"../jsdoc/comments-to-open-api\";\nimport parseFile from \"../parse-file\";\nimport SpecBuilder from \"../spec-builder\";\nimport swaggerJsDocumentCommentsToOpenApi from \"../swagger-jsdoc/comments-to-open-api\";\nimport validate from \"../validate\";\n\nconst exclude = [\n \"coverage/**\",\n \".github/**\",\n \"packages/*/test{,s}/**\",\n \"**/*.d.ts\",\n \"test{,s}/**\",\n \"test{,-*}.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}\",\n \"**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}\",\n \"**/__tests__/**\",\n \"**/{ava,babel,nyc}.config.{js,cjs,mjs}\",\n \"**/jest.config.{js,cjs,mjs,ts}\",\n \"**/{karma,rollup,webpack}.config.js\",\n \"**/.{eslint,mocha}rc.{js,cjs}\",\n \"**/.{travis,yarnrc}.yml\",\n \"**/{docker-compose,docker}.yml\",\n \"**/.yamllint.{yaml,yml}\",\n \"**/node_modules/**\",\n \"**/pnpm-lock.yaml\",\n \"**/pnpm-workspace.yaml\",\n \"**/{package,package-lock}.json\",\n \"**/yarn.lock\",\n \"**/package.json5\",\n \"**/.next/**\",\n];\n\nconst errorHandler = (error: any) => {\n if (error) {\n console.error(error);\n exit(1);\n }\n};\n\nclass SwaggerCompilerPlugin {\n private readonly assetsPath: string;\n\n private readonly ignore: ReadonlyArray<string> | string;\n\n private readonly sources: string[];\n\n private readonly swaggerDefinition: BaseDefinition;\n\n private readonly verbose: boolean;\n\n public constructor(\n assetsPath: string,\n sources: string[],\n swaggerDefinition: BaseDefinition,\n options: {\n ignore?: ReadonlyArray<string> | string;\n verbose?: boolean;\n },\n ) {\n this.assetsPath = assetsPath;\n this.swaggerDefinition = swaggerDefinition;\n this.sources = sources;\n this.verbose = options.verbose ?? false;\n this.ignore = options.ignore ?? [];\n }\n\n public apply(compiler: Compiler): void {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n compiler.hooks.make.tapAsync(\"SwaggerCompilerPlugin\", async (_, callback: VoidFunction): Promise<void> => {\n console.log(\"Build paused, switching to swagger build\");\n\n const spec = new SpecBuilder(this.swaggerDefinition);\n\n // eslint-disable-next-line no-restricted-syntax,unicorn/prevent-abbreviations\n for await (const dir of this.sources) {\n const files = await collect(dir, {\n extensions: [\".js\", \".cjs\", \".mjs\", \".ts\", \".tsx\", \".jsx\", \".yaml\", \".yml\"],\n includeDirs: false,\n minimatchOptions: {\n match: {\n debug: this.verbose,\n matchBase: true,\n },\n skip: {\n debug: this.verbose,\n matchBase: true,\n },\n },\n skip: [...this.ignore, ...exclude],\n });\n\n if (this.verbose) {\n console.log(`Found ${files.length} files in ${dir}`);\n\n console.log(files);\n }\n\n files.forEach((file) => {\n if (this.verbose) {\n console.log(`Parsing file ${file}`);\n }\n\n try {\n const parsedJsDocumentFile = parseFile(file, jsDocumentCommentsToOpenApi, this.verbose);\n\n spec.addData(parsedJsDocumentFile.map((item) => item.spec));\n\n const parsedSwaggerJsDocumentFile = parseFile(file, swaggerJsDocumentCommentsToOpenApi, this.verbose);\n\n spec.addData(parsedSwaggerJsDocumentFile.map((item) => item.spec));\n } catch (error) {\n console.error(error);\n exit(1);\n }\n });\n }\n\n try {\n if (this.verbose) {\n console.log(\"Validating swagger spec\");\n\n console.log(JSON.stringify(spec, null, 2));\n }\n\n await validate(JSON.parse(JSON.stringify(spec)));\n } catch (error: any) {\n console.error(error.toJSON());\n exit(1);\n }\n\n const { assetsPath } = this;\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n mkdir(dirname(assetsPath), { recursive: true }, (error) => {\n if (error) {\n errorHandler(error);\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n writeFile(assetsPath, JSON.stringify(spec, null, 2), errorHandler);\n });\n\n if (this.verbose) {\n console.log(`Written swagger spec to \"${this.assetsPath}\" file`);\n }\n\n console.log(\"switching back to normal build\");\n\n callback();\n });\n }\n}\n\nexport default SwaggerCompilerPlugin;\n"]}
|