Skip to content

Commit

Permalink
freeze objects returned from some methods when the method creates the…
Browse files Browse the repository at this point in the history
… object
  • Loading branch information
notEthan committed Jan 29, 2022
1 parent bba280c commit 8649f08
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/scorpio/openapi/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def faraday_builder
attr_writer :faraday_adapter
def faraday_adapter
return @faraday_adapter if instance_variable_defined?(:@faraday_adapter)
[Faraday.default_adapter]
[Faraday.default_adapter].freeze
end

attr_writer :logger
Expand Down Expand Up @@ -157,7 +157,7 @@ def base_url(scheme: self.scheme, server: nil, server_variables: nil)
scheme: scheme,
host: host,
path: basePath,
)
).freeze
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/scorpio/openapi/operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ def request_schemas
if requestBody && requestBody['content']
# oamt is for Scorpio::OpenAPI::V3::MediaType
oamts = requestBody['content'].values.select { |oamt| oamt.key?('schema') }
oamts.map { |oamt| JSI::Schema.ensure_schema(oamt['schema']) }
oamts.map { |oamt| JSI::Schema.ensure_schema(oamt['schema']) }.freeze
else
[]
[].freeze
end
end

Expand Down Expand Up @@ -291,7 +291,7 @@ def request_schema(media_type: nil)

# @return [Array<JSI::Schema>]
def request_schemas
request_schema ? [request_schema] : []
request_schema ? [request_schema].freeze : [].freeze
end

# @param status [Integer, String] response status
Expand Down
2 changes: 1 addition & 1 deletion lib/scorpio/openapi/v3/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def expanded_url(given_server_variables)
server_variables = given_server_variables
end
template = Addressable::Template.new(url)
template.expand(server_variables)
template.expand(server_variables).freeze
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/scorpio/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def path
if query_params
path.query_values = query_params
end
path
path.freeze
end

# @return [Addressable::URI] the full URL for this request
Expand All @@ -188,7 +188,7 @@ def url
end
# we do not use Addressable::URI#join as the paths should just be concatenated, not resolved.
# we use File.join just to deal with consecutive slashes.
Addressable::URI.parse(File.join(base_url, path))
Addressable::URI.parse(File.join(base_url, path)).freeze
end

# @return [::Ur::ContentType] the value of the request Content-Type header
Expand Down

0 comments on commit 8649f08

Please sign in to comment.