Render API Blueprints on-the-fly using Django templates
Project description
django-apiblueprint-view
Render API Blueprints on-the-fly using Django templates
Installation
-
pip install django-apiblueprint-view
-
Add to
INSTALLED_APPS
in django settings:
INSTALLED_APPS = [
...
'apiblueprint_view',
]
Usage
from apiblueprint_view.views import ApiBlueprintView
urlpatterns = [
url(r'^docs/$', ApiBlueprintView.as_view(blueprint='/path/to/blueprint.apibp')),
]
Styling
Custom HTML Template
Define a custom base template. It must include the tag
{% include 'api_docs/docs_parent.html' %}
Pass it into ApiBlueprintView.as_view()
as a parameter.
from apiblueprint_view.views import ApiBlueprintView
urlpatterns = [
url(r'^docs/$', ApiBlueprintView.as_view(
blueprint='/path/to/blueprint.apibp',
template_name='my_base_template.html'
)),
]
Custom CSS
ApiBlueprintView.as_view()
may accept a styles
dictionary describing custom CSS classes which should be attached to rendered HTML tags. For example:
from apiblueprint_view.views import ApiBlueprintView
urlpatterns = [
url(r'^docs/$', ApiBlueprintView.as_view(
blueprint='/path/to/blueprint.apibp',
template_name='my_base_template.html',
styles={
'action': {'class': 'foo bar'},
'method': {'class': 'baz'}
}
)),
]
The following keys are valid. All keys are optional:
'action'
: Container<div>
for an API action'action_transaction'
: Container<div>
for a HTTP transaction (request and response)'action_request'
: Container<div>
for a HTTP request'action_response'
: Container<div>
for a HTTP response'action_schema'
: Container<div>
for a HTTP request or response schema'action_headers'
: Container<div>
for HTTP request or response headers'action_body'
: Container<div>
for a HTTP request or response body'action_example'
: Container<div>
for an API action example URL'description'
: Container<div>
for some text describing an action, resource, request, response, etc'parameters'
: Container<div>
for a list of parameters'method'
: Generic<span>
containing an HTTP method'method_CONNECT'
:<span>
containing the textCONNECT
'method_DELETE'
:<span>
containing the textDELETE
'method_GET'
:<span>
containing the textGET
'method_HEAD'
:<span>
containing the textHEAD
'method_OPTIONS'
:<span>
containing the textOPTIONS
'method_PATCH'
:<span>
containing the textPATCH
'method_POST'
:<span>
containing the textPOST
'method_PUT'
:<span>
containing the textPUT
'method_TRACE'
:<span>
containing the textTRACE
'resource'
: Container<div>
for an API resource'resource_group'
: Container<div>
for an API resource group
Highlight.js can be used to add syntax highlighting
Including Files
You can include other files in your blueprint by using an include directive with a path to the included file relative to the current file's directory. Included files can include other files, so be careful of circular references.
<!-- include(filename.md) -->
This syntax is not a part of the API Blueprint spec, but is also supported in some other tools e.g: aglio.
The include directive has the potential to introduce remote file inclusion or directory traversal vulnerabilities if your application renders user-supplied content. There are a couple of settings to help mitigate this. Set APIBP_PROCESS_INCLUDES = False
in your django settings to completely ignore include directives (the default is True
). There is also a whitelist of allowed file types to include. The default whitelist is ['.md', '.apibp', '.json']
but this can be overridden by setting APIBP_INCLUDE_WHITELIST
to a list of allowed extensions in your django settings.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file django_apiblueprint_view-2.5.1.tar.gz
.
File metadata
- Download URL: django_apiblueprint_view-2.5.1.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3bb045c358993a92ab64dee78fc48add1982a6cd9f309a39529912c72211b47 |
|
MD5 | b2590c935c38393ca977f545b7376ed0 |
|
BLAKE2b-256 | 58ffb7040206ec20922d8838c65b37945ee2b330d170d46fa23e896309038a1d |
File details
Details for the file django_apiblueprint_view-2.5.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
.
File metadata
- Download URL: django_apiblueprint_view-2.5.1-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
- Upload date:
- Size: 1.2 MB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b4f553965c1d06e77c90ee8eac77249f6a2f49f568f5c0336d21e106d33c401 |
|
MD5 | 6431f21d25fc37bdcdcf1cdd63d54c18 |
|
BLAKE2b-256 | ea1fd017da315ea1a61d0ad670f68944fcf159d4b88d8431c289f3e6854d7a4d |
File details
Details for the file django_apiblueprint_view-2.5.1-py3-none-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: django_apiblueprint_view-2.5.1-py3-none-macosx_11_0_x86_64.whl
- Upload date:
- Size: 466.6 kB
- Tags: Python 3, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 409d465884be7fd42d948c1aa7bf13177f9a11faf7086e7683287d9d1e5b7d26 |
|
MD5 | 1ae476b3d968f8cf26f9661d88731580 |
|
BLAKE2b-256 | badd07a17ab6e2de1e50811e1f8caf81d0e48664e840160fcbddc13aa8ee80f9 |