Skip to content

Commit bb2bac5

Browse files
lukaszzazulakkirill-of-turov
authored andcommitted
fix(utils): disallow schema type array value string (swagger-api#10691)
* fix(utils): disallow schema type array value string
1 parent 7b7d1b7 commit bb2bac5

4 files changed

Lines changed: 37 additions & 3 deletions

File tree

src/core/utils/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ function validateValueBySchema(value, schema, requiredByParam, bypassRequiredChe
466466
let stringCheck = type === "string" && value
467467
let arrayCheck = type === "array" && Array.isArray(value) && value.length
468468
let arrayListCheck = type === "array" && Im.List.isList(value) && value.count()
469-
let arrayStringCheck = type === "array" && typeof value === "string" && value
470469
let fileCheck = type === "file" && value instanceof win.File
471470
let booleanCheck = type === "boolean" && (value || value === false)
472471
let numberCheck = type === "number" && (value || value === 0)
@@ -475,7 +474,7 @@ function validateValueBySchema(value, schema, requiredByParam, bypassRequiredChe
475474
let objectStringCheck = type === "object" && typeof value === "string" && value
476475

477476
const allChecks = [
478-
stringCheck, arrayCheck, arrayListCheck, arrayStringCheck, fileCheck,
477+
stringCheck, arrayCheck, arrayListCheck, fileCheck,
479478
booleanCheck, numberCheck, integerCheck, objectCheck, objectStringCheck,
480479
]
481480

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
describe("Try it out with schema type array but example type string", () => {
2+
it("shows a validation error message when Execute is clicked", () => {
3+
cy
4+
.visit("?tryItOutEnabled=true&url=/documents/features/try-it-out-schema-type-array-example-type-string.yaml")
5+
.get("#operations-default-get_")
6+
.click()
7+
.get(".btn.execute")
8+
.click()
9+
.get(".validation-errors")
10+
.should("exist")
11+
})
12+
})
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
openapi: 3.0.3
2+
info:
3+
title: test
4+
version: 1.0.0
5+
paths:
6+
/:
7+
get:
8+
parameters:
9+
- in: query
10+
name: test
11+
required: true
12+
schema:
13+
type: array
14+
example: 'test1'
15+
items:
16+
type: string
17+
enum:
18+
- 'test1'
19+
- 'test2'
20+
- 'test3'
21+
responses:
22+
default:
23+
description: ok

test/unit/core/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ describe("utils", () => {
749749
type: "array"
750750
}
751751
value = "[1]"
752-
assertValidateParam(param, value, [])
752+
assertValidateParam(param, value, ["Required field is not provided"])
753753

754754
// valid array, items match type
755755
param = {

0 commit comments

Comments
 (0)