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
+11-5
Original file line number
Diff line number
Diff line change
@@ -273,15 +273,22 @@ By default, openapiTS will generate `updated_at?: string;` because it’s not su
273
273
274
274
```js
275
275
const types = openapiTS(mySchema, {
276
-
transform(node: SchemaObject, options): string {
277
-
if ("format" in node && node.format === "date-time") {
276
+
transform(schemaObject, metadata): string {
277
+
if ("format" in schemaObject && schemaObject.format === "date-time") {
278
278
return "Date";
279
279
}
280
280
},
281
281
});
282
282
```
283
283
284
-
This will generate `updated_at?: Date` instead. Note that you will still have to do the parsing of your data yourself, but this will save you from having to manually override certain types in your schema. Also be sure to check the `options` parameter for additional context that may be helpful.
284
+
That would result in the following change:
285
+
286
+
```diff
287
+
- updated_at?: string;
288
+
+ updated_at?: Date;
289
+
```
290
+
291
+
Any [Schema Object](https://spec.openapis.org/oas/latest.html#schema-object) present in your schema will be run through this formatter (even remote ones!). Also be sure to check the `metadata` parameter for additional context that may be helpful.
285
292
286
293
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).
287
294
@@ -291,8 +298,7 @@ There are many other uses for this besides checking `format`. Because this must
291
298
292
299
1. Support converting any valid OpenAPI schema to TypeScript types, no matter how complicated.
293
300
1. This library does **NOT** validate your schema, there are other libraries for that.
294
-
1. The generated TypeScript types **must** match your schema as closely as possible (e.g. no renaming to
295
-
`PascalCase`)
301
+
1. The generated TypeScript types **must** match your schema as closely as possible (e.g. no renaming to `PascalCase`)
296
302
1. This library should never require Java, node-gyp, or some other complex environment to work. This should require Node.js and nothing else.
297
303
1. This library will never require a running OpenAPI server to work.
0 commit comments