From 1b766cd5b3b75c17458fc3e7160f2d7f3cb7d688 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 18 Nov 2022 16:21:57 -0500 Subject: [PATCH] allow-user-to-pass-env-variables-when-generating-docs Why This is to allow users to use environment variables in their `open_api.yaml` file. Like so: ``` swagger: '2.0' info: title: My Api description: About my api version: "1.0.0" host: <%= ENV.fetch('host_name') %> ``` They could then call the generate command like: ``` host_name=env_specific_host.com rake docs:generate ``` This way someone can generate multiple different swaggers with different environemnts --- lib/rspec_api_documentation/writers/open_api_writer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rspec_api_documentation/writers/open_api_writer.rb b/lib/rspec_api_documentation/writers/open_api_writer.rb index ed5d0420..da5447a3 100644 --- a/lib/rspec_api_documentation/writers/open_api_writer.rb +++ b/lib/rspec_api_documentation/writers/open_api_writer.rb @@ -18,7 +18,7 @@ def write def load_config return JSON.parse(File.read("#{configurations_dir}/open_api.json")) if File.exist?("#{configurations_dir}/open_api.json") - YAML.load_file("#{configurations_dir}/open_api.yml") if File.exist?("#{configurations_dir}/open_api.yml") + YAML.load(ERB.new(File.read("#{configurations_dir}/open_api.yml")).result) if File.exist?("#{configurations_dir}/open_api.yml") end end