Skip to content

Commit

Permalink
fix(tags mode): add default tag if operation has none
Browse files Browse the repository at this point in the history
  • Loading branch information
sverps committed Apr 30, 2020
1 parent f0e87bf commit ad188f5
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions src/core/writers/tagsMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import { generateImports } from '../generators/imports';
import { generateModelsInline } from '../generators/modelsInline';
import { resolvePath } from '../resolvers/path';

const addDefaultTagIfEmpty = (operation: GeneratorOperation) => ({
...operation,
tags: operation.tags.length ? operation.tags : ['default'],
});

const generateTargetTags = (
currentAcc: { [key: string]: GeneratorTarget },
operation: GeneratorOperation,
Expand Down Expand Up @@ -64,28 +69,30 @@ export const generateTarget = (
operations: GeneratorOperations,
info: InfoObject,
) =>
Object.values(operations).reduce((acc, operation, index, arr) => {
const targetTags = generateTargetTags(acc, operation, info);

if (index === arr.length - 1) {
const footer = generateClientFooter();

return Object.entries(targetTags).reduce((acc, [tag, target]) => {
return {
...acc,
[tag]: {
definition: target.definition + footer.definition,
implementation: target.implementation + footer.implementation,
implementationMocks:
target.implementationMocks + footer.implementationMock,
imports: generalTypesFilter(target.imports),
},
};
}, {});
}

return targetTags;
}, {} as { [key: string]: GeneratorTarget });
Object.values(operations)
.map(addDefaultTagIfEmpty)
.reduce((acc, operation, index, arr) => {
const targetTags = generateTargetTags(acc, operation, info);

if (index === arr.length - 1) {
const footer = generateClientFooter();

return Object.entries(targetTags).reduce((acc, [tag, target]) => {
return {
...acc,
[tag]: {
definition: target.definition + footer.definition,
implementation: target.implementation + footer.implementation,
implementationMocks:
target.implementationMocks + footer.implementationMock,
imports: generalTypesFilter(target.imports),
},
};
}, {});
}

return targetTags;
}, {} as { [key: string]: GeneratorTarget });

export const writeTagsMode = ({
operations,
Expand Down

0 comments on commit ad188f5

Please sign in to comment.