Skip to content

Commit 5065613

Browse files
author
Lucia Sarni
authored
fix(requestBody): hide read only properties (#6490)
1 parent 5fc43fa commit 5065613

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

src/core/plugins/oas3/components/request-body.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ const RequestBody = ({
135135
<tbody>
136136
{
137137
Map.isMap(bodyProperties) && bodyProperties.entrySeq().map(([key, prop]) => {
138+
if (prop.get("readOnly")) return
139+
138140
let commonExt = showCommonExtensions ? getCommonExtensions(prop) : null
139141
const required = schemaForMediaType.get("required", List()).includes(key)
140142
const type = prop.get("type")
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
openapi: 3.0.0
2+
info:
3+
title: "Swagger Test"
4+
version: "1.0.0"
5+
servers:
6+
- url: https://api.example.com/v1
7+
paths:
8+
/users:
9+
get:
10+
tags:
11+
- User
12+
summary: Get Users
13+
responses:
14+
200:
15+
description: User List
16+
content:
17+
application/json:
18+
schema:
19+
type: array
20+
items:
21+
$ref: '#/components/schemas/User'
22+
post:
23+
tags:
24+
- User
25+
summary: Create a user
26+
requestBody:
27+
content:
28+
application/x-www-form-urlencoded:
29+
schema:
30+
$ref: '#/components/schemas/User'
31+
responses:
32+
201:
33+
description: Created successfully
34+
put:
35+
tags:
36+
- User
37+
summary: Update user
38+
requestBody:
39+
content:
40+
application/x-www-form-urlencoded:
41+
schema:
42+
$ref: '#/components/schemas/User'
43+
responses:
44+
201:
45+
description: Created successfully
46+
components:
47+
schemas:
48+
User:
49+
type: object
50+
properties:
51+
id:
52+
type: integer
53+
readOnly: true
54+
name:
55+
type: string
56+
required:
57+
- name
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
describe("#6158: read-only property is not hidden in `POST/PUT`", () => {
2+
describe("POST", () => {
3+
it("should hide property 'id'", () => {
4+
cy.visit("/?url=/documents/bugs/6158.yaml")
5+
.get("#operations-User-post_users")
6+
.click()
7+
.get(".parameters[data-property-name='id']")
8+
.should("not.exist")
9+
.get(".parameters[data-property-name='name']")
10+
.should("exist")
11+
})
12+
it("should hide property 'id' when trying it out", () => {
13+
cy.visit("/?url=/documents/bugs/6158.yaml")
14+
.get("#operations-User-post_users")
15+
.click()
16+
.get(".try-out__btn")
17+
.click()
18+
.get(".parameters[data-property-name='id']")
19+
.should("not.exist")
20+
.get("input[placeholder='id']")
21+
.should("not.exist")
22+
.get(".parameters[data-property-name='name']")
23+
.should("exist")
24+
.get("input[placeholder='name']")
25+
.should("exist")
26+
})
27+
})
28+
describe("PUT", () => {
29+
it("should hide property 'id'", () => {
30+
cy.visit("/?url=/documents/bugs/6158.yaml")
31+
.get("#operations-User-put_users")
32+
.click()
33+
.get(".parameters[data-property-name='id']")
34+
.should("not.exist")
35+
.get(".parameters[data-property-name='name']")
36+
.should("exist")
37+
})
38+
it("should hide property 'id' when trying it out", () => {
39+
cy.visit("/?url=/documents/bugs/6158.yaml")
40+
.get("#operations-User-put_users")
41+
.click()
42+
.get(".try-out__btn")
43+
.click()
44+
.get(".parameters[data-property-name='id']")
45+
.should("not.exist")
46+
.get("input[placeholder='id']")
47+
.should("not.exist")
48+
.get(".parameters[data-property-name='name']")
49+
.should("exist")
50+
.get("input[placeholder='name']")
51+
.should("exist")
52+
})
53+
})
54+
})

0 commit comments

Comments
 (0)