Add test examples to DFC API documentation

In other API specs, you provide example values in the schema. So the
specs contain examples which can be used for the documentation. But
instead of defining example data separately, we can use the generated
data by the specs. This way we document real output and don't have to
double up on documentation.

Note that we don't have schema definitions for the DFC API yet. And it
wouldn't make sense to replicate the DFC Ontology manually in JSON
Schema for this purpose. The DFC Connector ensures already that we
comply with the ontology. But I hope that we can use a tool at some
point to generate JSON Schema from the DFC Ontology which would add more
detail to the Swagger docs, I think.
This commit is contained in:
Maikel Linke
2023-06-23 16:00:01 +10:00
parent b14c9bdf4c
commit db77d1591c
6 changed files with 102 additions and 5 deletions

View File

@@ -106,6 +106,25 @@ RSpec.configure do |config|
ActionController::Base.perform_caching = caching
end
# Take example responses from Rswag specs for API documentation.
# https://github.com/rswag/rswag#enable-auto-generation-examples-from-responses
config.after(:each, :rswag_autodoc) do |example|
next if response&.body.blank?
example.metadata[:response][:content] ||= {}
example.metadata[:response][:content].deep_merge!(
{
"application/json" => {
examples: {
test_example: {
value: JSON.parse(response.body, symbolize_names: true)
}
}
}
}
)
end
# Show javascript errors in test output with `js_debug: true`
config.after(:each, :js_debug) do
errors = page.driver.browser.manage.logs.get(:browser)