pgjones / quart-schema

Quart-Schema is a Quart extension that provides schema validation and auto-generated API documentation.
MIT License
76 stars 24 forks source link

`HttpSecurityScheme` uses wrong bearerFormat attribute name #83

Open DanielHabenicht opened 1 month ago

DanielHabenicht commented 1 month ago

The generated OpenAPI schema is invalid if the bearer_format option is specified:

QuartSchema(
    app,
    security=[{"bearerAuth": []}],
    security_schemes={"bearerAuth": {"type": "http", "bearer_format": "JWT", "scheme": "bearer"}},
)

# because of
@dataclass
class HttpSecurityScheme(SecuritySchemeBase):
    scheme: str
    bearer_format: Optional[str] = None
    type: Literal["http"] = "http"

Resulting Schema:

// ...
        "securitySchemes": {
            "bearerAuth": {
                "bearer_format": "JWT",
                "scheme": "bearer",
                "type": "http"
            }
        }

It should be bearerFormat as specified: https://spec.openapis.org/oas/v3.1.0#fixed-fields-22

DanielHabenicht commented 1 month ago

Should I make a PR where the attribute is aliased?

@dataclass
class HttpSecurityScheme(SecuritySchemeBase):
    scheme: str
    bearer_format: Optional[str] = Field(None, alias='bearerFormat')
    type: Literal["http"] = "http"

Or do you want to handle it centrally for all attributes?