Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PUT body does not get imported from openapi yaml file #3383

Open
2 tasks done
FabianDach opened this issue Oct 29, 2024 · 9 comments · May be fixed by #3459
Open
2 tasks done

PUT body does not get imported from openapi yaml file #3383

FabianDach opened this issue Oct 29, 2024 · 9 comments · May be fixed by #3459
Assignees
Labels
bug Something isn't working

Comments

@FabianDach
Copy link

I have checked the following:

  • I use the newest version of bruno.
  • I've searched existing issues and found nothing related to my issue.

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:

---
openapi: 3.0.3
info:
  title: Example API
  version: 1.0.0
paths:
  /:
    post:
      operationId: testPost
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/test"
    put:
      operationId: testPut
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/test"

components:
  schemas:
    test:
      type: object
      properties:
        id:
          format: int64
          type: integer
        name:
          type: string

POST bru:


meta {
  name: testPost
  type: http
  seq: 1
}

post {
  url: {{baseUrl}}/test/
  body: json
  auth: none
}

body:json {
  {
    "id": "",
    "name": ""
  }
}

PUT .bru:


meta {
  name: testPut
  type: http
  seq: 2
}

put {
  url: {{baseUrl}}/test/
  body: json
  auth: none
}

Screenshots/Live demo link

image
image

@FabianDach FabianDach added the bug Something isn't working label Oct 29, 2024
@arshan1019
Copy link

I was able to reproduce the bug. I'll be happy to work on this issue. 👍

@sreelakshmi-bruno
Copy link
Collaborator

Hi @FabianDach, thanks for reporting this. @arshan1019, please go for it!

@directentis1
Copy link

directentis1 commented Nov 5, 2024

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.

@arshan1019
Copy link

arshan1019 commented Nov 5, 2024

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:
Patch Request

for PUT Request:
PUT Request

for POST Request:
Post Request
Notice the POST Request body is also not imported.

@arshan1019
Copy link

arshan1019 commented Nov 5, 2024

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

image

Pls correct me if I am wrong. I am new to this stuff.

@arshan1019
Copy link

arshan1019 commented Nov 5, 2024

@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:

2024-11-06.02-07-36.-.Trim.mp4

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?

@sreelakshmi-bruno
Copy link
Collaborator

Hi @arshan1019, the solution looks good! Please raise a PR for this. Thanks!

@arshan1019
Copy link

Sure

arshan1019 added a commit to arshan1019/bruno that referenced this issue Nov 8, 2024
@arshan1019 arshan1019 linked a pull request Nov 8, 2024 that will close this issue
5 tasks
@arshan1019
Copy link

@sreelakshmi-bruno I have raised the PR -> #3459

@anusree-bruno anusree-bruno assigned lohxt1 and unassigned lohxt1 Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants