diff --git a/lib/pact_broker/api.rb b/lib/pact_broker/api.rb index d4b1f0d48..daa7cfc07 100644 --- a/lib/pact_broker/api.rb +++ b/lib/pact_broker/api.rb @@ -38,9 +38,12 @@ module PactBroker add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'latest-untagged'], Api::Resources::LatestPact, {resource_name: "latest_untagged_pact_publication", tag: :untagged} add ['pacts', 'provider', :provider_name, 'latest'], Api::Resources::LatestProviderPacts, {resource_name: "latest_provider_pact_publications"} add ['pacts', 'provider', :provider_name, 'latest', :tag], Api::Resources::LatestProviderPacts, {resource_name: "latest_tagged_provider_pact_publications"} - add ['pacts', 'provider', :provider_name, 'wip'], Api::Resources::WipProviderPacts, {resource_name: "wip_provider_pact_publications"} add ['pacts', 'latest'], Api::Resources::LatestPacts, {resource_name: "latest_pacts"} + if ENV['RACK_ENV'] != 'production' + add ['pacts', 'provider', :provider_name, 'wip'], Api::Resources::WipProviderPacts, {resource_name: "wip_provider_pact_publications"} + end + # Deprecated pact add ['pact', 'provider', :provider_name, 'consumer', :consumer_name, 'version', :consumer_version_number], Api::Resources::Pact, {resource_name: "pact_publications", deprecated: "true"} # Deprecate, singular /pact add ['pact', 'provider', :provider_name, 'consumer', :consumer_name, 'latest'], Api::Resources::LatestPact, {resource_name: "latest_pact_publications", deprecated: "true"} diff --git a/lib/pact_broker/api/resources/index.rb b/lib/pact_broker/api/resources/index.rb index 1908cb937..fbb8df222 100644 --- a/lib/pact_broker/api/resources/index.rb +++ b/lib/pact_broker/api/resources/index.rb @@ -16,84 +16,88 @@ def allowed_methods end def to_json + { _links: links }.to_json + end + + def links { - _links: { - 'self' => - { - href: base_url, - title: 'Index', - templated: false - }, - 'pb:publish-pact' => { - href: base_url + '/pacts/provider/{provider}/consumer/{consumer}/version/{consumerApplicationVersion}', - title: 'Publish a pact', - templated: true - }, - 'pb:latest-pact-versions' => - { - href: base_url + '/pacts/latest', - title: 'Latest pact versions', - templated: false - }, - 'pb:pacticipants' => - { - href: base_url + '/pacticipants', - title: 'Pacticipants', - templated: false - }, - 'pb:latest-provider-pacts' => - { - href: base_url + '/pacts/provider/{provider}/latest', - title: 'Latest pacts by provider', - templated: true - }, - 'pb:latest-provider-pacts-with-tag' => - { - href: base_url + '/pacts/provider/{provider}/latest/{tag}', - title: 'Latest pacts for provider with the specified tag', - templated: true - }, - 'pb:provider-pacts-with-tag' => - { - href: base_url + '/pacts/provider/{provider}/tag/{tag}', - title: 'All pact versions for the provider with the specified consumer version tag', - templated: true - }, - 'pb:provider-pacts' => - { - href: base_url + '/pacts/provider/{provider}', - title: 'All pact versions for the specified provider', - templated: true - }, - 'pb:wip-provider-pacts' => - { - href: base_url + '/pacts/provider/{provider}/wip', - title: 'WIP pact versions for the specified provider', - templated: true - }, - 'pb:latest-version' => { - href: base_url + '/pacticipants/{pacticipant}/latest-version', - title: 'Latest pacticipant version', - templated: true - }, - 'pb:latest-tagged-version' => { - href: base_url + '/pacticipants/{pacticipant}/latest-version/{tag}', - title: 'Latest pacticipant version with the specified tag', - templated: true - }, - 'pb:webhooks' => { - href: base_url + '/webhooks', - title: 'Webhooks', - templated: false - }, - 'curies' => - [{ - name: 'pb', - href: base_url + '/doc/{rel}?context=index', - templated: true - }] - } - }.to_json + 'self' => + { + href: base_url, + title: 'Index', + templated: false + }, + 'pb:publish-pact' => { + href: base_url + '/pacts/provider/{provider}/consumer/{consumer}/version/{consumerApplicationVersion}', + title: 'Publish a pact', + templated: true + }, + 'pb:latest-pact-versions' => + { + href: base_url + '/pacts/latest', + title: 'Latest pact versions', + templated: false + }, + 'pb:pacticipants' => + { + href: base_url + '/pacticipants', + title: 'Pacticipants', + templated: false + }, + 'pb:latest-provider-pacts' => + { + href: base_url + '/pacts/provider/{provider}/latest', + title: 'Latest pacts by provider', + templated: true + }, + 'pb:latest-provider-pacts-with-tag' => + { + href: base_url + '/pacts/provider/{provider}/latest/{tag}', + title: 'Latest pacts for provider with the specified tag', + templated: true + }, + 'pb:provider-pacts-with-tag' => + { + href: base_url + '/pacts/provider/{provider}/tag/{tag}', + title: 'All pact versions for the provider with the specified consumer version tag', + templated: true + }, + 'pb:provider-pacts' => + { + href: base_url + '/pacts/provider/{provider}', + title: 'All pact versions for the specified provider', + templated: true + }, + 'pb:wip-provider-pacts' => + { + href: base_url + '/pacts/provider/{provider}/wip', + title: 'WIP pact versions for the specified provider', + templated: true + }, + 'pb:latest-version' => { + href: base_url + '/pacticipants/{pacticipant}/latest-version', + title: 'Latest pacticipant version', + templated: true + }, + 'pb:latest-tagged-version' => { + href: base_url + '/pacticipants/{pacticipant}/latest-version/{tag}', + title: 'Latest pacticipant version with the specified tag', + templated: true + }, + 'pb:webhooks' => { + href: base_url + '/webhooks', + title: 'Webhooks', + templated: false + }, + 'curies' => + [{ + name: 'pb', + href: base_url + '/doc/{rel}?context=index', + templated: true + }] + }.tap do | it | + it.delete('pb:wip-provider-pacts') if ENV['RACK_ENV'] == 'production' + end end end end