Skip to content

Commit 1dcc7f8

Browse files
authored
Merge pull request #422 from Erol/add-parameter-defaults-and-enums-to-api-blueprint
Add parameter/attribute defaults, enums and annotations for API Blueprint
2 parents 57ece91 + fa1c79a commit 1dcc7f8

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

features/api_blueprint_documentation.feature

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ Feature: Generate API Blueprint documentation from test examples
115115
attribute :name, 'The order name', required: true, :example => 'a name'
116116
attribute :amount, required: false
117117
attribute :description, 'The order description', type: 'string', required: false, example: "a description"
118+
attribute :category, 'The order category', type: 'string', required: false, default: 'normal', enum: %w[normal priority]
119+
attribute :metadata, 'The order metadata', type: 'json', required: false, annotation: <<-MARKDOWN
120+
+ instructions (optional, string)
121+
+ notes (optional, string)
122+
MARKDOWN
118123
119124
get 'Returns a single order' do
120125
explanation "This is used to return orders."
@@ -360,6 +365,14 @@ Feature: Generate API Blueprint documentation from test examples
360365
+ name: a name (required) - The order name
361366
+ amount (optional)
362367
+ description: a description (optional, string) - The order description
368+
+ category (optional, string) - The order category
369+
+ Default: `normal`
370+
+ Members
371+
+ `normal`
372+
+ `priority`
373+
+ metadata (optional, json) - The order metadata
374+
+ instructions (optional, string)
375+
+ notes (optional, string)
363376
364377
### Deletes a specific order [DELETE]
365378

lib/rspec_api_documentation/views/api_blueprint_index.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ def fields(property_name, examples)
8686
property[:properties_description] = nil
8787
end
8888

89+
property[:has_default?] = true if property[:default]
90+
property[:has_enum?] = true if property[:enum]
91+
92+
property[:annotations] = property[:annotation].lines.map(&:chomp) if property[:annotation]
93+
8994
property[:description] = nil if description_blank?(property)
9095
property
9196
end

templates/rspec_api_documentation/api_blueprint_index.mustache

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,37 @@ explanation: {{ explanation }}
2727
+ Parameters
2828
{{# parameters }}
2929
+ {{ name }}{{# example }}: {{ example }}{{/ example }}{{# properties_description }} ({{ properties_description }}){{/ properties_description }}{{# description }} - {{ description }}{{/ description }}
30+
{{# has_default?}}
31+
+ Default: `{{default}}`
32+
{{/ has_default?}}
33+
{{# has_enum?}}
34+
+ Members
35+
{{# enum}}
36+
+ `{{.}}`
37+
{{/ enum}}
38+
{{/ has_enum?}}
39+
{{# annotations }}
40+
{{ . }}
41+
{{/ annotations }}
3042
{{/ parameters }}
3143
{{/ has_parameters? }}
3244
{{# has_attributes? }}
3345

3446
+ Attributes (object)
3547
{{# attributes }}
3648
+ {{ name }}{{# example }}: {{ example }}{{/ example }}{{# properties_description }} ({{ properties_description }}){{/ properties_description }}{{# description }} - {{ description }}{{/ description }}
49+
{{# has_default?}}
50+
+ Default: `{{default}}`
51+
{{/ has_default?}}
52+
{{# has_enum?}}
53+
+ Members
54+
{{# enum}}
55+
+ `{{.}}`
56+
{{/ enum}}
57+
{{/ has_enum?}}
58+
{{# annotations }}
59+
{{ . }}
60+
{{/ annotations }}
3761
{{/ attributes }}
3862
{{/ has_attributes? }}
3963
{{# http_methods }}

0 commit comments

Comments
 (0)