Skip to content

Commit

Permalink
Prevent duplicated methods to be generated
Browse files Browse the repository at this point in the history
Fixes #33
  • Loading branch information
luisfpg committed Aug 9, 2019
1 parent 8c4297a commit b77b866
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ export class Operation {
const methodPart = this.id + (hasRequestBodyVariants ? this.variantMethodPart(requestBodyVariant) : '');
for (const successResponseVariant of successResponseVariants) {
const methodName = methodPart + (hasResponseVariants ? this.variantMethodPart(successResponseVariant) : '');
this.variants.push(new OperationVariant(this, methodName, requestBodyVariant, successResponseVariant, this.options));
if (!this.variants.find(v => v.methodName === methodName)) {
// It is possible to have multiple content types which end up in the same method.
// For example: application/json, application/foo-bar+json, text/json ...
this.variants.push(new OperationVariant(this, methodName, requestBodyVariant, successResponseVariant, this.options));
}
}
}
}
Expand All @@ -185,6 +189,10 @@ export class Operation {
return '$Any';
}
type = last(type.split('/')) as string;
const plus = type.lastIndexOf('+');
if (plus >= 0) {
type = type.substr(plus + 1);
}
return `$${typeName(type)}`;
} else {
return '';
Expand Down

0 comments on commit b77b866

Please sign in to comment.