Skip to content

Commit

Permalink
change --igrnoreOperationId to --useOperationId; make the flag consis…
Browse files Browse the repository at this point in the history
…tent throughout the codebase and documentation
  • Loading branch information
askvortcov committed Feb 20, 2024
1 parent 8cd10e9 commit c812bd0
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const params = program
.option('--exportCore <value>', 'Write core files to disk', true)
.option('--exportServices <value>', 'Write services to disk', true)
.option('--exportModels <value>', 'Write models to disk', true)
.option('--ignoreOperationId <value>', 'Use operation id', true)
.option('--useOperationId <value>', 'Use operation id to generate operation names', true)
.option('--exportSchemas <value>', 'Write schemas to disk', false)
.option('--indent <value>', 'Indentation options [4, 2, tabs]', '4')
.option('--postfixServices <value>', 'Service name postfix', 'Service')
Expand All @@ -42,7 +42,7 @@ if (OpenAPI) {
exportServices: JSON.parse(params.exportServices) === true,
exportModels: JSON.parse(params.exportModels) === true,
exportSchemas: JSON.parse(params.exportSchemas) === true,
ignoreOperationId: JSON.parse(params.ignoreOperationId) === true,
useOperationId: JSON.parse(params.useOperationId) === true,
indent: params.indent,
postfixServices: params.postfixServices,
postfixModels: params.postfixModels,
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type Options = {
exportServices?: boolean;
exportModels?: boolean;
exportSchemas?: boolean;
ignoreOperationId?: boolean;
useOperationId?: boolean;
indent?: Indent;
postfixServices?: string;
postfixModels?: string;
Expand Down Expand Up @@ -63,7 +63,7 @@ export const generate = async ({
exportServices = true,
exportModels = true,
exportSchemas = false,
ignoreOperationId = false,
useOperationId = true,
indent = Indent.SPACE_4,
postfixServices = 'Service',
postfixModels = '',
Expand Down Expand Up @@ -104,7 +104,7 @@ export const generate = async ({
}

case OpenApiVersion.V3: {
const client = parseV3(openApi, ignoreOperationId);
const client = parseV3(openApi, useOperationId);
const clientFinal = postProcessClient(client);
if (!write) break;
await writeClient(
Expand Down
6 changes: 3 additions & 3 deletions src/openApi/v3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { getServiceVersion } from './parser/getServiceVersion';
* Parse the OpenAPI specification to a Client model that contains
* all the models, services and schema's we should output.
* @param openApi The OpenAPI spec that we have loaded from disk.
* @param ignoreOperationId should the operationId be ignored when generating operation names
* @param useOperationId should the operationId be used when generating operation names
*/
export const parse = (openApi: OpenApi, ignoreOperationId: boolean): Client => {
export const parse = (openApi: OpenApi, useOperationId: boolean): Client => {
const version = getServiceVersion(openApi.info.version);
const server = getServer(openApi);
const models = getModels(openApi);
const services = getServices(openApi, ignoreOperationId);
const services = getServices(openApi, useOperationId);

return { version, server, models, services };
};
4 changes: 2 additions & 2 deletions src/openApi/v3/parser/getOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export const getOperation = (
tag: string,
op: OpenApiOperation,
pathParams: OperationParameters,
ignoreOperationId: boolean
useOperationId: boolean
): Operation => {
const serviceName = getServiceName(tag);
const operationName = getOperationName(url, method, ignoreOperationId, op.operationId);
const operationName = getOperationName(url, method, useOperationId, op.operationId);

// Create a new operation object for this method.
const operation: Operation = {
Expand Down
46 changes: 23 additions & 23 deletions src/openApi/v3/parser/getOperationName.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ import { getOperationName } from './getOperationName';

describe('getOperationName', () => {
it('should produce correct result', () => {
expect(getOperationName('/api/v{api-version}/users', 'GET', false, 'GetAllUsers')).toEqual('getAllUsers');
expect(getOperationName('/api/v{api-version}/users', 'GET', false, undefined)).toEqual('getApiUsers');
expect(getOperationName('/api/v{api-version}/users', 'POST', false, undefined)).toEqual('postApiUsers');
expect(getOperationName('/api/v1/users', 'GET', false, 'GetAllUsers')).toEqual('getAllUsers');
expect(getOperationName('/api/v1/users', 'GET', false, undefined)).toEqual('getApiV1Users');
expect(getOperationName('/api/v1/users', 'POST', false, undefined)).toEqual('postApiV1Users');
expect(getOperationName('/api/v1/users/{id}', 'GET', false, undefined)).toEqual('getApiV1UsersById');
expect(getOperationName('/api/v1/users/{id}', 'POST', false, undefined)).toEqual('postApiV1UsersById');
expect(getOperationName('/api/v{api-version}/users', 'GET', true, 'GetAllUsers')).toEqual('getAllUsers');
expect(getOperationName('/api/v{api-version}/users', 'GET', true, undefined)).toEqual('getApiUsers');
expect(getOperationName('/api/v{api-version}/users', 'POST', true, undefined)).toEqual('postApiUsers');
expect(getOperationName('/api/v1/users', 'GET', true, 'GetAllUsers')).toEqual('getAllUsers');
expect(getOperationName('/api/v1/users', 'GET', true, undefined)).toEqual('getApiV1Users');
expect(getOperationName('/api/v1/users', 'POST', true, undefined)).toEqual('postApiV1Users');
expect(getOperationName('/api/v1/users/{id}', 'GET', true, undefined)).toEqual('getApiV1UsersById');
expect(getOperationName('/api/v1/users/{id}', 'POST', true, undefined)).toEqual('postApiV1UsersById');

expect(getOperationName('/api/v{api-version}/users', 'GET', false, 'fooBar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', false, 'FooBar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', false, 'Foo Bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', false, 'foo bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', false, 'foo-bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', false, 'foo_bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', false, 'foo.bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', false, '@foo.bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', false, '$foo.bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', false, '_foo.bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', false, '-foo.bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', false, '123.foo.bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', true, 'fooBar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', true, 'FooBar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', true, 'Foo Bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', true, 'foo bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', true, 'foo-bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', true, 'foo_bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', true, 'foo.bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', true, '@foo.bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', true, '$foo.bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', true, '_foo.bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', true, '-foo.bar')).toEqual('fooBar');
expect(getOperationName('/api/v{api-version}/users', 'GET', true, '123.foo.bar')).toEqual('fooBar');

expect(getOperationName('/api/v1/users', 'GET', true, 'GetAllUsers')).toEqual('getApiV1Users');
expect(getOperationName('/api/v{api-version}/users', 'GET', true, 'fooBar')).toEqual('getApiUsers');
expect(getOperationName('/api/v1/users', 'GET', false, 'GetAllUsers')).toEqual('getApiV1Users');
expect(getOperationName('/api/v{api-version}/users', 'GET', false, 'fooBar')).toEqual('getApiUsers');
expect(
getOperationName('/api/v{api-version}/users/{userId}/location/{locationId}', 'GET', true, 'fooBar')
getOperationName('/api/v{api-version}/users/{userId}/location/{locationId}', 'GET', false, 'fooBar')
).toEqual('getApiUsersByUserIdLocationByLocationId');
});
});
4 changes: 2 additions & 2 deletions src/openApi/v3/parser/getOperationName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import camelCase from 'camelcase';
export const getOperationName = (
url: string,
method: string,
ignoreOperationId: boolean,
useOperationId: boolean,
operationId?: string
): string => {
if (operationId && !ignoreOperationId) {
if (useOperationId && operationId) {
return camelCase(
operationId
.replace(/^[^a-zA-Z]+/g, '')
Expand Down
4 changes: 2 additions & 2 deletions src/openApi/v3/parser/getServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getOperationParameters } from './getOperationParameters';
/**
* Get the OpenAPI services
*/
export const getServices = (openApi: OpenApi, ignoreOperationId: boolean): Service[] => {
export const getServices = (openApi: OpenApi, useOperationId: boolean): Service[] => {
const services = new Map<string, Service>();
for (const url in openApi.paths) {
if (openApi.paths.hasOwnProperty(url)) {
Expand Down Expand Up @@ -37,7 +37,7 @@ export const getServices = (openApi: OpenApi, ignoreOperationId: boolean): Servi
tag,
op,
pathParams,
ignoreOperationId
useOperationId
);

// If we have already declared a service, then we should fetch that and
Expand Down

0 comments on commit c812bd0

Please sign in to comment.