Skip to content

Commit

Permalink
feat: move operationId config option to services object
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanshatford committed Apr 19, 2024
1 parent 9eadc04 commit 279da8e
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-worms-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": minor
---

feat: move operationId config option to services object
16 changes: 16 additions & 0 deletions docs/openapi-ts/migrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ This config option is deprecated and will be removed.

This config option is deprecated and will be removed.

## v0.42.0

### Moved `operationId`

This config option has been moved. You can now configure it using the `services.operationId` option.

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

## v0.41.0

### Removed `postfixServices`
Expand Down
2 changes: 0 additions & 2 deletions packages/openapi-ts/bin/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const params = program
.option('--format [value]', 'Process output folder with formatter?')
.option('--lint [value]', 'Process output folder with linter?')
.option('--name <value>', 'Custom client class name')
.option('--operationId [value]', 'Use operationd ID?')
.option('--request <value>', 'Path to custom request file')
.option('--schemas [value]', 'Write schemas to disk')
.option('--services [value]', 'Write services to disk')
Expand Down Expand Up @@ -74,7 +73,6 @@ async function start() {
'exportCore',
'format',
'lint',
'operationId',
'schemas',
'services',
'types',
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 @@ -108,6 +108,7 @@ const getServices = (userConfig: UserConfig): Config['services'] => {
let services: Config['services'] = {
export: true,
name: '{{name}}Service',
operationId: true,
response: 'body',
};
if (typeof userConfig.services === 'boolean') {
Expand Down Expand Up @@ -168,7 +169,6 @@ const initConfig = async (
input,
lint = false,
name,
operationId = true,
request,
useOptions = true,
} = userConfig;
Expand Down Expand Up @@ -212,7 +212,6 @@ const initConfig = async (
input,
lint,
name,
operationId,
output,
request,
schemas,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ describe('getOperationName', () => {
format: false,
input: '',
lint: false,
operationId: true,
output: '',
schemas: {
export: false,
},
services: {
export: false,
operationId: true,
response: 'body',
},
types: {
Expand All @@ -41,13 +41,13 @@ describe('getOperationName', () => {
format: false,
input: '',
lint: false,
operationId: false,
output: '',
schemas: {
export: false,
},
services: {
export: false,
operationId: false,
response: 'body',
},
types: {
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-ts/src/openApi/common/parser/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getOperationName = (
): string => {
const config = getConfig();

if (config.operationId && operationId) {
if (config.services.operationId && operationId) {
return camelCase(sanitizeNamespaceIdentifier(operationId).trim());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ describe('getServices', () => {
format: false,
input: '',
lint: false,
operationId: false,
output: '',
schemas: {},
services: {},
services: {
operationId: false,
},
types: {},
useOptions: true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ describe('getServices', () => {
format: false,
input: '',
lint: false,
operationId: true,
output: '',
schemas: {},
services: {},
services: {
operationId: true,
},
types: {},
useOptions: true,
});
Expand Down
12 changes: 6 additions & 6 deletions packages/openapi-ts/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface UserConfig {
*/
dryRun?: boolean;
/**
* Export enum definitions?
* Generate enum definitions?
* @default false
*/
enums?: 'javascript' | 'typescript' | false;
Expand All @@ -46,11 +46,6 @@ export interface UserConfig {
* Custom client class name
*/
name?: string;
/**
* Use operation ID to generate operation names?
* @default true
*/
operationId?: boolean;
/**
* The relative location of the output directory
*/
Expand Down Expand Up @@ -101,6 +96,11 @@ export interface UserConfig {
* @default '{{name}}Service'
*/
name?: string;
/**
* Use operation ID to generate operation names?
* @default true
*/
operationId?: boolean;
/**
* Define shape of returned value from service calls
* @default 'body'
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 @@ -18,7 +18,6 @@ describe('registerHandlebarHelpers', () => {
format: true,
input: '',
lint: false,
operationId: true,
output: '',
schemas: {},
services: {},
Expand Down Expand Up @@ -46,7 +45,6 @@ describe('registerHandlebarTemplates', () => {
format: true,
input: '',
lint: false,
operationId: true,
output: '',
schemas: {},
services: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('writeClientClass', () => {
input: '',
lint: false,
name: 'AppClient',
operationId: true,
output: '',
schemas: {},
services: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('writeClient', () => {
format: true,
input: '',
lint: false,
operationId: true,
output: './dist',
schemas: {},
services: {},
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 @@ -35,7 +35,6 @@ describe('writeCore', () => {
input: '',
lint: false,
name: 'AppClient',
operationId: true,
output: '',
schemas: {},
services: {},
Expand Down Expand Up @@ -90,7 +89,6 @@ describe('writeCore', () => {
input: '',
lint: false,
name: 'AppClient',
operationId: true,
output: '',
schemas: {},
services: {},
Expand Down Expand Up @@ -128,7 +126,6 @@ describe('writeCore', () => {
input: '',
lint: false,
name: 'AppClient',
operationId: true,
output: '',
schemas: {},
services: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('processIndex', () => {
format: false,
input: '',
lint: false,
operationId: true,
output: '',
schemas: {},
services: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('processTypesAndEnums', () => {
input: '',
lint: false,
name: 'AppClient',
operationId: true,
output: '',
schemas: {},
services: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('processSchemas', () => {
input: '',
lint: false,
name: 'AppClient',
operationId: true,
output: '',
schemas: {},
services: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('processServices', () => {
format: false,
input: '',
lint: false,
operationId: true,
output: '',
schemas: {},
services: {},
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 @@ -223,8 +223,6 @@ describe('cli', () => {
'false',
'--lint',
'false',
'--operationId',
'false',
'--useOptions',
'false',
'--dry-run',
Expand All @@ -237,7 +235,6 @@ describe('cli', () => {
expect(result.stderr.toString()).toContain('services: false');
expect(result.stderr.toString()).toContain('format: false');
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('useOptions: false');
});
Expand All @@ -262,8 +259,6 @@ describe('cli', () => {
'true',
'--lint',
'true',
'--operationId',
'true',
'--useOptions',
'true',
'--dry-run',
Expand All @@ -276,7 +271,6 @@ describe('cli', () => {
expect(result.stderr.toString()).toContain('services: true');
expect(result.stderr.toString()).toContain('format: true');
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('useOptions: true');
});
Expand All @@ -297,7 +291,6 @@ describe('cli', () => {
'bar',
'--format',
'--lint',
'--operationId',
'--useOptions',
'--dry-run',
'true',
Expand All @@ -307,7 +300,6 @@ describe('cli', () => {
expect(result.stderr.toString()).toContain('exportCore: true');
expect(result.stderr.toString()).toContain('format: true');
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('useOptions: true');
expect(result.stderr.toString()).toContain("types: 'foo");
Expand Down

0 comments on commit 279da8e

Please sign in to comment.