postman_markdoc 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/postman_markdoc +13 -0
- data/lib/postman_markdoc.rb +41 -0
- data/lib/postman_markdoc/collection_parser.rb +26 -0
- data/lib/postman_markdoc/markdown_generator.rb +42 -0
- data/lib/postman_markdoc/request_parser.rb +37 -0
- metadata +49 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 9c42037a2ac6222e6234c07e352297e46da29641
|
|
4
|
+
data.tar.gz: 99d99b89233208bd94044a474789203e3532a127
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 808a8caf23bd5c532e218804e65d6d78c9039469d13fbf24f0d37ab3886233b243c9e94336743f334ac420e8f7185e51ed2446dc078ba41f89f4e92364ba1b52
|
|
7
|
+
data.tar.gz: eafcfdaabbfbdb9e08dcc70d7154123d4b73395e81d3eaf019f897424d6d275480f40585072f87ce924461b7af8aff5612895af1965d083c5c54b6254e5971d2
|
data/bin/postman_markdoc
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#! /usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'postman_markdoc'
|
|
4
|
+
stdin = STDIN.tty? ? nil : STDIN.read
|
|
5
|
+
files = ARGV
|
|
6
|
+
if stdin.nil? && files == []
|
|
7
|
+
puts "USAGE: specify files of collections"
|
|
8
|
+
puts "postman_markdown collection1.json collection2.json"
|
|
9
|
+
elsif stdin.nil?
|
|
10
|
+
puts PostmanMarkdoc.files_to_markdown(*files)
|
|
11
|
+
else
|
|
12
|
+
puts PostmanMarkdoc.raw_json_to_markdown(stdin)
|
|
13
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
class PostmanMarkdoc
|
|
4
|
+
|
|
5
|
+
# accepts filenames as arguments
|
|
6
|
+
# returns markdown string
|
|
7
|
+
def self.files_to_markdown(*file_names)
|
|
8
|
+
raw_json = file_names.map{|f| IO.read(f)}
|
|
9
|
+
collections = raw_json.map{|json| JSON.parse(json)}
|
|
10
|
+
self.new(*collections).markdown
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# accepts raw json collection string as argument
|
|
14
|
+
# returns markdown string
|
|
15
|
+
def self.raw_json_to_markdown(raw_json)
|
|
16
|
+
collection = JSON.parse(raw_json)
|
|
17
|
+
self.new(collection).markdown
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
attr_reader :collections, :markdown
|
|
21
|
+
|
|
22
|
+
# accepts hash representations of postman json collections
|
|
23
|
+
def initialize(*args)
|
|
24
|
+
@collections = args
|
|
25
|
+
generate_markdown
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def generate_markdown
|
|
29
|
+
@markdown = ""
|
|
30
|
+
collections.each do |collection|
|
|
31
|
+
@markdown << PostmanMarkdoc::MarkdownGenerator.generate(
|
|
32
|
+
data: collection
|
|
33
|
+
).content
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
require_relative 'postman_markdoc/collection_parser.rb'
|
|
40
|
+
require_relative 'postman_markdoc/markdown_generator.rb'
|
|
41
|
+
require_relative 'postman_markdoc/request_parser.rb'
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class PostmanMarkdoc::CollectionParser
|
|
2
|
+
|
|
3
|
+
attr_reader :data
|
|
4
|
+
|
|
5
|
+
def initialize(data)
|
|
6
|
+
@data = data
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def name
|
|
10
|
+
data['info']['name']
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def description
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def requests
|
|
17
|
+
@requests = item.map{|i| PostmanMarkdoc::RequestParser.new(i)}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def item
|
|
23
|
+
@data['item'] || []
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
class PostmanMarkdoc::MarkdownGenerator
|
|
2
|
+
|
|
3
|
+
def self.generate(*args)
|
|
4
|
+
generator = self.new(*args)
|
|
5
|
+
generator.generate
|
|
6
|
+
generator
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
attr_reader :data, :content
|
|
10
|
+
|
|
11
|
+
def initialize(options = {})
|
|
12
|
+
@data = options[:data]
|
|
13
|
+
@content = options[:content] || ""
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def generate
|
|
17
|
+
collection = PostmanMarkdoc::CollectionParser.new(data)
|
|
18
|
+
@content << "## #{collection.name}\n\n"
|
|
19
|
+
if collection.description != nil
|
|
20
|
+
@content << "#{collection.description}\n\n"
|
|
21
|
+
end
|
|
22
|
+
collection.requests.each do |request|
|
|
23
|
+
@content << "### #{request.method} #{request.name}\n\n"
|
|
24
|
+
@content << "```\n#{request.url}\n```\n\n"
|
|
25
|
+
if request.description. != nil
|
|
26
|
+
@content << "#{request.description}\n\n"
|
|
27
|
+
end
|
|
28
|
+
if request.headers != []
|
|
29
|
+
@content << "#### Headers\n```\n"
|
|
30
|
+
request.headers.each do |header|
|
|
31
|
+
@content << header['key']
|
|
32
|
+
@content << "\t\t\t\t\t"
|
|
33
|
+
@content << header['value']
|
|
34
|
+
@content << "\n"
|
|
35
|
+
end
|
|
36
|
+
@content << "```\n"
|
|
37
|
+
end
|
|
38
|
+
@content << "#### Body\n```\n#{request.body}\n```\n"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
class PostmanMarkdoc::RequestParser
|
|
2
|
+
|
|
3
|
+
attr_reader :data
|
|
4
|
+
|
|
5
|
+
def initialize(data)
|
|
6
|
+
@data = data
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def name
|
|
10
|
+
data['name']
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def description
|
|
14
|
+
request['description']
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def method
|
|
18
|
+
request['method']
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def headers
|
|
22
|
+
@headers ||= request['header'] || []
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def body
|
|
26
|
+
request['body']['raw']
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def url
|
|
30
|
+
request['url']['raw']
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def request
|
|
34
|
+
data['request']
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: postman_markdoc
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Raman Walwyn-Venugopal
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-03-15 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description:
|
|
14
|
+
email: ramanvenu94@gmail.com
|
|
15
|
+
executables:
|
|
16
|
+
- postman_markdoc
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- bin/postman_markdoc
|
|
21
|
+
- lib/postman_markdoc.rb
|
|
22
|
+
- lib/postman_markdoc/collection_parser.rb
|
|
23
|
+
- lib/postman_markdoc/markdown_generator.rb
|
|
24
|
+
- lib/postman_markdoc/request_parser.rb
|
|
25
|
+
homepage: https://rubygems.org/gems/postman_markdoc
|
|
26
|
+
licenses:
|
|
27
|
+
- MIT
|
|
28
|
+
metadata: {}
|
|
29
|
+
post_install_message:
|
|
30
|
+
rdoc_options: []
|
|
31
|
+
require_paths:
|
|
32
|
+
- lib
|
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '0'
|
|
43
|
+
requirements: []
|
|
44
|
+
rubyforge_project:
|
|
45
|
+
rubygems_version: 2.5.1
|
|
46
|
+
signing_key:
|
|
47
|
+
specification_version: 4
|
|
48
|
+
summary: Convert Postman Collections to Markdown
|
|
49
|
+
test_files: []
|