File tree Expand file tree Collapse file tree 5 files changed +77
-2
lines changed Expand file tree Collapse file tree 5 files changed +77
-2
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,29 @@ GET /_cat/allocation/{node_id}
27
27
```
28
28
<!-- spec_insert_end -->
29
29
30
+ <!-- spec_insert_start
31
+ api: cat.allocation
32
+ component: example_code
33
+ query_params: v
34
+ -->
35
+ {% capture step1_rest %}
36
+ GET /_ cat/allocation?v
37
+ {% endcapture %}
38
+
39
+ {% capture step1_python %}
40
+ response = client.cat.allocation(v: true)
41
+ {% endcapture %}
42
+
43
+ {% capture step1_javascript %}
44
+ // TODO: add JS client call for cat.allocation
45
+ {% endcapture %}
46
+
47
+ {% include code-block.html
48
+ rest=step1_rest
49
+ python=step1_python
50
+ javascript=step1_javascript
51
+ %}
52
+ <!-- spec_insert_end -->
30
53
31
54
<!-- spec_insert_start
32
55
api: cat.allocation
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ class ExampleCode < BaseMustacheRenderer
4
+ self . template_file = "#{ __dir__ } /templates/example_code.mustache"
5
+
6
+ def initialize ( action , args )
7
+ super ( action , args )
8
+ end
9
+
10
+ def query_params
11
+ @args . raw [ 'query_params' ] &.split ( ',' ) &.map ( &:strip ) || [ ]
12
+ end
13
+
14
+ def rest_code
15
+ method = @action . http_verbs . first . upcase rescue 'GET'
16
+ path = @action . urls . first rescue '/'
17
+ query = query_params
18
+ query_string = query . any? ? "?#{ query . join ( '&' ) } " : ""
19
+ "#{ method } #{ path } #{ query_string } "
20
+ end
21
+
22
+ def python_code
23
+ query = query_params
24
+ args = query . map { |k | "#{ k } : true" } . join ( ', ' )
25
+ "response = client.#{ @action . full_name } (#{ args } )"
26
+ end
27
+
28
+ def javascript_code
29
+ "// TODO: add JS client call for #{ @action . full_name } "
30
+ end
31
+ end
Original file line number Diff line number Diff line change 7
7
require_relative 'path_parameters'
8
8
require_relative 'query_parameters'
9
9
require_relative 'body_parameters'
10
+ require_relative 'example_code'
10
11
11
12
# Class to render spec insertions
12
13
class SpecInsert < BaseMustacheRenderer
@@ -40,8 +41,10 @@ def content
40
41
BodyParameters . new ( @action , @args , is_request : true ) . render
41
42
when :response_body_parameters
42
43
BodyParameters . new ( @action , @args , is_request : false ) . render
44
+ when :example_code
45
+ ExampleCode . new ( @action , @args ) . render
43
46
else
44
- raise SpecInsertError , "Invalid component: #{ @args . component } "
47
+ raise SpecInsertError , "Invalid component: #{ @args . component } , from spec_insert.rb "
45
48
end
46
49
end
47
50
end
Original file line number Diff line number Diff line change
1
+ {% capture step1_rest %}
2
+ { {{rest_code} }}
3
+ {% endcapture %}
4
+
5
+ {% capture step1_python %}
6
+ { {{python_code} }}
7
+ {% endcapture %}
8
+
9
+ {% capture step1_javascript %}
10
+ { {{javascript_code} }}
11
+ {% endcapture %}
12
+
13
+ {% include code-block .html
14
+ rest= step1_rest
15
+ python= step1_python
16
+ javascript= step1_javascript
17
+ %}
Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ module Utils
13
13
'query_parameters' => 'Query Parameters' ,
14
14
'path_parameters' => 'Path Parameters' ,
15
15
'request_body_parameters' => 'Request Body Parameters' ,
16
- 'response_body_parameters' => 'Response Body Parameters'
16
+ 'response_body_parameters' => 'Response Body Parameters' ,
17
+ 'example_code' => 'Example Code'
17
18
} . freeze
18
19
19
20
# @return [Array<String>] list of markdown files to insert the spec components into
You can’t perform that action at this time.
0 commit comments