From b77b8667ef5c61040a43797efda1d87e5e57ca3c Mon Sep 17 00:00:00 2001 From: Luis Fernando Planella Gonzalez Date: Fri, 9 Aug 2019 08:44:09 -0300 Subject: [PATCH] Prevent duplicated methods to be generated Fixes #33 --- lib/operation.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/operation.ts b/lib/operation.ts index 4d0d44c..0453f9a 100644 --- a/lib/operation.ts +++ b/lib/operation.ts @@ -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)); + } } } } @@ -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 '';