Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write and use OpenAPI specification #352

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ jobs:
name: Check styles using rubocop
command: bundle exec rubocop

- run:
name: Validate API specification
command: |
sudo npm install -g openapi-enforcer-cli
result=$(openapi-enforcer validate openapi.yml)
[[ $result =~ "Document is valid" ]] && {
echo "API specification is valid OAS (but may have warnings, see below)"
echo $result
exit 0
} || {
echo $result
exit 1
}

# Run rspec in parallel
- run:
name: Run rspec in parallel
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'rails', '~> 6.0.2'

gem 'bootsnap', '>= 1.1.0', require: false
gem 'committee' # Validates HTTP requests/responses per OpenAPI specification
gem 'config', '~> 2.0'
gem 'druid-tools'
gem 'honeybadger', '~> 4.1'
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Test Coverage](https://api.codeclimate.com/v1/badges/cc78d20264a4eaf8a782/test_coverage)](https://codeclimate.com/github/sul-dlss/workflow-server-rails/test_coverage)
[![Maintainability](https://api.codeclimate.com/v1/badges/cc78d20264a4eaf8a782/maintainability)](https://codeclimate.com/github/sul-dlss/workflow-server-rails/maintainability)
[![](https://images.microbadger.com/badges/image/suldlss/workflow-server.svg)](https://microbadger.com/images/suldlss/workflow-server "Get your own image badge on microbadger.com")
[![OpenAPI Validator](http://validator.swagger.io/validator?url=https://raw.githubusercontent.com/sul-dlss/workflow-server-rails/master/openapi.yml)](http://validator.swagger.io/validator/debug?url=https://raw.githubusercontent.com/sul-dlss/workflow-server-rails/master/openapi.yml)

This is a Rails-based workflow service that replaced SDR's Java-based workflow service. It is consumed by the users of dor-workflow-client (argo, hydrus, hydra_etd, pre-assembly, dor-indexing-app, robots) and *soon* the goobi application (currently proxying through dor-services-app).

Expand Down
28 changes: 28 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

# JSONAPIError class for returning properly formatted errors in openapi
class JSONAPIError < Committee::ValidationError
def error_body
{
errors: [
{ status: id, detail: message }
]
}
end

def render
[
status,
{ 'Content-Type' => 'application/vnd.api+json' },
[JSON.generate(error_body)]
]
end
end

module WorkflowServer
# Base Application
class Application < Rails::Application
Expand All @@ -33,6 +52,15 @@ class Application < Rails::Application
config.logger = ActiveSupport::TaggedLogging.new(logger)
end

accept_proc = proc { |request| request.path.start_with?('/') }
aaron-collier marked this conversation as resolved.
Show resolved Hide resolved
config.middleware.use Committee::Middleware::RequestValidation, schema_path: 'openapi.yml',
strict: true, error_class: JSONAPIError,
accept_request_filter: accept_proc
# TODO: we can uncomment this at a later date to ensure we are passing back
# valid responses.
#
# config.middleware.use Committee::Middleware::ResponseValidation, schema_path: 'openapi.yml'

# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
Expand Down
19 changes: 19 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Workflow Server API documentation</title>

<meta name="viewport" content="width=device-width, initial-scale=1">

<style>
body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<redoc spec-url='https://raw.githubusercontent.com/sul-dlss/workflow_server-rails/master/openapi.yml'></redoc>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to change master to main

<script src="https://cdn.jsdelivr.net/npm/[email protected]/bundles/redoc.standalone.js"> </script>
</body>
</html>
Loading