Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/developer/rest_api_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,24 @@ The OpenAPI Tools are a collection of tools to support writing, verifying and
displaying Rest API Documentations. They also provide some ideas on how to
further integrate the documentation into other parts of your code base, e.g. for
input validation.

### Use Existing Enumerates

If the endpoint requests or returns a common enumerate type, you can use the `schemas`
generated from Rucio's codebase, such that:
```yaml
properties:
options:
description: "..."
type: object
properties:
object1:
description: "..."
$ref: '#/components/schemas/Object1'
object2:
description: "..."
$ref: '#/components/schemas/Object2'

```
Where `Object1` and `Object2` can reference any enumerate type in
[constants.py](https://github.com/rucio/rucio/blob/master/lib/rucio/db/sqla/constants.py)
19 changes: 19 additions & 0 deletions tools/run_in_docker/generate_rest_api_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from enum import Enum
from inspect import isclass

from apispec import APISpec
from apispec_webframeworks.flask import FlaskPlugin
from rucio.db.sqla import constants
from rucio.vcsversion import VERSION
from rucio.web.rest.flaskapi.v1.main import application

Expand Down Expand Up @@ -89,6 +93,20 @@
"""


def collect_enums() -> dict:
"""Create a dictionary of all the enumerate types that can be used for spec API docs"""
enum_specs = {}

for k, v in constants.__dict__.items():
if isclass(v) and issubclass(v, Enum):
try:
enum_specs[k] = {"type": "string", "enum": [e.value for e in v]}
except TypeError:
pass

return enum_specs


spec = APISpec(
title="Rucio",
version=VERSION,
Expand Down Expand Up @@ -116,6 +134,7 @@
"description": "The Rucio Token obtained by one of the /auth endpoints.", # noqa: E501
},
},
"schemas": collect_enums(),
},
security=[{"AuthToken": []}],
)
Expand Down