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

api: openapi specification generation #40

Merged

Conversation

diegodelemos
Copy link
Member

  • Adds CLI to generate OpenAPI spec out of docstrings.

  • Adds initial test to validate spec.

Signed-off-by: Diego Rodriguez diego.rodriguez@cern.ch

@diegodelemos diegodelemos force-pushed the openapi-marshmallow-integration branch 8 times, most recently from 850a222 to 3cdf4d7 Compare May 11, 2017 14:53

import json

import click
Copy link
Member

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.)

Copy link
Member Author

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)

Copy link
Member

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 && \
Copy link
Member

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
Copy link
Member

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?

Copy link
Member Author

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):
Copy link
Member

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.

@tiborsimko tiborsimko mentioned this pull request May 12, 2017
@diegodelemos diegodelemos force-pushed the openapi-marshmallow-integration branch 4 times, most recently from 339e468 to 60e7d97 Compare May 12, 2017 14:32
@diegodelemos
Copy link
Member Author

@tiborsimko


.. code-block:: console

$ flask openapi create output_file
Copy link
Member

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

CLI
---

The REANA Job Controller package offers the possibility to create its OpenAPI specification file using the flask CLI.
Copy link
Member

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
Copy link
Member

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 && \
Copy link
Member

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.


---
get:
description: Get a Job by its id
Copy link
Member

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."

type: string
responses:
200:
description: The Job.
Copy link
Member

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.

"status": "started"
---
get:
description: Get all Jobs
Copy link
Member

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.

- application/json
responses:
200:
description: Job list.
Copy link
Member

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.

This resource is expecting JSON data with all the necessary
information of a new job.
description: Create a new Job.
Copy link
Member

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:
Copy link
Member

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.

@diegodelemos diegodelemos force-pushed the openapi-marshmallow-integration branch from 60e7d97 to e9b7dad Compare May 15, 2017 09:20
@diegodelemos diegodelemos force-pushed the openapi-marshmallow-integration branch 2 times, most recently from 044d2f6 to e3dda5b Compare May 15, 2017 12:34
@diegodelemos diegodelemos force-pushed the openapi-marshmallow-integration branch from e3dda5b to 8f0b5d2 Compare May 15, 2017 12:49
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants