From 7cc692d12d13a84896dc7699e261935fb96fe76d Mon Sep 17 00:00:00 2001 From: Viktor Shamal Andersen Date: Tue, 15 Oct 2024 10:21:23 +0200 Subject: [PATCH] Convert header response to strings instead of symbols (#5) * Update app.rb Change headers from symbols to strings * Use double quotes to align with style guide --------- Co-authored-by: viktorshamal --- lib/apicraft/middlewares/introspector.rb | 2 +- lib/apicraft/middlewares/mocker.rb | 2 +- lib/apicraft/middlewares/request_validator.rb | 2 +- lib/apicraft/web/app.rb | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/apicraft/middlewares/introspector.rb b/lib/apicraft/middlewares/introspector.rb index ac5aadf..a0adf92 100644 --- a/lib/apicraft/middlewares/introspector.rb +++ b/lib/apicraft/middlewares/introspector.rb @@ -25,7 +25,7 @@ def call(env) [ 200, - { 'Content-Type': "application/json" }, + { "Content-Type" => "application/json" }, [schema.to_json] ] end diff --git a/lib/apicraft/middlewares/mocker.rb b/lib/apicraft/middlewares/mocker.rb index 4a5d3c8..2c7800d 100644 --- a/lib/apicraft/middlewares/mocker.rb +++ b/lib/apicraft/middlewares/mocker.rb @@ -30,7 +30,7 @@ def call(env) [ code.to_i, { - 'Content-Type': content_type + "Content-Type" => content_type }, [ content&.send(convertor(content_type)) diff --git a/lib/apicraft/middlewares/request_validator.rb b/lib/apicraft/middlewares/request_validator.rb index f91760c..1760158 100644 --- a/lib/apicraft/middlewares/request_validator.rb +++ b/lib/apicraft/middlewares/request_validator.rb @@ -31,7 +31,7 @@ def call(env) rescue OpenAPIParser::OpenAPIError => e [ config.request_validation_http_code, - { 'Content-Type': content_type }, + { "Content-Type" => content_type }, [ response_body(e)&.send(convertor(content_type)) ].compact diff --git a/lib/apicraft/web/app.rb b/lib/apicraft/web/app.rb index 37b326f..6d4b42a 100644 --- a/lib/apicraft/web/app.rb +++ b/lib/apicraft/web/app.rb @@ -23,19 +23,19 @@ def self.call(env) [ 200, - { 'Content-Type': content_type }, + { "Content-Type" => content_type }, [content] ] rescue Errors::RouteNotFound [ 404, - { 'Content-Type': "text/plain" }, + { "Content-Type" => "text/plain" }, ["Error: not found"] ] rescue StandardError => e [ 500, - { 'Content-Type': "text/plain" }, + { "Content-Type" => "text/plain" }, ["Error: #{e.message}"] ] end @@ -54,8 +54,8 @@ def self.unauthorized_response [ 401, { - "Content-Type": "text/plain", - "WWW-Authenticate": "Basic realm=\"Restricted Area\"" + "Content-Type" => "text/plain", + "WWW-Authenticate" => "Basic realm=\"Restricted Area\"" }, ["Unauthorized"] ]