Skip to content

Commit c8c59fe

Browse files
committed
manual merge of #135
1 parent 450746f commit c8c59fe

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

src/main/resources/ruby/swagger/configuration.mustache

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ module Swagger
33
class Configuration
44
require 'swagger/version'
55

6-
attr_accessor :format, :api_key, :username, :password, :auth_token, :scheme, :host, :base_path,
7-
:user_agent, :logger, :inject_format
6+
attr_accessor :format, :api_key, :username, :password, :auth_token, :scheme, :host, :base_path, :user_agent, :logger, :inject_format, :force_ending_format, :camelize_params
87

98
# Defaults go in here..
109
def initialize
@@ -14,8 +13,10 @@ module Swagger
1413
@base_path = '/v4'
1514
@user_agent = "ruby-#{Swagger::VERSION}"
1615
@inject_format = true
16+
@force_ending_format = false
17+
@camelize_params = true
1718
end
1819

1920
end
2021

21-
end
22+
end

src/main/resources/ruby/swagger/request.mustache

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ module Swagger
8787
end
8888
end
8989

90+
# Stick a .{format} placeholder on the end of the path if there isn't
91+
# one already or an actual format like json or xml
92+
# e.g. /words/blah => /words/blah.{format}
93+
if Swagger.configuration.force_ending_format
94+
unless ['.json', '.xml', '{format}'].any? {|s| p.downcase.include? s }
95+
p = "#{p}.#{format}"
96+
end
97+
end
98+
9099
p = p.sub("{format}", self.format.to_s)
91100

92101
URI.encode [Swagger.configuration.base_path, p].join("/").gsub(/\/+/, '/')
@@ -121,7 +130,9 @@ module Swagger
121130
self.params.each_pair do |key, value|
122131
next if self.path.include? "{#{key}}" # skip path params
123132
next if value.blank? && value.class != FalseClass # skip empties
124-
key = key.to_s.camelize(:lower).to_sym unless key.to_sym == :api_key # api_key is not a camelCased param
133+
if Swagger.configuration.camelize_params
134+
key = key.to_s.camelize(:lower).to_sym unless key.to_sym == :api_key # api_key is not a camelCased param
135+
end
125136
query_values[key] = value.to_s
126137
end
127138

@@ -185,4 +196,4 @@ module Swagger
185196
end
186197

187198
end
188-
end
199+
end

src/main/scala/com/wordnik/swagger/codegen/BasicRubyGenerator.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ object BasicRubyGenerator extends BasicRubyGenerator {
2626

2727
class BasicRubyGenerator extends BasicGenerator {
2828

29-
override def toApiName(name: String) = {
30-
name(0).toUpper + name.substring(1) + "_api"
31-
}
32-
3329
override def apiPackage = Some("lib")
3430

3531
// location of templates
@@ -58,9 +54,13 @@ class BasicRubyGenerator extends BasicGenerator {
5854
}
5955
}
6056

61-
override def toModelFilename(name: String) = name.toLowerCase
62-
override def toApiFilename(name: String) = name.toLowerCase + "_api"
57+
override def toApiName(name: String) = {
58+
var fixedName = name.replaceAll("(\\{|\\})","")
59+
fixedName(0).toUpper + fixedName.substring(1) + "_api"
60+
}
6361

62+
override def toModelFilename(name: String) = name.toLowerCase.replaceAll("(\\{|\\})","")
63+
override def toApiFilename(name: String) = name.toLowerCase.replaceAll("(\\{|\\})","") + "_api"
6464
override def toVarName(name: String): String = toUnderscore(name)
6565

6666
override def toMethodName(name: String): String = toUnderscore(name)

0 commit comments

Comments
 (0)