Closed FabianDach closed 2 days ago
I was able to reproduce the bug. I'll be happy to work on this issue. 👍
Hi @FabianDach, thanks for reporting this. @arshan1019, please go for it!
I also got problem with PUT Request's body. It's seem like that with a large request, thee payload has been stripped down some byte in the end, make the request failed.
I redirected to a proxy and find out that.
Hey @directentis1 @FabianDach @sreelakshmi-bruno
I don't think the issue is specific to PUT
requests. The issue is there regardless of the Request Method
Here’s my YAML file for reference:
openapi: 3.0.3
info:
title: Example API
version: 1.0.0
paths:
/:
patch:
operationId: testPatch
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/test"
put:
operationId: testPut
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/test"
post:
operationId: testPost
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/test"
components:
schemas:
test:
type: object
properties:
id:
format: int64
type: integer
name:
type: string
The output:
for PATCH
Request:
for PUT
Request:
for POST
Request:
Notice the POST
Request body is also not imported.
This is the code responsible for resolution of the references.
I suspect the visitedItems
Set that is shared among the recursive calls. When the first reference is resolved, the visitedItems
set is updated with the refPath
. Now for the 2nd and 3rd (considering the linked yaml file in the above comment), the code checks if the refPath
already present in the visitedItems
Set. Since its already present in the Set and marked as visited it does not parse (resolve) the reference resulting in no body for the 2nd and 3rd requests.
Additionally, during the recursive resolution process, if a $ref is encountered again, the function uses the shared visitedItems
Pls correct me if I am wrong. I am new to this stuff.
@sreelakshmi-bruno @directentis1 @FabianDach Hopefully, I was able to solve the issue. The key was to pass a new instance of visitedItems Set for each recursive call by using new Set(visitedItems). This way, each branch of the recursion maintains its own tracking of resolved references.
After the fix: Output:
https://github.com/user-attachments/assets/a533d4a5-ed07-4b5c-9aa9-7aff04e8a04e
generated .bru files 👉
testPatch.bru
meta {
name: testPatch
type: http
seq: 3
}
post {
url: {{baseUrl}}/
body: json
auth: none
}
body:json {
{
"id": "",
"name": ""
}
}
testPost.bru
meta {
name: testPost
type: http
seq: 1
}
patch {
url: {{baseUrl}}/
body: json
auth: none
}
body:json {
{
"id": "",
"name": ""
}
}
testPut.bru
meta {
name: testPut
type: http
seq: 2
}
put {
url: {{baseUrl}}/
body: json
auth: none
}
body:json {
{
"id": "",
"name": ""
}
}
what do you guys think?
Hi @arshan1019, the solution looks good! Please raise a PR for this. Thanks!
Sure
@sreelakshmi-bruno I have raised the PR -> #3459
Thanks @arshan1019 !
PR has been merged. This is set to be released in v1.35.0
You're Welcome @helloanoop 👍
I have checked the following:
Describe the bug
When importing a collection from an openapi yaml file, the request body will not be imported if the http method is PUT.
.bru file to reproduce the bug
YAML FILE:
POST bru:
PUT .bru:
Screenshots/Live demo link