Skip to content

Conversation

@goneri
Copy link

@goneri goneri commented Oct 8, 2025

parameters can be defined at the path and operation levels.

Path level:

A list of parameters that are applicable for all the operations described
under this path.These parameters can be overridden at the operation level,
but cannot be removed there. The list MUST NOT include duplicated parameters.
A unique parameter is defined by a combination of a name and location. The
list can use the Reference Object to link to parameters that are defined
in the OpenAPI Object's components.parameters.

Summary by CodeRabbit

  • Bug Fixes

    • Path-level parameters are now correctly merged with operation-level parameters; operation-level values take precedence to prevent conflicts and incorrect requests.
    • Improved handling when path parameters are optional or missing, reducing edge-case errors and improving API compatibility.
  • Public API

    • Callers should expect optional path-level parameters to be considered when building requests; interfaces now accept and respect these parameters.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 8, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

generateInputSchemaAndDetails now accepts optional path-level parameters and merges them with operation-level parameters; operation-level parameters override on matching name+in. extractToolsFromApi now forwards pathItem.parameters. Returned outputs remain inputSchema, parameters, and requestBodyContentType.

Changes

Cohort / File(s) Summary
Parser: parameter signature & merge logic
src/parser/extract-tools.ts
Updated generateInputSchemaAndDetails signature to (operation, pathParameters?). Merges path-level and operation-level parameters into allParameters, deduplicating by name+in with operation parameters taking precedence. extractToolsFromApi now passes pathItem.parameters. JSDoc updated.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Extractor as extractToolsFromApi
  participant SchemaGen as generateInputSchemaAndDetails
  participant OpParams as Operation.parameters
  participant PathParams as PathItem.parameters (optional)

  Extractor->>SchemaGen: generateInputSchemaAndDetails(operation, pathItem.parameters?)
  SchemaGen->>OpParams: read operation.parameters
  SchemaGen->>PathParams: read pathParameters (if present)
  note over SchemaGen: Merge parameters\n- Build allParameters from path + operation\n- Deduplicate by name+in\n- Operation parameters override path parameters on conflict
  SchemaGen-->>Extractor: return { inputSchema, parameters, requestBodyContentType }
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review deduplication by name+in and precedence implementation in src/parser/extract-tools.ts.
  • Verify TypeScript signature and JSDoc changes and any external call sites.

Poem

I hop through code with careful cheer,
Path and op parameters draw near.
When names collide, the op will steer,
Schemas tidy, inputs clear.
A carrot nudge — the merge is done, hooray! 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "parameters: merge the path and operation parameters" directly and accurately describes the main change in the changeset. The PR's primary objective is to implement proper handling and merging of path-level and operation-level parameters in OpenAPI parsing, where operation parameters can override path parameters. The title is concise, specific, and uses clear descriptive language that a teammate scanning git history would immediately understand without being vague or generic.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8ee9fc3 and 64b195b.

📒 Files selected for processing (1)
  • src/parser/extract-tools.ts (2 hunks)
🔇 Additional comments (3)
src/parser/extract-tools.ts (3)

84-84: LGTM: Call site correctly updated to pass path-level parameters.

The call to generateInputSchemaAndDetails now correctly passes pathItem.parameters, enabling support for path-level parameters as intended.


116-126: LGTM: Function signature correctly updated.

The signature change appropriately adds support for path-level parameters while maintaining backward compatibility through the optional parameter.


209-209: LGTM: Return statement correctly uses merged parameters.

The function now returns allParameters, which correctly includes both path-level and operation-level parameters after merging.

goneri added a commit to goneri/poc-aap-mcp that referenced this pull request Oct 8, 2025
@goneri goneri force-pushed the goneri/parameters-merge-the-path-and-operation-parameters_14458 branch 2 times, most recently from f02524d to cb02fb1 Compare October 17, 2025 19:39
@harsha-iiiv
Copy link
Owner

@coderabbitai review this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 28, 2025

