From 5e02ed4212cadeeddd94de9ad38eccc9b1a7e855 Mon Sep 17 00:00:00 2001 From: Kalin Chernev Date: Mon, 1 Mar 2021 17:00:38 +0100 Subject: [PATCH] Migrate fix from v6.0.8 --- examples/yaml-anchors-aliases/example.js | 1 + .../reference-specification.json | 9 +++++++++ .../x-amazon-apigateway-integrations.yaml | 7 +++++++ package.json | 2 +- src/specification.js | 13 ++++++++----- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/examples/yaml-anchors-aliases/example.js b/examples/yaml-anchors-aliases/example.js index a94cec7a..7d038618 100644 --- a/examples/yaml-anchors-aliases/example.js +++ b/examples/yaml-anchors-aliases/example.js @@ -12,6 +12,7 @@ module.exports = (app) => { * 200: * description: OK * x-amazon-apigateway-integration: *default-integration + * x-second-integration: *second-integration */ app.get('/aws', () => {}); diff --git a/examples/yaml-anchors-aliases/reference-specification.json b/examples/yaml-anchors-aliases/reference-specification.json index 081b4814..2c41d683 100644 --- a/examples/yaml-anchors-aliases/reference-specification.json +++ b/examples/yaml-anchors-aliases/reference-specification.json @@ -16,6 +16,15 @@ "type": "aws_proxy", "uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789:function:helloworldlambda/invocations" } + }, + "x-second-integration": { + "type": "object", + "x-amazon-apigateway-integration": { + "httpMethod": "GET", + "passthroughBehavior": "when_no_match", + "type": "aws_proxy", + "uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789:function:helloworldlambda/invocations" + } } } }, diff --git a/examples/yaml-anchors-aliases/x-amazon-apigateway-integrations.yaml b/examples/yaml-anchors-aliases/x-amazon-apigateway-integrations.yaml index 9f1beaa8..33159aed 100644 --- a/examples/yaml-anchors-aliases/x-amazon-apigateway-integrations.yaml +++ b/examples/yaml-anchors-aliases/x-amazon-apigateway-integrations.yaml @@ -6,3 +6,10 @@ x-amazon-apigateway-integrations: passthroughBehavior: when_no_match type: aws_proxy uri: 'arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789:function:helloworldlambda/invocations' + second-integration: &second-integration + type: object + x-amazon-apigateway-integration: + httpMethod: GET + passthroughBehavior: when_no_match + type: aws_proxy + uri: 'arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789:function:helloworldlambda/invocations' diff --git a/package.json b/package.json index ea15c232..cd061f42 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "swagger-jsdoc", "description": "Generates swagger doc based on JSDoc", - "version": "7.0.0-rc.3", + "version": "7.0.0-rc.4", "engines": { "node": ">=12.0.0" }, diff --git a/src/specification.js b/src/specification.js index 3a3ea39a..0ba69707 100644 --- a/src/specification.js +++ b/src/specification.js @@ -248,6 +248,7 @@ export async function extract(options) { if (yamlDocsErrors.length) { for (const docWithErr of yamlDocsErrors) { const errsToDelete = []; + docWithErr.errors.forEach((error, index) => { if (error.name === 'YAMLReferenceError') { // This should either be a smart regex or ideally a YAML library method using the error.range. @@ -268,12 +269,14 @@ export async function extract(options) { yamlDocsReady.push(readyDocument); errsToDelete.push(index); } - - // Cleanup solved errors in order to allow for parser to pass through. - for (const errIndex of errsToDelete) { - docWithErr.errors.splice(errIndex, 1); - } }); + // reverse sort the deletion array so we always delete from the end + errsToDelete.sort((a, b) => b - a); + + // Cleanup solved errors in order to allow for parser to pass through. + for (const errIndex of errsToDelete) { + docWithErr.errors.splice(errIndex, 1); + } } const errReport = yamlDocsErrors