-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Update openapi_first and use it's coverage thing (#783)
* Update openapi_first and use it's coverage thing This removes skip_oas_request_validation, because the app wrapped by OpenapiFirst::Test.app does not raise errors, but just tracks requests/responses to collect coverage data. * Add test about responding with application/problem+json Fix API coverage issue. This results in removal of this test output:
- Loading branch information
Showing
5 changed files
with
33 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,20 @@ | ||
OAS_COVERAGE_CHECK_ENABLED = ENV["OAS_COVERAGE_CHECK_ENABLED"] == "true" | ||
|
||
# fairly crappy OAS coverage check | ||
if OAS_COVERAGE_CHECK_ENABLED | ||
require "openapi_first" | ||
require "openapi_first/coverage" | ||
require "support/openapi_first/pact_broker_coverage" | ||
|
||
endpoints_to_be_called = OpenapiFirst::PactBrokerCoverage.build_endpoints_list(OpenapiFirst.load("pact_broker_oas.yaml")) | ||
|
||
RSpec.configure do | config | | ||
config.after(:suite) do | ||
if endpoints_to_be_called.any? | ||
raise "Missing coverage of #{endpoints_to_be_called.join("\n")}" | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
||
RSpec.shared_context "app" do | ||
let(:app) do | example | | ||
require "openapi_first" | ||
require "pact_broker/api" | ||
require "pact_broker/application_context" | ||
require "rack/pact_broker/application_context" | ||
application_context = PactBroker::ApplicationContext.default_application_context | ||
builder = Rack::Builder.new | ||
|
||
# If the feature spec should be used to validate the OAS, add the metadata `validate_oas: true` to the top level spec | ||
if example.metadata[:validate_oas] | ||
# To test the validation responses, a deliberately invalid request must be sent. | ||
# To stop the middleware raising that as an error, | ||
# add the metadata `skip_oas_request_validation: true` to the individual spec. | ||
unless example.metadata[:skip_oas_request_validation] | ||
builder.use OpenapiFirst::RequestValidation, spec: "pact_broker_oas.yaml", raise_error: true | ||
end | ||
|
||
builder.use OpenapiFirst::ResponseValidation, spec: "pact_broker_oas.yaml", raise_error: true | ||
end | ||
|
||
if OAS_COVERAGE_CHECK_ENABLED | ||
builder.use OpenapiFirst::PactBrokerCoverage, endpoints_to_be_called | ||
end | ||
|
||
builder.use(PactBroker::Middleware::MockPuma) | ||
builder.use(Rack::PactBroker::ApplicationContext, application_context) | ||
builder.run(PactBroker.build_api(application_context)) | ||
builder.to_app | ||
|
||
# If the feature spec should be used to validate the OAS, add the metadata `validate_oas: true` to the top level spec | ||
if example.metadata[:validate_oas] | ||
OpenapiFirst::Test.app(builder.to_app) | ||
else | ||
builder.to_app | ||
end | ||
end | ||
end |