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

Dot in path got replace by \\. in openapi definition #1422

Closed
cocazoulou opened this issue Oct 17, 2024 · 1 comment · Fixed by #1423
Closed

Dot in path got replace by \\. in openapi definition #1422

cocazoulou opened this issue Oct 17, 2024 · 1 comment · Fixed by #1423
Labels
Milestone

Comments

@cocazoulou
Copy link

cocazoulou commented Oct 17, 2024

Describe the Bug

If I have a . in my uri path it got replace by \\. in openapi definition and break swagger parameter replacement.

Steps To Reproduce

Here my server.ps1 file

server.ps1
Start-PodeServer {
    
	New-PodeLoggingMethod -Terminal | Enable-PodeRequestLogging
	New-PodeLoggingMethod -Terminal | Enable-PodeErrorLogging
	Add-PodeEndpoint -Address 127.0.0.1 -Port 8080 -Protocol Http
	#Initialize OpenApi
	Enable-PodeOpenApi -Path '/docs/openapi' -DefinitionTag 'user' -DisableMinimalDefinitions

	# OpenApi Info
	Add-PodeOAInfo -Title 'Swagger Petstore - OpenAPI 3.0' `
		-Version 1.0.17 `
		-Description 'This is a sample Pet Store Server based on the OpenAPI 3.0 specification. ...' `
		-TermsOfService 'http://swagger.io/terms/' `
		-LicenseName 'All rights reserved' `
		-LicenseUrl 'https://localhost' `
		-ContactName 'API Support' `
		-ContactEmail '[email protected]' `
		-ContactUrl 'http://example.com/support' `
		-DefinitionTag 'user'

	# Endpoint for the API
	Add-PodeOAServerEndpoint -url '/api' -Description 'default endpoint' -DefinitionTag 'user'

	# OpenApi external documentation links
	$extDoc = New-PodeOAExternalDoc -Description 'Find out more about Swagger' -Url 'http://swagger.io'
	$extDoc | Add-PodeOAExternalDoc

	# OpenApi documentation viewer
	Enable-PodeOAViewer -Type Swagger -Path '/docs/swagger'  -Title 'Swagger' -DefinitionTag 'user'
	Enable-PodeOAViewer -Bookmarks -Path '/docs' -Title 'Bookmark' -DefinitionTag 'user'
	
	Select-PodeOADefinition -tag 'user' -ScriptBlock {
		Add-PodeRouteGroup -Path '/api' -Routes {
			Add-PodeRoute -Method Get -Path '/v4.2/:potato' -ScriptBlock {
				Set-PodeResposneStatus -Code 400
				Write-PodeJsonResponse -Value $WebEvent.Parameters['potato']
			} -Passthru | Set-PodeOARouteInfo -Summary 'Failed' -Description 'Failed' -OperationId 'Failed' -Passthru | `
				Set-PodeOARequest -PassThru -Parameters ( 
				New-PodeOAStringProperty -Name 'potato' -Description 'Potato Name' -Required | 
				ConvertTo-PodeOAParameter -In Path -Required 
			)
			Add-PodeRoute -Method Get -Path '/:potato' -ScriptBlock {
				Set-PodeResposneStatus -Code 200
				Write-PodeJsonResponse -Value $WebEvent.Parameters['potato']
			} -Passthru | Set-PodeOARouteInfo -Summary 'Worked' -Description 'Worked' -OperationId 'Worked' -Passthru | `
				Set-PodeOARequest -PassThru -Parameters ( 
				New-PodeOAStringProperty -Name 'potato' -Description 'Potato Name' -Required | 
				ConvertTo-PodeOAParameter -In Path -Required 
			)
		}
	}
}

And it's generating the following openapi definition
See "/v4\\.2/{potato}" -> Should be "/v4.2/{potato}"

openapi JSON
{
    "openapi": "3.0.3",
    "info": {
        "license": {
            "name": "All rights reserved",
            "url": "https://localhost"
        },
        "title": "Swagger Petstore - OpenAPI 3.0",
        "version": "1.0.17",
        "description": "This is a sample Pet Store Server based on the OpenAPI 3.0 specification. ...",
        "termsOfService": "http://swagger.io/terms/",
        "contact": {
            "name": "API Support",
            "email": "[email protected]",
            "url": "http://example.com/support"
        }
    },
    "servers": [
        {
            "url": "/api",
            "description": "default endpoint"
        }
    ],
    "paths": {
        "/{potato}": {
            "get": {
                "summary": "Worked",
                "description": "Worked",
                "operationId": "Worked",
                "parameters": [
                    {
                        "description": "Potato Name",
                        "schema": {
                            "type": "string"
                        },
                        "required": true,
                        "in": "path",
                        "name": "potato"
                    }
                ],
                "security": [
                    {
                        "Authenticate": []
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "default": {
                        "description": "Internal server error"
                    }
                }
            }
        },
        "/v4\\.2/{potato}": {
            "get": {
                "summary": "Failed",
                "description": "Failed",
                "operationId": "Failed",
                "parameters": [
                    {
                        "description": "Potato Name",
                        "schema": {
                            "type": "string"
                        },
                        "required": true,
                        "in": "path",
                        "name": "potato"
                    }
                ],
                "security": [
                    {
                        "Authenticate": []
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "default": {
                        "description": "Internal server error"
                    }
                }
            }
        }
    },
    "components": {
        "securitySchemes": {
            "Authenticate": {
                "type": "http",
                "scheme": "bearer"
            }
        }
    }
}

Expected Behavior

The . shouldn't be replace in the OA Definition.

Platform

  • OS: Windows
  • Browser: Chrome/Edge
  • Versions:
    • Pode: 2.11.0
    • PowerShell: 5.1 and 7.4.5

Additional Context

I've pretty much know where the issue is coming from. In Private/Helper.ps#L3149 it escape the whole path for Regex control char. I'm not sure if it's required somewhere else or not.

@mdaneri
Copy link
Contributor

mdaneri commented Oct 18, 2024

Now should work

Badgerati added a commit that referenced this issue Oct 20, 2024
Fix OpenAPI Route Path Conversion for Placeholder Unescaping and Relocate Function (#1422)
@github-project-automation github-project-automation bot moved this from Backlog to Done in 🚀 Pode Roadmap Oct 20, 2024
@Badgerati Badgerati added this to the 2.11.1 milestone Oct 20, 2024
@Badgerati Badgerati mentioned this issue Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
3 participants