0.2.4 • Published 5 years ago

pretty-swag v0.2.4

Weekly downloads
716
License
MIT
Repository
github
Last release
5 years ago

pretty-swag

pretty-swag is a UI for Swagger Specification V2. It is inspired by Swagger Editor.

An example of the generated html from petstore spec can be found here

Bugs filing and suggestions are always welcome.

Changelog

See CHANGELOG

Requirement

Node js

Installation

npm install pretty-swag -g

Usage

pretty-swag -i input.json
pretty-swag -c config.json
pretty-swag -i input.json -o output.html
pretty-swag -i input.json -o output.html -f lite
pretty-swag -i input.json -o output.html -f offline -m true
pretty-swag -i input.json -o output.html -f offline -m true -th default

API Usage

Syntax prettySwag.run(input,output,config,callback);

API Example

const prettySwag = require('pretty-swag');

config = {};
config.format = "singleFile";
config.markdown = true;
config.fixedNav = true;
config.autoTags = true;
config.theme = {
    "default": "blue",
    "GET": "blue",
    "POST": "indigo",
    "DELETE": "red",
    "PUT": "amber"
};

input = "input.json";
output = "doc.html";

prettySwag.run(input,output,config,function(err){
    if(err){
        console.log(err);
    }
    else{
        console.log("success");
    }
});

When dst equals null, no file will be written and the html will be returned as second parameter.

...
prettySwag.run(input,null,config,function(err,data){
    if(err){
        console.log(err);
    }
    else{
        console.log(data); // Plain html
    }
});

Command switch

SwitchNameOptionalDescription
-iinputNoLocation of a Swagger spec file(can be JSON or YAML)
-ooutputYesLocation of generated document(s). Default to doc.html
-fformatYesFormat of the output (singlefile, offline, lite, noicon). Default to singlefile
-mmarkdownYesRender Summary & Description as markdown. true or false. Default to false
-ththemeYesOne of the supported colors or pre-defined theme default
-cconfigYesLocation of a configuration file
-fixedNavfixedNavYesInclude this flag to fixed the navigation bar on screen
-autoTagsautoTagsYesInclude this flag to turn on/off automatically generate tags by path and method name
-noDatenoDateYesInclude this flag to remove generated date
-noCreditnoCreditYesInclude this flag to remove credit
-noNavnoNavYesInclude this flag to remove navigation bar. Default to false
-noReqnoRequestYesInclude this flag to remove request panel. Default to false
-noBaseURLnoBaseURLYesInclude this flag to suppress baseURL. Default to false
-indentindentYesInclude this flag to specify space per indentation. Default to 3
-vversionYesTo show pertty-swag current version
-collapsePathcollapse.pathYesCollapse path by default. true or false. Default to false
-collapseMethodcollapse.methodYesCollapse method by default. true or false. Default to false
-collapseToolcollapse.toolYesCollapse tool by default. true or false. Default to true
-home.urlhome.urlYesA home URL. Leave it blank to suppress the display
-home.locationhome.locationYesA location on navigation bar. Either L (Left) RL (Right before Expand) RR(Right most)
-home.texthome.textYesA text on navigation bar. Default to Home

Configuration File

Valid keys are:

  • input
  • output
  • format
  • markdown
  • theme
  • fixedNav
  • hideNav
  • autoTags
  • noDate
  • noCredit
  • noRequest
  • indent
  • collapse
  • customCSS
  • home

Example of Configuration file

{
  "input": "/tmp/petstore.json",
  "output": "/tmp/petstore.html",
  "format": "singlefile",
  "markdown": true,
  "theme": {
    "default": "blue",
    "GET": "blue",
    "POST": "indigo",
    "DELETE": "red",
    "PUT": "amber"
  },
  "fixedNav": true,
  "autoTags": true,
  "indent": 2,
  "collapse":{
    "path":true
    ,"method":true
    ,"tool":true
  }
  "home":{
      "URL": "https://github.com/twskj/pretty-swag/"
      ,"location": "RR"
      ,"text": "Home"
  }
}

Available Colors

  • red
  • pink
  • purple
  • deep-purple
  • indigo
  • blue
  • light-blue
  • cyan
  • teal
  • green
  • light-green
  • lime
  • yellow
  • amber
  • orange
  • deep-orange
  • brown
  • grey
  • blue-grey
  • black
  • white

Output format

  • SingleFile - A single html embedded all fonts and icon in one file. (Default).
  • Offline - A html file and a resource folder for css and js.
  • Lite - A single html but need the internet connection to obtain required resources.
  • NoIcon - Does not use Roboto font, and no icons (Useful when dealing with older IEs)

Features

  • Search / Filter by Tag

  • Collapsible Panel

  • Fold / Unfold Schema

  • Live Request / Response Feedback

  • Syntax Highlight code block

  • Download and Preview response data

