swagger-editor icon indicating copy to clipboard operation
swagger-editor copied to clipboard

"exporting static HTML documentation" would be a great feature

Open kongfujianlong opened this issue 11 years ago • 65 comments

I really like the swagger YAML format and the HTML document generated by the swagger-editor. Actually, I really hope I can get a standalone HTML document, with exactly the same look as the one generated by the editor, but without the YAML editing part.

I understand there are other tools like swagger-codegen and swagger-to-markdown to generate static document. But the HTML document interactively generated by the editor is obviously a much better choice for a lot people: (1) It's interactive, meaning easier to correct mistakes. (2) The HTML generated is very user friendly, and based on my research, looks better than the static documents generated by other tools. (3) Most importantly, it's easy to use and there is no need to deploy anything. For people like me who really just want to generate a tiny RESTful document it doesn't make sense to go through all the complicated tools.

Hence, I would really appreciate if swagger-editor can support exporting the interactively generated HTML document to a standalone HTML page, and I can ship to customer right away.

kongfujianlong avatar Sep 22 '15 15:09 kongfujianlong

You can add this to your branding.css file to hide anything but the preview

.total-wrapper > header,
.editor.pane,
.ui-splitbar,
[tooltip-popup],
.jump-to-yaml {
    display: none !important;
}

.preview.pane {
    position: fixed;
    left: 0 !important;
    top: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: 100% !important;
}

Swagger Editor preview pane is not designed to be a replacement of Swagger UI so the "hack" above is not officially supported. We will add more editor specific stuff to the right pane.

I've started a project based on this feedback for rendering Swagger documents in a nicer way. Check it out here: https://github.com/mohsen1/swagger-docs

mohsen1 avatar Sep 22 '15 16:09 mohsen1

given the amount of time it takes swagger to render the ArangoDB Documentation, it would indeed cool if it could be pre-generated on the server, so the client doesn't have to do as much work.

dothebart avatar Sep 23 '15 09:09 dothebart

I really like the HTML rendering available in the editor (It is better for an overview and as a standalone documentation than swagger-ui), and I would appreciate an "export as HTML" feature (and/or a way to produce this rendering from a command line tool).

If the right pane could be rendered in separate browser window/tab, we could easily save it using browser UI functions...

dolmen avatar Sep 28 '15 12:09 dolmen

The modification of this 2 files do the similar trick that suit my needs. Please feel free to use if that suit your needs as well.

Or use it @ http://io.api.zay-dev.com


Step 1. Replace the whole content of the index.html under the root directory with the following HTML

<!doctype html><head><meta charset="utf-8"><title>Swagger Editor</title><meta name="description" content="Swagger Editor"><meta name="viewport" content="width=device-width"><link rel="icon" type="image/png" href="./images/favicon-32x32.png" sizes="32x32"><link rel="icon" type="image/png" href="./images/favicon-16x16.png" sizes="16x16"><link rel="stylesheet" href="styles/main.css"><link rel="stylesheet" href="styles/branding.css"><body><div class="total-wrapper" ui-view></div><script src="scripts/vendor.js"></script><script src="scripts/scripts.js"></script><script src="scripts/branding.js"></script>
<script type="text/javascript">
    var PreviewWidth = 0,
        PreviewLeft = 0;

    function Download () {
        while (true) {
            var items = $(".json-schema-view.collapsed .toggle-handle"),
                length = items.length;
            if (length <= 0) break;
            else items.click();
        }
        $(".total-wrapper>header, main>.stretch>.editor, main>.stretch>.ui-splitbar, .all-tags").hide();

        PreviewWidth = $("main>.stretch>.preview").css("width");
        PreviewLeft = $("main>.stretch>.preview").css("left");
        $("main>.stretch>.preview").css({"width":"","left":""});

        var base64doc = btoa(unescape(encodeURIComponent(document.documentElement.innerHTML))),
            a = document.createElement('a'),
            e = document.createEvent("HTMLEvents");
        a.download = 'template.html';
        a.href = 'data:text/html;base64,' + base64doc;
        e.initEvent('click');
        a.dispatchEvent(e);
    }

    function RestoreFromDownload () {
        var items = $(".json-schema-view .toggle-handle"),
            length = items.length;
        items.click();

        $("main>.stretch>.preview").css({"width": PreviewWidth, "left": PreviewLeft});

        $(".total-wrapper>header, main>.stretch>.editor, main>.stretch>.ui-splitbar, .all-tags").show();
        PreviewWidth = 0;
        PreviewLeft = 0;
    }
</script>

