Skip to content
Snippets Groups Projects
Commit e79936f8 authored by Justin Ehlert's avatar Justin Ehlert
Browse files

Refactor JSON Schemas and remove ABAO

parent 68a07fb0
No related branches found
No related tags found
No related merge requests found
Showing
with 679 additions and 1529 deletions
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"_id": {
"type": "string"
},
"database": {
"type": "integer"
}
},
"required": [
"_id",
"database"
]
"$ref": "../definitions/version.json#/definitions/version-output"
}
......@@ -26,6 +26,16 @@ tags:
description: Job operations
- name: collections
description: Collection operations
- name: sessions
description: Session operations
- name: acquisitions
description: Acquisition operations
- name: projects
description: Project operations
- name: reports
description: Site-wide reports
- name: batch
description: Batch job operations
paths:
$include:
......@@ -45,6 +55,12 @@ paths:
- paths/devices.yaml
- paths/groups.yaml
- paths/collections.yaml
- paths/sessions.yaml
- paths/acquisitions.yaml
- paths/projects.yaml
- paths/report.yaml
- paths/batch.yaml
securityDefinitions:
ApiKey:
......
......@@ -1250,6 +1250,12 @@
"find-up": "1.1.2"
}
},
"pluralize": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/pluralize/-/pluralize-7.0.0.tgz",
"integrity": "sha512-ARhBOdzS3e41FbkW/XWrTEtukqqLoK5+Z/4UeDaLuSW+39JPeFgs4gCGqsrJHVZX0fUrx//4OF0K1CUGwlIFow==",
"dev": true
},
"portscanner": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/portscanner/-/portscanner-1.2.0.tgz",
......
......@@ -20,6 +20,7 @@
"load-grunt-tasks": "^3.5.2",
"lodash": "^4.17.4",
"mustache": "^2.3.0",
"pluralize": "^7.0.0",
"swagger-ui-dist": "^3.6.0"
}
}
$template_arguments:
resource: acquisition
tag: acquisitions
parameter: AcquisitionId
/acquisitions:
$template: templates/container.yaml
arguments:
list-output-schema: schemas/output/acquisition-list.json
create-input-schema: schemas/input/acquisition.json
/acquisitions/{AcquisitionId}:
$template: templates/container-item.yaml
arguments:
update-input-schema: schemas/input/acquisition-update.json
get-output-schema: schemas/output/acquisition.json
# ===== Tags =====
/acquisitions/{AcquisitionId}/tags:
$template: templates/tags.yaml
/acquisitions/{AcquisitionId}/tags/{TagValue}:
$template: templates/tags-tag.yaml
# ===== Packfile =====
/acquisitions/{AcquisitionId}/packfile-start:
$template: templates/packfile-start.yaml
/acquisitions/{AcquisitionId}/packfile:
$template: templates/packfile.yaml
/acquisitions/{AcquisitionId}/packfile-end:
$template: templates/packfile-end.yaml
# ===== Files =====
/acquisitions/{AcquisitionId}/files:
$template: templates/file-list-upload.yaml
/acquisitions/{AcquisitionId}/files/{FileName}:
$template: templates/file-item.yaml
# ===== Notes =====
/acquisitions/{AcquisitionId}/notes:
$template: templates/notes.yaml
/acquisitions/{AcquisitionId}/notes/{NoteId}:
$template: templates/notes-note.yaml
# ===== Analyses =====
/acquisitions/{AcquisitionId}/analyses:
$template: templates/analyses-list.yaml
/acquisitions/{AcquisitionId}/analyses/{AnalysisId}:
$template: templates/analysis-item.yaml
/acquisitions/{AcquisitionId}/analyses/{AnalysisId}/files:
$template: templates/analysis-files.yaml
/acquisitions/{AcquisitionId}/analyses/{AnalysisId}/files/{Filename}:
$template: templates/analysis-files-create-ticket-filename.yaml
/acquisitions/{AcquisitionId}/analyses/{AnalysisId}/notes:
$template: templates/analysis-notes.yaml
/acquisitions/{AcquisitionId}/analyses/{AnalysisId}/notes/{NoteId}:
$template: templates/analysis-notes-item.yaml
/batch:
get:
summary: Get a list of batch jobs the user has created.
description: Requires login.
operationId: get_all_batch_jobs
tags:
- batch
responses:
'200':
schema:
$ref: schemas/output/batch-list.json
post:
summary: Create a batch job proposal and insert it as 'pending'.
operationId: create_batch_job
tags:
- batch
parameters:
- name: body
in: body
schema:
$ref: schemas/input/batch-insert.json
responses:
'200':
schema:
$ref: schemas/output/batch-insert.json
/batch/{BatchId}:
parameters:
- in: path
type: string
name: BatchId
required: true
get:
summary: Get batch job details.
parameters:
- in: query
type: boolean
name: jobs
description: If true, return job objects instead of job ids
operationId: get_batch_job
tags:
- batch
responses:
'200':
schema:
$ref: schemas/output/batch.json
'404':
$ref: '#/responses/404:resource-not-found'
/batch/{BatchId}/run:
parameters:
- in: path
type: string
name: BatchId
required: true
post:
summary: Launch a job.
description: |
Creates jobs from proposed inputs, returns jobs enqueued.
Moves 'pending' batch job to 'running'.
operationId: run_batch_job
tags:
- batch
responses:
'200':
schema:
$ref: schemas/output/job-list.json
/batch/{BatchId}/cancel:
parameters:
- in: path
type: string
name: BatchId
required: true
post:
summary: Cancel a Job
description: |
Cancels jobs that are still pending, returns number of jobs cancelled.
Moves a 'running' batch job to 'cancelled'.
operationId: cancel_batch_job
tags:
- batch
responses:
'200':
schema:
example:
canceled_jobs: 4
......@@ -7,8 +7,8 @@
responses:
'200':
description: ''
schema:
example: |
examples:
'application/javascript': |
config = {
"auth": {
"auth_endpoint": "https://accounts.google.com/o/oauth2/auth",
......
......@@ -26,8 +26,13 @@
tags:
- jobs
responses:
default:
'200':
description: ''
schema:
$ref: schemas/output/job.json
examples:
response:
$ref: examples/output/job.json
/jobs/stats:
get:
summary: Get stats about all current jobs
......
$template_arguments:
resource: project
tag: projects
parameter: ProjectId
/projects:
$template: templates/container.yaml
arguments:
list-output-schema: schemas/output/project-list.json
create-input-schema: schemas/input/project.json
/projects/{ProjectId}:
$template: templates/container-item.yaml
arguments:
update-input-schema: schemas/input/project-update.json
get-output-schema: schemas/output/project.json
/projects/groups:
get:
summary: List all groups which have a project in them
operationId: get_all_projects_groups
tags:
- 'projects'
responses:
'200':
description: ''
schema:
$ref: schemas/output/groups-list.json
'/projects/{ProjectId}/sessions':
parameters:
- in: path
type: string
name: ProjectId
required: true
get:
summary: List all sessions for the given project.
operationId: get_project_sessions
tags:
- 'projects'
responses:
'200':
schema:
$ref: schemas/output/session-list.json
'/projects/{ProjectId}/acquisitions':
get:
summary: List all acquisitions for the given project.
operationId: get_project_acquisitions
tags:
- 'projects'
responses:
'200':
schema:
$ref: schemas/output/acquisition-list.json
'/projects/{ProjectId}/rules':
parameters:
- in: path
type: string
name: ProjectId
required: true
get:
operationId: get_project_rules
tags:
- 'projects'
responses:
'200':
schema:
$ref: schemas/output/rule-list.json
post:
summary: Create a new rule for a project.
operationId: add_project_rule
tags:
- 'projects'
responses:
default:
description: ''
parameters:
- in: body
name: body
schema:
$ref: schemas/input/rule-new.json
'/projects/{ProjectId}/rules/{RuleId}':
parameters:
- in: path
type: string
name: ProjectId
required: true
- in: path
type: string
name: RuleId
required: true
put:
summary: Update a rule on a project.
operationId: modify_project_rule
tags:
- 'projects'
responses:
default:
description: ''
parameters:
- in: body
name: body
schema:
$ref: schemas/input/rule-update.json
'/projects/{ProjectId}/template':
parameters:
- in: path
type: string
name: ProjectId
required: true
post:
summary: Set the session template for a project.
operationId: set_project_template
tags:
- 'projects'
parameters:
- in: body
name: body
schema:
$ref: schemas/input/project-template.json
responses:
'200':
$ref: '#/responses/200:modified-with-count'
'404':
$ref: '#/responses/404:resource-not-found'
delete:
summary: Remove the session template for a project.
operationId: remove_project_template
tags:
- 'projects'
responses:
'200':
$ref: '#/responses/200:deleted-with-count'
'404':
$ref: '#/responses/404:resource-not-found'
'/projects/{ProjectId}/recalc':
parameters:
- in: path
type: string
name: ProjectId
required: true
post:
summary: Recalculate if sessions in the project satisfy the template.
description: Returns list of modified session ids.
operationId: recalc_project
tags:
- 'projects'
responses:
'200':
description: |
Project's sessions' compliance was recalculated.
Returns list of session that were modified.
schema:
$ref: schemas/output/session-template-recalc.json
'404':
$ref: '#/responses/404:resource-not-found'
/projects/recalc:
post:
summary: Recalculate all sessions against their project templates.
description: |
Iterates all projects that have a session template.
Recalculate if projects' sessions satisfy the template.
Returns list of modified session ids.
operationId: recalc_all_projects
tags:
- 'projects'
responses:
'200':
description: |
Projects' sessions' compliance was recalculated.
Returns list of session that were modified.
schema:
$ref: schemas/output/session-template-recalc.json
# ===== Tags =====
/projects/{ProjectId}/tags:
$template: templates/tags.yaml
/projects/{ProjectId}/tags/{TagValue}:
$template: templates/tags-tag.yaml
# ===== Packfile =====
/projects/{ProjectId}/packfile-start:
$template: templates/packfile-start.yaml
/projects/{ProjectId}/packfile:
$template: templates/packfile.yaml
/projects/{ProjectId}/packfile-end:
$template: templates/packfile-end.yaml
# ===== Files =====
/projects/{ProjectId}/files:
$template: templates/file-list-upload.yaml
/projects/{ProjectId}/files/{FileName}:
$template: templates/file-item.yaml
# ===== Permissions =====
/projects/{ProjectId}/permissions:
$template: templates/permissions.yaml
/projects/{ProjectId}/permissions/{UserId}:
$template: templates/permissions-user.yaml
# ===== Notes =====
/projects/{ProjectId}/notes:
$template: templates/notes.yaml
/projects/{ProjectId}/notes/{NoteId}:
$template: templates/notes-note.yaml
# ===== Analyses =====
/projects/{ProjectId}/analyses:
$template: templates/analyses-list.yaml
/projects/{ProjectId}/analyses/{AnalysisId}:
$template: templates/analysis-item.yaml
/projects/{ProjectId}/analyses/{AnalysisId}/files:
$template: templates/analysis-files.yaml
/projects/{ProjectId}/analyses/{AnalysisId}/files/{Filename}:
$template: templates/analysis-files-create-ticket-filename.yaml
/projects/{ProjectId}/analyses/{AnalysisId}/notes:
$template: templates/analysis-notes.yaml
/projects/{ProjectId}/analyses/{AnalysisId}/notes/{NoteId}:
$template: templates/analysis-notes-item.yaml
/report/site:
get:
operationId: get_site_report
tags:
- 'reports'
responses:
'200':
description: ''
schema:
$ref: schemas/output/report-site.json
/report/project:
get:
operationId: get_project_report
tags:
- 'reports'
parameters:
- in: query
type: string
name: projects
description: Specify multiple times to include projects in the report
- in: query
type: string
name: start_date
description: Report start date
- in: query
type: string
name: end_date
description: Report end date
responses:
'200':
description: ''
schema:
$ref: schemas/output/report-project.json
$template_arguments:
resource: session
tag: sessions
parameter: SessionId
/sessions:
$template: templates/container.yaml
arguments:
list-output-schema: schemas/output/session-list.json
create-input-schema: schemas/input/session.json
/sessions/{SessionId}:
$template: templates/container-item.yaml
arguments:
update-input-schema: schemas/input/session.json
get-output-schema: schemas/output/session.json
'/sessions/{SessionId}/jobs':
parameters:
- in: path
type: string
name: SessionId
required: true
get:
summary: Return any jobs that use inputs from this session
operationId: get_session_jobs
tags:
- 'sessions'
parameters:
- in: query
type: string
name: states
description: filter results by job state
- in: query
type: string
name: tags
description: filter results by job tags
responses:
'200':
schema:
$ref: schemas/output/session-jobs.json
# ===== Tags =====
/sessions/{SessionId}/tags:
$template: templates/tags.yaml
/sessions/{SessionId}/tags/{TagValue}:
$template: templates/tags-tag.yaml
# ===== Packfile =====
/sessions/{SessionId}/packfile-start:
$template: templates/packfile-start.yaml
/sessions/{SessionId}/packfile:
$template: templates/packfile.yaml
/sessions/{SessionId}/packfile-end:
$template: templates/packfile-end.yaml
# ===== Files =====
/sessions/{SessionId}/files:
$template: templates/file-list-upload.yaml
/sessions/{SessionId}/files/{FileName}:
$template: templates/file-item.yaml
# ===== Notes =====
/sessions/{SessionId}/notes:
$template: templates/notes.yaml
/sessions/{SessionId}/notes/{NoteId}:
$template: templates/notes-note.yaml
'/sessions/{SessionId}/acquisitions':
parameters:
- in: path
type: string
name: SessionId
required: true
get:
summary: List acquisitions in a session
operationId: get_session_acquisitions
tags:
- 'sessions'
responses:
'200':
description: ''
schema:
$ref: schemas/output/acquisition-list.json
# ===== Analyses =====
/sessions/{SessionId}/analyses:
parameters:
- required: true
type: string
in: path
name: 'SessionId'
post:
summary: Create an analysis and upload files.
description: |
When query param "job" is "true", send JSON to create
an analysis and job. Otherwise, multipart/form-data
to upload files and create an analysis.
operationId: add_session_analysis
tags:
- 'sessions'
parameters:
- in: body
name: body
schema:
$ref: schemas/input/analysis-job.json
- in: query
type: boolean
name: job
responses:
'200':
description: ''
/sessions/{SessionId}/analyses/{AnalysisId}:
$template: templates/analysis-item.yaml
/sessions/{SessionId}/analyses/{AnalysisId}/files:
$template: templates/analysis-files.yaml
/sessions/{SessionId}/analyses/{AnalysisId}/files/{Filename}:
$template: templates/analysis-files-create-ticket-filename.yaml
/sessions/{SessionId}/analyses/{AnalysisId}/notes:
$template: templates/analysis-notes.yaml
/sessions/{SessionId}/analyses/{AnalysisId}/notes/{NoteId}:
$template: templates/analysis-notes-item.yaml
......@@ -53,10 +53,10 @@
Redirects to the image file of the current user's avatar
/users/{UserId}:
parameters:
- required: true
- in: path
type: string
in: path
name: UserId
required: true
get:
summary: Get information about the specified user
operationId: get_user
......
......@@ -24,4 +24,8 @@
'400:invalid-body-json':
description: |
JSON did not validate against schema for this endpoint
JSON did not validate against schema for this endpoint.
'404:resource-not-found':
description: |
The specified resource could not be found.
\ No newline at end of file
......@@ -5,10 +5,24 @@ var path = require('path');
var fs = require('fs');
var process = require('process');
var yaml = require('js-yaml');
var pluralize = require('pluralize');
var Mustache = require('mustache');
var walk = require('./walk');
var TEMPLATE_FUNCS = {
'pluralize': function() {
return function(text, render) {
return pluralize.plural(render(text));
};
},
'singularize': function() {
return function(text, render) {
return pluralize.singular(render(text));
};
}
};
// Throws if args are missing
function validateTemplateArgs(tmplpath, template, args) {
var i, param;
......@@ -73,18 +87,20 @@ SwaggerResolver.prototype.loadFile = function(relpath) {
};
SwaggerResolver.prototype.visit = function(obj) {
if( !obj ) {
return obj;
}
// obj will have $template or $include, not both
if( obj.hasOwnProperty('$include') ) {
obj = this.resolveIncludes(obj);
// Recursively resolve content
obj = this.resolveObject(obj);
} else if( obj.hasOwnProperty('$template') ) {
obj = this.resolveTemplate(obj);
// Recursively resolve content
obj = this.resolveObject(obj);
} else if( obj.hasOwnProperty('$template_arguments') ) {
// Save off template arguments for later
this.templateArguments = obj['$template_arguments'];
delete obj['$template_arguments'];
}
......@@ -102,8 +118,10 @@ SwaggerResolver.prototype.resolveIncludes = function(obj) {
delete obj['$include'];
for( i = 0; i < includes.length; i++ ) {
// Load the include file
// Load and resolve the include file
inc = this.loadFile(includes[i]);
inc = this.resolveObject(inc);
// And merge its contents into obj
_.extend(obj, inc);
}
......@@ -124,7 +142,7 @@ SwaggerResolver.prototype.resolveTemplate = function(obj) {
}
// Validate arguments?
args = obj['arguments']||this.templateArguments||{};
args = _.extend({}, TEMPLATE_FUNCS, this.templateArguments, obj['arguments']);
validateTemplateArgs(tmplpath, tmpl, args);
// Render the template, and parse
......
......@@ -59,7 +59,7 @@ module.exports = function(grunt) {
if( !root.definitions ) {
root.definitions = {};
}
_.extend(root.definitions, schemas.getComplexDefinitions());
// _.extend(root.definitions, schemas.getComplexDefinitions());
// Write destination file
var data = JSON.stringify(root, null, 2);
......
parameters:
- name: resource
type: string
- name: tag
type: string
- name: parameter
type: string
- name: update-input-schema
type: string
- name: get-output-schema
type: string
template: |
parameters:
- in: path
type: string
name: '{{parameter}}'
required: true
get:
summary: Get a single {{resource}}
operationId: get_{{resource}}
tags:
- '{{tag}}'
responses:
'200':
schema:
$ref: {{{get-output-schema}}}
put:
summary: Update a {{resource}}
operationId: modify_{{resource}}
tags:
- '{{tag}}'
parameters:
- in: body
name: body
schema:
$ref: {{{update-input-schema}}}
responses:
'200':
$ref: '#/responses/200:modified-with-count'
'400':
$ref: '#/responses/400:invalid-body-json'
delete:
summary: Delete a {{resource}}
operationId: delete_{{resource}}
tags:
- '{{tag}}'
responses:
'200':
$ref: '#/responses/200:deleted-with-count'
parameters:
- name: resource
type: string
- name: tag
type: string
- name: list-output-schema
type: string
- name: create-input-schema
type: string
template: |
get:
summary: Get a list of {{#pluralize}}{{resource}}{{/pluralize}}
operationId: get_all_{{#pluralize}}{{resource}}{{/pluralize}}
tags:
- '{{tag}}'
responses:
'200':
schema:
$ref: {{{list-output-schema}}}
post:
summary: Create a new {{resource}}
operationId: create_{{resource}}
tags:
- '{{tag}}'
parameters:
- in: body
name: body
schema:
$ref: {{{create-input-schema}}}
responses:
'200':
schema:
$ref: schemas/output/container-new.json
'400':
$ref: '#/responses/400:invalid-body-json'
......@@ -19,7 +19,6 @@ Options:
-l, --lint Run linting
-u, --unit Run unit tests
-i, --integ Run integration tests
-a, --abao Run abao tests
-h, --help Print this help and exit
-- PYTEST_ARGS Arguments passed to py.test
......@@ -40,7 +39,6 @@ function main() {
local RUN_LINT=false
local RUN_UNIT=false
local RUN_INTEG=false
local RUN_ABAO=false
local PYTEST_ARGS=
while [[ "$#" > 0 ]]; do
......@@ -48,7 +46,6 @@ function main() {
-l|--lint) RUN_ALL=false; RUN_LINT=true ;;
-u|--unit) RUN_ALL=false; RUN_UNIT=true ;;
-i|--integ) RUN_ALL=false; RUN_INTEG=true ;;
-a|--abao) RUN_ALL=false; RUN_ABAO=true ;;
-h|--help) usage; exit 0 ;;
--) PYTEST_ARGS="${@:2}"; break ;;
*) echo "Invalid argument: $1" >&2; usage; exit 1 ;;
......@@ -61,8 +58,7 @@ function main() {
RUN_LINT=true
RUN_UNIT=true
RUN_INTEG=true
RUN_ABAO=true
elif ${RUN_LINT} && ${RUN_UNIT} && ${RUN_INTEG} && ${RUN_ABAO}; then
elif ${RUN_LINT} && ${RUN_UNIT} && ${RUN_INTEG}; then
# All filtering options were used, the same as none
RUN_ALL=true
fi
......@@ -100,7 +96,7 @@ function main() {
py.test --cov=api --cov-report= tests/unit_tests/python $PYTEST_ARGS
fi
if ${RUN_INTEG} || ${RUN_ABAO}; then
if ${RUN_INTEG}; then
echo "Spinning up dependencies ..."
uwsgi --http "localhost:8081" --master --http-keepalive \
--so-keepalive --add-header "Connection: Keep-Alive" \
......@@ -123,38 +119,10 @@ function main() {
printf '.'
sleep 1
done
fi
if ${RUN_INTEG}; then
echo "Running integration tests ..."
py.test tests/integration_tests/python $PYTEST_ARGS
fi
if ${RUN_ABAO}; then
echo "Running abao tests ..."
# Create resources that Abao relies on
python tests/integration_tests/abao/load_fixture.py
# If no VIRTUAL_ENV, make sure /usr/local/bin is in the path
if [[ -z "${VIRTUAL_ENV:-}" ]]; then
PATH="/usr/local/bin:$PATH"
npm install tests/integration_tests
else
npm install --global tests/integration_tests
fi
PATH="$(npm bin):$PATH"
# Allow us to require modules from package.json,
# since abao_test_hooks.js is not being called from the package directory
integration_test_node_modules="$(pwd)/node_modules/scitran-core-integration-tests/node_modules"
# Have to change into definitions directory to resolve
# relative $ref's in the jsonschema's
pushd raml/schemas/definitions
NODE_PATH="$integration_test_node_modules" abao ../../api.raml "--server=$SCITRAN_SITE_API_URL" "--hookfiles=../../../tests/integration_tests/abao/abao_test_hooks.js"
popd
fi
}
......
......@@ -5,10 +5,3 @@ cd "$( dirname "${BASH_SOURCE[0]}" )/../.."
sudo pip install -U -r "tests/integration_tests/requirements-integration-test.txt"
NODE_URL="https://nodejs.org/dist/v6.4.0/node-v6.4.0-linux-x64.tar.gz"
if [[ -z "${VIRTUAL_ENV:-}" ]]; then
curl $NODE_URL | sudo tar xz -C /usr/local --strip-components 1
else
curl $NODE_URL | tar xz -C $VIRTUAL_ENV --strip-components 1
fi
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment