Skip to content

Commit

Permalink
Merge pull request #165 from exoego/feat
Browse files Browse the repository at this point in the history
Allow path-based config overrides
  • Loading branch information
exoego committed Jan 5, 2024
2 parents c1f6d52 + f391238 commit 71764c0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lib/rspec/openapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ module RSpec::OpenAPI
@path_records = Hash.new { |h, k| h[k] = [] }
@ignored_path_params = %i[controller action format]

# This is the configuraion override file name we look for within each path.
@config_filename = 'rspec_openapi.rb'

class << self
attr_accessor :path,
:title,
Expand All @@ -49,5 +52,7 @@ class << self
:response_headers,
:path_records,
:ignored_path_params

attr_reader :config_filename
end
end
10 changes: 9 additions & 1 deletion lib/rspec/openapi/result_recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ def initialize(path_records)
end

def record_results!
title = RSpec::OpenAPI.title
@path_records.each do |path, records|
# Look for a path-specific config file and run it.
config_file = File.join(File.dirname(path), RSpec::OpenAPI.config_filename)
begin
require config_file if File.exist?(config_file)
rescue => e
puts "WARNING: Unable to load #{config_file}: #{e}"
end

title = RSpec::OpenAPI.title
RSpec::OpenAPI::SchemaFile.new(path).edit do |spec|
schema = RSpec::OpenAPI::DefaultSchema.build(title)
schema[:info].merge!(RSpec::OpenAPI.info)
Expand Down
4 changes: 2 additions & 2 deletions spec/roda/doc/openapi.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"openapi": "3.0.3",
"info": {
"title": "OpenAPI Documentation",
"version": "1.0.0"
"title": "Override title",
"version": "7.7.7"
},
"servers": [

Expand Down
4 changes: 2 additions & 2 deletions spec/roda/doc/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
openapi: 3.0.3
info:
title: OpenAPI Documentation
version: 1.0.0
title: Override title
version: 7.7.7
servers: []
paths:
"/roda":
Expand Down
2 changes: 2 additions & 0 deletions spec/roda/doc/rspec_openapi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RSpec::OpenAPI.title = 'Override title'
RSpec::OpenAPI.application_version = '7.7.7'

0 comments on commit 71764c0

Please sign in to comment.