Giter Site home page Giter Site 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 naofum avatar pmundt 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  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

swagger-spec-to-pdf's Issues

Use yaml file as source instead of JSON

I have developed my Swagger source in YAML directly - I'd like to be able to use this tool without having to convert my source to JSON only to have it converted back to YAML prior to being rendered to the PDF.

Can this be done?

Support for openapi spec 3.0 ?

I was trying out this library with a swagger JSON file that is in the openapi v3.0 spec format. I noticed that some fields were excluded from the final pdf output. Fields like host and the responseBody object in the path are not being output in the final pdf. Any way these fields can be included in the final output?

Failed in executing electron script.http-server stopped.

Getting this error. There is no other information printed on the console

> swagger2pdf -v
1.1.0

Full Log:

Starting up http-server, serving /usr/lib/node_modules/swagger-spec-to-pdf/swagger-editor


http-server version: 14.1.1

http-server settings: 
CORS: disabled
Cache:  -1 seconds
Connection Timeout: 120 seconds
Directory Listings: visible
AutoIndex: visible
Serve GZIP Files: false
Serve Brotli Files: false
Default File Extension: none

Available on:
  http://127.0.0.1: 19849
  http://192.168.0.106: 19849
  http://172.16.0.1: 19849
  http://192.168.30.12: 19849
Hit CTRL-C to stop the server

throw er; // Unhandled 'error' event

unable to use swagger2pdf. Any help here is appreciated

Ubuntu 16.04 LTS

demouser@SGLinuxVM:$ node -v
v4.2.6
demouser@SGLinuxVM:
$ npm -v
3.5.2
demouser@SGLinuxVM:~$

demouser@SGLinuxVM:/usr/local/bin/node_modules/swagger-spec-to-pdf/bin$./swagger2pdf -s ../swagger-spec-sample.json -o ../dump/events.js:141
throw er; // Unhandled 'error' event
^

Error: spawn /usr/local/bin/node_modules/swagger-spec-to-pdf/node_modules/.bin/http-server ENOENT
at exports._errnoException (util.js:870:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
at onErrorNT (internal/child_process.js:344:16)
at nextTickCallbackWith2Args (node.js:441:9)
at process._tickCallback (node.js:355:17)

throw er; // Unhandled 'error' event (on v1.0.5)

Hi, I'm having this error below when trying to run the bin.
even with the sample json file.

Please help.

$ ./bin/swagger2pdf -s swagger-spec-sample.json -o ./dump/
events.js:182
throw er; // Unhandled 'error' event
^

Error: spawn D:\8-workspace\iot-dev\git-repo\librarian\node_modules\http-server\bin\http-server ENOENT
at exports._errnoException (util.js:1014:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:189:19)
at onErrorNT (internal/child_process.js:366:16)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9)

$ ./bin/swagger2pdf -v
1.0.5

$ npm -v
5.0.3

$ node -v
v8.1.0

throw er; // Unhandled 'error' event (on v1.0.7)

Hi, again.
I updated to 1.0.7
however getting almost the same error.

Please help.

$ swagger2pdf -v
1.0.7

$ swagger2pdf -s my_sample_swagger.json -o ./dump/
events.js:182
throw er; // Unhandled 'error' event
^

Error: spawn http-server ENOENT
at exports._errnoException (util.js:1014:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:189:19)
at onErrorNT (internal/child_process.js:366:16)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9)

Not intended Button and Text

Hello,

First of all : Thanks for this tool !

Now, I've some little troubble.
In the PDF generatedn there is unexpected test :
"Authenticate" and "Try this operation" Buttons texts
And
"API Design First Workflow
Easily create API specifications
Try a sample here"
At the end of document.

Is it possible to remove them ?
Thks in advance.

unhandled error

Tried to get this running ubuntu 16.04 64bit today, here's my error

holla@watson[538]: ./node_modules/swagger-spec-to-pdf/bin/swagger2pdf -s swagger.json -o ./dump/
events.js:141
throw er; // Unhandled 'error' event
^

