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
845 stars 92 forks source link

Incorrect OpenAPI Generation with -NoDefaultResponses Parameter #1366

Closed mdaneri closed 1 month ago

mdaneri commented 2 months ago

Describe the Bug

When Enable-PodeOpenAPI is invoked using the -NoDefaultResponses parameter and an OpenAPI path is created without adding a response, the generated OpenAPI specification is not correct.

Steps To Reproduce

  1. Run the following PowerShell commands:

    Enable-PodeOpenApi -Path '/docs/openapi' -OpenApiVersion '3.0.3' -DisableMinimalDefinitions -NoDefaultResponses
    
    Add-PodeRoute -Method 'Get' -Path '/hello' -ScriptBlock {
        Write-PodeJsonResponse -Value @{'message' = 'Hello!'} -StatusCode 200
    } -PassThru | Set-PodeOARouteInfo -Summary 'Hello from the server'
  2. This generates the following OpenAPI YAML:

    /hello: 
      get: 
        summary: Hello from the server
        responses: []

This output is not compliant with the OpenAPI specification.

Expected Behavior

If no response is added, a default response should be automatically added. The corrected OpenAPI YAML should look like this:

/hello: 
  get: 
    summary: Hello from the server
    responses: 
      default: 
        description: No description

Fix

Automatically add a default response when no responses are specified to ensure compliance with the OpenAPI specification.