Skip to content

Bug: OpenAPI generation doesn't follow Path templating specs #3398

Closed
@rubenfonseca

Description

@rubenfonseca

Expected Behaviour

When I generate OpenAPI specs, I'm expecting the paths to follow the specification on Path templating.

Current Behaviour

For legacy reasons, Powertools generates OpenAPI specs containing <> (e.g: /todos/<todo_id>) which breaks any tool that uses the standard spec.

Code snippet

from aws_lambda_powertools.event_handler import APIGatewayRestResolver

app = APIGatewayRestResolver(enable_validation=True)


@app.get("/todos/<todo_id>")
def handle(todo_id: int):
    print(todo_id)
    return "hello"


def lambda_handler(event, context):
    app.resolve(event, context)

print(app.get_openapi_json_schema())

Possible Solution

Keep the existing behaviour, but change the OpenAPI spec to emit the correct standard

Steps to Reproduce

  1. Use the code snippet above.
  2. Use Swagger to visualize the API
  3. Try to invoke /todos/1
  4. Result: Swagger doesn't know how to map 1 to <todo_id>

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.7

Packaging format used

PyPi

Debugging logs

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Shipped

Relationships

None yet

Development

No branches or pull requests

Issue actions