Giter Club home page Giter Club logo

redoc's Introduction

sphinxcontrib-redoc

pypi-version travis-ci

The Sphinx extension that renders OpenAPI (fka Swagger) specs with love (❤️) using amazing ReDoc. Don't believe it? Here's the proof. Now stop frustrating and start moving your projects to OpenAPI and ReDoc with this small first step:

$ pip install sphinxcontrib-redoc

Any feedback, any contribution is really appreciated!

redoc's People

Contributors

amn41 avatar etene avatar fmigneault avatar ikalnytskyi avatar mere-teresa avatar rth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

redoc's Issues

Fails to build some targets

Apparently, sphinx-build fails to build some targets (e.g. text, latexpdf, XML) with this extension included.
An IOError Exception is thrown.

IOError: [Errno 2] No such file or directory: u'/mnt/g/git/api-docs/build/text/_static/redoc.js'

This appears to happen because redoc.py is unable to copy the redoc.js to the target folder for some reason.

Build target in the traceback: text

The full traceback:
sphinx-err-Zm6iYM.log

Redoc 2

Redoc just released version 2 alpha with support for OpenAPI 3, is there any plan to support the newest Redoc? :-)

No Support for OpenAPI 3.0

Attempting to render an OpenAPI 3.0 specification partially works but is missing attributes like "server" which replaced "host" and "requestBody" which replaced "parameters.body" in the upgrade from swagger 2.0 to OpenAPI 3.0

Propagate ReDoc options from Sphinx's `conf.py`

So far ReDoc has the following options:

  • lazy-rendering
  • suppress-warnings
  • hide-hostname
  • required-props-first
  • expand-responses

It would be nice to have a way to propagate them from Sphinx's conf.py to ReDoc page as one may be eager to have them in some cases.

possibility to config to use other reddoc.js

It would be nice to be able to provide URL for the reddoc.js to be used.
Plugin could use it to download script and put it instead of bundled reddoc.js into the _static.

It would give a possibility to update reddoc without updating this extension. (for example OpenAPI 3.0 supported only in RedDoc 2.x) and ATM some tricks are needed to be able to use this extension to render it.

Fails to copy `redoc.js` to `{outdir}/_static`.

If Sphinx fails to build docs there's a chance that sphinxcontrib-redoc fails to copy redoc.js to {outdir}/_static. The reason is that it unconditionally tries to copy redoc.js when build is finished (successfully or unsuccessfully) without ensuring that {outdir}/_static exists.

Here's the traceback example:

Traceback (most recent call last):
  File "/Users/ikalnytskyi/devel/xsnippet-api/.tox/docs/lib/python3.6/site-packages/sphinx/cmdline.py", line 296, in main
    app.build(opts.force_all, filenames)
  File "/Users/ikalnytskyi/devel/xsnippet-api/.tox/docs/lib/python3.6/site-packages/sphinx/application.py", line 348, in build
    self.emit('build-finished', err)
  File "/Users/ikalnytskyi/devel/xsnippet-api/.tox/docs/lib/python3.6/site-packages/sphinx/application.py", line 589, in emit
    results.append(callback(self, *args))
  File "/Users/ikalnytskyi/devel/xsnippet-api/.tox/docs/lib/python3.6/site-packages/sphinxcontrib/redoc.py", line 61, in assets
    os.path.join(app.builder.outdir, '_static', 'redoc.js'))
  File "/Users/ikalnytskyi/devel/xsnippet-api/.tox/docs/lib/python3.6/site-packages/sphinx/util/osutil.py", line 150, in copyfile
    shutil.copyfile(source, dest)
  File "/Users/ikalnytskyi/devel/xsnippet-api/.tox/docs/lib/python3.6/shutil.py", line 121, in copyfile
    with open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/ikalnytskyi/devel/xsnippet-api/docs/_build/_static/redoc.js'

Error in docs

Example from https://sphinxcontrib-redoc.readthedocs.io/en/stable/:

redoc = [ { 'name': 'Batcomputer API', 'page': 'api', 'spec': 'specs/batcomputer.yml', 'embed': True, }, { 'name': 'Example API', 'page': 'example/index', 'spec': 'http://example.com/openapi.yml', 'opts': { 'lazy': False, 'nowarnings': False, 'nohostname': False, 'required-props-first': True, 'expand-responses': ["200", "201"], } }, ]

ReDoc doesn't have options "lazy", but it has "lazy-rendering". Another opts is written with error too.

Referenced `yml` files are not copied

My (local) yml spec file references to another (local) yml in the definition. However, the extension seems not able to detect the reference and copy them.
For example:

a.yml

# ...
components:
  schemas:
    user:
      $ref: 'b.yml#/components/schemas/user'
# ...

b.yml

# ...
components:
  schemas:
    user:
      type: object
