-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix: infinite recursion in buildEmptyJsonBody #4547
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
Closed
pooja-bruno
wants to merge
5
commits into
usebruno:main
from
pooja-bruno:fix/infinite-recursion-in-buildEmptyJsonBody
Closed
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ec1a7c9
Fix: infinite recursion in buildEmptyJsonBody
pooja-bruno c321d9e
add: unit test for circular ref
pooja-bruno a7c2f16
rm: comments
pooja-bruno d520791
fix: useing json object directly in tests
pooja-bruno df16ce7
mv: test to openapi-to-bruno file
pooja-bruno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
251 changes: 251 additions & 0 deletions
251
packages/bruno-converters/tests/openapi/openapi-circular-references.spec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
import { describe, it, expect } from '@jest/globals'; | ||
import openApiToBruno from '../../src/openapi/openapi-to-bruno'; | ||
|
||
describe('openapi-circular-references', () => { | ||
it('should handle simple circular references in schema correctly', async () => { | ||
const circularRefsData = JSON.parse(circularRefsJson); | ||
const brunoCollection = openApiToBruno(circularRefsData); | ||
|
||
expect(brunoCollection).toMatchObject(circularRefsOutput); | ||
}); | ||
|
||
it('should handle complex circular reference chains correctly', async () => { | ||
const complexCircularRefsData = JSON.parse(complexCircularRefsJson); | ||
|
||
const brunoCollection = openApiToBruno(complexCircularRefsData); | ||
|
||
expect(brunoCollection).toMatchObject(circularRefsOutput); | ||
}); | ||
}); | ||
|
||
const circularRefsJson = `{ | ||
"components": { | ||
"schemas": { | ||
"schema_1": { | ||
"additionalProperties": false, | ||
"description": "schema_1", | ||
"properties": { | ||
"conditions": { | ||
"$ref": "#/components/schemas/schema_1" | ||
} | ||
}, | ||
"type": "object" | ||
}, | ||
"schema_2": { | ||
"additionalProperties": false, | ||
"description": "schema_2", | ||
"properties": { | ||
"conditionGroup": { | ||
"description": "nested schema_1", | ||
"items": { "$ref": "#/components/schemas/schema_1" }, | ||
"type": "array" | ||
}, | ||
"operation": { | ||
"description": "operation", | ||
"enum": ["ANY", "ALL"], | ||
"type": "string" | ||
} | ||
}, | ||
"type": "object" | ||
} | ||
} | ||
}, | ||
"info": { | ||
"description": "circular reference openapi sample json spec", | ||
"title": "circular reference openapi sample json spec", | ||
"version": "0.1" | ||
}, | ||
"openapi": "3.0.1", | ||
"paths": { | ||
"/": { | ||
"post": { | ||
"deprecated": false, | ||
"description": "echo ping api", | ||
"operationId": "echo ping", | ||
"parameters": [], | ||
"requestBody": { | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/schema_1" | ||
} | ||
} | ||
}, | ||
"description": "echo ping api", | ||
"required": true | ||
}, | ||
"responses": { | ||
"200": { | ||
"content": { | ||
"application/json": { | ||
"example": "ping" | ||
} | ||
}, | ||
"description": "Returned if the request is successful." | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"servers": [{ "url": "https://echo.usebruno.com" }] | ||
}`; | ||
|
||
// More complex circular reference test with a longer chain | ||
const complexCircularRefsJson = `{ | ||
"components": { | ||
"schemas": { | ||
"schema_1": { | ||
"additionalProperties": false, | ||
"description": "schema_1", | ||
"properties": { | ||
"conditionGroup": { | ||
"description": "nested schema_1", | ||
"items": { "$ref": "#/components/schemas/schema_2" }, | ||
"type": "array" | ||
} | ||
}, | ||
"type": "object" | ||
}, | ||
"schema_2": { | ||
"additionalProperties": false, | ||
"description": "schema_2", | ||
"properties": { | ||
"conditionGroup": { | ||
"description": "nested schema_2", | ||
"items": { "$ref": "#/components/schemas/schema_3" }, | ||
"type": "array" | ||
} | ||
}, | ||
"type": "object" | ||
}, | ||
"schema_3": { | ||
"additionalProperties": false, | ||
"description": "schema_3", | ||
"properties": { | ||
"conditionGroup": { | ||
"description": "nested schema_3", | ||
"items": { "$ref": "#/components/schemas/schema_4" }, | ||
"type": "array" | ||
} | ||
}, | ||
"type": "object" | ||
}, | ||
"schema_4": { | ||
"additionalProperties": false, | ||
"description": "schema_4", | ||
"properties": { | ||
"conditionGroup": { | ||
"description": "nested schema_4", | ||
"items": { "$ref": "#/components/schemas/schema_5" }, | ||
"type": "array" | ||
} | ||
}, | ||
"type": "object" | ||
}, | ||
"schema_5": { | ||
"additionalProperties": false, | ||
"description": "schema_4", | ||
"properties": { | ||
"conditionGroup": { | ||
"description": "nested schema_5", | ||
"items": { "$ref": "#/components/schemas/schema_1" }, | ||
"type": "array" | ||
} | ||
}, | ||
"type": "object" | ||
}, | ||
"schema_6": { | ||
"additionalProperties": false, | ||
"description": "schema_3", | ||
"properties": { | ||
"conditionGroup": { | ||
"description": "nested schema_3", | ||
"items": { "$ref": "#/components/schemas/schema_1" }, | ||
"type": "array" | ||
}, | ||
"operation": { | ||
"description": "operation", | ||
"enum": ["ANY", "ALL"], | ||
"type": "string" | ||
} | ||
}, | ||
"type": "object" | ||
} | ||
} | ||
}, | ||
"info": { | ||
"description": "circular reference openapi sample json spec", | ||
"title": "circular reference openapi sample json spec", | ||
"version": "0.1" | ||
}, | ||
"openapi": "3.0.1", | ||
"paths": { | ||
"/": { | ||
"post": { | ||
"deprecated": false, | ||
"description": "echo ping api", | ||
"operationId": "echo ping", | ||
"parameters": [], | ||
"requestBody": { | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/schema_1" | ||
} | ||
} | ||
}, | ||
"description": "echo ping api", | ||
"required": true | ||
}, | ||
"responses": { | ||
"200": { | ||
"content": { | ||
"application/json": { | ||
"example": "ping" | ||
} | ||
}, | ||
"description": "Returned if the request is successful." | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"servers": [{ "url": "https://echo.usebruno.com" }] | ||
}`; | ||
|
||
const circularRefsOutput = { | ||
"environments": [ | ||
{ | ||
"name": "Environment 1", | ||
"variables": [ | ||
{ | ||
"enabled": true, | ||
"name": "baseUrl", | ||
"secret": false, | ||
"type": "text", | ||
"value": "https://echo.usebruno.com", | ||
}, | ||
], | ||
}, | ||
], | ||
"items": [ | ||
{ | ||
"name": "echo ping", | ||
"type": "http-request", | ||
"request": { | ||
"url": "{{baseUrl}}/", | ||
"method": "POST", | ||
"auth": { | ||
"mode": "none", | ||
}, | ||
"headers": [], | ||
"params": [], | ||
"body": { | ||
"mode": "json", | ||
} | ||
}, | ||
}, | ||
], | ||
"name": "circular reference openapi sample json spec", | ||
"version": "1", | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.