Skip to content

Commit

Permalink
Merge pull request #435 from hey-api/feat/move-use-dates-option
Browse files Browse the repository at this point in the history
feat: replace useDateType with option in types object
  • Loading branch information
jordanshatford authored Apr 19, 2024
2 parents 62c87b3 + 49ef56f commit 5503bcd
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 44 deletions.
5 changes: 5 additions & 0 deletions .changeset/soft-ladybugs-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": minor
---

feat: replace useDateType with option in types object
14 changes: 14 additions & 0 deletions docs/openapi-ts/migrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ export default {
}
```

### Removed `useDateType`

This config option has been removed. You can now configure date type using the `types.dates` option.

```js{5}
export default {
input: 'path/to/openapi.json',
output: 'src/client',
type: {
dates: true,
},
}
```

## v0.40.0

### Renamed `models.gen.ts` file
Expand Down
5 changes: 0 additions & 5 deletions packages/openapi-ts/bin/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ const params = program
.option('--schemas [value]', 'Write schemas to disk')
.option('--services [value]', 'Write services to disk')
.option('--types [value]', 'Write types to disk')
.option(
'--useDateType [value]',
'Output Date instead of string for the format "date-time" in the models',
)
.option('--useOptions [value]', 'Use options instead of arguments')
.parse(process.argv)
.opts();
Expand Down Expand Up @@ -82,7 +78,6 @@ async function start() {
'schemas',
'services',
'types',
'useDateType',
'useOptions',
]);
await createClient(userConfig);
Expand Down
1 change: 0 additions & 1 deletion packages/openapi-ts/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export function handlebarsPlugin(): Plugin {
ifdef: true,
notEquals: true,
transformServiceName: true,
useDateType: true,
},
knownHelpersOnly: true,
noEscape: true,
Expand Down
3 changes: 1 addition & 2 deletions packages/openapi-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ const getServices = (userConfig: UserConfig): Config['services'] => {

const getTypes = (userConfig: UserConfig): Config['types'] => {
let types: Config['types'] = {
dates: false,
export: true,
name: 'preserve',
};
Expand Down Expand Up @@ -169,7 +170,6 @@ const initConfig = async (
name,
operationId = true,
request,
useDateType = false,
useOptions = true,
} = userConfig;

Expand Down Expand Up @@ -218,7 +218,6 @@ const initConfig = async (
schemas,
services,
types,
useDateType,
useOptions,
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ describe('getOperationName', () => {
types: {
export: false,
},
useDateType: false,
useOptions: false,
};

Expand All @@ -54,7 +53,6 @@ describe('getOperationName', () => {
types: {
export: false,
},
useDateType: false,
useOptions: false,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('getServices', () => {
schemas: {},
services: {},
types: {},
useDateType: false,
useOptions: true,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('getServices', () => {
schemas: {},
services: {},
types: {},
useDateType: false,
useOptions: true,
});

Expand Down
10 changes: 5 additions & 5 deletions packages/openapi-ts/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ export interface UserConfig {
| boolean
| string
| {
/**
* Output Date instead of string for format "date-time"
* @default false
*/
dates?: boolean;
/**
* Generate types?
* @default true
Expand All @@ -130,11 +135,6 @@ export interface UserConfig {
*/
name?: 'PascalCase' | 'preserve';
};
/**
* Output Date instead of string for the format "date-time" in the models
* @default false
*/
useDateType?: boolean;
/**
* Use options or arguments functions
* @default true
Expand Down
2 changes: 0 additions & 2 deletions packages/openapi-ts/src/utils/__tests__/handlebars.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe('registerHandlebarHelpers', () => {
schemas: {},
services: {},
types: {},
useDateType: false,
useOptions: false,
});
registerHandlebarHelpers();
Expand Down Expand Up @@ -52,7 +51,6 @@ describe('registerHandlebarTemplates', () => {
schemas: {},
services: {},
types: {},
useDateType: false,
useOptions: false,
});
const templates = registerHandlebarTemplates();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe('writeClientClass', () => {
schemas: {},
services: {},
types: {},
useDateType: false,
useOptions: true,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe('writeClient', () => {
schemas: {},
services: {},
types: {},
useDateType: false,
useOptions: false,
});

Expand Down
3 changes: 0 additions & 3 deletions packages/openapi-ts/src/utils/write/__tests__/core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe('writeCore', () => {
schemas: {},
services: {},
types: {},
useDateType: false,
useOptions: true,
});

Expand Down Expand Up @@ -96,7 +95,6 @@ describe('writeCore', () => {
schemas: {},
services: {},
types: {},
useDateType: false,
useOptions: true,
});

Expand Down Expand Up @@ -135,7 +133,6 @@ describe('writeCore', () => {
schemas: {},
services: {},
types: {},
useDateType: false,
useOptions: true,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe('processIndex', () => {
schemas: {},
services: {},
types: {},
useDateType: false,
useOptions: true,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe('processTypesAndEnums', () => {
schemas: {},
services: {},
types: {},
useDateType: false,
useOptions: true,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe('processSchemas', () => {
schemas: {},
services: {},
types: {},
useDateType: false,
useOptions: true,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe('processServices', () => {
schemas: {},
services: {},
types: {},
useDateType: false,
useOptions: false,
});

Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-ts/src/utils/write/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const base = (model: Model) => {
if (model.base === 'binary') {
return compiler.typedef.union(['Blob', 'File']);
}
if (config.useDateType && model.format === 'date-time') {
if (config.types.dates && model.format === 'date-time') {
return compiler.typedef.basic('Date');
}
// transform root level model names
Expand Down
8 changes: 0 additions & 8 deletions packages/openapi-ts/test/bin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@ describe('cli', () => {
'false',
'--operationId',
'false',
'--useDateType',
'false',
'--useOptions',
'false',
'--dry-run',
Expand All @@ -241,7 +239,6 @@ describe('cli', () => {
expect(result.stderr.toString()).toContain('lint: false');
expect(result.stderr.toString()).toContain('operationId: false');
expect(result.stderr.toString()).toContain('schemas: false');
expect(result.stderr.toString()).toContain('useDateType: false');
expect(result.stderr.toString()).toContain('useOptions: false');
});

Expand All @@ -267,8 +264,6 @@ describe('cli', () => {
'true',
'--operationId',
'true',
'--useDateType',
'true',
'--useOptions',
'true',
'--dry-run',
Expand All @@ -283,7 +278,6 @@ describe('cli', () => {
expect(result.stderr.toString()).toContain('lint: true');
expect(result.stderr.toString()).toContain('operationId: true');
expect(result.stderr.toString()).toContain('schemas: true');
expect(result.stderr.toString()).toContain('useDateType: true');
expect(result.stderr.toString()).toContain('useOptions: true');
});

Expand All @@ -304,7 +298,6 @@ describe('cli', () => {
'--format',
'--lint',
'--operationId',
'--useDateType',
'--useOptions',
'--dry-run',
'true',
Expand All @@ -316,7 +309,6 @@ describe('cli', () => {
expect(result.stderr.toString()).toContain('lint: true');
expect(result.stderr.toString()).toContain('operationId: true');
expect(result.stderr.toString()).toContain('schemas: true');
expect(result.stderr.toString()).toContain('useDateType: true');
expect(result.stderr.toString()).toContain('useOptions: true');
expect(result.stderr.toString()).toContain("types: 'foo");
expect(result.stderr.toString()).toContain("services: 'bar'");
Expand Down
22 changes: 15 additions & 7 deletions packages/openapi-ts/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ describe('OpenAPI v3', () => {
exportCore: false,
schemas: false,
services: false,
types: '^ModelWithPattern',
useDateType: true,
types: {
dates: true,
include: '^ModelWithPattern',
},
} as UserConfig,
description: 'generate Date types',
name: 'v3_date',
Expand All @@ -130,8 +132,10 @@ describe('OpenAPI v3', () => {
...config,
schemas: false,
services: '^Defaults',
types: '^ModelWithString',
useDateType: true,
types: {
dates: true,
include: '^ModelWithString',
},
useOptions: false,
} as UserConfig,
description: 'generate legacy positional arguments',
Expand All @@ -142,8 +146,10 @@ describe('OpenAPI v3', () => {
...config,
schemas: false,
services: '^Defaults',
types: '^ModelWithString',
useDateType: true,
types: {
dates: true,
include: '^ModelWithString',
},
} as UserConfig,
description: 'generate optional arguments',
name: 'v3_options',
Expand All @@ -153,7 +159,9 @@ describe('OpenAPI v3', () => {
...config,
name: 'ApiClient',
schemas: false,
useDateType: true,
types: {
dates: true,
},
} as UserConfig,
description: 'generate client',
name: 'v3_client',
Expand Down

0 comments on commit 5503bcd

Please sign in to comment.