@@ -32,11 +32,7 @@ const swaggerToTS = require('swagger-to-ts');
32
32
33
33
const file = ' ./spec/swagger.json' ;
34
34
const typeData = swaggerToTS (readFileSync (file, ' UTF-8' ), ' MySpec' );
35
- writeFileSync (' ./types/swagger.ts' ), typeData);
36
- ```
37
-
38
- ``` js
39
- import MySpec from ' ./types/swagger.ts' ;
35
+ writeFileSync (' ./types/swagger.ts' , typeData);
40
36
```
41
37
42
38
#### From Swagger YAML
@@ -49,13 +45,10 @@ similar.
49
45
const { readFileSync , writeFileSync } = require (' fs' );
50
46
const yaml = require (' js-yaml' );
51
47
52
- const file = ' ./spec/swagger.json' ;
53
- const typeData = swaggerToTS (yaml .safeLoad (fs .readFileSync (file, ' UTF-8' )), ' MySpec' );
54
- writeFileSync (' ./types/swagger.ts' ), typeData);
55
- ```
56
-
57
- ``` js
58
- import MySpec from ' ./types/swagger.ts' ;
48
+ const file = ' ./spec/swagger.yaml' ;
49
+ const json = yaml .safeLoad (fs .readFileSync (file, ' UTF-8' ));
50
+ const typeData = swaggerToTS (json, ' MySpec' );
51
+ writeFileSync (' ./types/swagger.ts' , typeData);
59
52
```
60
53
61
54
#### Generating multiple files
@@ -75,10 +68,8 @@ const source2 = glob.sync('./swaggerspec/v2/**/*.yaml');
75
68
[... source1, ... source2].forEach (file => {
76
69
const basename = path .basename (file);
77
70
const filename = basename .replace (/ \. ya? ml$ / i , ' .ts' );
78
- const typeData = swaggerToTS (
79
- yaml .safeLoad (readFileSync (file, ' UTF-8' )),
80
- basename
81
- );
71
+ const json = yaml .safeLoad (readFileSync (file, ' UTF-8' ));
72
+ const typeData = swaggerToTS (json, basename);
82
73
writeFileSync (path .resolve (__dirname , ' types' , filename), typeData);
83
74
});
84
75
```
@@ -121,7 +112,7 @@ It’s recommended to name the file `*.ts` and `import` the definitions. `*.d.ts
121
112
can’t be imported; they’re meant to be shipped alongside modules.
122
113
123
114
``` js
124
- import Swagger from ' ../types/swagger' ;
115
+ import { Swagger } from ' ../types/swagger' ;
125
116
126
117
const logIn = (user : Swagger .User ) => {
127
118
// …
0 commit comments