Skip to content
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

Fix OpenAPI Route Path Conversion for Placeholder Unescaping and Relocate Function (#1422) #1423

Merged
merged 2 commits into from
Oct 20, 2024

Conversation

mdaneri
Copy link
Contributor

@mdaneri mdaneri commented Oct 18, 2024

Description:

This pull request addresses issue #1422 regarding the handling of route placeholders for OpenAPI in Pode. The main issue was the improper unescaping of route placeholders, which affected OpenAPI route path generation.

Code Changes:

  1. Function Rename:
    The function ConvertTo-PodeOpenApiRoutePath has been renamed to ConvertTo-PodeOARoutePath for consistency with Pode's OpenAPI helper naming conventions.

  2. Placeholder Unescaping:
    Placeholders (e.g., :potato) are now correctly unescaped using [regex]::Unescape to handle special characters properly in OpenAPI paths.

  3. Function Relocation:
    The ConvertTo-PodeOARoutePath function has been moved from ./Private/Route.ps1 to ./Private/OpenApi.ps1 to better align with its intended purpose and OpenAPI-specific functionality.

  4. New Pester Test:
    A new Pester 5.5 test has been added to validate the function's behavior. This test ensures that the function correctly converts routes like '/v4.2/:potato' and '/:potato' into OpenAPI-compliant formats (e.g., '/v4.2/{potato}' and '/{potato}').

Previous Implementation:

function ConvertTo-PodeOpenApiRoutePath {
    param(
        [Parameter(Mandatory = $true)]
        [string]
        $Path
    )

    return (Resolve-PodePlaceholder -Path $Path -Pattern '\:(?<tag>[\w]+)' -Prepend '{' -Append '}')
}

Updated Implementation:

function ConvertTo-PodeOARoutePath {
    param(
        [Parameter(Mandatory = $true)]
        [string]
        $Path
    )

    return ([regex]::Unescape((Resolve-PodePlaceholder -Path $Path -Pattern '\:(?<tag>[\w]+)' -Prepend '{' -Append '}')))
}

Testing:

  • Added a new Pester 5.5 test to validate the function's behavior. The test confirms that paths such as '/v4.2/:potato' and '/:potato' are correctly converted to '/v4.2/{potato}' and '/{potato}', including proper handling of special characters.

mdaneri and others added 2 commits October 18, 2024 07:23
fix Badgerati#1422
fix ConvertTo-PodeOpenApiRoutePath
Move ConvertTo-PodeOpenApiARoutePath to OpenAPI file and renamed it to ConvertTo-PodeOARoutePath

Add test
@Badgerati Badgerati linked an issue Oct 20, 2024 that may be closed by this pull request
@Badgerati Badgerati added this to the 2.11.1 milestone Oct 20, 2024
Copy link
Owner

@Badgerati Badgerati left a comment

Choose a reason for hiding this comment

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

LGTM

@Badgerati Badgerati merged commit 56e34f5 into Badgerati:develop Oct 20, 2024
15 checks passed
@Badgerati Badgerati mentioned this pull request Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dot in path got replace by \\. in openapi definition
2 participants