Repository navigation
fix(converters): Make OpenAPI→Bruno conversion use correct default parameter serialization methods - #7783
Conversation
…on methods for parameters
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (2)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository: usebruno/bruno/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThis PR refactors OpenAPI parameter value conversion by introducing a helper function Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 📦 Arrays now dance to location's tune, Comment |
There was a problem hiding this comment.
Pull request overview
Updates the OpenAPI → Bruno converter to align default array parameter serialization with OpenAPI v3 defaults per parameter location (comma-joined for path/header, exploded into multiple entries for query), and adds regression tests to validate these behaviors.
Changes:
- Adjusted parameter value extraction to emit multiple Bruno param entries for array values in
query(OAS default explode behavior). - Updated handling of array defaults/examples to avoid JSON-stringifying arrays for
path/headerparameters. - Added a comprehensive test suite covering array serialization defaults across
path,header,query, and unmappedcookie.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/bruno-converters/src/openapi/openapi-to-bruno.js | Updates parameter entry generation to follow OAS default serialization rules for arrays by location. |
| packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-path-parameters.spec.js | Adds coverage for default array serialization across parameter locations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const paramEntriesFromValue = (val, paramIn) => { | ||
| const explodeByDefault = paramIn === 'query' || paramIn === 'cookie'; |
There was a problem hiding this comment.
paramEntriesFromValue treats only param.in === 'query' as explode-by-default. However this converter also supports the non-standard in: 'querystring' (see later mapping in transformOpenapiRequestItem), so array values for querystring params will currently be serialized as a single comma-joined entry instead of one entry per item. Consider treating 'querystring' the same as 'query' in the explode default logic (and ideally add a small test for an array querystring param to lock this in).
| const paramEntriesFromValue = (val, paramIn) => { | |
| const explodeByDefault = paramIn === 'query' || paramIn === 'cookie'; | |
| // Bruno also supports non-standard `querystring` params, which should behave like `query`. | |
| const paramEntriesFromValue = (val, paramIn) => { | |
| const explodeByDefault = paramIn === 'query' || paramIn === 'querystring' || paramIn === 'cookie'; |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/bruno-converters/src/openapi/openapi-to-bruno.js (1)
75-80:⚠️ Potential issue | 🟠 MajorPreserve explicit empty array defaults.
Line 78uses a truthy check, soschema.default: []is treated as “no default” and falls back to enum-derived entries. That changes intended behavior for valid specs.Suggested fix
- if (arrayDefault) { + if (arrayDefault !== null) { return paramEntriesFromValue(arrayDefault, param.in); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bruno-converters/src/openapi/openapi-to-bruno.js` around lines 75 - 80, The code treats an explicit empty array default (schema.default = []) as falsy and skips it; change the conditional so empty arrays are preserved: keep the existing assignment to arrayDefault (const arrayDefault = schema.default !== undefined && Array.isArray(schema.default) ? schema.default : null) but replace the truthy check if (arrayDefault) with an explicit null-check (if (arrayDefault !== null)) or test Array.isArray(schema.default) before calling paramEntriesFromValue(arrayDefault, param.in) so paramEntriesFromValue is invoked for [] as well; reference symbols: arrayDefault, schema.default, paramEntriesFromValue, param.in.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-path-parameters.spec.js`:
- Around line 705-732: Add a new test case in the same spec that calls
openApiToBruno with a path parameter whose schema has type: 'array', items.enum:
['a','b','c'] and default: [] to ensure an explicit empty default does not fall
back to enum values; locate the pattern around the existing test that finds the
parameter via result.items.find(i => i.name === 'Get by
types').request.params.find(p => p.name === 'types') and assert that for
default: [] the resulting typesParam.value is '' (empty string) and
typesParam.enabled is false.
---
Outside diff comments:
In `@packages/bruno-converters/src/openapi/openapi-to-bruno.js`:
- Around line 75-80: The code treats an explicit empty array default
(schema.default = []) as falsy and skips it; change the conditional so empty
arrays are preserved: keep the existing assignment to arrayDefault (const
arrayDefault = schema.default !== undefined && Array.isArray(schema.default) ?
schema.default : null) but replace the truthy check if (arrayDefault) with an
explicit null-check (if (arrayDefault !== null)) or test
Array.isArray(schema.default) before calling paramEntriesFromValue(arrayDefault,
param.in) so paramEntriesFromValue is invoked for [] as well; reference symbols:
arrayDefault, schema.default, paramEntriesFromValue, param.in.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 64590c63-5a6e-450d-9716-7aaa4e9b159d
📒 Files selected for processing (2)
packages/bruno-converters/src/openapi/openapi-to-bruno.jspackages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-path-parameters.spec.js
| it('items.enum default array', () => { | ||
| const spec = { | ||
| openapi: '3.0.0', | ||
| info: { title: 'API', version: '1.0.0' }, | ||
| servers: [{ url: 'https://api.example.com' }], | ||
| paths: { | ||
| '/items/{types}': { | ||
| get: { | ||
| summary: 'Get by types', | ||
| operationId: 'getByTypes', | ||
| parameters: [ | ||
| { | ||
| name: 'types', | ||
| in: 'path', | ||
| required: true, | ||
| schema: { type: 'array', items: { type: 'string', enum: ['a', 'b', 'c'] }, default: ['a', 'b'] } | ||
| } | ||
| ], | ||
| responses: { 200: { description: 'OK' } } | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| const result = openApiToBruno(spec); | ||
| const typesParam = result.items.find((i) => i.name === 'Get by types').request.params.find((p) => p.name === 'types'); | ||
| expect(typesParam.value).toBe('a,b'); | ||
| expect(typesParam.enabled).toBe(true); | ||
| }); |
There was a problem hiding this comment.
Add an empty-array default regression case.
Please add a case where schema.default is [] (with items.enum present) to ensure explicit empty defaults do not fall back to enum values.
As per coding guidelines: Cover both the "happy path" and the realistically problematic paths.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-path-parameters.spec.js`
around lines 705 - 732, Add a new test case in the same spec that calls
openApiToBruno with a path parameter whose schema has type: 'array', items.enum:
['a','b','c'] and default: [] to ensure an explicit empty default does not fall
back to enum values; locate the pattern around the existing test that finds the
parameter via result.items.find(i => i.name === 'Get by
types').request.params.find(p => p.name === 'types') and assert that for
default: [] the resulting typesParam.value is '' (empty string) and
typesParam.enabled is false.
…ternal' into fix/openapi-parameters-default-serialization-methods
c14584c
into
usebruno:fix/openapi-parameters-default-serialization-methods-internal
… serialization (#9400) * fix(converters): Make OpenAPI→Bruno conversion use correct default parameter serialization methods (#7783) * chore: remove merge-related comments * fix: make openapi to bruno conversion use correct default serialization methods for parameters --------- Co-authored-by: Arpit <[email protected]> * fix:OpenAPI to Bruno conversion missing standard parameter serialization (#9391) * fix: comments addressed * fix: comments addressed * fix: comments addressed * fix: comments addressed * fix: comments addressed --------- Co-authored-by: Alexander Roidl <[email protected]> Co-authored-by: Arpit <[email protected]>
Description
The OpenAPI specification v3 states certain methods for how parameter values should be serialized. As of now Bruno aims to support only primitive and array values, while ignoring
styleandexplodeinstructions. Therefore I was looking at the standard serialization method for each type of parameter in their documentation on parameter serialization.The aim of this PR is to fix the default serialization methods for several scenarios/parameter types, as seen below:
explode: false
→ comma-join
param.example: [3,4,5]"3,4,5""3,4,5"param.examples[0].value: [10,20,30]"10,20,30""10,20,30"schema.default: ["admin","user"]"admin,user"'["admin","user"]'schema.example: [7,8,9]"7,8,9""7,8,9"schema.examples: [[1,2,3]]"1,2,3""[]"items.enum+schema.default: ["a","b"]"a,b"'["a","b"]'explode: false
→ comma-join
param.example: [1,2,3]"1,2,3""1,2,3"param.examples[0].value: ["a","b","c"]"a,b,c""a,b,c"schema.default: ["read","write"]"read,write"'["read","write"]'schema.example: [4,5,6]"4,5,6""4,5,6"schema.examples: [["x","y","z"]]"x,y,z""[]"explode: true
→ one entry per item
param.example: [3,4,5]["3","4","5"]"3,4,5"param.examples[0].value: ["foo","bar","baz"]["foo","bar","baz"]"foo,bar,baz"schema.default: ["active","pending"]["active","pending"]'["active","pending"]'schema.example: ["red","green","blue"]["red","green","blue"]"red,green,blue"schema.examples: [["foo","bar","baz"]]["foo","bar","baz"]"[]"This can be validated by running the updated tests of this branch on the current
mainbranch:git checkout main git checkout fix/openapi-parameters-default-serialization-methods -- packages/bruno-converters/tests/openapi/openapi-to-bruno/openapi-path-parameters.spec.js npm run test --workspace=packages/bruno-convertersContribution Checklist:
Summary by CodeRabbit