Step 2. Replace the whole content of the header.html under views/header with the following HTML

<div class="main-header"><a href="http://swagger.io" target="_blank" class="logo" ng-if="!showHeaderBranding()"></a><div ng-include="'templates/branding-left.html'" ng-if="showHeaderBranding()" class="branding-3rdparty"></div><section class="menu-bar"><div class="file dropdown" ng-if="showFileMenu()"><button class="btn btn-default dropdown-toggle" ng-click="onFileMenuOpen()" data-toggle="dropdown" id="fileMenu"><span>File</span> <span class="caret"></span></button><ul class="dropdown-menu"><li><a dropdown-toggle ng-click="newProject()" tabindex="-1" track-event="file new">New</a></li><li><a dropdown-toggle id="open-example" ng-click="openExamples()" tabindex="-1" track-event="file open-example">Open Example&hellip;</a></li><li class="divider"></li><li><a dropdown-toggle ng-click="openPasteJSON()" tabindex="-1" track-event="file paste-json">Paste JSON&hellip;</a></li><li><a dropdown-toggle ng-click="openImportUrl()" tabindex="-1" track-event="file import url">Import URL&hellip;</a></li><li><a dropdown-toggle ng-click="openImportFile()" tabindex="-1" track-event="file import file">Import File&hellip;</a></li><li class="divider"></li>
<li><a href="#" class="download-html">Download HTML</a></li>
<li class="divider"></li>
<li><a download="swagger.yaml" data-downloadurl="{{yamlDownloadUrl}}" href="{{yamlDownloadHref}}" tabindex="-1" track-event="file download yaml">Download YAML</a></li><li><a download="swagger.json" downloadurl="{{jsonDownloadUrl}}" href="{{jsonDownloadHref}}" tabindex="-1" track-event="file download json">Download JSON</a></li></ul></div><div class="preferences dropdown"><button id="preferences" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span>Preferences</span> <span class="caret"></span></button><ul class="dropdown-menu"><li><a class="font-size">Font Size&nbsp; <span ng-click="adjustFontSize(1)" stop-event class="adjust" track-event="preferences font+">+</span><span ng-click="adjustFontSize(-1)" stop-event class="adjust" track-event="preferences font-">–</span></a></li><li><a dropdown-toggle ng-click="openEditorPreferences()" tabindex="-1" track-event="preferences settings">Editor Settings</a></li><li><a dropdown-toggle ng-click="resetSettings()" tabindex="-1" track-event="preferences reset-settings">Reset Editor Settings</a></li><li class="divider"></li><li><a dropdown-toggle tabindex="-1" ng-click="openPreferences()" track-event="preferences preferences">Preferences&hellip;</a></li></ul></div><!-- Handling of Code Generator service availability issues --><span class="text-danger dropdown-toggle" ng-if="serversNotAvailable">Server code generator is unreachable!</span> <span class="text-danger dropdown-toggle" ng-if="clientsNotAvailable">Client code generator is unreachable!</span><div class="dropdown" ng-if="servers && servers.length && !disableCodeGen"><button class="btn btn-default dropdown-toggle" data-toggle="dropdown" id="ServerMenu"><span>Generate Server</span> <span class="caret"></span></button><ul class="dropdown-menu"><li ng-repeat="server in ::servers track by $index"><a dropdown-toggle tabindex="-1" ng-click="getSDK('server', server)" track-event="generate-server {{server}}"><span class="name">{{capitalizeGeneratorName(server)}}</span> <span class="badge">Alpha</span></a></li></ul></div><div class="code-gen dropdown" ng-if="clients && clients.length && !disableCodeGen"><button class="btn btn-default dropdown-toggle" data-toggle="dropdown" id="ClientMenu"><span>Generate Client</span> <span class="caret"></span></button><ul class="dropdown-menu"><li ng-repeat="client in ::clients track by $index"><a dropdown-toggle tabindex="-1" ng-click="getSDK('client', client)" track-event="generate-client {{client}}"><span class="name">{{capitalizeGeneratorName(client)}}</span> <span class="badge">Alpha</span></a></li></ul></div><div class="help dropdown"><button class="dropdown-icon btn btn-default dropdown-toggle" id="helpMenu" data-toggle="dropdown"><span>Help</span> <span class="caret"></span></button><ul class="dropdown-menu"><li><a tabindex="-1" href="https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md" target="_blank">Swagger 2.0 Specs</a></li><li><a tabindex="-1" href="http://swagger.io/" target="_blank">Swagger Website</a></li><li><a dropdown-toggle tabindex="-1" ng-click="openAbout()">About Swagger Editor</a></li><li class="divider"></li><li><a href="https://github.com/swagger-api/swagger-editor/issues/new?labels=From%20Editor" target="_blank">Report A Bug</a></li><li class="divider"></li><li><a dropdown-toggle ng-click="toggleAboutEditor(true)" tabindex="-1">Show Introduction Help</a></li></ul></div></section><section class="status-bar"><div class="status {{statusClass}}" ng-if="status"><i ng-if="statusClass == 'working'" class="fa fa-spinner fa-pulse"></i> <i ng-if="statusClass == 'error'" class="fa fa fa-times"></i> <i ng-if="statusClass == 'success'" class="fa fa-check"></i> <span>{{status}}</span></div><div class="brandRight" ng-include="'templates/branding-right.html'" ng-if="showHeaderBranding()"></div></section></div>
<script type="text/javascript">
    var BindCount = 0;
    function BindDownloadOnclick () {
        BindCount++;
        $(".download-html").off("click").on("click", function () {
            Download();
            confirm("Press OK to restore page from download. But I don't think the cancel button will really cancel...");
            RestoreFromDownload();
        });

        console.log(BindCount);
        if (BindCount < 50) setTimeout(function () { BindDownloadOnclick(); }, 200);
    }
    BindDownloadOnclick();
