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
api: openapi specification generation #40
api: openapi specification generation #40
Conversation
850a222
to
3cdf4d7
Compare
reana_job_controller/cli.py
Outdated
|
||
import json | ||
|
||
import click |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add click
to the required dependencies in setup.py
. (And test in a fresh environment for others.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
click
comes with Flask
0.11:
Collecting click>=2.0 (from Flask>=0.11->reana-job-controller==0.0.1.dev20170123)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the saying goes, "better be safe than sorry" :), so an explicit click
dependency may be safer than an implicit one, in the case when Flask would decide to make it optional. (Well, that's not probable...)
run-tests.sh
Outdated
@@ -23,7 +23,7 @@ | |||
pydocstyle reana_job_controller && \ | |||
isort -rc -c -df **/*.py && \ | |||
check-manifest --ignore ".travis-*" && \ | |||
sphinx-build -qnNW docs docs/_build/html && \ | |||
sphinx-build -qnN docs docs/_build/html && \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be good to generate a "temporary" OpenAPI specs and compare it with previously-generated and committed one, so that developers are alerted if they changed something important and need to regenerate it.
def get_openapi_spec(): | ||
"""Get OpenAPI Spec. | ||
|
||
FIXME add openapi spec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should make issues for these FIXMEs if we don't have time to attack them within a day or two?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely, there are things such as validating OpenAPI spec file which is generated in run_tests.sh
which is far from being acceptable. I will open issues 👍
@openapi.command() | ||
@click.argument('output', type=click.File('w')) | ||
@with_appcontext | ||
def create(output): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to plug CLI call into Sphinx documentation. Perhaps a new "CLI" chapter, perhaps simply under "Getting started" for now.
339e468
to
60e7d97
Compare
docs/gettingstarted.rst
Outdated
|
||
.. code-block:: console | ||
|
||
$ flask openapi create output_file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FLASK_APP=reana_job_controller/app.py flask openapi create openapi.json
docs/gettingstarted.rst
Outdated
CLI | ||
--- | ||
|
||
The REANA Job Controller package offers the possibility to create its OpenAPI specification file using the flask CLI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using the Flask CLI:
@@ -23,6 +23,7 @@ include COPYING | |||
include *.rst | |||
include *.sh | |||
include pytest.ini | |||
include docs/openapi.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to include this file in the repository, otherwise RTFD wouldn't build the documentation.
run-tests.sh
Outdated
python setup.py test && \ | ||
sphinx-build -qnNW -b doctest docs docs/_build/doctest && \ | ||
sphinx-build -qnN -b doctest docs docs/_build/doctest && \ | ||
rm -rf docs/openapi.json && \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment above regarding having the OpenAPI spec file in the package.
reana_job_controller/app.py
Outdated
|
||
--- | ||
get: | ||
description: Get a Job by its id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a bit more descriptive, for example:
"Returns details about a given job."
reana_job_controller/app.py
Outdated
type: string | ||
responses: | ||
200: | ||
description: The Job. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto for description of responses:
- 200 Request succeeded. The response contains details about the given job ID.
- 404 Request failed. The given job ID does not seem to exist.
reana_job_controller/app.py
Outdated
"status": "started" | ||
--- | ||
get: | ||
description: Get all Jobs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returns list of all active jobs.
reana_job_controller/app.py
Outdated
- application/json | ||
responses: | ||
200: | ||
description: Job list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
200: Request succeeded. The response contains the list of all active jobs.
reana_job_controller/app.py
Outdated
This resource is expecting JSON data with all the necessary | ||
information of a new job. | ||
description: Create a new Job. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creates a new job.
(BTW summary vs description to be discussed live...)
required: true | ||
schema: | ||
$ref: '#/definitions/JobRequest' | ||
responses: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 201: Request succeeded. The job has been launched.
- 400: Request failed. The incoming data specification seems malformed.
- 500: Request failed. Internal controller error. The job could probably not have been allocated.
60e7d97
to
e9b7dad
Compare
044d2f6
to
e3dda5b
Compare
e3dda5b
to
8f0b5d2
Compare
* Adds CLI to generate OpenAPI spec out of docstrings. * Adds initial test to validate spec. * Adds Marshmallow validation for `/jobs` POST endpoint. Signed-off-by: Diego Rodriguez <diego.rodriguez@cern.ch>
Adds CLI to generate OpenAPI spec out of docstrings.
Adds initial test to validate spec.
Signed-off-by: Diego Rodriguez diego.rodriguez@cern.ch