@@ -32,11 +32,7 @@ const swaggerToTS = require('swagger-to-ts');
3232
3333const file = ' ./spec/swagger.json' ;
3434const 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);
4036```
4137
4238#### From Swagger YAML
@@ -49,13 +45,10 @@ similar.
4945const { readFileSync , writeFileSync } = require (' fs' );
5046const yaml = require (' js-yaml' );
5147
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);
5952```
6053
6154#### Generating multiple files
@@ -75,10 +68,8 @@ const source2 = glob.sync('./swaggerspec/v2/**/*.yaml');
7568[... source1, ... source2].forEach (file => {
7669 const basename = path .basename (file);
7770 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);
8273 writeFileSync (path .resolve (__dirname , ' types' , filename), typeData);
8374});
8475```
@@ -121,7 +112,7 @@ It’s recommended to name the file `*.ts` and `import` the definitions. `*.d.ts
121112can’t be imported; they’re meant to be shipped alongside modules.
122113
123114``` js
124- import Swagger from ' ../types/swagger' ;
115+ import { Swagger } from ' ../types/swagger' ;
125116
126117const logIn = (user : Swagger .User ) => {
127118 // …
0 commit comments