Skip to content

Commit

Permalink
Add custom title
Browse files Browse the repository at this point in the history
  • Loading branch information
blacksam07 committed Nov 8, 2023
1 parent b95658c commit 8374cb7
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 3 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 @@ -29,6 +30,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
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

0 comments on commit 8374cb7

Please sign in to comment.