Error: spawn /home/holla/api/node_modules/swagger-spec-to-pdf/node_modules/http-server/bin/http-server ENOENT
at exports._errnoException (util.js:870:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
at onErrorNT (internal/child_process.js:344:16)
at nextTickCallbackWith2Args (node.js:441:9)
at process._tickCallback (node.js:355:17)
at Function.Module.runMain (module.js:444:11)
at startup (node.js:136:18)
at node.js:966:3

any ideas?

Stalled conversion from yaml to pdf

I may just be doing something wrong, but when running "swagger2pdf -y ..."with a yaml doc, an http server starts up, and an Electron window opens, and eventually the command window says "Done.", but no pdf is created in my desired folder. I've left this running for an hour and nothing else happens. Is there something else I should do to continue with the yaml-to-pdf conversion?

I attached an image of my command window.

image

Install error on Ubuntu 16.04

What I type?

$ sudo npm install -g swagger-spec-to-pdf

What I get?

> [email protected] preinstall /usr/local/lib/node_modules/swagger-spec-to-pdf
> npm i -g http-server

npm ERR! path /usr/local/bin/http-server
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall unlink
npm ERR! Error: EACCES: permission denied, unlink '/usr/local/bin/http-server'
npm ERR!  { Error: EACCES: permission denied, unlink '/usr/local/bin/http-server'
npm ERR!   cause: 
npm ERR!    { Error: EACCES: permission denied, unlink '/usr/local/bin/http-server'
npm ERR!      errno: -13,
npm ERR!      code: 'EACCES',
npm ERR!      syscall: 'unlink',
npm ERR!      path: '/usr/local/bin/http-server' },
npm ERR!   stack: 'Error: EACCES: permission denied, unlink \'/usr/local/bin/http-server\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'unlink',
npm ERR!   path: '/usr/local/bin/http-server' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

Try it without global flag and sudo

$ npm install swagger-spec-to-pdf

get same error message as above

Try manual install http-server as mentioned as error message above

$ npm i -g http-server

http-server is installed, then run again

$ npm install swagger-spec-to-pdf

still get same error message as above

What should I do to getting this done?
Please advise.

Install error on osx

/usr/local/bin/http-server -> /usr/local/lib/node_modules/http-server/bin/http-server
/usr/local/bin/hs -> /usr/local/lib/node_modules/http-server/bin/http-server
/usr/local/lib
└── [email protected] 

/usr/local/lib
└── (empty)

npm ERR! Darwin 16.7.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "swagger-spec-to-pdf"
npm ERR! node v7.7.3
npm ERR! npm  v4.1.2
npm ERR! path /usr/local/lib/node_modules/.staging/array-find-index-e700d7ae
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename

npm ERR! enoent ENOENT: no such file or directory, rename '/usr/local/lib/node_modules/.staging/array-find-index-e700d7ae' -> '/usr/local/lib/node_modules/swagger-spec-to-pdf/node_modules/array-find-index'
npm ERR! enoent ENOENT: no such file or directory, rename '/usr/local/lib/node_modules/.staging/array-find-index-e700d7ae' -> '/usr/local/lib/node_modules/swagger-spec-to-pdf/node_modules/array-find-index'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/tony/ffc1_azurefunctions/swagger_static/npm-debug.log

runtime error

I am getting the following error

C:\tryouts\node_modules\swagger-spec-to-pdf>node ./bin/swagger2pdf -s ./swagger-spec-sample.json
Hello thereHello thereevents.js:160
throw er; // Unhandled 'error' event
^
Error: spawn C:\tryouts\node_modules\swagger-spec-to-pdf\node_modules.bin\http-server ENOENT
at exports._errnoException (util.js:1022:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:359:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)

thoughts?

Unhandled 'error' event

>swagger2pdf -s api.json -o dump\

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: spawn http-server ENOENT
    at exports._errnoException (util.js:1020:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
    at onErrorNT (internal/child_process.js:367:16)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)

>npm -v
5.3.0

>node -v
v6.11.2

>swagger2pdf -v
1.0.7

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.