Skip to content

Add parameter/attribute defaults, enums and annotations for API Blueprint #422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions features/api_blueprint_documentation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ Feature: Generate API Blueprint documentation from test examples
attribute :name, 'The order name', required: true, :example => 'a name'
attribute :amount, required: false
attribute :description, 'The order description', type: 'string', required: false, example: "a description"
attribute :category, 'The order category', type: 'string', required: false, default: 'normal', enum: %w[normal priority]
attribute :metadata, 'The order metadata', type: 'json', required: false, annotation: <<-MARKDOWN
+ instructions (optional, string)
+ notes (optional, string)
MARKDOWN

get 'Returns a single order' do
explanation "This is used to return orders."
Expand Down Expand Up @@ -360,6 +365,14 @@ Feature: Generate API Blueprint documentation from test examples
+ name: a name (required) - The order name
+ amount (optional)
+ description: a description (optional, string) - The order description
+ category (optional, string) - The order category
+ Default: `normal`
+ Members
+ `normal`
+ `priority`
+ metadata (optional, json) - The order metadata
+ instructions (optional, string)
+ notes (optional, string)

### Deletes a specific order [DELETE]

Expand Down
5 changes: 5 additions & 0 deletions lib/rspec_api_documentation/views/api_blueprint_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def fields(property_name, examples)
property[:properties_description] = nil
end

property[:has_default?] = true if property[:default]
property[:has_enum?] = true if property[:enum]

property[:annotations] = property[:annotation].lines.map(&:chomp) if property[:annotation]

property[:description] = nil if description_blank?(property)
property
end
Expand Down
24 changes: 24 additions & 0 deletions templates/rspec_api_documentation/api_blueprint_index.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,37 @@ explanation: {{ explanation }}
+ Parameters
{{# parameters }}
+ {{ name }}{{# example }}: {{ example }}{{/ example }}{{# properties_description }} ({{ properties_description }}){{/ properties_description }}{{# description }} - {{ description }}{{/ description }}
{{# has_default?}}
+ Default: `{{default}}`
{{/ has_default?}}
{{# has_enum?}}
+ Members
{{# enum}}
+ `{{.}}`
{{/ enum}}
{{/ has_enum?}}
{{# annotations }}
{{ . }}
{{/ annotations }}
{{/ parameters }}
{{/ has_parameters? }}
{{# has_attributes? }}

+ Attributes (object)
{{# attributes }}
+ {{ name }}{{# example }}: {{ example }}{{/ example }}{{# properties_description }} ({{ properties_description }}){{/ properties_description }}{{# description }} - {{ description }}{{/ description }}
{{# has_default?}}
+ Default: `{{default}}`
{{/ has_default?}}
{{# has_enum?}}
+ Members
{{# enum}}
+ `{{.}}`
{{/ enum}}
{{/ has_enum?}}
{{# annotations }}
{{ . }}
{{/ annotations }}
{{/ attributes }}
{{/ has_attributes? }}
{{# http_methods }}
Expand Down