You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+95-31Lines changed: 95 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -8,14 +8,15 @@
8
8
9
9
# 📘️ openapi-typescript
10
10
11
-
🚀 Convert [OpenAPI](https://spec.openapis.org/oas/latest.html) schemas to TypeScript interfaces painlessly using pure Node.js. No Java, node-gyp, or running OpenAPI servers necessary. Uses [Prettier](https://npmjs.com/prettier) to format the output.
11
+
🚀 Convert static [OpenAPI](https://spec.openapis.org/oas/latest.html) schemas to TypeScript types quickly using pure Node.js. Fast, lightweight, (almost) dependency-free, and no Java/node-gyp/running OpenAPI servers necessary.
12
12
13
13
**Features**
14
14
15
-
- ✅ Supports YAML and JSON
15
+
- ✅ Supports YAML and JSON formats
16
+
- ✅ Supports advanced OpenAPI 3.1 features like [discriminators](https://spec.openapis.org/oas/v3.1.0#discriminator-object)
16
17
- ✅ Supports loading via remote URL (simple authentication supported with the `--auth` flag)
Import any top-level item from the generated spec to use it. It works best if you also alias types to save on typing:
64
63
@@ -70,7 +69,7 @@ type APIResponse = components["schemas"]["APIResponse"];
70
69
71
70
Because OpenAPI schemas may have invalid TypeScript characters as names, the square brackets are a safe way to access every property.
72
71
73
-
##### Operations
72
+
##### 🏗️ Operations
74
73
75
74
Operations can be imported directly by their [operationId](https://spec.openapis.org/oas/latest.html#operation-object):
76
75
@@ -80,9 +79,9 @@ import { operations } from "./generated-schema.ts";
80
79
typegetUsersById=operations["getUsersById"];
81
80
```
82
81
83
-
_Thanks to [@gr2m](https://github.com/gr2m) for the operations feature!_
82
+
_Thanks, [@gr2m](https://github.com/gr2m)!_
84
83
85
-
#### openapi-typescript-fetch
84
+
#### ⚾ openapi-typescript-fetch
86
85
87
86
The generated spec can also be used with [openapi-typescript-fetch](https://www.npmjs.com/package/openapi-typescript-fetch) which implements a typed fetch client for openapi-typescript.
88
87
@@ -132,31 +131,96 @@ try {
132
131
133
132
#### Outputting to stdout
134
133
135
-
Simply omit the `--output` flag to return to stdout:
|`--output [location]`|`-o`| (stdout) | Where should the output file be saved? |
146
-
|`--auth [token]`||| (optional) Provide an auth token to be passed along in the request (only if accessing a private schema) |
147
-
|`--header`|`-x`|| (optional) Provide an array of or singular headers as an alternative to a JSON object. Each header must follow the `key: value` pattern |
148
-
|`--headersObject`|`-h`|| (optional) Provide a JSON object as string of HTTP headers for remote schema request. This will take priority over `--header`|
149
-
|`--httpMethod`|`-m`|`GET`| (optional) Provide the HTTP Verb/Method for fetching a schema from a remote URL |
Though this is a contrived example, you could use this feature to automatically infer typing based on the URL in a fetch client or in some other useful place in your application.
0 commit comments