@@ -27,7 +27,7 @@ To compare actual generated output, see the [example](./example) folder.
27
27
``` bash
28
28
npx @manifoldco/swagger-to-ts schema.yaml --wrapper " declare namespace OpenAPI" --output schema.d.ts
29
29
30
- # 🚀 schema.yaml -> schema.ts [2ms]
30
+ # 🚀 schema.yaml -> schema.d. ts [2ms]
31
31
```
32
32
33
33
This will save a ` schema.ts ` file in the current folder under the TypeScript
@@ -51,7 +51,7 @@ the `{}`):
51
51
52
52
``` bash
53
53
npx @manifoldco/swagger-to-ts schema.yaml --wrapper " namespace API"
54
- npx @manifoldco/swagger-to-ts schema.yaml --wrapper " declare namespace API"
54
+ npx @manifoldco/swagger-to-ts schema.yaml --wrapper " export namespace API"
55
55
npx @manifoldco/swagger-to-ts schema.yaml --wrapper " declare namespace API"
56
56
npx @manifoldco/swagger-to-ts schema.yaml --wrapper " declare module '@api'"
57
57
```
@@ -70,9 +70,9 @@ Within interfaces, you may want to convert `snake_case` properties to
70
70
` camelCase ` by adding the ` --camelcase ` flag:
71
71
72
72
``` bash
73
- npx @manifoldco/swagger-to-ts schema.yaml --wrapper " declare namespace OpenAPI" --output schema.d.ts
73
+ npx @manifoldco/swagger-to-ts schema.yaml --camelcase -- wrapper " declare namespace OpenAPI" --output schema.d.ts
74
74
75
- # 🚀 schema.yaml -> schema.ts [2ms]
75
+ # 🚀 schema.yaml -> schema.d. ts [2ms]
76
76
```
77
77
78
78
#### Generating multiple schemas
@@ -84,8 +84,8 @@ something like the following:
84
84
``` json
85
85
"scripts" : {
86
86
"generate:specs" : " npm run generate:specs:one && npm run generate:specs:two" ,
87
- "generate:specs:one" : " npx @manifoldco/swagger-to-ts one.yaml -o one.ts" ,
88
- "generate:specs:two" : " npx @manifoldco/swagger-to-ts two.yaml -o two.ts"
87
+ "generate:specs:one" : " npx @manifoldco/swagger-to-ts one.yaml -o one.d. ts" ,
88
+ "generate:specs:two" : " npx @manifoldco/swagger-to-ts two.yaml -o two.d. ts"
89
89
}
90
90
```
91
91
@@ -113,27 +113,24 @@ npm i --save-dev @manifoldco/swagger-to-ts
113
113
const { readFileSync } = require (' fs' );
114
114
const swaggerToTS = require (' @manifoldco/swagger-to-ts' );
115
115
116
- const input = JSON .parse (readFileSync (' spec.json' , ' utf8' )); // Input be any JS object (OpenAPI format)
116
+ const input = JSON .parse (readFileSync (' spec.json' , ' utf8' )); // Input can be any JS object (OpenAPI format)
117
117
const output = swaggerToTS (input, { wrapper: ' declare namespace MyAPI' }); // Outputs TypeScript defs as a string (to be parsed, or written to a file)
118
118
```
119
119
120
120
The Node API is a bit more flexible: it will only take a JS object as input
121
121
(OpenAPI format), and return a string of TS definitions. This lets you pull
122
- from any source (a Swagger server, local files, etc.), and similarly lets put
123
- the output anywhere. It even allows for some post-processing in-between if
124
- desired.
122
+ from any source (a Swagger server, local files, etc.), and similarly lets you
123
+ parse, post-process, and save the output anywhere.
125
124
126
- If you are working with local files, you’ll have to read/write files
127
- yourself. Also, if your specs are in YAML, you’ll have to convert them to JS
128
- objects. A library such as [ js-yaml] [ js-yaml ] does make this trivial, though!
129
- Lastly, if you’re batching large folders of specs, [ glob] [ glob ] may also come
130
- in handy.
125
+ If your specs are in YAML, you’ll have to convert them to JS objects using a
126
+ library such as [ js-yaml] [ js-yaml ] . If you’re batching large folders of
127
+ specs, [ glob] [ glob ] may also come in handy.
131
128
132
129
#### Node Options
133
130
134
131
| Name | Type | Default | Description |
135
132
| :---------- | :-------: | :--------------------------: | :--------------------------------------------------------- |
136
- | ` -- wrapper` | ` string ` | ` declare namespace OpenAPI2 ` | How should this export the types? |
133
+ | ` wrapper ` | ` string ` | ` declare namespace OpenAPI2 ` | How should this export the types? |
137
134
| ` swagger ` | ` number ` | ` 2 ` | Which Swagger version to use. Currently only supports ` 2 ` . |
138
135
| ` camelcase ` | ` boolean ` | ` false ` | Convert ` snake_case ` properties to ` camelCase ` |
139
136
0 commit comments