Skip to content

Commit 92809bf

Browse files
committed
fixed code styles and docs
1 parent ac3d19b commit 92809bf

File tree

11 files changed

+26
-17
lines changed

11 files changed

+26
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to FastOpenAPI are documented in this file.
44

55
FastOpenAPI follows the [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format.
66

7+
## [0.5.0] - Unreleased
8+
9+
### Added
10+
- Class-level cache for model schemas
11+
712
## [0.4.0] - 2025-03-20
813

914
### Added

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ pip install fastopenapi[falcon]
3636
pip install fastopenapi[flask]
3737
```
3838
```bash
39+
pip install fastopenapi[quart]
40+
```
41+
```bash
3942
pip install fastopenapi[sanic]
4043
```
4144
```bash

benchmarks/falcon/FALCON.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ DELETE record: 18.6130 sec total, 1.86 ms per request
4343

4444
---
4545

46-
[<< Back](README.md)
46+
[<< Back](../README.md)
4747

4848
---

benchmarks/flask/FLASK.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ DELETE record: 26.7906 sec total, 2.68 ms per request
4343

4444
---
4545

46-
[<< Back](README.md)
46+
[<< Back](../README.md)
4747

4848
---

benchmarks/quart/QUART.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ DELETE record: 40.6837 sec total, 4.07 ms per request
4343

4444
---
4545

46-
[<< Back](README.md)
46+
[<< Back](../README.md)
4747

4848
---

benchmarks/sanic/SANIC.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ DELETE record: 19.9205 sec total, 1.99 ms per request
4343

4444
---
4545

46-
[<< Back](README.md)
46+
[<< Back](../README.md)
4747

4848
---

benchmarks/starlette/STARLETTE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ DELETE record: 21.9329 sec total, 2.19 ms per request
4444

4545
---
4646

47-
[<< Back](README.md)
47+
[<< Back](../README.md)
4848

4949
---

benchmarks/tornado/TORNADO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ DELETE record: 19.9923 sec total, 2.00 ms per request
4343

4444
---
4545

46-
[<< Back](README.md)
46+
[<< Back](../README.md)
4747

4848
---

fastopenapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.4.0"
1+
__version__ = "0.5.0"

fastopenapi/base_router.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import typing
44
from collections.abc import Callable
55
from http import HTTPStatus
6-
from typing import Any, Dict, ClassVar
6+
from typing import Any, ClassVar
77

88
from pydantic import BaseModel
99

@@ -43,8 +43,9 @@ class BaseRouter:
4343
It can include sub-routers and generate an OpenAPI specification from
4444
the declared routes.
4545
"""
46+
4647
# Class-level cache for model schemas to avoid redundant processing
47-
_model_schema_cache: ClassVar[Dict[str, dict]] = {}
48+
_model_schema_cache: ClassVar[dict[str, dict]] = {}
4849

4950
def __init__(
5051
self,
@@ -264,31 +265,31 @@ def _serialize_response(result: Any) -> Any:
264265
@classmethod
265266
def _get_model_schema(cls, model: type[BaseModel], definitions: dict) -> dict:
266267
"""
267-
Get the OpenAPI schema for a Pydantic model, with caching for better performance.
268+
Get the OpenAPI schema for a Pydantic model, with caching for better performance
268269
"""
269270
model_name = model.__name__
270271
cache_key = f"{model.__module__}.{model_name}"
271-
272+
272273
# Check if the schema is already in the class-level cache
273274
if cache_key not in cls._model_schema_cache:
274275
# Generate the schema if it's not in the cache
275276
model_schema = model.model_json_schema(
276277
ref_template="#/components/schemas/{model}"
277278
)
278-
279+
279280
# Process and store nested definitions
280281
for key in ("definitions", "$defs"):
281282
if key in model_schema:
282283
definitions.update(model_schema[key])
283284
del model_schema[key]
284-
285+
285286
# Add schema to the cache
286287
cls._model_schema_cache[cache_key] = model_schema
287-
288+
288289
# Make sure the schema is in the definitions dictionary
289290
if model_name not in definitions:
290291
definitions[model_name] = cls._model_schema_cache[cache_key]
291-
292+
292293
return {"$ref": f"#/components/schemas/{model_name}"}
293294

294295
@staticmethod
@@ -370,4 +371,4 @@ def resolve_endpoint_params(
370371
def openapi(self) -> dict:
371372
if self._openapi_schema is None:
372373
self._openapi_schema = self.generate_openapi()
373-
return self._openapi_schema
374+
return self._openapi_schema

0 commit comments

Comments
 (0)