Skip to content

fix(openapi): normalize path parameters to curly brace notation for Swagger compatibility#704

Merged
ozziest merged 4 commits intoaxe-api:developfrom
mahendra7041:fix/normalize-openapi-path-params
Mar 1, 2026
Merged

fix(openapi): normalize path parameters to curly brace notation for Swagger compatibility#704
ozziest merged 4 commits intoaxe-api:developfrom
mahendra7041:fix/normalize-openapi-path-params

Conversation

@mahendra7041
Copy link
Copy Markdown
Contributor

Description

This PR fixes the issue with dynamic path parameters in the auto-generated Swagger documentation.

Dynamic routes are now generated using the OpenAPI-compliant {param} syntax so endpoints execute correctly.

Closes #703

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an incompatibility issue where dynamic path parameters in the generated Swagger documentation were not correctly recognized, leading to execution problems. By standardizing the path parameter format to the OpenAPI-compliant curly brace notation, the change ensures that all dynamic routes are properly interpreted and functional within the Swagger UI and related tools.

Highlights

  • Swagger Compatibility: Implemented a fix to ensure dynamic path parameters in auto-generated Swagger documentation are OpenAPI-compliant.
  • Path Normalization: Dynamic routes are now normalized to use the {param} syntax instead of :param notation, resolving issues with endpoint execution in Swagger.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • packages/axe-api/src/Builders/SwaggerBuilder.ts
    • Introduced path normalization logic to convert dynamic route parameters from ':param' to '{param}' format.
    • Updated the paths and modelPatterns objects to use the normalized path for consistency with OpenAPI specifications.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly normalizes path parameters from :param to the OpenAPI-compliant {param} format for standard endpoints. This is a good fix for ensuring compatibility with tools like Swagger UI. However, the same normalization is missing for custom routes, which could lead to them being represented incorrectly in the generated documentation. I've left a specific comment on how to address this to make the fix complete.

for (const endpoint of docs.get()) {
if (paths[endpoint.url] === undefined) {
paths[endpoint.url] = {};
const normalizePath = endpoint.url.replace(/:([^/]+)/g, "{$1}");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

This is a good fix for standard endpoints. To improve reusability and ensure all routes are handled consistently, I recommend extracting this normalization logic into a dedicated helper function.

Currently, the custom routes processed later in this function (lines 643-660) are not being normalized. This means that custom routes with parameters (e.g., /users/:id/action) will still have incorrect paths in the generated OpenAPI specification. Using a shared helper function for both standard and custom routes would solve this issue and make the code more maintainable.

Suggested change
const normalizePath = endpoint.url.replace(/:([^/]+)/g, "{$1}");
const normalizePath = normalizeSwaggerPath(endpoint.url);

@ozziest ozziest requested a review from Copilot February 28, 2026 19:40
@ozziest ozziest changed the base branch from master to develop February 28, 2026 19:42
Copy link
Copy Markdown

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 updates the Swagger/OpenAPI document generation so that dynamic route parameters are emitted in OpenAPI-compatible curly-brace syntax ({param}) instead of Express-style colon syntax (:param), fixing “try it out” execution for parameterized endpoints (Issue #703).

Changes:

  • Added a normalizeSwaggerPath() helper to convert :param segments to {param}.
  • Updated generated paths and modelPatterns keys to use the normalized path for both standard and custom documented routes.

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


const normalizeSwaggerPath = (path: string) => {
return path.replace(/:([^/]+)/g, "{$1}");
}
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

normalizeSwaggerPath is missing a terminating semicolon after the function expression, which is inconsistent with the surrounding const ... = (...) => { ... }; style in this file and can violate the project's lint/format rules. Add the semicolon after the closing brace.

Suggested change
}
};

Copilot uses AI. Check for mistakes.
Comment on lines +621 to +623
const normalizePath = normalizeSwaggerPath(endpoint.url);
if (paths[normalizePath] === undefined) {
paths[normalizePath] = {};
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

The local variable name normalizePath is misleading (it reads like a function). Since it holds the normalized path string, consider renaming it to normalizedPath (and update its uses in this block) to make the code easier to follow.

Copilot uses AI. Check for mistakes.
Comment on lines +620 to +641
@@ -634,26 +638,27 @@ const generateDocumentation = async () => {
path.requestBody = requestBody;
}

paths[endpoint.url][endpoint.method.toLowerCase()] = path;
paths[normalizePath][endpoint.method.toLowerCase()] = path;
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

This PR changes the generated OpenAPI paths keys to use {param} syntax, but there are no tests asserting the new behavior. Since SwaggerBuilder.spec.js already exists for this module, add coverage that verifies (1) an endpoint url like /api/v1/books/:id becomes a paths entry /api/v1/books/{id}, and (2) custom routes are normalized similarly, so Swagger "try it out" uses the substituted parameter value.

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Mar 1, 2026

@ozziest ozziest merged commit 9293445 into axe-api:develop Mar 1, 2026
8 of 12 checks passed
@ozziest
Copy link
Copy Markdown
Member

ozziest commented Mar 1, 2026

@mahendra7041 , thank you very much for your contribution. 🤗

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.

Dynamic Path Parameters Not Functioning in Auto-Generated Swagger Documentation

3 participants