@@ -73,49 +73,53 @@ Also you can use `npx`:
73
73
You can use this package from nodejs:
74
74
``` js
75
75
const { generateApi } = require (' swagger-typescript-api' );
76
+ const path = require (" path" );
77
+ const fs = require (" fs" );
76
78
77
- // example with url
79
+ /* NOTE: all fields are optional expect one of `output`, ` url`, `spec` */
78
80
generateApi ({
79
- name: " MySuperbApi.ts" , // name of output typescript file
80
- url: ' http://api.com/swagger.json' , // url where located swagger schema
81
- })
82
- .then (({ files, configuration }) => {
83
- files .forEach (({ content, name }) => {
84
- fs .writeFile (path, content);
85
- });
86
- })
87
- .catch (e => console .error (e))
88
-
89
- // example with local file
90
- generateApi ({
91
- name: " ApiModule.ts" , // name of output typescript file
92
- input: resolve (process .cwd (), ' ./foo/swagger.json' ) // path to swagger schema
93
- })
94
- .then (({ files, configuration }) => {
95
- files .forEach (({ content, name }) => {
96
- fs .writeFile (path, content);
97
- });
98
- })
99
- .catch (e => console .error (e))
100
-
101
- // example with parsed schema
102
- generateApi ({
103
- name: " ApiModule.ts" , // name of output typescript file
81
+ name: " MySuperbApi.ts" ,
82
+ output: path .resolve (process .cwd (), " ./src/__generated__" ),
83
+ url: ' http://api.com/swagger.json' ,
84
+ input: path .resolve (process .cwd (), ' ./foo/swagger.json' ),
104
85
spec: {
105
86
swagger: " 2.0" ,
106
87
info: {
107
88
version: " 1.0.0" ,
108
89
title: " Swagger Petstore" ,
109
90
},
110
- host: " petstore.swagger.io" ,
111
- basePath: " /api" ,
112
- schemes: [" http" ],
113
- consumes: [" application/json" ],
114
- produces: [" application/json" ],
115
- paths: {
116
- // ...
117
- }
118
91
// ...
92
+ },
93
+ templates: path .resolve (process .cwd (), ' ./api-templates' ),
94
+ httpClientType: " axios" , // or "fetch"
95
+ defaultResponseAsSuccess: false ,
96
+ generateRouteTypes: false ,
97
+ generateResponses: true ,
98
+ toJS: false ,
99
+ extractRequestParams: false ,
100
+ prettier: {
101
+ printWidth: 120 ,
102
+ tabWidth: 2 ,
103
+ trailingComma: " all" ,
104
+ parser: " typescript" ,
105
+ },
106
+ defaultResponseType: " void" ,
107
+ singleHttpClient: true ,
108
+ cleanOutput: false ,
109
+ enumNamesAsValues: false ,
110
+ moduleNameFirstTag: false ,
111
+ generateUnionEnums: false ,
112
+ extraTemplates: [],
113
+ hooks: {
114
+ onCreateComponent : (component ) => {},
115
+ onCreateRequestParams : (rawType ) => {},
116
+ onCreateRoute : (routeData ) => {},
117
+ onCreateRouteName : (routeNameInfo , rawRouteInfo ) => {},
118
+ onFormatRouteName : (routeInfo , templateRouteName ) => {},
119
+ onFormatTypeName : (typeName , rawTypeName ) => {},
120
+ onInit : (configuration ) => {},
121
+ onParseSchema : (originalSchema , parsedSchema ) => {},
122
+ onPrepareConfig : (currentConfiguration ) => {},
119
123
}
120
124
})
121
125
.then (({ files, configuration }) => {
0 commit comments