-
Notifications
You must be signed in to change notification settings - Fork 472
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
Add fixed fields #431
Add fixed fields #431
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,18 +103,28 @@ def path_item(routes, options) | |
|
||
def method_object(route, options, path) | ||
method = {} | ||
method[:summary] = summary_object(route) | ||
method[:description] = description_object(route, options[:markdown]) | ||
method[:produces] = produces_object(route, options[:produces] || options[:format]) | ||
method[:consumes] = consumes_object(route, options[:format]) | ||
method[:parameters] = params_object(route) | ||
method[:responses] = response_object(route, options[:markdown]) | ||
method[:tags] = tag_object(route, options[:version].to_s) | ||
method[:deprecated] = deprecated_object(route) | ||
method[:operationId] = GrapeSwagger::DocMethods::OperationId.build(route, path) | ||
method.delete_if { |_, value| value.blank? } | ||
|
||
[route.request_method.downcase.to_sym, method] | ||
end | ||
|
||
def summary_object(route) | ||
summary = route.options[:desc] if route.options.key?(:desc) | ||
summary = route.description if route.description.present? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this assumes, that, if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part was mostly interpretation, but when comparing Open API v1.2 Operation Object and Open API v2 Operation Object specs, desc 'Add a new pet to the store' do
detail 'More details'
end To produce: {
...
"summary": "Add a new pet to the store",
"description": "Add a new pet to the store\n More details",
...
} More importantly, I base on what appears in SwaggerUI so that the route summary appears next to the route name, as pictured: This was the default behavior for when I used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also open for proposals 😉 want to say I'm fine with your suggestion above, I want only one point mention, yeap swagger-ui is changing a lot at the moment, cause IMO a valid swagger is much more important then a nice looking one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, I will split this PR into two separate ones to keep the changes atomic. I will close this one and open another. |
||
summary = route.options[:summary] if route.options.key?(:summary) | ||
|
||
summary | ||
end | ||
|
||
def description_object(route, markdown) | ||
description = route.options[:desc] if route.options.key?(:desc) | ||
description = route.description if route.description.present? | ||
|
@@ -189,6 +199,10 @@ def tag_object(route, version) | |
Array(route.path.split('{')[0].split('/').reject(&:empty?).delete_if { |i| ((i == route.prefix.to_s) || (i == version)) }.first) | ||
end | ||
|
||
def deprecated_object(route) | ||
route.options.key?(:deprecated) && route.options[:deprecated] | ||
end | ||
|
||
private | ||
|
||
def partition_params(route) | ||
|
@@ -237,9 +251,7 @@ def expose_params_from_model(model) | |
|
||
GrapeSwagger.model_parsers.each do |klass, ancestor| | ||
next unless model.ancestors.map(&:to_s).include?(ancestor) | ||
|
||
parser = klass.new(model, self) | ||
|
||
break | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'spec_helper' | ||
|
||
describe 'swagger spec v2.0 deprecation' do | ||
include_context "#{MODEL_PARSER} swagger example" | ||
|
||
def app | ||
Class.new(Grape::API) do | ||
format :json | ||
|
||
desc 'This is a test sample', deprecated: true | ||
get '/old' do | ||
present true | ||
end | ||
|
||
desc 'This is another test sample', deprecated: false | ||
get '/new' do | ||
present true | ||
end | ||
|
||
version 'v1', using: :path | ||
add_swagger_documentation api_version: 'v1', | ||
base_path: '/api', | ||
info: { | ||
title: 'The API title to be displayed on the API homepage.', | ||
description: 'A description of the API.', | ||
contact_name: 'Contact name', | ||
contact_email: 'Contact@email.com', | ||
contact_url: 'Contact URL', | ||
license: 'The name of the license.', | ||
license_url: 'www.The-URL-of-the-license.org', | ||
terms_of_service_url: 'www.The-URL-of-the-terms-and-service.com' | ||
} | ||
end | ||
end | ||
|
||
before do | ||
get '/v1/swagger_doc' | ||
end | ||
|
||
let(:json) { JSON.parse(last_response.body) } | ||
|
||
describe 'deprecation' do | ||
it { expect(json['paths']['/old']['get']['deprecated']).to eql true } | ||
it { expect(json['paths']['/new']['get']).to_not include 'deprecated' } | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this back please.