Skip to content

Commit c24b3ef

Browse files
authored
Update README (#74)
1 parent 7877006 commit c24b3ef

File tree

2 files changed

+31
-34
lines changed

2 files changed

+31
-34
lines changed

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"printWidth": 100,
3+
"proseWrap": "always",
34
"singleQuote": true,
45
"trailingComma": "es5"
56
}

README.md

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ npx @manifoldco/swagger-to-ts schema.yaml --wrapper "declare namespace OpenAPI"
3030
# 🚀 schema.yaml -> schema.d.ts [2ms]
3131
```
3232

33-
This will save a `schema.ts` file in the current folder under the TypeScript
34-
[namespace][namespace] `OpenAPI` (namespaces are required because chances of
35-
collision among specs is highly likely). The CLI can accept YAML or JSON for
36-
the input file.
33+
This will save a `schema.ts` file in the current folder under the TypeScript [namespace][namespace]
34+
`OpenAPI` (namespaces are required because chances of collision among specs is highly likely). The
35+
CLI can accept YAML or JSON for the input file.
3736

3837
#### Wrapper option
3938

@@ -46,8 +45,7 @@ declare namespace MyNamespace {}
4645
declare module MyModule {}
4746
```
4847

49-
The `--wrapper` flag lets you specify any of the above with a string (omit
50-
the `{}`):
48+
The `--wrapper` flag lets you specify any of the above with a string (omit the `{}`):
5149

5250
```bash
5351
npx @manifoldco/swagger-to-ts schema.yaml --wrapper "namespace API"
@@ -56,24 +54,24 @@ npx @manifoldco/swagger-to-ts schema.yaml --wrapper "declare namespace API"
5654
npx @manifoldco/swagger-to-ts schema.yaml --wrapper "declare module '@api'"
5755
```
5856

59-
By default, wrapper is `declare namespace OpenAPI2`. You can skip exposing types via a wrapper by adding the `--nowrapper` flag:
57+
By default, wrapper is `declare namespace OpenAPI2`. You can skip exposing types via a wrapper by
58+
adding the `--nowrapper` flag:
6059

6160
```bash
6261
npx @manifoldco/swagger-to-ts schema.yaml --nowrapper
6362
```
6463

65-
As mentioned before, this uses [Prettier][prettier] to clean up output, so
66-
extra spaces are generally OK here. Prettier also will err on cleanup if you
67-
specify invalid TypeScript, letting you know on generation if anything went
68-
wrong.
64+
As mentioned before, this uses [Prettier][prettier] to clean up output, so extra spaces are
65+
generally OK here. Prettier also will err on cleanup if you specify invalid TypeScript, letting you
66+
know on generation if anything went wrong.
6967

70-
_Note: previous versions of the CLI tool used `--namespace` and `--export`.
71-
These have both been deprecated in favor of `--wrapper`._
68+
_Note: previous versions of the CLI tool used `--namespace` and `--export`. These have both been
69+
deprecated in favor of `--wrapper`._
7270

7371
#### CamelCasing properties
7472

75-
Within interfaces, you may want to convert `snake_case` properties to
76-
`camelCase` by adding the `--camelcase` flag:
73+
Within interfaces, you may want to convert `snake_case` properties to `camelCase` by adding the
74+
`--camelcase` flag:
7775

7876
```bash
7977
npx @manifoldco/swagger-to-ts schema.yaml --camelcase --wrapper "declare namespace OpenAPI" --output schema.d.ts
@@ -83,9 +81,8 @@ npx @manifoldco/swagger-to-ts schema.yaml --camelcase --wrapper "declare namespa
8381

8482
#### Generating multiple schemas
8583

86-
Say you have multiple schemas you need to parse. I’ve found the simplest way
87-
to do that is to use npm scripts. In your `package.json`, you can do
88-
something like the following:
84+
Say you have multiple schemas you need to parse. I’ve found the simplest way to do that is to use
85+
npm scripts. In your `package.json`, you can do something like the following:
8986

9087
```json
9188
"scripts": {
@@ -97,18 +94,19 @@ something like the following:
9794

9895
Rinse and repeat for more specs.
9996

100-
For anything more complicated, or for generating specs dynamically, you can
101-
also use the Node API (below).
97+
For anything more complicated, or for generating specs dynamically, you can also use the Node API
98+
(below).
10299

103100
#### CLI Options
104101

105-
| Option | Alias | Default | Description |
106-
| :-------------------- | :---- | :--------------------------: | :--------------------------------------------------------- |
107-
| `--wrapper` | `-w` | `declare namespace OpenAPI2` | How should this export the types? |
108-
| `--output [location]` | `-o` | (stdout) | Where should the output file be saved? |
109-
| `--swagger [version]` | `-s` | `2` | Which Swagger version to use. Currently only supports `2`. |
110-
| `--camelcase` | `-c` | `false` | Convert `snake_case` properties to `camelCase`? |
111-
| `--nowrapper` | `-nw` | `false` | Disables rendering a wrapper |
102+
| Option | Alias | Default | Description |
103+
| :-------------------- | :---- | :--------------------------: | :----------------------------------------------------------------------- |
104+
| `--wrapper` | `-w` | `declare namespace OpenAPI2` | How should this export the types? |
105+
| `--output [location]` | `-o` | (stdout) | Where should the output file be saved? |
106+
| `--swagger [version]` | `-s` | `2` | specify Swagger version (currently only supports `2`) |
107+
| `--camelcase` | `-c` | `false` | convert `snake_case` properties to `camelCase` |
108+
| `--injectWarning` | `-iw` | `false` | injects an “autogenerated file” warning at the top of the generated file |
109+
| `--nowrapper` | `-nw` | `false` | disables rendering a wrapper |
112110

113111
### Node
114112

@@ -124,14 +122,12 @@ const input = JSON.parse(readFileSync('spec.json', 'utf8')); // Input can be any
124122
const output = swaggerToTS(input, { wrapper: 'declare namespace MyAPI' }); // Outputs TypeScript defs as a string (to be parsed, or written to a file)
125123
```
126124

127-
The Node API is a bit more flexible: it will only take a JS object as input
128-
(OpenAPI format), and return a string of TS definitions. This lets you pull
129-
from any source (a Swagger server, local files, etc.), and similarly lets you
130-
parse, post-process, and save the output anywhere.
125+
The Node API is a bit more flexible: it will only take a JS object as input (OpenAPI format), and
126+
return a string of TS definitions. This lets you pull from any source (a Swagger server, local
127+
files, etc.), and similarly lets you parse, post-process, and save the output anywhere.
131128

132-
If your specs are in YAML, you’ll have to convert them to JS objects using a
133-
library such as [js-yaml][js-yaml]. If you’re batching large folders of
134-
specs, [glob][glob] may also come in handy.
129+
If your specs are in YAML, you’ll have to convert them to JS objects using a library such as
130+
[js-yaml][js-yaml]. If you’re batching large folders of specs, [glob][glob] may also come in handy.
135131

136132
#### Node Options
137133

0 commit comments

Comments
 (0)