Merged
Conversation
89f26e7 to
7558bc7
Compare
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.
Support for baked OpenAPI Specification files (
PYTHONOPTIMIZE=2/-OO)BlackSheep can enrich OpenAPI Documentation by parsing request handler docstrings. This does not work when Python runs with
PYTHONOPTIMIZE=2(or-OO), because docstrings are stripped at that level of optimisation.This PR adds a first-class solution: the ability to bake the OpenAPI spec to disk at build/CI time and load it at runtime instead of regenerating it.
Changes
OpenAPIHandler.save_spec(destination)Writes the current in-memory spec to disk. Both the JSON and YAML variants are always written, regardless of which extension is given. Intended to be called once — in a CI step or a dedicated bake script — after the application has started without
-OO.spec_file=constructor parameter onOpenAPIHandlerWhen set,
build_docsloads the pre-baked spec from disk instead of callinggenerate_documentation. If the files are missing on first startup, the spec is generated, saved automatically, and loaded from disk on every subsequent startup (first-startup auto-bake).APP_SPEC_FILEenvironment variableAn alternative to
spec_file=that requires no code change between environments. Set it in TEST / PROD to activate the baked-spec path; leave it unset in development to keep auto-generation.PYTHONOPTIMIZE=2warning in docstring parsingWhen Python runs with
optimize >= 2and a request handler has no docstring, a singleUserWarningis issued at startup advising the user to bake the spec file.Workflow
On the first deployment startup (files not yet present) the spec is generated and saved automatically. From the second startup onward it is read directly from disk, skipping generation entirely — which also improves startup time for large APIs.