# ...

and in conf.py

# ...
redoc = [
    {
        "name": "My API",
        "page": "path/to/a",
        "spec": "path/to/a.yml",
    },
]
# ...

The extension detects "path/to/a.yml" and copy it to _build/html/_spec. However, b.yml is not copied and the page just failed to load.

Could there be a way to list the yml files I want to use for rendering the docs page, and the extension will copy and prepare them (and manipulate the paths) for me?

Download YAML file too

Hi and first of all: thanks for this amazing project!

I was wondering if there could be an option for downloading the API spec in YAML too. The download button retrieves only a JSON version.

My use case is that we as an organisation actually works with the YAML versions as they are easier on the eyes and easier for non-tech people to look at and/or edit.

Integration with rest of documentation

I don't see how I can integrate the generated api.html into my documentation. It's just there in the documentation folder and I cannot even link to it unless I use absolute links, right? So what does this extension actually do related to Sphinx? It would be great if I could link to it from a toctree.

Internationalization

Hi! Thank you for this extension!

I need to possibly specify in conf.py multiple yaml files for different languages.

Sphinx-contrib extension error: urlopen error [Errno -3]

On mentioning the below URL in conf.py, I get an extension error.

redoc_uri = 'https://unpkg.com/[email protected]/bundles/redoc.standalone.js'

Error:

Extension error (sphinxcontrib.redoc):
Handler <function assets at 0x7f76cf766310> for event 'build-finished' threw an exception (exception: <urlopen error [Errno -3] Temporary failure in name resolution>)

Minor Issue in docs

Very small issue.

Here's the screenshot of the docs

SphinxRedoc
There is no semicolon here. But In the source It is present. I wonder how it's missing here.

Redoc page rendering only when used in toctree directive.

Unable to render the page when used in more than one place and without a directive.

I have defined like:

redoc = [
    {
        'name': 'File Upload APIs',
        'page': 'spec/file_upload_apis',
        'spec': 'yaml_spec/openapi.yaml',
        'embed': True,
    }
]
  1. The spec/file_upload_apis.rst is the placeholder file where I want the Redoc API documentation to be rendered.
  2. The hyperlink to the above page looks like:

spec/pa_amr_apis.rst

.. toctree::
   :maxdepth: 5       

   file_upload_apis      //This works when used in toctree directive


file_upload_apis        // This does not work anywhere outside toctree directive

Should I have to use file_upload_apis only within some directive? And not on any page were I want ?

Can't use relative URL to spec.yaml file

I'm trying to use a relative URL to the spec.yaml file, which fails because it's interpreted as a file path:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/sphinx/cmdline.py", line 304, in main
    app.build(args.force_all, filenames)
  File "/usr/lib/python3.6/site-packages/sphinx/application.py", line 331, in build
    self.builder.build_update()
  File "/usr/lib/python3.6/site-packages/sphinx/builders/__init__.py", line 338, in build_update
    'out of date' % len(to_build))
  File "/usr/lib/python3.6/site-packages/sphinx/builders/__init__.py", line 402, in build
    self.finish()
  File "/usr/lib/python3.6/site-packages/sphinx/builders/html.py", line 621, in finish
    self.finish_tasks.add_task(self.gen_additional_pages)
  File "/usr/lib/python3.6/site-packages/sphinx/util/parallel.py", line 50, in add_task
    res = task_func()
  File "/usr/lib/python3.6/site-packages/sphinx/builders/html.py", line 648, in gen_additional_pages
    for pagename, context, template in pagelist:
  File "/usr/lib/python3.6/site-packages/sphinxcontrib/redoc.py", line 47, in render
    os.path.join(specpath, specname))
  File "/usr/lib/python3.6/site-packages/sphinx/util/osutil.py", line 165, in copyfile
    if not path.exists(dest) or not filecmp.cmp(source, dest):
  File "/usr/lib/python3.6/filecmp.py", line 51, in cmp
    s1 = _sig(os.stat(f1))
FileNotFoundError: [Errno 2] No such file or directory: '/api/rest/spec.yaml'

I need to use a relative path because the generated docs will be deployed on multiple hosts, and I don't want to bind the spec to a specific host. As a workaround I'm using the full URL in the config, then edit the generated html file manually before deployment.

Externalize redoc config

Is there a way to externalize the redoc config?
I'm trying not to utilize conf.py and using redoc.py to have the entries for yaml files.
redoc.py is available in /services...

Below is the entry in conf.py and it doesn't seem to be generating any html.

Any ideas?

conf.py

import os
import sys

sys.path.insert(0, os.path.abspath('./services'))

redoc.py located at /services

redoc = [
    {
        'name': 'User API',
        'page': 'userapi',
        'spec': 'userapispec.yml'
    }
]

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.