Skip to main content

Documentation generator for Swagger API

Project description

Swagger API Docs Generator for Foliant

The static site on the picture was built with Slate backend together with SwaggerDoc preprocessor

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

This preprocessor requires Widdershins to be installed on your system (unless you are using Foliant with Full Docker Image):

npm install -g widdershins

Config

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

preprocessors:
    - swaggerdoc

The preprocessor has a number of options:

preprocessors:
    - swaggerdoc:
        spec_url: http://localhost/swagger.json
        spec_path: swagger.json
        additional_json_path: tags.json
        mode: widdershins
        template: swagger.j2
        environment: env.yaml

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

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

If both url and path are specified — preprocessor first tries to fetch spec 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 spec_url="http://localhost/swagger.json"
            mode="jinja"
            template="swagger.j2">
</swaggerdoc>

<swaggerdoc spec_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

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:
        spec_path: swagger.yml
        environment:
            user_templates: !path ./widdershins_templates/

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.

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.5.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

File details

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

File metadata

  • Download URL: foliantcontrib.swaggerdoc-1.2.5.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for foliantcontrib.swaggerdoc-1.2.5.tar.gz
Algorithm Hash digest
SHA256 cae721f80c7ef3e31fb8080b089901da30fa170b63aac87af645f3ae4ea9ef5a
MD5 285b80579df9e5f914d9892d9e8dab2c
BLAKE2b-256 a52ecff6d8792186f4ba0be57f8ef7c88b74eb4dc11098db5a36b8b54976801d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: foliantcontrib.swaggerdoc-1.2.5-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for foliantcontrib.swaggerdoc-1.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 fb5f72b6635b7bc3795e8b1b11a0c4f5173b70691410761e05bb656d53d6ac1d
MD5 ba83d3952ec596abf92f05317d82fd12
BLAKE2b-256 c61db02f1abc5b983d0bf56fcec462b75d50eaa267d1036d05ca6a152cb83949

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 Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page