Giter VIP home page Giter VIP logo

swagger-spec-to-pdf's Introduction

swagger-spec-to-pdf

NPM version NPM downloads License

Install:

npm install -g swagger-spec-to-pdf

Usage:

usage: swagger2pdf [-h] [-v] [-s SRC] [-j] [-y] [-o OUTPUT]

Optional arguments:
  -h, --help            Show this help message and exit.
  -v, --version         Show program's version number and exit.
  -s SRC, --src SRC     Swagger spec JSON file.
  -j, --json            Spec file in JSON format (default).
  -y, --yaml            Spec file in YAML format.
  -o OUTPUT, --output OUTPUT
                        Output path of the pdf file.

Exec:

For JSON files:

swagger2pdf -j -s ./swagger-spec-sample.json -o ./dump/

For YAML files:

swagger2pdf -y -s ./swagger-spec-sample.yaml -o ./dump/

In either case, the execution will take several seconds to complete.

Sample:

See: ./dump/swagger-spec-sample.pdf

Change log:

1.1.0: Support swagger spec files in YAML format, see: PR#13.

Appendix:

Working Theory

In the case of a JSON input file:

  1. Read source swagger json spec
  2. Convert it into yaml format
  3. Dump yaml into the spec dir of swagger editor
  4. Use electron to render swagger editor page (nicely formatted api page)
  5. Dump the page into pdf

In the case of a YAML input file, steps 1-2 are bypassed.

Swagger Editor

Version of swagger editor embedded is: 2.9.9
You can get it from: here
If you want to use some other version:

  • clone the repo
  • replace the editor in ./swagger-editor
  • Add codes below into the bottom of file swagger-editor/index.html
  • npm install .
<script type="text/javascript">
    $("document").ready(function() {
        setTimeout(function() {
            var fileMenuTimer = setInterval(function() {
                // open file menu
                var fileMenu = $("#fileMenu");
                if (fileMenu.length) {
                    clearInterval(fileMenuTimer);
                    fileMenu.click();

                    // open example selector
                    var exampleButton = $("#open-example");
                    var exampleButtonTimer = setInterval(function() {
                        if (exampleButton.length) {
                            clearInterval(exampleButtonTimer);
                            exampleButton.click();

                            // click open button
                            setTimeout(function() {
                                $(".modal-large .btn-primary").click();
                            }, 1000);
                        }
                    }, 300);
                }
            }, 300);
        }, 1000);
    });
</script>

Done, just use it.

swagger-spec-to-pdf's People

Contributors

agreatfool avatar pmundt avatar naofum avatar

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.