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
|`--help`||| Display inline help message and exit |
144
+
|`--version`||| Display this library’s version and exit |
143
145
|`--output [location]`|`-o`| (stdout) | Where should the output file be saved? |
144
146
|`--auth [token]`||| Provide an auth token to be passed along in the request (only if accessing a private schema) |
145
147
|`--header`|`-x`|| Provide an array of or singular headers as an alternative to a JSON object. Each header must follow the `key: value` pattern |
@@ -271,16 +273,10 @@ By default, openapiTS will generate `updated_at?: string;` because it’s not su
271
273
272
274
```js
273
275
const types = openapiTS(mySchema, {
274
-
/** transform: runs before Schema Object is converted into a TypeScript type */
275
276
transform(node: SchemaObject, options): string {
276
277
if ("format" in node && node.format === "date-time") {
277
-
return "Date"; // return the TypeScript “Date” type, as a string
278
+
return "Date";
278
279
}
279
-
// if no string returned, handle it normally
280
-
},
281
-
/** post-transform: runs after TypeScript type has been transformed */
282
-
postTransform(type: string, options): string {
283
-
// if no string returned, keep TypeScript type as-is
284
280
},
285
281
});
286
282
```
@@ -289,6 +285,8 @@ This will generate `updated_at?: Date` instead. Note that you will still have to
289
285
290
286
There are many other uses for this besides checking `format`. Because this must return a **string** you can produce any arbitrary TypeScript code you’d like (even your own custom types).
291
287
288
+
✨ Don’t forget about `postTransform()` as well! It works the same way, but runs _after_ the TypeScript transformation so you can extend/modify types as-needed.
289
+
292
290
## 🏅 Project Goals
293
291
294
292
1. Support converting any valid OpenAPI schema to TypeScript types, no matter how complicated.
0 commit comments