From de3d063ca3c98ffeb761dbe3fee847862ca33f50 Mon Sep 17 00:00:00 2001 From: Tim Lai Date: Thu, 24 Jun 2021 16:25:54 -0700 Subject: [PATCH] fix(sample-gen): parameter array missing items fallback (#7376) * fixes #7375 --- src/core/plugins/samples/fn.js | 4 ++++ .../parameter-array-missing-items.yaml | 24 +++++++++++++++++++ .../features/parameter-array-missing-items.js | 10 ++++++++ 3 files changed, 38 insertions(+) create mode 100644 test/e2e-cypress/static/documents/features/parameter-array-missing-items.yaml create mode 100644 test/e2e-cypress/tests/features/parameter-array-missing-items.js diff --git a/src/core/plugins/samples/fn.js b/src/core/plugins/samples/fn.js index 3db65d9a..cfcc9375 100644 --- a/src/core/plugins/samples/fn.js +++ b/src/core/plugins/samples/fn.js @@ -500,6 +500,10 @@ export const sampleFromSchemaGeneric = (schema, config={}, exampleOverride = und } if(type === "array") { + if (!items) { + return + } + let sampleArray if(respectXML) { items.xml = items.xml || schema?.xml || {} diff --git a/test/e2e-cypress/static/documents/features/parameter-array-missing-items.yaml b/test/e2e-cypress/static/documents/features/parameter-array-missing-items.yaml new file mode 100644 index 00000000..a19a2b16 --- /dev/null +++ b/test/e2e-cypress/static/documents/features/parameter-array-missing-items.yaml @@ -0,0 +1,24 @@ +openapi: 3.0.0 +info: + title: test + version: "1.0.0" +paths: + /example1: + get: + description: test fetching + parameters: + - in: query + name: basicName + content: + application/json: + schema: + type: object + properties: + color: + oneOf: + - type: array # invalid definition b/c type: array is missing 'items' + - type: string + - type: integer + responses: + '200': + description: successfull fetch \ No newline at end of file diff --git a/test/e2e-cypress/tests/features/parameter-array-missing-items.js b/test/e2e-cypress/tests/features/parameter-array-missing-items.js new file mode 100644 index 00000000..b6b3b22e --- /dev/null +++ b/test/e2e-cypress/tests/features/parameter-array-missing-items.js @@ -0,0 +1,10 @@ +describe("Parameter - Invalid definition with missing array 'items' (#7375)", () => { + it("should render gracefully with fallback to default value", () => { + cy.visit("/?url=/documents/features/parameter-array-missing-items.yaml") + .get("#operations-default-get_example1") + .click() + .get("tbody > tr > .parameters-col_description textarea") + .should("exist") + .should("contains.text", "{}") + }) +})