Skip to content

Commit 53829f1

Browse files
mathis-mtim-lai
andauthored
fix: required properties (#7206)
* fix: required properties schema required properties should not be treated like required: true. this lead to objects that requires properties being treated as required itself * test: try-it-out-schema-required-override-allowed Co-authored-by: Tim Lai <[email protected]>
1 parent 0e770b3 commit 53829f1

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

src/core/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ function validateValueBySchema(value, schema, requiredByParam, bypassRequiredChe
429429
let minItems = schema.get("minItems")
430430
let pattern = schema.get("pattern")
431431

432-
const schemaRequiresValue = requiredByParam || requiredBySchema
432+
const schemaRequiresValue = requiredByParam || requiredBySchema === true
433433
const hasValue = value !== undefined && value !== null
434434
const isValidEmpty = !schemaRequiresValue && !hasValue
435435

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
swagger: '2.0'
2+
info:
3+
version: '1.0'
4+
title: "schema required properties should not be treated like required: true"
5+
paths:
6+
'/v1/any-path':
7+
put:
8+
summary: lorem
9+
operationId: setDeliveryLocation
10+
produces:
11+
- application/json
12+
parameters:
13+
- in: body
14+
name: body
15+
description: ipsum
16+
required: false
17+
schema:
18+
$ref: '#/definitions/TopModel'
19+
responses:
20+
'200':
21+
description: successful operation
22+
definitions:
23+
TopModel:
24+
type: object
25+
properties:
26+
testProperty:
27+
$ref: '#/definitions/NestedModel'
28+
NestedModel:
29+
type: object
30+
required:
31+
- validated
32+
properties:
33+
validated:
34+
type: boolean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
describe("Try It Out: schema required properties can be overriden", () => {
2+
it("should execute", () => {
3+
cy
4+
.visit("?tryItOutEnabled=true&url=/documents/features/try-it-out-schema-required-override-allowed.yaml")
5+
.get("#operations-default-setDeliveryLocation")
6+
.click()
7+
.get(".body-param__text")
8+
.should("include.value", "testProperty")
9+
.clear() // swagger-ui will auto insert "{}" into textarea
10+
.get(".execute-wrapper > .btn")
11+
.click()
12+
.get(".curl-command")
13+
.should("exist")
14+
})
15+
})

0 commit comments

Comments
 (0)