Skip to content
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

Allow for resource-level deprecations #567

Merged
merged 1 commit into from
Nov 2, 2017
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
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ app_info
meta
Hash or array with custom metadata.

deprecated
Boolean value indicating if the resource is marked as deprecated. (Default false)

Example:
~~~~~~~~

Expand All @@ -154,6 +157,7 @@ Example:
error 500, "Server crashed for some <%= reason %>", :meta => {:anything => "you can think of"}
error :unprocessable_entity, "Could not save the entity."
meta :author => {:name => 'John', :surname => 'Doe'}
deprecated false
description <<-EOS
== Long description
Example resource for rest api documentation
Expand Down
6 changes: 5 additions & 1 deletion app/views/apipie/apipies/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
<h2>
<a href='<%= api[:doc_url] %><%= @doc[:link_extension] %>'>
<%= api[:name] %>
</a><br>
</a>
<% if api[:deprecated] %>
<code>DEPRECATED</code>
<% end %>
<br>
<small><%= api[:short_description] %></small>
</h2>
<table class='table'>
Expand Down
3 changes: 3 additions & 0 deletions app/views/apipie/apipies/resource.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<div class='page-header'>
<h1>
<%= @resource[:name] %>
<% if @resource[:deprecated] %>
<code>DEPRECATED</code>
<% end %>
<br>
<small><%= raw @resource[:short_description] %></small>
</h1>
Expand Down
8 changes: 7 additions & 1 deletion lib/apipie/dsl_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def _apipie_dsl_data_init
:formats => nil,
:api_versions => [],
:meta => nil,
:show => true
:show => true,
:deprecated => false
}
end
end
Expand Down Expand Up @@ -76,6 +77,11 @@ def path(path)
def app_info(app_info)
_apipie_dsl_data[:app_info] = app_info
end

def deprecated(value)
_apipie_dsl_data[:deprecated] = value
end

end

module Action
Expand Down
2 changes: 1 addition & 1 deletion lib/apipie/method_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def method_apis_to_json(lang = nil)
:api_url => create_api_url(api),
:http_method => api.http_method.to_s,
:short_description => Apipie.app.translate(api.short_description, lang),
:deprecated => api.options[:deprecated]
:deprecated => resource._deprecated || api.options[:deprecated]
}
end
end
Expand Down
7 changes: 5 additions & 2 deletions lib/apipie/resource_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ module Apipie
# id - resouce name
# formats - acceptable request/response format types
# headers - array of headers
# deprecated - boolean indicating if resource is deprecated
class ResourceDescription

attr_reader :controller, :_short_description, :_full_description, :_methods, :_id,
:_path, :_name, :_params_args, :_errors_args, :_formats, :_parent, :_metadata,
:_headers
:_headers, :_deprecated

def initialize(controller, resource_name, dsl_data = nil, version = nil, &block)

Expand Down Expand Up @@ -42,6 +43,7 @@ def update_from_dsl_data(dsl_data)
@_metadata = dsl_data[:meta]
@_api_base_url = dsl_data[:api_base_url]
@_headers = dsl_data[:headers]
@_deprecated = dsl_data[:deprecated] || false

if dsl_data[:app_info]
Apipie.configuration.app_info[_version] = dsl_data[:app_info]
Expand Down Expand Up @@ -109,7 +111,8 @@ def to_json(method_name = nil, lang = nil)
:formats => @_formats,
:metadata => @_metadata,
:methods => methods,
:headers => _headers
:headers => _headers,
:deprecated => @_deprecated
}
end

Expand Down
7 changes: 7 additions & 0 deletions spec/lib/method_description_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
method = Apipie::MethodDescription.new(:a, @resource, dsl_data)
expect(method.method_apis_to_json.first[:deprecated]).to eq(true)
end

it "should return the deprecated flag if resource is deprecated" do
@resource.instance_variable_set("@_deprecated", true)
dsl_data[:api_args] = [[:GET, "/foo/bar", "description", {}]]
method = Apipie::MethodDescription.new(:a, @resource, dsl_data)
expect(method.method_apis_to_json.first[:deprecated]).to eq(true)
end
end

describe "params descriptions" do
Expand Down