Skip to content

Commit

Permalink
fix(sample-gen): parameter array missing items fallback (#7376)
Browse files Browse the repository at this point in the history
* fixes #7375
  • Loading branch information
tim-lai authored Jun 24, 2021
1 parent 96d5218 commit de3d063
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/core/plugins/samples/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions test/e2e-cypress/tests/features/parameter-array-missing-items.js
Original file line number Diff line number Diff line change
@@ -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", "{}")
})
})

0 comments on commit de3d063

Please sign in to comment.