swagger-typescript-api 10.0.2 → 11.0.0--alpha
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 +263 -41
- package/index.d.ts +97 -0
- package/index.js +242 -115
- package/package.json +121 -116
- package/src/code-formatter.js +101 -0
- package/src/code-gen-process.js +456 -0
- package/src/configuration.js +425 -0
- package/src/constants.js +14 -31
- package/src/index.js +20 -271
- package/src/schema-components-map.js +60 -0
- package/src/schema-parser/schema-formatters.js +145 -0
- package/src/schema-parser/schema-parser.js +497 -0
- package/src/schema-parser/schema-routes.js +902 -0
- package/src/swagger-schema-resolver.js +187 -0
- package/src/templates.js +174 -155
- package/src/translators/JavaScript.js +3 -14
- package/src/type-name.js +79 -0
- package/src/util/file-system.js +76 -0
- package/src/{utils → util}/id.js +9 -9
- package/src/util/internal-case.js +5 -0
- package/src/util/logger.js +100 -0
- package/src/{utils/resolveName.js → util/name-resolver.js} +94 -97
- package/src/util/object-assign.js +11 -0
- package/src/util/pascal-case.js +5 -0
- package/src/{utils → util}/random.js +14 -14
- package/templates/base/data-contract-jsdoc.ejs +29 -24
- package/templates/base/data-contracts.ejs +3 -3
- package/templates/base/interface-data-contract.ejs +1 -0
- package/templates/base/route-docs.ejs +3 -4
- package/templates/base/route-type.ejs +2 -2
- package/templates/default/procedure-call.ejs +2 -2
- package/templates/default/route-types.ejs +2 -2
- package/templates/modular/api.ejs +2 -2
- package/templates/modular/procedure-call.ejs +2 -2
- package/templates/modular/route-types.ejs +2 -2
- package/src/apiConfig.js +0 -30
- package/src/common.js +0 -28
- package/src/components.js +0 -91
- package/src/config.js +0 -106
- package/src/filePrefix.js +0 -14
- package/src/files.js +0 -56
- package/src/formatFileContent.js +0 -81
- package/src/logger.js +0 -59
- package/src/modelNames.js +0 -78
- package/src/modelTypes.js +0 -31
- package/src/output.js +0 -165
- package/src/prettierOptions.js +0 -23
- package/src/render/utils/fmtToJSDocLine.js +0 -10
- package/src/render/utils/index.js +0 -31
- package/src/render/utils/templateRequire.js +0 -17
- package/src/routeNames.js +0 -46
- package/src/routes.js +0 -809
- package/src/schema.js +0 -474
- package/src/swagger.js +0 -152
- package/src/typeFormatters.js +0 -121
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/swagger-typescript-api)
|
|
4
4
|
[](https://github.com/acacode/swagger-typescript-api/actions/workflows/main.yml) <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
5
|
-
[](#contributors)
|
|
6
6
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
7
7
|
|
|
8
8
|
<img src="https://raw.githubusercontent.com/acacode/swagger-typescript-api/master/assets/swagger-typescript-api-logo.png" align="left"
|
|
@@ -71,6 +71,8 @@ Options:
|
|
|
71
71
|
--clean-output clean output folder before generate api. WARNING: May cause data loss (default: false)
|
|
72
72
|
--api-class-name <string> name of the api class
|
|
73
73
|
--patch fix up small errors in the swagger source definition (default: false)
|
|
74
|
+
--debug additional information about processes inside this tool (default: false)
|
|
75
|
+
--another-array-type generate array types as Array<Type> (by default Type[]) (default: false)
|
|
74
76
|
-h, --help display help for command
|
|
75
77
|
```
|
|
76
78
|
|
|
@@ -120,7 +122,19 @@ generateApi({
|
|
|
120
122
|
enumNamesAsValues: false,
|
|
121
123
|
moduleNameFirstTag: false,
|
|
122
124
|
generateUnionEnums: false,
|
|
125
|
+
addReadonly: false,
|
|
123
126
|
extraTemplates: [],
|
|
127
|
+
anotherArrayType: false,
|
|
128
|
+
codeGenConstructs: (constructs) => ({
|
|
129
|
+
...constructs,
|
|
130
|
+
RecordType: (key, value) => `MyRecord<key, value>`
|
|
131
|
+
}),
|
|
132
|
+
primitiveTypeConstructs: (constructs) => ({
|
|
133
|
+
...constructs,
|
|
134
|
+
string: {
|
|
135
|
+
'date-time': 'Date'
|
|
136
|
+
}
|
|
137
|
+
}),
|
|
124
138
|
hooks: {
|
|
125
139
|
onCreateComponent: (component) => {},
|
|
126
140
|
onCreateRequestParams: (rawType) => {},
|
|
@@ -202,8 +216,213 @@ When we change it to `--module-name-index 1` then Api class have two properties
|
|
|
202
216
|
This option will group your API operations based on their first tag - mirroring how the Swagger UI groups displayed operations
|
|
203
217
|
|
|
204
218
|
|
|
219
|
+
## Modification internal codegen structs with NodeJS API:
|
|
220
|
+
|
|
221
|
+
You are able to modify TypeScript internal structs using for generating output with using `generateApi` options `codeGenConstructs` and `primitiveTypeConstructs`.
|
|
222
|
+
|
|
223
|
+
### `codeGenConstructs`
|
|
224
|
+
|
|
225
|
+
This option has type `(struct: CodeGenConstruct) => Partial<CodeGenConstruct>`.
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
generateApi({
|
|
229
|
+
// ...
|
|
230
|
+
codeGenConstructs: (struct) => ({
|
|
231
|
+
Keyword: {
|
|
232
|
+
Number: "number",
|
|
233
|
+
String: "string",
|
|
234
|
+
Boolean: "boolean",
|
|
235
|
+
Any: "any",
|
|
236
|
+
Void: "void",
|
|
237
|
+
Unknown: "unknown",
|
|
238
|
+
Null: "null",
|
|
239
|
+
Undefined: "undefined",
|
|
240
|
+
Object: "object",
|
|
241
|
+
File: "File",
|
|
242
|
+
Date: "Date",
|
|
243
|
+
Type: "type",
|
|
244
|
+
Enum: "enum",
|
|
245
|
+
Interface: "interface",
|
|
246
|
+
Array: "Array",
|
|
247
|
+
Record: "Record",
|
|
248
|
+
Intersection: "&",
|
|
249
|
+
Union: "|",
|
|
250
|
+
},
|
|
251
|
+
CodeGenKeyword: {
|
|
252
|
+
UtilRequiredKeys: "UtilRequiredKeys",
|
|
253
|
+
},
|
|
254
|
+
/**
|
|
255
|
+
* $A[] or Array<$A>
|
|
256
|
+
*/
|
|
257
|
+
ArrayType: (content) => {
|
|
258
|
+
if (this.anotherArrayType) {
|
|
259
|
+
return `Array<${content}>`;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return `(${content})[]`;
|
|
263
|
+
},
|
|
264
|
+
/**
|
|
265
|
+
* "$A"
|
|
266
|
+
*/
|
|
267
|
+
StringValue: (content) => `"${content}"`,
|
|
268
|
+
/**
|
|
269
|
+
* $A
|
|
270
|
+
*/
|
|
271
|
+
BooleanValue: (content) => `${content}`,
|
|
272
|
+
/**
|
|
273
|
+
* $A
|
|
274
|
+
*/
|
|
275
|
+
NumberValue: (content) => `${content}`,
|
|
276
|
+
/**
|
|
277
|
+
* $A
|
|
278
|
+
*/
|
|
279
|
+
NullValue: (content) => content,
|
|
280
|
+
/**
|
|
281
|
+
* $A1 | $A2
|
|
282
|
+
*/
|
|
283
|
+
UnionType: (contents) => _.join(_.uniq(contents), ` | `),
|
|
284
|
+
/**
|
|
285
|
+
* ($A1)
|
|
286
|
+
*/
|
|
287
|
+
ExpressionGroup: (content) => (content ? `(${content})` : ""),
|
|
288
|
+
/**
|
|
289
|
+
* $A1 & $A2
|
|
290
|
+
*/
|
|
291
|
+
IntersectionType: (contents) => _.join(_.uniq(contents), ` & `),
|
|
292
|
+
/**
|
|
293
|
+
* Record<$A1, $A2>
|
|
294
|
+
*/
|
|
295
|
+
RecordType: (key, value) => `Record<${key}, ${value}>`,
|
|
296
|
+
/**
|
|
297
|
+
* readonly $key?:$value
|
|
298
|
+
*/
|
|
299
|
+
TypeField: ({ readonly, key, optional, value }) =>
|
|
300
|
+
_.compact([readonly && "readonly ", key, optional && "?", ": ", value]).join(""),
|
|
301
|
+
/**
|
|
302
|
+
* [key: $A1]: $A2
|
|
303
|
+
*/
|
|
304
|
+
InterfaceDynamicField: (key, value) => `[key: ${key}]: ${value}`,
|
|
305
|
+
/**
|
|
306
|
+
* $A1 = $A2
|
|
307
|
+
*/
|
|
308
|
+
EnumField: (key, value) => `${key} = ${value}`,
|
|
309
|
+
/**
|
|
310
|
+
* $A0.key = $A0.value,
|
|
311
|
+
* $A1.key = $A1.value,
|
|
312
|
+
* $AN.key = $AN.value,
|
|
313
|
+
*/
|
|
314
|
+
EnumFieldsWrapper: (contents) =>
|
|
315
|
+
_.map(contents, ({ key, value }) => ` ${key} = ${value}`).join(",\n"),
|
|
316
|
+
/**
|
|
317
|
+
* {\n $A \n}
|
|
318
|
+
*/
|
|
319
|
+
ObjectWrapper: (content) => `{\n${content}\n}`,
|
|
320
|
+
/**
|
|
321
|
+
* /** $A *\/
|
|
322
|
+
*/
|
|
323
|
+
MultilineComment: (contents, formatFn) =>
|
|
324
|
+
[
|
|
325
|
+
...(contents.length === 1
|
|
326
|
+
? [`/** ${contents[0]} */`]
|
|
327
|
+
: ["/**", ...contents.map((content) => ` * ${content}`), " */"]),
|
|
328
|
+
].map((part) => `${formatFn ? formatFn(part) : part}\n`),
|
|
329
|
+
/**
|
|
330
|
+
* $A1<...$A2.join(,)>
|
|
331
|
+
*/
|
|
332
|
+
TypeWithGeneric: (typeName, genericArgs) => {
|
|
333
|
+
return `${typeName}${genericArgs.length ? `<${genericArgs.join(",")}>` : ""}`;
|
|
334
|
+
},
|
|
335
|
+
})
|
|
336
|
+
})
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
For example, if you need to generate output `Record<string, any>` instead of `object` you can do it with using following code:
|
|
340
|
+
|
|
341
|
+
```ts
|
|
342
|
+
generateApi({
|
|
343
|
+
// ...
|
|
344
|
+
codeGenConstructs: (struct) => ({
|
|
345
|
+
Keyword: {
|
|
346
|
+
Object: "Record<string, any>",
|
|
347
|
+
}
|
|
348
|
+
})
|
|
349
|
+
})
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### `primitiveTypeConstructs`
|
|
353
|
+
|
|
354
|
+
It is type mapper or translator swagger schema objects. `primitiveTypeConstructs` translates `type`/`format` schema fields to typescript structs.
|
|
355
|
+
This option has type
|
|
356
|
+
```ts
|
|
357
|
+
type PrimitiveTypeStructValue =
|
|
358
|
+
| string
|
|
359
|
+
| ((schema: Record<string, any>, parser: import("./src/schema-parser/schema-parser").SchemaParser) => string);
|
|
360
|
+
|
|
361
|
+
type PrimitiveTypeStruct = Record<
|
|
362
|
+
"integer" | "number" | "boolean" | "object" | "file" | "string" | "array",
|
|
363
|
+
string | ({ $default: PrimitiveTypeStructValue } & Record<string, PrimitiveTypeStructValue>)
|
|
364
|
+
>
|
|
365
|
+
|
|
366
|
+
declare const primitiveTypeConstructs: (struct: PrimitiveTypeStruct) => Partial<PrimitiveTypeStruct>
|
|
367
|
+
|
|
368
|
+
generateApi({
|
|
369
|
+
// ...
|
|
370
|
+
primitiveTypeConstructs: (struct) => ({
|
|
371
|
+
integer: () => "number",
|
|
372
|
+
number: () => "number",
|
|
373
|
+
boolean: () => "boolean",
|
|
374
|
+
object: () => "object",
|
|
375
|
+
file: () => "File",
|
|
376
|
+
string: {
|
|
377
|
+
$default: () => "string",
|
|
378
|
+
|
|
379
|
+
/** formats */
|
|
380
|
+
binary: () => "File",
|
|
381
|
+
file: () => "File",
|
|
382
|
+
"date-time": () => "string",
|
|
383
|
+
time: () => "string",
|
|
384
|
+
date: () => "string",
|
|
385
|
+
duration: () => "string",
|
|
386
|
+
email: () => "string",
|
|
387
|
+
"idn-email": () => "string",
|
|
388
|
+
"idn-hostname": () => "string",
|
|
389
|
+
ipv4: () => "string",
|
|
390
|
+
ipv6: () => "string",
|
|
391
|
+
uuid: () => "string",
|
|
392
|
+
uri: () => "string",
|
|
393
|
+
"uri-reference": () => "string",
|
|
394
|
+
"uri-template": () => "string",
|
|
395
|
+
"json-pointer": () => "string",
|
|
396
|
+
"relative-json-pointer": () => "string",
|
|
397
|
+
regex: () => "string",
|
|
398
|
+
},
|
|
399
|
+
array: (schema, parser) => {
|
|
400
|
+
const content = parser.getInlineParseContent(schema.items);
|
|
401
|
+
return parser.checkAndAddNull(schema, `(${content})[]`);
|
|
402
|
+
},
|
|
403
|
+
})
|
|
404
|
+
})
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
For example, if you need to change `"string"/"date-time"` default output as `string` to `Date` you can do it with using following code:
|
|
408
|
+
|
|
409
|
+
```ts
|
|
410
|
+
|
|
411
|
+
generateApi({
|
|
412
|
+
primitiveTypeConstructs: (struct) => ({
|
|
413
|
+
string: {
|
|
414
|
+
"date-time": "Date",
|
|
415
|
+
},
|
|
416
|
+
})
|
|
417
|
+
})
|
|
418
|
+
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
See more about [swagger schema type/format data here](https://json-schema.org/understanding-json-schema/reference/string.html#dates-and-times)
|
|
422
|
+
|
|
205
423
|
## 📄 Mass media
|
|
206
424
|
|
|
425
|
+
- [5 Lessons learned about swagger-typescript-api](https://christo8989.medium.com/5-lessons-learned-about-swagger-typescript-api-511240b34c1)
|
|
207
426
|
- [Why Swagger schemes are needed in frontend development ?](https://dev.to/js2me/why-swagger-schemes-are-needed-in-frontend-development-2cb4)
|
|
208
427
|
- [Migration en douceur vers TypeScript (French)](https://www.premieroctet.com/blog/migration-typescript/)
|
|
209
428
|
- [swagger-typescript-api usage (Japanese)](https://zenn.dev/watahaya/articles/2f4a716c47903b)
|
|
@@ -222,46 +441,49 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
222
441
|
<!-- prettier-ignore-start -->
|
|
223
442
|
<!-- markdownlint-disable -->
|
|
224
443
|
<table>
|
|
225
|
-
<
|
|
226
|
-
<
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
<
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
<
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
<
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
<
|
|
263
|
-
|
|
264
|
-
|
|
444
|
+
<tbody>
|
|
445
|
+
<tr>
|
|
446
|
+
<td align="center"><a href="https://github.com/js2me"><img src="https://avatars1.githubusercontent.com/u/16340911?v=4?s=100" width="100px;" alt="Sergey S. Volkov"/><br /><sub><b>Sergey S. Volkov</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=js2me" title="Code">💻</a> <a href="https://github.com/acacode/swagger-typescript-api/commits?author=js2me" title="Documentation">📖</a> <a href="#design-js2me" title="Design">🎨</a> <a href="#example-js2me" title="Examples">💡</a> <a href="#maintenance-js2me" title="Maintenance">🚧</a> <a href="#ideas-js2me" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/acacode/swagger-typescript-api/issues?q=author%3Ajs2me" title="Bug reports">🐛</a></td>
|
|
447
|
+
<td align="center"><a href="https://github.com/andrefilimono"><img src="https://avatars0.githubusercontent.com/u/7794526?v=4?s=100" width="100px;" alt="Filimonov Andrey"/><br /><sub><b>Filimonov Andrey</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=andrefilimono" title="Code">💻</a> <a href="#ideas-andrefilimono" title="Ideas, Planning, & Feedback">🤔</a> <a href="#design-andrefilimono" title="Design">🎨</a></td>
|
|
448
|
+
<td align="center"><a href="https://github.com/Fl0pZz"><img src="https://avatars2.githubusercontent.com/u/9510124?v=4?s=100" width="100px;" alt="Rafael Fakhreev"/><br /><sub><b>Rafael Fakhreev</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=Fl0pZz" title="Code">💻</a> <a href="#ideas-Fl0pZz" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
449
|
+
<td align="center"><a href="https://azzola.dev"><img src="https://avatars3.githubusercontent.com/u/1297597?v=4?s=100" width="100px;" alt="Lucas Azzola"/><br /><sub><b>Lucas Azzola</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=azz" title="Code">💻</a> <a href="#ideas-azz" title="Ideas, Planning, & Feedback">🤔</a> <a href="#design-azz" title="Design">🎨</a></td>
|
|
450
|
+
<td align="center"><a href="https://github.com/JennieJi"><img src="https://avatars3.githubusercontent.com/u/1913045?v=4?s=100" width="100px;" alt="Jennie"/><br /><sub><b>Jennie</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=JennieJi" title="Code">💻</a> <a href="#ideas-JennieJi" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
451
|
+
<td align="center"><a href="https://github.com/jomarquez21"><img src="https://avatars1.githubusercontent.com/u/16705169?v=4?s=100" width="100px;" alt="Jose Enrique Marquez"/><br /><sub><b>Jose Enrique Marquez</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=jomarquez21" title="Code">💻</a> <a href="https://github.com/acacode/swagger-typescript-api/issues?q=author%3Ajomarquez21" title="Bug reports">🐛</a></td>
|
|
452
|
+
<td align="center"><a href="https://glassechidna.com.au"><img src="https://avatars1.githubusercontent.com/u/482276?v=4?s=100" width="100px;" alt="Benjamin Dobell"/><br /><sub><b>Benjamin Dobell</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=Benjamin-Dobell" title="Code">💻</a> <a href="https://github.com/acacode/swagger-typescript-api/issues?q=author%3ABenjamin-Dobell" title="Bug reports">🐛</a></td>
|
|
453
|
+
</tr>
|
|
454
|
+
<tr>
|
|
455
|
+
<td align="center"><a href="http://fixate.it"><img src="https://avatars0.githubusercontent.com/u/1510520?v=4?s=100" width="100px;" alt="Larry Botha"/><br /><sub><b>Larry Botha</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=larrybotha" title="Code">💻</a> <a href="https://github.com/acacode/swagger-typescript-api/issues?q=author%3Alarrybotha" title="Bug reports">🐛</a></td>
|
|
456
|
+
<td align="center"><a href="https://github.com/nikalun"><img src="https://avatars3.githubusercontent.com/u/13102962?v=4?s=100" width="100px;" alt="Nikolay Lukinykh"/><br /><sub><b>Nikolay Lukinykh</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=nikalun" title="Code">💻</a> <a href="#ideas-nikalun" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/acacode/swagger-typescript-api/issues?q=author%3Anikalun" title="Bug reports">🐛</a></td>
|
|
457
|
+
<td align="center"><a href="https://github.com/Mvbraathen"><img src="https://avatars0.githubusercontent.com/u/16756739?v=4?s=100" width="100px;" alt="Marius Bråthen"/><br /><sub><b>Marius Bråthen</b></sub></a><br /><a href="#security-Mvbraathen" title="Security">🛡️</a></td>
|
|
458
|
+
<td align="center"><a href="https://github.com/xesjkeee"><img src="https://avatars2.githubusercontent.com/u/17751886?v=4?s=100" width="100px;" alt="Evgeny Vlasov"/><br /><sub><b>Evgeny Vlasov</b></sub></a><br /><a href="#ideas-xesjkeee" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
459
|
+
<td align="center"><a href="https://github.com/kel666"><img src="https://avatars1.githubusercontent.com/u/2040661?v=4?s=100" width="100px;" alt="Fabio"/><br /><sub><b>Fabio</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/issues?q=author%3Akel666" title="Bug reports">🐛</a> <a href="https://github.com/acacode/swagger-typescript-api/commits?author=kel666" title="Code">💻</a></td>
|
|
460
|
+
<td align="center"><a href="https://github.com/Fabiencdp"><img src="https://avatars.githubusercontent.com/u/6182473?v=4?s=100" width="100px;" alt="Fabien"/><br /><sub><b>Fabien</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/issues?q=author%3AFabiencdp" title="Bug reports">🐛</a></td>
|
|
461
|
+
<td align="center"><a href="https://about.me/julienrousseau"><img src="https://avatars.githubusercontent.com/u/3296671?v=4?s=100" width="100px;" alt="Rousseau Julien"/><br /><sub><b>Rousseau Julien</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/issues?q=author%3ARoXuS" title="Bug reports">🐛</a></td>
|
|
462
|
+
</tr>
|
|
463
|
+
<tr>
|
|
464
|
+
<td align="center"><a href="http://sebastianarias.dev"><img src="https://avatars.githubusercontent.com/u/9751266?v=4?s=100" width="100px;" alt="Sebastián Arias"/><br /><sub><b>Sebastián Arias</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/issues?q=author%3ALarox" title="Bug reports">🐛</a></td>
|
|
465
|
+
<td align="center"><a href="https://github.com/Styn"><img src="https://avatars.githubusercontent.com/u/6705137?v=4?s=100" width="100px;" alt="Stijn Lammens"/><br /><sub><b>Stijn Lammens</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/issues?q=author%3AStyn" title="Bug reports">🐛</a> <a href="https://github.com/acacode/swagger-typescript-api/commits?author=Styn" title="Code">💻</a></td>
|
|
466
|
+
<td align="center"><a href="http://emilecantin.com"><img src="https://avatars.githubusercontent.com/u/885486?v=4?s=100" width="100px;" alt="Emile Cantin"/><br /><sub><b>Emile Cantin</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/issues?q=author%3Aemilecantin" title="Bug reports">🐛</a> <a href="https://github.com/acacode/swagger-typescript-api/commits?author=emilecantin" title="Code">💻</a></td>
|
|
467
|
+
<td align="center"><a href="https://github.com/armsnyder"><img src="https://avatars.githubusercontent.com/u/9969202?v=4?s=100" width="100px;" alt="Adam Snyder"/><br /><sub><b>Adam Snyder</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=armsnyder" title="Code">💻</a> <a href="https://github.com/acacode/swagger-typescript-api/issues?q=author%3Aarmsnyder" title="Bug reports">🐛</a></td>
|
|
468
|
+
<td align="center"><a href="https://github.com/jnpoyser"><img src="https://avatars.githubusercontent.com/u/7920428?v=4?s=100" width="100px;" alt="James Poyser"/><br /><sub><b>James Poyser</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=jnpoyser" title="Code">💻</a> <a href="#ideas-jnpoyser" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
469
|
+
<td align="center"><a href="http://ru.linkedin.com/in/lisikhin"><img src="https://avatars.githubusercontent.com/u/475367?v=4?s=100" width="100px;" alt="Alexey"/><br /><sub><b>Alexey</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/issues?q=author%3ANihisil" title="Bug reports">🐛</a></td>
|
|
470
|
+
<td align="center"><a href="http://imaniu.com"><img src="https://avatars.githubusercontent.com/u/50100681?v=4?s=100" width="100px;" alt="江麻妞"/><br /><sub><b>江麻妞</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=jiangmaniu" title="Code">💻</a></td>
|
|
471
|
+
</tr>
|
|
472
|
+
<tr>
|
|
473
|
+
<td align="center"><a href="https://kspr.dev"><img src="https://avatars.githubusercontent.com/u/5294519?v=4?s=100" width="100px;" alt="Kasper Moskwiak"/><br /><sub><b>Kasper Moskwiak</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=kmoskwiak" title="Code">💻</a> <a href="#ideas-kmoskwiak" title="Ideas, Planning, & Feedback">🤔</a></td>
|
|
474
|
+
<td align="center"><a href="https://github.com/baggoedw"><img src="https://avatars.githubusercontent.com/u/92381702?v=4?s=100" width="100px;" alt="baggoedw"/><br /><sub><b>baggoedw</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=baggoedw" title="Code">💻</a></td>
|
|
475
|
+
<td align="center"><a href="https://marcusdunn.github.io"><img src="https://avatars.githubusercontent.com/u/51931484?v=4?s=100" width="100px;" alt="Marcus Dunn"/><br /><sub><b>Marcus Dunn</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=MarcusDunn" title="Code">💻</a> <a href="https://github.com/acacode/swagger-typescript-api/issues?q=author%3AMarcusDunn" title="Bug reports">🐛</a></td>
|
|
476
|
+
<td align="center"><a href="https://www.danielplayfaircal.com/"><img src="https://avatars.githubusercontent.com/u/1217649?v=4?s=100" width="100px;" alt="Daniel Playfair Cal"/><br /><sub><b>Daniel Playfair Cal</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=hedgepigdaniel" title="Code">💻</a> <a href="https://github.com/acacode/swagger-typescript-api/issues?q=author%3Ahedgepigdaniel" title="Bug reports">🐛</a></td>
|
|
477
|
+
<td align="center"><a href="https://www.linkedin.com/in/patrick-shaw/"><img src="https://avatars.githubusercontent.com/u/5153619?v=4?s=100" width="100px;" alt="Patrick Shaw"/><br /><sub><b>Patrick Shaw</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/pulls?q=is%3Apr+reviewed-by%3APatrickShaw" title="Reviewed Pull Requests">👀</a></td>
|
|
478
|
+
<td align="center"><a href="https://www.linkedin.com/in/jinkwon-lee"><img src="https://avatars.githubusercontent.com/u/1798916?v=4?s=100" width="100px;" alt="JK"/><br /><sub><b>JK</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=jinkwon" title="Code">💻</a></td>
|
|
479
|
+
<td align="center"><a href="https://github.com/RoCat"><img src="https://avatars.githubusercontent.com/u/3562317?v=4?s=100" width="100px;" alt="RoCat"/><br /><sub><b>RoCat</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=RoCat" title="Code">💻</a> <a href="#ideas-RoCat" title="Ideas, Planning, & Feedback">🤔</a> <a href="#design-RoCat" title="Design">🎨</a></td>
|
|
480
|
+
</tr>
|
|
481
|
+
<tr>
|
|
482
|
+
<td align="center"><a href="https://github.com/ApacheEx"><img src="https://avatars.githubusercontent.com/u/1918108?v=4?s=100" width="100px;" alt="Oleg Kuzava"/><br /><sub><b>Oleg Kuzava</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=ApacheEx" title="Code">💻</a> <a href="https://github.com/acacode/swagger-typescript-api/issues?q=author%3AApacheEx" title="Bug reports">🐛</a></td>
|
|
483
|
+
<td align="center"><a href="http://nikz.se"><img src="https://avatars.githubusercontent.com/u/7352072?v=4?s=100" width="100px;" alt="Niklas Frank"/><br /><sub><b>Niklas Frank</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=nksfrank" title="Code">💻</a> <a href="https://github.com/acacode/swagger-typescript-api/issues?q=author%3Anksfrank" title="Bug reports">🐛</a></td>
|
|
484
|
+
<td align="center"><a href="https://quentinbrunet.com"><img src="https://avatars.githubusercontent.com/u/20137632?v=4?s=100" width="100px;" alt="Quentin Brunet"/><br /><sub><b>Quentin Brunet</b></sub></a><br /><a href="https://github.com/acacode/swagger-typescript-api/commits?author=qboot" title="Code">💻</a></td>
|
|
485
|
+
</tr>
|
|
486
|
+
</tbody>
|
|
265
487
|
</table>
|
|
266
488
|
|
|
267
489
|
<!-- markdownlint-restore -->
|
package/index.d.ts
CHANGED
|
@@ -123,8 +123,67 @@ interface GenerateApiParamsBase {
|
|
|
123
123
|
* authorization token
|
|
124
124
|
*/
|
|
125
125
|
authorizationToken?: string;
|
|
126
|
+
/**
|
|
127
|
+
* generate readonly properties (default: false)
|
|
128
|
+
*/
|
|
129
|
+
addReadonly?: boolean;
|
|
130
|
+
|
|
131
|
+
primitiveTypeConstructs?: (struct: PrimitiveTypeStruct) => Partial<PrimitiveTypeStruct>;
|
|
132
|
+
|
|
133
|
+
codeGenConstructs?: (struct: CodeGenConstruct) => Partial<CodeGenConstruct>;
|
|
126
134
|
}
|
|
127
135
|
|
|
136
|
+
type CodeGenConstruct = {
|
|
137
|
+
Keyword: {
|
|
138
|
+
Number: string;
|
|
139
|
+
String: string;
|
|
140
|
+
Boolean: string;
|
|
141
|
+
Any: string;
|
|
142
|
+
Void: string;
|
|
143
|
+
Unknown: string;
|
|
144
|
+
Null: string;
|
|
145
|
+
Undefined: string;
|
|
146
|
+
Object: string;
|
|
147
|
+
File: string;
|
|
148
|
+
Date: string;
|
|
149
|
+
Type: string;
|
|
150
|
+
Enum: string;
|
|
151
|
+
Interface: string;
|
|
152
|
+
Array: string;
|
|
153
|
+
Record: string;
|
|
154
|
+
Intersection: string;
|
|
155
|
+
Union: string;
|
|
156
|
+
};
|
|
157
|
+
CodeGenKeyword: {
|
|
158
|
+
UtilRequiredKeys: string;
|
|
159
|
+
};
|
|
160
|
+
ArrayType: (content: any) => string;
|
|
161
|
+
StringValue: (content: any) => string;
|
|
162
|
+
BooleanValue: (content: any) => string;
|
|
163
|
+
NumberValue: (content: any) => string;
|
|
164
|
+
NullValue: (content: any) => string;
|
|
165
|
+
UnionType: (content: any) => string;
|
|
166
|
+
ExpressionGroup: (content: any) => string;
|
|
167
|
+
IntersectionType: (content: any) => string;
|
|
168
|
+
RecordType: (content: any) => string;
|
|
169
|
+
TypeField: (content: any) => string;
|
|
170
|
+
InterfaceDynamicField: (content: any) => string;
|
|
171
|
+
EnumField: (content: any) => string;
|
|
172
|
+
EnumFieldsWrapper: (content: any) => string;
|
|
173
|
+
ObjectWrapper: (content: any) => string;
|
|
174
|
+
MultilineComment: (content: any) => string;
|
|
175
|
+
TypeWithGeneric: (content: any) => string;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
type PrimitiveTypeStructValue =
|
|
179
|
+
| string
|
|
180
|
+
| ((schema: Record<string, any>, parser: import("./src/schema-parser/schema-parser").SchemaParser) => string);
|
|
181
|
+
|
|
182
|
+
type PrimitiveTypeStruct = Record<
|
|
183
|
+
"integer" | "number" | "boolean" | "object" | "file" | "string" | "array",
|
|
184
|
+
string | ({ $default: PrimitiveTypeStructValue } & Record<string, PrimitiveTypeStructValue>)
|
|
185
|
+
>;
|
|
186
|
+
|
|
128
187
|
interface GenerateApiParamsFromPath extends GenerateApiParamsBase {
|
|
129
188
|
/**
|
|
130
189
|
* path to swagger schema
|
|
@@ -320,6 +379,12 @@ export interface GenerateApiConfiguration {
|
|
|
320
379
|
hasDescription: boolean;
|
|
321
380
|
};
|
|
322
381
|
config: {
|
|
382
|
+
input: string;
|
|
383
|
+
output: string;
|
|
384
|
+
url: string;
|
|
385
|
+
spec: any;
|
|
386
|
+
fileName: string;
|
|
387
|
+
authorizationToken?: string;
|
|
323
388
|
generateResponses: boolean;
|
|
324
389
|
defaultResponseAsSuccess: boolean;
|
|
325
390
|
generateRouteTypes: boolean;
|
|
@@ -331,10 +396,35 @@ export interface GenerateApiConfiguration {
|
|
|
331
396
|
convertedFromSwagger2: boolean;
|
|
332
397
|
moduleNameIndex: number;
|
|
333
398
|
moduleNameFirstTag: boolean;
|
|
399
|
+
extraTemplates: { name: string; path: string }[];
|
|
334
400
|
disableStrictSSL: boolean;
|
|
335
401
|
disableProxy: boolean;
|
|
336
402
|
extractRequestParams: boolean;
|
|
337
403
|
unwrapResponseData: boolean;
|
|
404
|
+
sortTypes: boolean;
|
|
405
|
+
singleHttpClient: boolean;
|
|
406
|
+
typePrefix: string;
|
|
407
|
+
typeSuffix: string;
|
|
408
|
+
patch: boolean;
|
|
409
|
+
cleanOutput: boolean;
|
|
410
|
+
debug: boolean;
|
|
411
|
+
anotherArrayType: boolean;
|
|
412
|
+
extractRequestBody: boolean;
|
|
413
|
+
httpClientType: "axios" | "fetch";
|
|
414
|
+
addReadonly: boolean;
|
|
415
|
+
extractResponseBody: boolean;
|
|
416
|
+
extractResponseError: boolean;
|
|
417
|
+
defaultResponseType: boolean;
|
|
418
|
+
toJS: boolean;
|
|
419
|
+
disableThrowOnError: boolean;
|
|
420
|
+
silent: boolean;
|
|
421
|
+
hooks: Hooks;
|
|
422
|
+
enumNamesAsValues: boolean;
|
|
423
|
+
version: string;
|
|
424
|
+
internalTemplateOptions: {
|
|
425
|
+
addUtilRequiredKeysType: boolean;
|
|
426
|
+
};
|
|
427
|
+
componentTypeNameResolver: typeof import("./src/util/name-resolver").ComponentTypeNameResolver;
|
|
338
428
|
fileNames: {
|
|
339
429
|
dataContracts: string;
|
|
340
430
|
routeTypes: string;
|
|
@@ -347,6 +437,11 @@ export interface GenerateApiConfiguration {
|
|
|
347
437
|
httpClient: string;
|
|
348
438
|
routeTypes: string;
|
|
349
439
|
routeName: string;
|
|
440
|
+
dataContractJsDoc: string;
|
|
441
|
+
interfaceDataContract: string;
|
|
442
|
+
typeDataContract: string;
|
|
443
|
+
enumDataContract: string;
|
|
444
|
+
objectFieldJsDoc: string;
|
|
350
445
|
};
|
|
351
446
|
routeNameDuplicatesMap: Map<string, string>;
|
|
352
447
|
apiClassName: string;
|
|
@@ -367,7 +462,9 @@ export interface GenerateApiConfiguration {
|
|
|
367
462
|
utils: {
|
|
368
463
|
formatDescription: (description: string, inline?: boolean) => string;
|
|
369
464
|
internalCase: (value: string) => string;
|
|
465
|
+
/** @deprecated */
|
|
370
466
|
classNameCase: (value: string) => string;
|
|
467
|
+
pascalCase: (value: string) => string;
|
|
371
468
|
getInlineParseContent: (rawTypeData: SchemaComponent["rawTypeData"], typeName?: string) => string;
|
|
372
469
|
getParseContent: (rawTypeData: SchemaComponent["rawTypeData"], typeName?: string) => ModelType;
|
|
373
470
|
getComponentByRef: (ref: string) => SchemaComponent;
|