Skip to content

Commit 4dbc98b

Browse files
authored
Merge pull request #9 from sanderegg/feature/#233_api_sharing
Feature/ITISFoundation#233 api sharing
2 parents 7f05229 + 174081c commit 4dbc98b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2787
-226
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ matrix:
4545
- pushd services/director; pip3 install -r requirements/ci.txt; popd
4646
- pip3 install packages/director-sdk/python
4747
- pushd services/web/server; pip3 install -r requirements/ci.txt; popd
48+
- pip3 install -r apis/tests/requirements.txt
49+
- pip3 install -r services/apihub/tests/requirements.txt
4850

4951
before_script:
5052
- pylint --version

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ before_test:
8787
${DOCKER_COMPOSE} -f packages/simcore-sdk/tests/docker-compose.yml build
8888

8989
run_test:
90+
pytest -v apis/tests
91+
pytest -v services/apihub/tests
9092
pytest --cov=pytest_docker -v packages/pytest_docker/tests
9193
pytest --cov=s3wrapper -v packages/s3wrapper/tests
9294
pytest --cov=simcore_sdk -v packages/simcore-sdk/tests

apis/README.md

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# APIs development guidelines
2+
3+
# Concept
4+
5+
REST APIs and models (defined as openAPI- or JSON-schemas) are defined in a central location (/apis) to allow for "design-first" development.
6+
7+
# Development guidelines
8+
9+
## Standards
10+
11+
The oSparc platform uses the following standards:
12+
- REST API: [Open API v3](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md)
13+
- Models and configuration [JSON Schema](https://json-schema.org/)
14+
15+
## Folder structure
16+
17+
```bash
18+
/apis/ # base folder
19+
/apis/director/ # service name folder (e.g. for director service)
20+
/apis/director/v0/ # service version (v0 for development, then v1, v2... only major)
21+
/apis/director/v0/openapi.yaml # openapi specifications in YAML
22+
/apis/director/v0/schemas/ # schemas only used by the director API
23+
/apis/director/v0/schemas/services.yaml # openapi encoded service only schema
24+
25+
/apis/shared/ # shared apis/schemas base folder
26+
/apis/shared/schemas/ # sub folder for schemas
27+
/apis/shared/schemas/health_check.yaml # openapi encoded shared schema
28+
/apis/shared/schemas/node-meta.json # jsonschema encoded shared schema
29+
/apis/shared/schemas/v1/error.yaml # openapi encoded shaared schema for version 1
30+
/apis/shared/schemas/v2/error.yaml # openapi encoded shaared schema for version 2
31+
32+
/tests/ # python tests folder to check schemas validity
33+
/tests/requirements.txt # requirements for python tests
34+
```
35+
36+
## Organization
37+
38+
### Openapi specifications file
39+
40+
Each API is defined within a file __openapi.yaml__ in YAML format. The file shall be located in the a subfolder named after the service/package and the major version subfolder.
41+
42+
#### Version subfolder
43+
44+
For initial development, the version shall be 0.1.0 and the subfolder v0
45+
For release, the version shall start from 1.0.0 and subfolder v1.
46+
The subolder digit corresponds to the version major digits. It shall be modified only when changes are not backwards compatible (e.g. changing a return value, removing parameters or resource, ...).
47+
48+
#### Schemas in separate files
49+
50+
Schemas shall always be defined in separate files.
51+
52+
Schemas format shall be either OpenAPI v3 or JSON schema Draft#7.
53+
54+
If these schemas are pertinent only to the current API they shall be contained together with the openapi specifications file inside a __schemas__ subfolder.
55+
If these schemas are shared with other APIs they should be located in the __/shared/schemas__ subfolder.
56+
57+
#### Versioning shared schemas
58+
59+
NOTE: If shared schemas need backward incompatible changes, then a new major version of this specific shared schema is necessary and all APIs that rely on this specific schema will need to be upgraded.
60+
In that case, a version subfolder shall be added in the __/shared/__ subfolder and the relevant schemas shall be moved there.
61+
62+
### Schemas defined with JSONSchema format that are used together with OpenAPI
63+
64+
Mixing JSONSchema with OpenAPI schema needs some additional steps:
65+
66+
1. Define the JSONSchema schema.
67+
2. Convert the JSONSchema formatted file to OpenAPI formatted file using the [converter](../scripts/jsonschema/openapi_converter).
68+
3. In the openapi specifications file ref the converted OpenAPI schema file.
69+
70+
## Using the openAPI
71+
72+
### Python: Current status (using aiohttp-apiset)
73+
74+
The current python-based packages use the aiohttp-apiset library to create routes from the defined API. The aiohttp-apiset library requires a physical file to create the routes. Therefore one needs to generate that file by following:
75+
76+
1. Generate a 1 file OpenAPI formatted file using [prance](https://pypi.org/project/prance/):
77+
```bash
78+
pip install prance
79+
prance compile path/to/input.yml path/to/output.yml
80+
```
81+
2. Copy the generated file in a folder in the python-based code and use it.
82+
83+
### Python: in development and should be available soon
84+
85+
Using the library [openapi-core](https://github.com/p1c2u/openapi-core) the library is able to download the api at starting point.
86+
The [apihub service](../services/apihub) serves the apis and schemas to the internal parts of the oSparc platform.
87+
88+
## references
89+
90+
- [defining reusable components - good practices](https://dev.to/mikeralphson/defining-reusable-components-with-the-openapi-specification-4077)
91+
- [official guidelines on OAS re-usability](https://github.com/OAI/OpenAPI-Specification/blob/master/guidelines/v2.0/REUSE.md)

0 commit comments

Comments
 (0)