@harsha-iiiv: I'll review the changes in this PR. This PR implements proper handling of path-level and operation-level parameter merging in OpenAPI parsing, where operation parameters can override path parameters based on name and location.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@harsha-iiiv harsha-iiiv requested a review from Copilot October 28, 2025 00:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements proper merging of path-level and operation-level parameters according to the OpenAPI specification. Path-level parameters are defined once and apply to all operations under a path, while operation-level parameters can override them.

Key Changes:

  • Modified generateInputSchemaAndDetails to accept optional path parameters and merge them with operation parameters
  • Updated parameter merging logic to ensure operation-level parameters override path-level parameters with the same name and location
  • Updated function call in extractToolsFromApi to pass path-level parameters

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@goneri goneri force-pushed the goneri/parameters-merge-the-path-and-operation-parameters_14458 branch from cb02fb1 to 3e5d690 Compare October 28, 2025 14:04
`parameters` can be defined at the path and operation levels.

Path level:

```
A list of parameters that are applicable for all the operations described
under this path.These parameters can be overridden at the operation level,
but cannot be removed there. The list MUST NOT include duplicated parameters.
A unique parameter is defined by a combination of a name and location. The
list can use the Reference Object to link to parameters that are defined
in the OpenAPI Object's components.parameters.
```
@goneri goneri force-pushed the goneri/parameters-merge-the-path-and-operation-parameters_14458 branch from 3e5d690 to abdcace Compare October 28, 2025 14:07
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
src/parser/extract-tools.ts (1)

133-156: Concatenation order is now correct! However, unsafe type casting remains unresolved.

The merge logic now correctly processes path parameters first, then operation parameters (pathParametersResolved.concat(operationParameters)), allowing operation parameters to override path parameters as required by the OpenAPI specification.

However, the unsafe casting on lines 134 and 138 still needs to be addressed. Parameters can be ReferenceObject types containing only a $ref property. Casting without resolving references will cause runtime errors when the code attempts to access properties like name, in, or schema on unresolved references.

Before casting, check for and resolve ReferenceObject types:

 const operationParameters: OpenAPIV3.ParameterObject[] = Array.isArray(operation.parameters)
-   ? operation.parameters.map((p) => p as OpenAPIV3.ParameterObject)
+   ? operation.parameters.map((p) => {
+       if ('$ref' in p) {
+         console.warn(`Unresolved parameter reference: ${p.$ref}`);
+         // Skip or throw error - references should be resolved before this point
+         throw new Error(`Parameter reference ${p.$ref} must be resolved before merging`);
+       }
+       return p as OpenAPIV3.ParameterObject;
+     })
   : [];

 const pathParametersResolved: OpenAPIV3.ParameterObject[] = Array.isArray(pathParameters)
-   ? pathParameters.map((p) => p as OpenAPIV3.ParameterObject)
+   ? pathParameters.map((p) => {
+       if ('$ref' in p) {
+         console.warn(`Unresolved parameter reference: ${p.$ref}`);
+         throw new Error(`Parameter reference ${p.$ref} must be resolved before merging`);
+       }
+       return p as OpenAPIV3.ParameterObject;
+     })
   : [];

Alternatively, if references are expected to be resolved elsewhere in the codebase, verify that resolution happens before this function is called.

🧹 Nitpick comments (1)
src/parser/extract-tools.ts (1)

147-147: Consider renaming pathParam to existing for clarity.

The variable name pathParam is misleading since allParameters contains both path and operation parameters at different stages of iteration.

   const existingIndex = allParameters.findIndex(
-    (pathParam) => pathParam.name === param.name && pathParam.in === param.in
+    (existing) => existing.name === param.name && existing.in === param.in
   );
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e5d690 and abdcace.

📒 Files selected for processing (1)
  • src/parser/extract-tools.ts (2 hunks)
🔇 Additional comments (2)
src/parser/extract-tools.ts (2)

83-86: LGTM! Call site correctly updated to pass path-level parameters.

The call to generateInputSchemaAndDetails now correctly includes pathItem.parameters, enabling the function to merge path-level and operation-level parameters as intended.


118-124: LGTM! Function signature properly updated with clear documentation.

The function signature correctly accepts optional path-level parameters, and the JSDoc clearly documents the new parameter's purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants