[PR #5983] fix(common): merge path-level parameters in OpenAPI import #5449

Open
opened 2026-03-17 02:53:24 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5983
Author: @mahmoodhamdi
Created: 3/13/2026
Status: 🔄 Open

Base: mainHead: fix/openapi-path-level-params


📝 Commits (1)

  • 1b16706 fix(common): merge path-level parameters in OpenAPI import

📊 Changes

1 file changed (+25 additions, -18 deletions)

View changed files

📝 packages/hoppscotch-common/src/helpers/import-export/import/openapi/index.ts (+25 -18)

📄 Description

What does this PR do?

Fixes the OpenAPI import to correctly handle path-level parameters. Previously, only operation-level parameters were being extracted, so endpoints like /resource/{classUnitType}/{classUnitCode} would lose their path variables and render as /resource// after import.

Why?

I was trying to import an OpenAPI 3.0 spec that had path parameters defined at the path item level (which is valid per the OpenAPI specification). All the path variables were missing from the imported requests — the URL showed empty segments instead of the variable placeholders.

In the OpenAPI spec, parameters can be defined both at the path item level (shared across all operations) and at the operation level (specific to GET, POST, etc.). The spec says operation-level parameters should override path-level ones with the same name and location.

Changes

  • Modified convertPathToHoppReqs in the OpenAPI import helper to merge pathObj.parameters (path-level) with info.parameters (operation-level)
  • Operation-level parameters take precedence when there is a conflict (same name + same location)
  • The merged parameter list is used for query params, headers, and request variables extraction
  • Applied the same fix to the response original request construction

Testing

  • Verified all existing tests pass (680 tests in hoppscotch-common)
  • TypeScript type checking passes
  • ESLint passes with no new warnings
  • Tested with the OpenAPI spec from the issue:
    paths:
      /availabilityclassifications/{classUnitType}/{classUnitCode}:
        parameters:
          - name: classUnitType
            in: path
            required: true
            schema:
              type: string
          - name: classUnitCode
            in: path
            required: true
            schema:
              type: string
        get:
          summary: Test
          responses:
            '200':
              description: OK
    
    After the fix, the endpoint correctly shows /availabilityclassifications/<<classUnitType>>/<<classUnitCode>> with both variables in requestVariables.

Closes #5860


Summary by cubic

Fixes OpenAPI import in hoppscotch-common to merge path-level and operation-level parameters. Preserves path variables in endpoints, with operation-level params overriding path-level ones.

  • Bug Fixes
    • Merge pathObj.parameters with info.parameters before parsing.
    • Use the merged list for query params, headers, and requestVariables.
    • Apply the same logic when building the response’s original request.
    • Closes #5860.

Written for commit 1b1670671c. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5983 **Author:** [@mahmoodhamdi](https://github.com/mahmoodhamdi) **Created:** 3/13/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/openapi-path-level-params` --- ### 📝 Commits (1) - [`1b16706`](https://github.com/hoppscotch/hoppscotch/commit/1b1670671c21fc6848ad5a9f9163db9ecd6d7fad) fix(common): merge path-level parameters in OpenAPI import ### 📊 Changes **1 file changed** (+25 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-common/src/helpers/import-export/import/openapi/index.ts` (+25 -18) </details> ### 📄 Description ## What does this PR do? Fixes the OpenAPI import to correctly handle path-level parameters. Previously, only operation-level parameters were being extracted, so endpoints like `/resource/{classUnitType}/{classUnitCode}` would lose their path variables and render as `/resource//` after import. ## Why? I was trying to import an OpenAPI 3.0 spec that had path parameters defined at the path item level (which is valid per the OpenAPI specification). All the path variables were missing from the imported requests — the URL showed empty segments instead of the variable placeholders. In the OpenAPI spec, parameters can be defined both at the path item level (shared across all operations) and at the operation level (specific to GET, POST, etc.). The spec says operation-level parameters should override path-level ones with the same name and location. ## Changes - Modified `convertPathToHoppReqs` in the OpenAPI import helper to merge `pathObj.parameters` (path-level) with `info.parameters` (operation-level) - Operation-level parameters take precedence when there is a conflict (same name + same location) - The merged parameter list is used for query params, headers, and request variables extraction - Applied the same fix to the response original request construction ## Testing - Verified all existing tests pass (680 tests in hoppscotch-common) - TypeScript type checking passes - ESLint passes with no new warnings - Tested with the OpenAPI spec from the issue: ```yaml paths: /availabilityclassifications/{classUnitType}/{classUnitCode}: parameters: - name: classUnitType in: path required: true schema: type: string - name: classUnitCode in: path required: true schema: type: string get: summary: Test responses: '200': description: OK ``` After the fix, the endpoint correctly shows `/availabilityclassifications/<<classUnitType>>/<<classUnitCode>>` with both variables in `requestVariables`. ## Related Issues Closes #5860 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes OpenAPI import in `hoppscotch-common` to merge path-level and operation-level parameters. Preserves path variables in endpoints, with operation-level params overriding path-level ones. - **Bug Fixes** - Merge `pathObj.parameters` with `info.parameters` before parsing. - Use the merged list for query params, headers, and `requestVariables`. - Apply the same logic when building the response’s original request. - Closes #5860. <sup>Written for commit 1b1670671c21fc6848ad5a9f9163db9ecd6d7fad. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5449
No description provided.