Skip to content

Bug: SwaggerUI does not show title property of schemas #7670

@victorperezpiqueras

Description

@victorperezpiqueras

Expected Behaviour

OpenApi schemas should display the title property instead of the name in the swaggerUI html page, when specified.

Current Behaviour

The title is never shown, although present in the openapi specification, which properly generates the title property, derived from pydantic models.

This seems like a similar issue to this one.

Code snippet

from pydantic import AwareDatetime, BaseModel, ConfigDict, Field
import requests
from requests import Response

from aws_lambda_powertools import Logger, Tracer
from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from aws_lambda_powertools.logging import correlation_paths
from aws_lambda_powertools.utilities.typing import LambdaContext

class ToDo(BaseModel):
    model_config = ConfigDict(
        from_attributes=True,
        title="todoTitle",
    )

tracer = Tracer()
logger = Logger()
app = APIGatewayRestResolver()
app.enable_swagger(path="/swagger")

@app.get("/todos")
@tracer.capture_method
def get_todos()->ToDo:
    return ToDo()


@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_REST)
@tracer.capture_lambda_handler
def lambda_handler(event: dict, context: LambdaContext) -> dict:
    return app.resolve(event, context)

Possible Solution

Minified JS version of swaggerUi might be outdated, as in the https://editor.swagger.io/ it seems to work, and there have been fixes in the swaggerui repo for a similar issue, as linked above.

Steps to Reproduce

  1. Create an api gateway following the snippet above
  2. Open the swaggerUI hosted at /swagger
  3. The ToDo schema does not show the defined title, but the pydantic model's name
  4. Open the /swagger?format=json and check the schema has the title property set
  5. Paste the json format in https://editor.swagger.io/, the title is shown instead of the name

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.12

Packaging format used

Lambda Layers

Debugging logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions