-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathrender_test.rb
More file actions
211 lines (195 loc) · 6.11 KB
/
render_test.rb
File metadata and controls
211 lines (195 loc) · 6.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
require_relative '../helpers'
require 'json_pointer'
class InteragentRenderTest < Minitest::Test
def test_render_for_valid_schema
markdown = render
assert_match(/An app in our PaaS ecosystem./, markdown)
end
def test_render_for_schema_with_property_defined_with_anyOf
pointer('#/definitions/app').merge!({
'properties' => {
'version' => {
'anyOf' => [
{ 'type' => 'string', 'example' => 'v10.9.rc1', 'minLength' => 1 },
{ 'type' => 'number', 'minimum' => 0 }
]
}
}
})
markdown = render
assert_match(/version.*v10\.9\.rc1/, markdown)
end
def test_render_for_schema_with_property_defined_with_oneOf
markdown = render
assert_match(/\*\*options\/\[OPTION1\]\.type\*\*/, markdown)
assert_match(/\*\*options\/\[OPTION2\]\.type\*\*/, markdown)
end
def test_render_for_toc
schema = Prmd::Schema.new(data)
template = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'prmd', 'templates'))
markdown = Prmd.render(schema, template: template, doc: { toc: true })
assert_match /^## The table of contents/, markdown
assert_match '<a href="#resource-app"', markdown
assert_match '- <a href="#app-create-app">POST /apps', markdown
assert_match '<a name="link-POST-app-/apps"', markdown
end
def test_render_for_example_as_an_array
# matches -d '[{...}]' taking into account line breaks and spacing
expression = /-d '\[[\s\n]+\{[\n\s]+\"name\": \"EXAMPLE\",[\n\s]+\"value\": \"example\"[\s\n]+\}[\n\s]+\]/
markdown = render
assert_match expression, markdown
end
private
def data
@data ||= {
'$schema' => 'http://interagent.github.io/interagent-hyper-schema',
'description' => 'My simple example API.',
'id' => 'http://example.com/schema',
'title' => 'Example API',
'definitions' => {
'app' => {
'description' => 'An app in our PaaS ecosystem.',
'title' => 'App',
'type' => 'object',
'definitions' => {
'identity' => {
'anyOf' => [
{
'$ref' => '#/definitions/app/definitions/name'
}
]
},
'name' => {
'description' => 'The app\'s name.',
'type' => 'string'
}
},
'links' => [
{
'description' => 'Create a new app.',
'href' => '/apps',
'method' => 'POST',
'rel' => 'create',
'title' => 'Create App'
}
],
'properties' => {
}
},
'config-var' => {
'description' => 'A configuration variable for an app.',
'title' => 'Config-var',
'type' => 'object',
'definitions' => {
'name' => {
'description' => 'The config-var\'s name.',
'type' => 'string',
'example' => 'EXAMPLE'
},
'value' => {
'description' => 'The config-var\'s value.',
'type' => 'string',
'example' => 'example'
},
'option-type1' => {
'type' => 'string',
'example' => 'OPTION1',
'enum' => 'OPTION1'
},
'option-type2' => {
'type' => 'string',
'example' => 'OPTION2',
'enum' => 'OPTION2'
},
'option1' => {
'properties' => {
'type' => {
'$ref' => '#/definitions/config-var/definitions/option-type1'
}
}
},
'option2' => {
'properties' => {
'type' => {
'$ref' => '#/definitions/config-var/definitions/option-type2'
}
}
},
'options' => {
'items' => {
'example'=> 'CHOICE1',
'oneOf' => [
{
'$ref' => '#/definitions/config-var/definitions/option1'
},
{
'$ref' => '#/definitions/config-var/definitions/option2'
}
]
}
}
},
'links' => [
{
'description' => 'Create many config-vars.',
'href' => '/config-vars',
'method' => 'PATCH',
'rel' => 'instances',
'title' => 'Create Config-var',
'schema' => {
'type' => [
'array'
],
'items' => {
'name' => {
'$ref' => '#/definitions/config-var/definitions/name'
},
'value' => {
'$ref' => '#/definitions/config-var/definitions/value'
},
'example' => [
{ 'name' => 'EXAMPLE', 'value' => 'example' }
]
}
}
}
],
'properties' => {
'name' => {
'$ref' => '#/definitions/config-var/definitions/name'
},
'value' => {
'$ref' => '#/definitions/config-var/definitions/value'
},
'options' => {
'$ref' => '#/definitions/config-var/definitions/options'
}
}
}
},
'links' => [
{
'href' => 'https://example.com',
'rel' => 'self'
}
],
'properties' => {
'app' => {
'$ref' => '#/definitions/app'
},
'config-var' => {
'$ref' => '#/definitions/config-var'
}
},
'type' => 'object'
}
end
def pointer(path)
JsonPointer.evaluate(data, path)
end
def render
schema = Prmd::Schema.new(data)
template = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'prmd', 'templates'))
Prmd.render(schema, template: template)
end
end