Skip to content

Commit

Permalink
global: update to apispec v3
Browse files Browse the repository at this point in the history
Update to apispec v3, as the version used before is not compatible with
PyYAML v6. This commit also removes the marshmallow plugin for apispec,
as the generated OpenAPI spec is different and causes issues with
reana-client. This is due to the fact that the OpenAPI specifications of
marshmallow schemas are now put inside the global `definitions` object,
instead of being inlined in the endpoint's specification as before.

Closes reanahub/reana-commons#399
  • Loading branch information
mdonadoni committed Jul 20, 2023
1 parent c459270 commit d8c04bd
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 8 deletions.
5 changes: 1 addition & 4 deletions docs/openapi.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"definitions": {},
"info": {
"description": "Submit workflows to be run on REANA Cloud",
"title": "REANA Server",
"version": "0.9.1a3"
},
"parameters": {},
"paths": {
"/account/settings/linkedaccounts/": {},
"/account/settings/linkedaccounts/static/{filename}": {},
Expand Down Expand Up @@ -4450,6 +4448,5 @@
"/signin": {},
"/signup/": {}
},
"swagger": "2.0",
"tags": []
"swagger": "2.0"
}
74 changes: 73 additions & 1 deletion reana_server/rest/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,79 @@ def info(user, **kwargs): # noqa
200:
description: >-
Request succeeded. The response contains general info about the cluster.
schema: InfoSchema
schema:
properties:
compute_backends:
properties:
title:
type: string
value:
items:
type: string
type: array
type: object
default_kubernetes_jobs_timeout:
properties:
title:
type: string
value:
type: string
type: object
default_kubernetes_memory_limit:
properties:
title:
type: string
value:
type: string
type: object
default_workspace:
properties:
title:
type: string
value:
type: string
type: object
kubernetes_max_memory_limit:
properties:
title:
type: string
value:
type: string
x-nullable: true
type: object
maximum_interactive_session_inactivity_period:
properties:
title:
type: string
value:
type: string
x-nullable: true
type: object
maximum_kubernetes_jobs_timeout:
properties:
title:
type: string
value:
type: string
type: object
maximum_workspace_retention_period:
properties:
title:
type: string
value:
type: string
x-nullable: true
type: object
workspaces_available:
properties:
title:
type: string
value:
items:
type: string
type: array
type: object
type: object
examples:
application/json:
{
Expand Down
8 changes: 5 additions & 3 deletions scripts/generate_openapi_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2017, 2018, 2020, 2021, 2022 CERN.
# Copyright (C) 2017, 2018, 2020, 2021, 2022, 2023 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -14,6 +14,7 @@

import click
from apispec import APISpec
from apispec_webframeworks.flask import FlaskPlugin
from flask import current_app
from flask.cli import with_appcontext
from reana_commons.utils import copy_openapi_specs
Expand Down Expand Up @@ -57,8 +58,9 @@ def build_openapi_spec(publish):
spec = APISpec(
title=package,
version=ver,
openapi_version="2.0",
info=dict(description=desc),
plugins=("apispec.ext.flask", "apispec.ext.marshmallow"),
plugins=(FlaskPlugin(),),
)

# Add marshmallow schemas to the specification here
Expand All @@ -67,7 +69,7 @@ def build_openapi_spec(publish):
# Collect OpenAPI docstrings from Flask endpoints
for key in current_app.view_functions:
if key != "static" and key != "get_openapi_spec":
spec.add_path(view=current_app.view_functions[key])
spec.path(view=current_app.view_functions[key])

spec_json = json.dumps(
spec.to_dict(), indent=2, separators=(",", ": "), sort_keys=True
Expand Down

0 comments on commit d8c04bd

Please sign in to comment.