Filtering

  • Use prefix - to exclude unwanted tags. For example -store will exclude api(s) that contain store tag.

Console

  • Press Ctrl + ` to bring up a console
  • Press tab to auto complete

Available Console Commands

CommandDescription
add header -g \<key> \<value>Adding the header to all paths/methods
remove header -g \<key> \<value>Remove a given header from all paths/methods

License

The contents of this repository are covered under the MIT License

Support on Beerpay

Like the project? buy me some :beers:!

Beerpay Beerpay

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.154

6 years ago

0.1.153

6 years ago

0.1.152

6 years ago

0.1.151

6 years ago

0.1.150

6 years ago

0.1.149

6 years ago

0.1.148

6 years ago

0.1.147

6 years ago

0.1.146

6 years ago

0.1.145

6 years ago

0.1.144

6 years ago

0.1.143

6 years ago

0.1.142

6 years ago

0.1.141

6 years ago

0.1.140

6 years ago

0.1.139

6 years ago

0.1.138

6 years ago

0.1.137

6 years ago

0.1.136

6 years ago

0.1.135

6 years ago

0.1.134

7 years ago

0.1.133

7 years ago

0.1.132

7 years ago

0.1.131

7 years ago

0.1.130

7 years ago

0.1.129

7 years ago

0.1.128

7 years ago

0.1.127

7 years ago

0.1.126

7 years ago

0.1.125

7 years ago

0.1.124

7 years ago

0.1.123

7 years ago

0.1.122

7 years ago

0.1.121

7 years ago

0.1.120

7 years ago

0.1.119

7 years ago

0.1.118

7 years ago

0.1.117

7 years ago

0.1.116

7 years ago

0.1.115

7 years ago

0.1.114

7 years ago

0.1.113

7 years ago

0.1.112

7 years ago

0.1.111

7 years ago

0.1.110

7 years ago

0.1.109

7 years ago

0.1.108

7 years ago

0.1.107

7 years ago

0.1.106

7 years ago

0.1.105

7 years ago

0.1.104

7 years ago

0.1.103

7 years ago

0.1.102

7 years ago

0.1.101

7 years ago

0.1.100

7 years ago

0.1.99

7 years ago

0.1.98

7 years ago

0.1.97

7 years ago

0.1.96

7 years ago

0.1.95

7 years ago

0.1.94

7 years ago

0.1.93

7 years ago

0.1.92

7 years ago

0.1.91

7 years ago

0.1.90

7 years ago

0.1.89

7 years ago

0.1.88

7 years ago

0.1.87

7 years ago

0.1.86

7 years ago

0.1.85

7 years ago

0.1.84

7 years ago

0.1.83

7 years ago

0.1.82

7 years ago

0.1.81

7 years ago

0.1.80

7 years ago

0.1.79

7 years ago

0.1.78

7 years ago

0.1.76

7 years ago

0.1.75

7 years ago

0.1.74

7 years ago

0.1.73

7 years ago

0.1.72

7 years ago

0.1.71

7 years ago

0.1.70

7 years ago

0.1.69

7 years ago

0.1.68

7 years ago

0.1.67

7 years ago

0.1.66

7 years ago

0.1.65

7 years ago

0.1.64

7 years ago

0.1.63

7 years ago

0.1.62

7 years ago

0.1.61

7 years ago

0.1.60

7 years ago

0.1.59

7 years ago

0.1.58

7 years ago

0.1.57

7 years ago

0.1.56

7 years ago

0.1.55

7 years ago

0.1.54

7 years ago

0.1.53

7 years ago

0.1.52

7 years ago

0.1.51

7 years ago

0.1.50

7 years ago

0.1.49

7 years ago

0.1.48

7 years ago

0.1.47

7 years ago

0.1.46

7 years ago

0.1.45

7 years ago

0.1.44

7 years ago

0.1.43

7 years ago

0.1.42

7 years ago

0.1.41

7 years ago

0.1.40

7 years ago

0.1.39

7 years ago

0.1.38

7 years ago

0.1.37

7 years ago

0.1.36

7 years ago

0.1.35

7 years ago

0.1.34

7 years ago

0.1.33

7 years ago

0.1.32

7 years ago

0.1.31

7 years ago

0.1.30

7 years ago

0.1.29

7 years ago

0.1.28

7 years ago

0.1.27

7 years ago

0.1.26

7 years ago

0.1.25

7 years ago

0.1.24

7 years ago

0.1.23

7 years ago

0.1.22

7 years ago

0.1.21

7 years ago

0.1.20

7 years ago

0.1.19

7 years ago

0.1.18

7 years ago

0.1.17

7 years ago

0.1.16

7 years ago

0.1.15

7 years ago

0.1.14

7 years ago

0.1.13

7 years ago

0.1.12

7 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago