Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration with rest of documentation #15

Open
Archelyst opened this issue Jul 4, 2018 · 5 comments
Open

Integration with rest of documentation #15

Archelyst opened this issue Jul 4, 2018 · 5 comments

Comments

@Archelyst
Copy link

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.

@ikalnytskyi
Copy link
Member

Unfortunately, I do not know how to integrate it to Sphinx properly, i.e. so you can integrate it with a toctree. Sphinx uses docutils internally, and docutils is a freaking mess. :(

However, it's not true that you need to do absolute links. You can do relative (to docs/) links.

The point of this extension is to have Sphinx as the only tool you need to produce all-in-one docs, where you have your Sphinx documentation and ReDoc-rendered OpenAPI spec. I.e. perform ReDoc bundling and spec copying when you run Sphinx to build the docs.

@rth
Copy link
Contributor

rth commented Mar 13, 2019

An imperfect solution is to link the ReDoc rendered spec to the main documentation with, the info->description field in the OpenAPI spec, e.g.

"info": {
        "description": "See <a href='./index.html'>main documentation</a> for more information about this project.",
        [...]
    }

and then in Sphinx create a new page that links to ReDoc rendered spec in the description.

Adding ReDoc rendered spec to sphinx's table of content (without passing by an intermediary page) would be ideal, and there is related discussion in sphinx-doc/sphinx#701 but with no clear solution as far as I can tell.

@pohutukawa
Copy link

What I'm just trying to do is to use the Sphinx raw:: html directive to include a file with the HTML fragments in it. It's a bit messy, but it sort of works when I pimp my build system to do the heavy lifting for me:

  • Strip the HTML boiler plate out of it (only keeping everything within the <body>...</body> tags in a file openapi.html
  • Raw include this file (above) with HTML content
  • Add some boiler plate of raw HTML resizing the width of the 3-panel-view to suit my needs.
    I'm not a HTML/UI person, but with a bit of help this is what I've cobbled up and what I'm using (for now):
.. only:: html

   .. _specs-details:
   
   OpenAPI Specs Details
   =====================

   .. raw:: html
            
      <script>
        function resizeOpenapiElement() {
          var openapiElement = document.getElementById('openapiWidget');
          var parentElement = openapiElement.parentNode;
          parentElement.style.width = '150%';
        }
        document.body.addEventListener('load', resizeOpenapiElement, true);
      </script>
      <div id="openapiWidget">

   .. raw:: html
      :file: _static/openapi.html

   .. raw:: html
            
      </div>

I hope that helps already. And I'm happy as, if somebody has suggestions on how to handle this in a tidier way ... ;-)

@pohutukawa
Copy link

Another update on this:
I am now just injecting a place holder {{openapi_redoc}} between the opening/closing <div> tags in the message above. I'm extracting the content of the <body> only from the generated ReDoc HTML content, which I'm then injecting for the above place holder. This is all (Python) scripted to give easily working reproducible builds.
I have subtly altered the Sphinx Makefile to call my patch_openapi_redoc.py script to do all the steps of the job described above right after the Sphinx build.

@sachin-suresh-rapyuta
Copy link

I tried the above .. only:: html snippet and is there a way we can use the .yaml file instead of the path to the .html file?
I have placed the yaml file in custom directory (specs/openapi.yaml), I get the entire junk (unformatted) of yaml in the section "OpenAPI Specs Details".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants