Skip to content

Commit 18f876a

Browse files
WeiQuan0605Samze
andauthored
Add OSBAPI version to /v3/info (#4163)
* Add OSBAPI version to /v3/info * Adapt unittest * Update docs/v3/source/includes/api_resources/_info.erb Co-authored-by: Sam Gunaratne <[email protected]> --------- Co-authored-by: Sam Gunaratne <[email protected]>
1 parent 9e93c3d commit 18f876a

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

app/controllers/v3/info_controller.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ def v3_info
1616
info.version = config.get(:info, :version) || 0
1717
info.support_address = config.get(:info, :support_address) || ''
1818

19+
osbapi_version_file = Rails.root.join('config/osbapi_version').to_s
20+
if File.exist?(osbapi_version_file)
21+
info.osbapi_version = File.read(osbapi_version_file).strip
22+
else
23+
info.osbapi_version = ''
24+
Rails.logger.warn("OSBAPI version file not found at #{osbapi_version_file}")
25+
end
26+
1927
render status: :ok, json: VCAP::CloudController::Presenters::V3::InfoPresenter.new(info)
2028
end
2129

@@ -29,5 +37,5 @@ def show_usage_summary
2937
end
3038

3139
class Info
32-
attr_accessor :build, :min_cli_version, :min_recommended_cli_version, :custom, :description, :name, :version, :support_address
40+
attr_accessor :build, :min_cli_version, :min_recommended_cli_version, :custom, :description, :name, :version, :support_address, :osbapi_version
3341
end

app/presenters/v3/info_presenter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def to_hash
1515
description: info.description,
1616
name: info.name,
1717
version: info.version,
18+
osbapi_version: info.osbapi_version,
1819
links: {
1920
self: { href: build_self },
2021
support: { href: info.support_address }

docs/v3/source/includes/api_resources/_info.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"description": "Put your apps here!",
1212
"name": "Cloud Foundry",
1313
"version": 123,
14+
"osbapi_version": "2.15",
1415
"links": {
1516
"self": { "href": "http://api.example.com/v3/info" } ,
1617
"support": { "href": "http://support.example.com" }
@@ -29,6 +30,7 @@
2930
"description": "",
3031
"name": "",
3132
"version": 0,
33+
"osbapi_version": "",
3234
"links": {
3335
"self": { "href": "http://api.example.com/v3/info" } ,
3436
"support": { "href": "" }

spec/request/info_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,22 @@
1414
description: TestConfig.config[:info][:description],
1515
name: TestConfig.config[:info][:name],
1616
version: TestConfig.config[:info][:version],
17+
osbapi_version: TestConfig.config[:info][:osbapi_version],
1718
links: {
1819
self: { href: "#{link_prefix}/v3/info" },
1920
support: { href: TestConfig.config[:info][:support_address] }
2021
}
2122
}
2223
end
2324

25+
before do
26+
allow(File).to receive(:exist?).and_call_original
27+
allow(File).to receive(:exist?).with(Rails.root.join('config/osbapi_version').to_s).and_return(true)
28+
allow(File).to receive(:read).with(Rails.root.join('config/osbapi_version').to_s).and_return('1.0.0')
29+
30+
TestConfig.override(info: TestConfig.config[:info].merge(osbapi_version: '1.0.0'))
31+
end
32+
2433
it 'includes data from the config' do
2534
get '/v3/info'
2635
expect(Oj.load(last_response.body)).to match_json_response(return_info_json)
@@ -38,6 +47,7 @@
3847
description: '',
3948
name: '',
4049
version: 0,
50+
osbapi_version: '',
4151
links: {
4252
self: { href: "#{link_prefix}/v3/info" },
4353
support: { href: '' }
@@ -47,6 +57,7 @@
4757

4858
before do
4959
TestConfig.override(info: nil)
60+
allow(File).to receive(:exist?).with(Rails.root.join('config/osbapi_version').to_s).and_return(false)
5061
end
5162

5263
it 'includes has proper empty values' do

0 commit comments

Comments
 (0)