Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion docs/openapi-ts/plugins/transformers.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,16 @@ export default {
};
```

This will generate types that use `Date` instead of `string` and appropriate transformers. Note that third-party date packages are not supported at the moment.
This will generate types that use `Date` instead of `string` and appropriate transformers for fields with `format: "date-time"`. Fields with `format: "date"` will remain as strings since they represent date-only values (e.g., `2024-01-20`) without time information.

::: tip
The OpenAPI specification defines two date formats:

- `date-time`: Full timestamp with time and timezone (e.g., `2024-01-20T15:30:00Z`) - **converted to `Date`**
- `date`: Date only without time (e.g., `2024-01-20`) - **kept as `string`**
:::

Note that third-party date packages are not supported at the moment.

## BigInt

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const bigIntExpressions: ExpressionTransformer = ({ dataExpression, schem
};

export const dateExpressions: ExpressionTransformer = ({ dataExpression, schema }) => {
if (schema.type !== 'string' || !(schema.format === 'date' || schema.format === 'date-time')) {
if (schema.type !== 'string' || !(schema.format === 'date-time')) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export type UserConfig = Plugin.Name<'@hey-api/transformers'> &
*/
bigInt?: boolean;
/**
* Convert date strings into Date objects?
* Convert date-time strings into Date objects?
* Only affects fields with format "date-time", not "date".
*
* @default true
*/
Expand All @@ -45,7 +46,8 @@ export type Config = Plugin.Name<'@hey-api/transformers'> &
*/
bigInt: boolean;
/**
* Convert date strings into Date objects?
* Convert date-time strings into Date objects?
* Only affects fields with format "date-time", not "date".
*
* @default true
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const stringToAst = ({
return $.type.or($.type('Blob'), $.type('File'));
}

if (schema.format === 'date-time' || schema.format === 'date') {
if (schema.format === 'date-time') {
// TODO: parser - add ability to skip type transformers
if (plugin.getPlugin('@hey-api/transformers')?.config.dates) {
return $.type('Date');
Expand Down
Loading