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 +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/jdoc/schema.rb +47 -1
- data/lib/jdoc/version.rb +1 -1
- data/lib/jdoc.rb +1 -0
- data/spec/fixtures/schema.yml +1 -1
- data/template.md.erb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b722b53c4f1b6c34b1391d78b3fb28e9e63d07c
|
4
|
+
data.tar.gz: 7cd3d992bd82307b617ebf3a763e8a485dd0df54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 693cd1ea1963567d84e9534f81aa6160af1204e3ec929ddd17fceb0329efbbcb68ae89b1a2019b5d9595cb1b055f8fc02173e1d4e6d5950cae8b60bf1b96a848
|
7
|
+
data.tar.gz: c81f05a6e4b42f0af9e27db63981109c8224b23a2f53bb057189ab401901ed23c1f5258d335ee30c920e1b47f45550bb47e3b9c9906ede51f4c3819a574a3616
|
data/CHANGELOG.md
CHANGED
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
|
-
#
|
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
data/lib/jdoc.rb
CHANGED
data/spec/fixtures/schema.yml
CHANGED
data/template.md.erb
CHANGED