jdoc 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 123bb745b74176f50d28727ac49d577c9a905360
4
- data.tar.gz: 920d22e689edefcec4150268505e8ea8c6396771
3
+ metadata.gz: 4b722b53c4f1b6c34b1391d78b3fb28e9e63d07c
4
+ data.tar.gz: 7cd3d992bd82307b617ebf3a763e8a485dd0df54
5
5
  SHA512:
6
- metadata.gz: 887e7113ba533a804ce16c512af98f176b2fb459e2968a45fddc4f99eaf666fd3f14d75e1fe42bfb0b925ec6024e5e4ed2fea293d0a26b23247e07efd645bd31
7
- data.tar.gz: 4a2b82a99ccc84a9039875cbea22010a20f157e6aff7d65df70a847fa03a034b0c2327b4e2f1c3aa4296c5ef657bfd67a55a702b54f5f915f0057f694f465039
6
+ metadata.gz: 693cd1ea1963567d84e9534f81aa6160af1204e3ec929ddd17fceb0329efbbcb68ae89b1a2019b5d9595cb1b055f8fc02173e1d4e6d5950cae8b60bf1b96a848
7
+ data.tar.gz: c81f05a6e4b42f0af9e27db63981109c8224b23a2f53bb057189ab401901ed23c1f5258d335ee30c920e1b47f45550bb47e3b9c9906ede51f4c3819a574a3616
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.0.6
2
+ * Use root API endpoint at example response
3
+
1
4
  ## 0.0.5
2
5
  * Remove dependency on multi_json
3
6
 
data/lib/jdoc/schema.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Jdoc
2
2
  class Schema
3
+ DEFAULT_ENDPOINT = "https://api.example.com"
4
+
3
5
  # Recursively extracts all links in given JSON schema
4
6
  # @param json_schema [JsonSchema::Schema]
5
7
  # @return [Array] An array of JsonSchema::Schema::Link
@@ -28,15 +30,59 @@ module Jdoc
28
30
  @json_schema.title
29
31
  end
30
32
 
33
+ # @return [String]
34
+ # @example
35
+ # host_with_port #=> "api.example.com"
36
+ # host_with_port #=> "api.example.com:3000"
37
+ def host_with_port
38
+ if [80, 443].include?(port)
39
+ host
40
+ else
41
+ "#{host}:#{port}"
42
+ end
43
+ end
44
+
31
45
  private
32
46
 
47
+ # @return [Fixnum] Port number for this API endpoint
48
+ def port
49
+ root_uri.port || 80
50
+ end
51
+
52
+ # @return [String] Host name of API, used at dummy Host header
53
+ # @example
54
+ # schema.host #=> "api.example.com"
55
+ def host
56
+ root_uri.host
57
+ end
58
+
33
59
  # @return [Array] All links defined in given JSON schema
34
60
  # @example
35
- # schema.links #=> [#<JsonSchema::Schema::Link>]
61
+ # links #=> [#<JsonSchema::Schema::Link>]
36
62
  def links
37
63
  @links ||= self.class.extract_links(@json_schema).map do |link|
38
64
  Link.new(link: link)
39
65
  end.sort
40
66
  end
67
+
68
+ # @return [URI::Generic] Root endpoint for the API
69
+ # @example
70
+ # root_uri #=> "https://api.example.com"
71
+ def root_uri
72
+ @root_endpoint = begin
73
+ if link = link_for_root_endpoint
74
+ URI(link.href)
75
+ else
76
+ URI(DEFAULT_ENDPOINT)
77
+ end
78
+ end
79
+ end
80
+
81
+ # @return [JsonSchema::Schema::Link]
82
+ def link_for_root_endpoint
83
+ @json_schema.links.find do |link|
84
+ link.rel == "self" && link.href
85
+ end
86
+ end
41
87
  end
42
88
  end
data/lib/jdoc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jdoc
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/jdoc.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "cgi"
2
2
  require "erubis"
3
3
  require "json_schema"
4
+ require "uri"
4
5
 
5
6
  require "jdoc/generator"
6
7
  require "jdoc/link"
@@ -75,6 +75,6 @@ type:
75
75
  - object
76
76
  description: A schema for a small example API.
77
77
  links:
78
- - href: http://localhost:5000
78
+ - href: https://api.example.com
79
79
  rel: self
80
80
  title: Example API
data/template.md.erb CHANGED
@@ -25,7 +25,7 @@
25
25
  ```
26
26
  <%= link.method %> <%= link.path %> HTTP/1.1
27
27
  Content-Type: application/json
28
- Host: api.example.com
28
+ Host: <%= schema.host_with_port %>
29
29
  <%= "\n" + link.request_body if link.has_request_body? -%>
30
30
  ```
31
31
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura