Skip to content

Commit be8886c

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

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
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: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
from enum import Enum
17+
from inspect import isclass
18+
1619
from apispec import APISpec
1720
from apispec_webframeworks.flask import FlaskPlugin
18-
from rucio.vcsversion import VERSION_INFO
21+
from rucio.db.sqla import constants
22+
from rucio.vcsversion import VERSION
1923
from rucio.web.rest.flaskapi.v1.main import application
2024

2125
description_text = """Each resource can be accessed or modified using specially
@@ -89,27 +93,23 @@
8993
"""
9094

9195

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

98100
for k, v in constants.__dict__.items():
99-
if isclass(v):
100-
try:
101-
enum_specs[k] = {
102-
"type": "string",
103-
"enum": [e.value for e in v]
104-
}
105-
except TypeError:
101+
if isclass(v) and issubclass(v, Enum):
102+
try:
103+
enum_specs[k] = {"type": "string", "enum": [e.value for e in v]}
104+
except TypeError:
106105
pass
107106

108107
return enum_specs
109108

109+
110110
spec = APISpec(
111111
title="Rucio",
112-
version=VERSION_INFO["version"],
112+
version=VERSION,
113113
openapi_version="3.0.2",
114114
plugins=[FlaskPlugin()],
115115
info={
@@ -134,7 +134,7 @@ def collect_enums() -> dict:
134134
"description": "The Rucio Token obtained by one of the /auth endpoints.", # noqa: E501
135135
},
136136
},
137-
"schemas": collect_enums()
137+
"schemas": collect_enums(),
138138
},
139139
security=[{"AuthToken": []}],
140140
)

0 commit comments

Comments
 (0)