Feat/openapi pydantic native - #86
Merged
Merged
Conversation
Contributor
|
👋 Thanks for your contribution, @NEFORCEO! Please make sure:
Maintainers will review it soon. |
Contributor
Merging this PR will improve performance by 40.35%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | test_response_req_text_from_json |
213.2 µs | 134.7 µs | +58.25% |
| ⚡ | test_response_repr |
196.4 µs | 134.2 µs | +46.43% |
| ⚡ | test_response_property_access |
194.5 µs | 135.2 µs | +43.82% |
| ⚡ | test_response_json_parsing |
205.6 µs | 144.7 µs | +42.04% |
| ⚡ | test_response_creation |
201.3 µs | 142.6 µs | +41.19% |
| ⚡ | test_middleware_after_response |
403.1 µs | 352.5 µs | +14.35% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing feat/openapi-pydantic-native (ce89aca) with master (6f3d441)1
Footnotes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚀 Description
Rebuilds OpenAPI schema generation entirely on Pydantic's own JSON Schema
generation (
model_json_schema()/TypeAdapter/models_json_schema())instead of a hand-written type mapper, and adds several Swagger UI /
docs features on top of it.
OpenAPI generator (
fasthttp/openapi/generator.py)enums, unions/
Optional, constraints, defaults, and nested models arenow handled correctly instead of falling back to
{"type": "string"}.models_json_schema()andmerged into
components/schemaswith proper$refrewriting.Field(description=...)now come throughnatively;
Doc(...)annotations (the project's existing docstringconvention) are still backfilled where Pydantic has no description.
json=/data=bodies now surface their literalvalues as OpenAPI
examples, so Swagger UI's "Try it out" pre-fills them.tagsare now grouped by hostname instead ofa single
"Default"bucket.Swagger UI / docs (
fasthttp/openapi/swagger.py,fasthttp/app.py,fasthttp/openapi/urls.py)/redocendpoint (ReDoc — read-only alternative view).classes (previous approach used a
filter: invert()hack thatdistorted method-color badges, logos, and the JSON viewer).
persistAuthorization,requestSnippetsEnabled, andfilterenabledin the Swagger UI config.
/requestproxy now returns response timing (x-fasthttp-duration-ms),visible in the Swagger UI response headers panel.
/redocalongside/docsand/openapi.json.Bug fix (
fasthttp/routing.py)Route.response_modelwas typed astype | None, which made Pydanticreject
response_model=list[Model]at route-registration time — apattern used throughout
examples/anddocs/. Widened toAny.Docs
docs/en/openapi.md,docs/ru/openapi.md, and the OpenAPI Swagger UItutorial pages updated with the new
/redocendpoint and dark modescreenshots. README updated with the same screenshots.
examples/openapi/pydantic_schema_example.pydemonstratingenums, nested models,
Fielddescriptions/examples, and error models.🧩 Type of Change
✅ Checklist
tests/test_openapi.pyrewritten against thenew
_SchemaCollectorAPI; full suite passes — 564 passed)docs/en,docs/ru, tutorial pages)generator.pyhelperswere renamed/removed; public API —
generate_openapi_schema,get_swagger_html,get_not_found_html, etc. — is unchanged asidefrom the additive
redoc_urlparameter)🔗 Related Issues
Fixes #
📸 Additional Context
New screenshots:
docs/photo/swagger_dark.png,docs/photo/redoc.png.Manually verified locally:
/docs,/redoc,/openapi.jsonall serve200 with
examples/openapi/pydantic_schema_example.py; generated schemainspected for enum
$refs, nested model dedup, and example prefill.