Badgerati / Pode

Pode is a Cross-Platform PowerShell web framework for creating REST APIs, Web Sites, and TCP/SMTP servers
https://badgerati.github.io/Pode
MIT License
853 stars 93 forks source link

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

Closed cocazoulou closed 1 week ago

cocazoulou commented 1 week ago

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 'example@example.com' ` -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": "example@example.com", "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

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 commented 1 week ago

Now should work