GithubHelp home page GithubHelp logo

raj196868 / django-apiblueprint-view Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chris48s/django-apiblueprint-view

0.0 0.0 0.0 598 KB

๐Ÿ“š Render API Blueprints on-the-fly using Django templates

Home Page: https://pypi.org/pypi/django-apiblueprint-view/

License: MIT License

Shell 1.72% Python 80.08% Makefile 1.25% HTML 16.95%

django-apiblueprint-view's Introduction

django-apiblueprint-view

Run tests codecov PyPI Version License Python Compatibility Django Support Code style: black

Render API Blueprints on-the-fly using Django templates

Installation

  1. pip install django-apiblueprint-view

  2. 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 text CONNECT
  • 'method_DELETE': <span> containing the text DELETE
  • 'method_GET': <span> containing the text GET
  • 'method_HEAD': <span> containing the text HEAD
  • 'method_OPTIONS': <span> containing the text OPTIONS
  • 'method_PATCH': <span> containing the text PATCH
  • 'method_POST': <span> containing the text POST
  • 'method_PUT': <span> containing the text PUT
  • 'method_TRACE': <span> containing the text TRACE
  • '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.

django-apiblueprint-view's People

Contributors

chris48s avatar dependabot[bot] avatar dependabot-preview[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.