Skip to content

Commit d1fb26e

Browse files
committed
Add instructions for adding enumerate types
1 parent b25e099 commit d1fb26e

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

docs/developer/rest_api_doc.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,24 @@ The OpenAPI Tools are a collection of tools to support writing, verifying and
9999
displaying Rest API Documentations. They also provide some ideas on how to
100100
further integrate the documentation into other parts of your code base, e.g. for
101101
input validation.
102+
103+
### Use Existing Enumerates
104+
105+
If the endpoint requests or returns a common enumerate type, you can use the `schemas`
106+
generated from rucio's codebase, such that:
107+
```yaml
108+
properties:
109+
options:
110+
description: "..."
111+
type: object
112+
properties:
113+
object1:
114+
description: "..."
115+
$ref: '#/components/schemas/Object1'
116+
object2:
117+
description: "..."
118+
$ref: '#/components/schemas/Object2'
119+
120+
```
121+
Where `Object1` and `Object2` can reference any enumerate type in
122+
[constants.py](https://github.com/rucio/rucio/blob/master/lib/rucio/db/sqla/constants.py)

tools/run_in_docker/generate_rest_api_docs.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,22 @@
8989
"""
9090

9191

92-
def collect_enums() -> dict:
92+
def collect_enums() -> dict:
9393
"""Create a dictionary of all the enumerate types that can be used for spec API docs"""
9494
enum_specs = {}
95-
from rucio.db.sqla import constants
95+
from rucio.db.sqla import constants
9696
from inspect import isclass
9797

9898
for k, v in constants.__dict__.items():
9999
if isclass(v):
100-
try:
101-
enum_specs[k] = {
102-
"type": "string",
103-
"enum": [e.value for e in v]
104-
}
105-
except TypeError:
100+
try:
101+
enum_specs[k] = {"type": "string", "enum": [e.value for e in v]}
102+
except TypeError:
106103
pass
107104

108105
return enum_specs
109106

107+
110108
spec = APISpec(
111109
title="Rucio",
112110
version=VERSION_INFO["version"],
@@ -134,7 +132,7 @@ def collect_enums() -> dict:
134132
"description": "The Rucio Token obtained by one of the /auth endpoints.", # noqa: E501
135133
},
136134
},
137-
"schemas": collect_enums()
135+
"schemas": collect_enums(),
138136
},
139137
security=[{"AuthToken": []}],
140138
)

0 commit comments

Comments
 (0)