Skip to main content

Documentation generator for Swagger API

Project description

Swagger API Docs Generator for Foliant

This preprocessor generates Markdown documentation from Swagger spec files . It uses Jinja2 templating engine or widdershins for generating Markdown from swagger spec files.

Installation

$ pip install foliantcontrib.swaggerdoc

Config

To enable the preprocessor, add pgsqldoc to preprocessors section in the project config:

preprocessors:
    - swaggerdoc

The preprocessor has a number of options:

preprocessors:
    - swaggerdoc:
        json_url: http://localhost/swagger.json
        json_path: swagger.json
        additional_json_path: tags.json
        mode: 'jinja'
        template: swagger.j2
        environment: env.yaml

json_url : URL to Swagger spec file. If it is a list — preprocessor takes the first url which works.

even though the parameters are called json_url and json_path, yaml format is supported too. Parameters may be softly renamed in future.

json_path : Local path to Swagger spec file (relative to project dir).

If both url and path are specified — preprocessor first tries to fetch JSON from url, and then (if that fails) looks for the file on local path.

additional_json_path : Only for jinja mode. Local path to swagger spec file with additional info (relative to project dir). It will be merged into original spec file, not overriding existing fields.

mode : Determines how the Swagger spec file would be converted to markdown. Should be one of: jinja, widdershins. Default: widdershins

jinja mode is deprecated. It may be removed in future

template : Only for jinja mode. Path to jinja-template for rendering the generated documentation. Path is relative to the project directory. If no template is specified preprocessor will use default template (and put it into project dir if it was missing). Default: swagger.j2

environment : Only for widdershins mode. Parameters for widdershins converter. You can either pass a string containing relative path to YAML or JSON file with all parameters (like in example above) or specify all parameters in YAML format under this key. More info on widdershins parameters.

Usage

Add a <swaggerdoc></swaggerdoc> tag at the position in the document where the generated documentation should be inserted:

# Introduction

This document contains the automatically generated documentation of our API.

<swaggerdoc></swaggerdoc>

Each time the preprocessor encounters the tag <swaggerdoc></swaggerdoc> it inserts the whole generated documentation text instead of it. The path or url to Swagger spec file are taken from foliant.yml.

You can also specify some parameters (or all of them) in the tag options:

# Introduction

Introduction text for API documentation.

<swaggerdoc json_url="http://localhost/swagger.json"
            mode="jinja"
            template="swagger.j2">
</swaggerdoc>

<swaggerdoc json_url="http://localhost/swagger.json"
            mode="widdershins"
            environment="env.yml">
</swaggerdoc>

Tag parameters have the highest priority.

This way you can have documentation from several different Swagger spec files in one foliant project (even in one md-file if you like it so).

Customizing output

Jinja

jinja mode is deprecated. It may be removed in future

In jinja mode the output markdown is generated by the Jinja2 template. In this template all fields from Swagger spec file are available under the dictionary named swagger_data.

To customize the output create a template which suits your needs. Then supply the path to it in the template parameter.

If you wish to use the default template as a starting point, build the foliant project with swaggerdoc preprocessor turned on. After the first build the default template will appear in your foliant project dir under name swagger.j2.

Widdershins

In widdershins mode the output markdown is generated by widdershins Node.js application. It supports customizing the output with doT.js templates.

  1. Clone the original widdershins repository and modify the templates located in one of the subfolders in the templates folder.
  2. Save the modified templates somewhere near your foliant project.
  3. Specify the path to modified templates in the user_templates field of the environment configuration. For example, like this:
preprocessors:
    - swaggerdoc:
        json_path: swagger.yml
        environment:
            user_templates: !path ./widdershins_templates/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

foliantcontrib.swaggerdoc-1.2.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file foliantcontrib.swaggerdoc-1.2.0.tar.gz.

File metadata

  • Download URL: foliantcontrib.swaggerdoc-1.2.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.1

File hashes

Hashes for foliantcontrib.swaggerdoc-1.2.0.tar.gz
Algorithm Hash digest
SHA256 21ae16708f9b6847e7980aaaf121d01545d0993ef2aa7f6e3d3e7fbb5233909c
MD5 181630d9ec2fca87a12d7d6b6a065b7b
BLAKE2b-256 f87ec03abdd9cc32e04fc8b6307087a4b7f5e3a0d742e0752fcee8454df9e4ae

See more details on using hashes here.

File details

Details for the file foliantcontrib.swaggerdoc-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: foliantcontrib.swaggerdoc-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.1

File hashes

Hashes for foliantcontrib.swaggerdoc-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63635bb9dcc638dff909817be3f3af32385fe965c27d35c113625fc028133eb2
MD5 4bf841410d1ed2dec81fcfacf851b861
BLAKE2b-256 92d796a658fd0fbf11e1cc55e9398c8e4193dca130eaa3a8e9fd456844726d11

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page