Skip to content

Commit

Permalink
Merge pull request #153 from exoego/add-custom-title
Browse files Browse the repository at this point in the history
Add custom title via RSpec::OpenAPI.title
  • Loading branch information
exoego authored Dec 1, 2023
2 parents 7804e0f + 2397ee0 commit c8ff1da
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ RSpec::OpenAPI.path = -> (example) {
end
}

RSpec::OpenAPI.title = 'OpenAPI Documentation'

# Disable generating `example`
RSpec::OpenAPI.enable_example = false

Expand Down
2 changes: 2 additions & 0 deletions lib/rspec/openapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

module RSpec::OpenAPI
@path = 'doc/openapi.yaml'
@title = File.basename(Dir.pwd)
@comment = nil
@enable_example = true
@description_builder = ->(example) { example.description }
Expand All @@ -30,6 +31,7 @@ module RSpec::OpenAPI

class << self
attr_accessor :path,
:title,
:comment,
:enable_example,
:description_builder,
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/openapi/result_recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(path_records)
end

def record_results!
title = File.basename(Dir.pwd)
title = RSpec::OpenAPI.title
@path_records.each do |path, records|
RSpec::OpenAPI::SchemaFile.new(path).edit do |spec|
schema = RSpec::OpenAPI::DefaultSchema.build(title)
Expand Down
1 change: 1 addition & 0 deletions spec/integration_tests/rails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'minitest/autorun'
require File.expand_path('../rails/config/environment', __dir__)

RSpec::OpenAPI.title = 'OpenAPI Documentation'
RSpec::OpenAPI.request_headers = %w[X-Authorization-Token]
RSpec::OpenAPI.response_headers = %w[X-Cursor]
RSpec::OpenAPI.path = File.expand_path("../rails/doc/openapi.#{ENV.fetch('OPENAPI_OUTPUT', nil)}", __dir__)
Expand Down
1 change: 1 addition & 0 deletions spec/integration_tests/roda_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

ENV['OPENAPI_OUTPUT'] ||= 'yaml'

RSpec::OpenAPI.title = 'OpenAPI Documentation'
RSpec::OpenAPI.path = File.expand_path("../roda/doc/openapi.#{ENV.fetch('OPENAPI_OUTPUT', nil)}", __dir__)

class RodaTest < Minitest::Test
Expand Down
2 changes: 1 addition & 1 deletion spec/rails/doc/openapi.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"openapi": "3.0.3",
"info": {
"title": "rspec-openapi",
"title": "OpenAPI Documentation",
"version": "1.0.0",
"description": "My beautiful API",
"license": {
Expand Down
2 changes: 1 addition & 1 deletion spec/rails/doc/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
---
openapi: 3.0.3
info:
title: rspec-openapi
title: OpenAPI Documentation
version: 1.0.0
description: My beautiful API
license:
Expand Down
1 change: 1 addition & 0 deletions spec/requests/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require File.expand_path('../rails/config/environment', __dir__)
require 'rspec/rails'

RSpec::OpenAPI.title = 'OpenAPI Documentation'
RSpec::OpenAPI.request_headers = %w[X-Authorization-Token]
RSpec::OpenAPI.response_headers = %w[X-Cursor]
RSpec::OpenAPI.path = File.expand_path("../rails/doc/openapi.#{ENV.fetch('OPENAPI_OUTPUT', nil)}", __dir__)
Expand Down
1 change: 1 addition & 0 deletions spec/requests/roda_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

ENV['OPENAPI_OUTPUT'] ||= 'yaml'

RSpec::OpenAPI.title = 'OpenAPI Documentation'
RSpec::OpenAPI.path = File.expand_path("../roda/doc/openapi.#{ENV.fetch('OPENAPI_OUTPUT', nil)}", __dir__)

RSpec::OpenAPI.description_builder = lambda do |example|
Expand Down
2 changes: 1 addition & 1 deletion spec/roda/doc/openapi.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"openapi": "3.0.3",
"info": {
"title": "rspec-openapi",
"title": "OpenAPI Documentation",
"version": "1.0.0"
},
"servers": [
Expand Down
2 changes: 1 addition & 1 deletion spec/roda/doc/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
openapi: 3.0.3
info:
title: rspec-openapi
title: OpenAPI Documentation
version: 1.0.0
servers: []
paths:
Expand Down

0 comments on commit c8ff1da

Please sign in to comment.