Materials-Consortia / Materials-Consortia/optimade-python-tools

add server(s) to openapi.json

Open
#193 29 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

OpenAPI
Dominant language
Python
Stars
91
Forks
54
PR merge metrics
No merged PRs in 30d

Description

The OpenAPI definition supports providing a list of API servers inside the openapi.json.

Adding a list of servers there then allows the Swagger documentation to select the server and actually start testing requests.

See here for a super quick test - it does not yet fully work because the optimade API needs to set the Access-Control-Allow-Origin: * header (which the Materials Cloud optimade servers currently don't do, but should! @CasperWA ).

Screenshot 2020-02-27 at 19 58 20

I have a couple of small suggestions:

  • figure out how to add the list of servers programmatically (I just edited the openapi.json). this should be easy
  • we can add servers from optimade providers to this list but, to start with, I would add only servers that set the 'Access-Control-Allow-Origin' header. While it is currently not demanded in the spec, this can be a positive "nudge" for providers to do this
  • top of the list should be a neutral "sample" server. We could use the heroku instance for this but it spins down after 30 minutes of inactivity. @blokhin if zeit.co has better conditions, do you think it is better to move from heroku there?
  • My playing around with this showed a flaw in the current openapi.json - all paths start with optimade/ and so the openapi.json enforces the optimade/ prefix. This is not mandated by the spec and the optimade/ prefix should be removed.
    I would probably even remove the /v0 prefix from the paths in the openapi.json, since - although mandated - it can be set by the provider. It makes more sense to specify a base URL https://dev-aiida-dev.materialscloud.org/curated-cofs/optimade/v0 than to specify a base URL https://dev-aiida-dev.materialscloud.org/curated-cofs/optimade).

If we put these few little points together, we should be rewarded with a fully functional online documentation that is integrated with a browser client for querying the databases provided in the list.
I think this would be very useful.

Mentioning also @ml-evs for info

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with openapi/openapi.json and the linked Swagger UI test, then trace how the definition is generated so the server list is not hand-edited. Review the requested server selection and removal of the optimade/ and possibly /v0 path prefixes. Done means the generated documentation exposes usable servers and the paths work against the selected base URL.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
api, documentation
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.