Skip to content

Commit

Permalink
Rename convert methods to be consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
robdodson committed Jul 29, 2023
1 parent 262a1bc commit d2fc59f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/Case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ const transforms = {

// A recursive function that looks at the models and their properties and
// converts each property name using the provided transform function.
export const convertModelNames = <T extends Model | OperationResponse>(model: T, type: Exclude<Case, Case.NONE>): T => {
export const convertModelCase = <T extends Model | OperationResponse>(model: T, type: Exclude<Case, Case.NONE>): T => {
return {
...model,
name: transforms[type](model.name),
link: model.link ? convertModelNames(model.link, type) : null,
enum: model.enum.map(modelEnum => convertEnumName(modelEnum, type)),
enums: model.enums.map(property => convertModelNames(property, type)),
properties: model.properties.map(property => convertModelNames(property, type)),
link: model.link ? convertModelCase(model.link, type) : null,
enum: model.enum.map(modelEnum => convertEnumCase(modelEnum, type)),
enums: model.enums.map(property => convertModelCase(property, type)),
properties: model.properties.map(property => convertModelCase(property, type)),
};
};

const convertEnumName = (modelEnum: Enum, type: Exclude<Case, Case.NONE>): Enum => {
const convertEnumCase = (modelEnum: Enum, type: Exclude<Case, Case.NONE>): Enum => {
return {
...modelEnum,
name: transforms[type](modelEnum.name),
Expand All @@ -48,7 +48,7 @@ export const convertServiceCase = (service: Service, type: Exclude<Case, Case.NO
...service,
operations: service.operations.map(op => ({
...op,
results: op.results.map(results => convertModelNames(results, type)),
results: op.results.map(results => convertModelCase(results, type)),
})),
};
};
4 changes: 2 additions & 2 deletions src/utils/writeClientModels.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { resolve } from 'path';

import type { Model } from '../client/interfaces/Model';
import { Case, convertModelNames } from '../Case';
import { Case, convertModelCase } from '../Case';
import type { HttpClient } from '../HttpClient';
import type { Indent } from '../Indent';
import { writeFile } from './fileSystem';
Expand Down Expand Up @@ -29,7 +29,7 @@ export const writeClientModels = async (
transformCase: Case
): Promise<void> => {
for (const model of models) {
const newModel = transformCase === Case.NONE ? model : convertModelNames(model, transformCase);
const newModel = transformCase === Case.NONE ? model : convertModelCase(model, transformCase);
const file = resolve(outputPath, `${model.name}.ts`);
const templateResult = templates.exports.model({
...newModel,
Expand Down

0 comments on commit d2fc59f

Please sign in to comment.