</script>

[optional] Step 3. Copy the following folders into the desctination folder of the download: /fonts /styles

lau235623 avatar Oct 05 '15 08:10 lau235623

It would be awesome to split editor and preview to different windows. I'm working on two monitors, one would be for editing, another for preview. x)

kticka avatar Oct 29 '15 16:10 kticka

I think that the editor pane for previsualizing html looks nicer than swagger ui. +1 for being able to export html from swagger-editor

vicaba avatar Nov 23 '15 12:11 vicaba

+1 export as html and/or option to display the preview without the editor and menu components would be nice

olivoil avatar Nov 23 '15 18:11 olivoil

+1 for exporting the html (preview of editor) for customers!

itayB avatar Nov 24 '15 19:11 itayB

+1 for exporting the html view of the preview editor pane, the docs produced by the server ui are not as good.

deefactorial avatar Nov 28 '15 19:11 deefactorial

The discrepancy between preview documentation and the one generated by swagger-codegen generate -i http://petstore.swagger.io/v2/swagger.json -l html -o /tmp/test/ is counter intuitive. It would be REALLY great if we could get the same look as preview's style for static HTML documentation.

wweic avatar Dec 12 '15 06:12 wweic

if it help someone: http://stackoverflow.com/questions/34188440/swagger-ui-editor-like-page-add-to-my-web-site/34308338#34308338

itayB avatar Dec 20 '15 10:12 itayB

+1 for exporting the html

jurikolo avatar Jan 06 '16 07:01 jurikolo

+1 for exporting the html

op1ekun avatar Jan 15 '16 15:01 op1ekun

+1

JamesMGreene avatar Jan 19 '16 15:01 JamesMGreene

+1

tommasop avatar Feb 12 '16 10:02 tommasop

This helped me: https://github.com/nknapp/bootprint-openapi

Also, check out this link to his bootprint-openapi playground...just paste your YAML file and view generated HTML doc: https://bootprint.knappi.org/

bhougland avatar Feb 12 '16 21:02 bhougland

Thanks for your suggestion, I've already used it and is very nice, still I think it would be "natural" to have an export to HTML directly in the editor.

Il giorno 12 feb 2016 22:49, alle ore 22:49, Benson Hougland [email protected] ha scritto:

This helped me: https://github.com/nknapp/bootprint-openapi

Also, check out this link to his bootprint-openapi playground...just paste your YAML file and view generated HTML doc: https://bootprint.knappi.org/


Reply to this email directly or view it on GitHub: https://github.com/swagger-api/swagger-editor/issues/664#issuecomment-183500914

tommasop avatar Feb 12 '16 22:02 tommasop

One of the main reasons I started using Swagger editor was because I saw how beautiful the documentation part of the editor looked like in the online demo. I must say I'm disappointed that you cannot export that (I was hoping for even an "Export as PDF" option). For now, generating a static HTML client will do.

Deusdies avatar Feb 29 '16 02:02 Deusdies

If you want to save it as PDF, you can print as pdf in chrome (just hide the editor section by clicking on the middle border and drag it to left). BTY this approche might be workaround to use this UI without the editor (and of course, hide the upper menu -all with js)

itayB avatar Feb 29 '16 05:02 itayB

+1 for exporting the HTML

anyong avatar Mar 19 '16 13:03 anyong