Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Metagenomics
metagenedb
Commits
65eab49d
Commit
65eab49d
authored
Aug 07, 2019
by
Kenzo-Hugo Hillion
♻
Browse files
add basis for swagger documentation of API
parent
70c740a1
Pipeline
#13594
failed with stages
in 1 minute and 41 seconds
Changes
8
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
backend/Pipfile
View file @
65eab49d
...
...
@@ -4,50 +4,52 @@ url = "https://pypi.org/simple"
verify_ssl
=
true
[dev-packages]
atomicwrites
=
"
==1.3.0
"
attrs
=
"
==19.1.0
"
coverage
=
"
==4.5.3
"
entrypoints
=
"
==0.3
"
flake8
=
"
==3.7.7
"
importlib-metadata
=
"
==0.18
"
kiwisolver
=
"
==1.1.0
"
mccabe
=
"
==0.6.1
"
more-itertools
=
"
==7.0.0
"
pluggy
=
"
==0.12.0
"
py
=
"
==1.8.0
"
pycodestyle
=
"
==2.5.0
"
pyflakes
=
"
==2.1.1
"
pyparsing
=
"
==2.4.0
"
pytest
=
"
==4.6.3
"
pytest-cov
=
"
==2.7.1
"
pytest-django
=
"
==3.5.0
"
wcwidth
=
"
==0.1.7
"
zipp
=
"
==0.5.1
"
Cycler
=
"
==0.10.0
"
atomicwrites
=
"
*
"
attrs
=
"
*
"
coverage
=
"
*
"
entrypoints
=
"
*
"
flake8
=
"
*
"
importlib-metadata
=
"
*
"
kiwisolver
=
"
*
"
mccabe
=
"
*
"
more-itertools
=
"
*
"
pluggy
=
"
*
"
py
=
"
*
"
pycodestyle
=
"
*
"
pyflakes
=
"
*
"
pyparsing
=
"
*
"
pytest
=
"
*
"
pytest-cov
=
"
*
"
pytest-django
=
"
*
"
wcwidth
=
"
*
"
zipp
=
"
*
"
Cycler
=
"
*
"
jupyter
=
"*"
[packages]
certifi
=
"
==2019.6.16
"
chardet
=
"
==3.0.4
"
django-cors-headers
=
"
==3.0.2
"
django-environ
=
"
==0.4.5
"
django-extensions
=
"
==2.1.7
"
django-filter
=
"
==2.1.0
"
djangorestframework
=
"
==3.9.4
"
djangorestframework-jwt
=
"
==1.11.0
"
idna
=
"
==2.8
"
numpy
=
"
==1.16.4
"
pandas
=
"
==0.24.2
"
psycopg2
=
"
==2.8.2
"
python-dateutil
=
"
==2.8.0
"
pytz
=
"
==2019.1
"
requests
=
"
==2.22.0
"
six
=
"
==1.12.0
"
sqlparse
=
"
==0.3.0
"
urllib3
=
"
==1.25.3
"
Django
=
"
==2.2.1
"
PyJWT
=
"
==1.7.1
"
certifi
=
"
*
"
chardet
=
"
*
"
django-cors-headers
=
"
*
"
django-environ
=
"
*
"
django-extensions
=
"
*
"
django-filter
=
"
*
"
djangorestframework
=
"
*
"
djangorestframework-jwt
=
"
*
"
idna
=
"
*
"
numpy
=
"
*
"
pandas
=
"
*
"
psycopg2
=
"
*
"
python-dateutil
=
"
*
"
pytz
=
"
*
"
requests
=
"
*
"
six
=
"
*
"
sqlparse
=
"
*
"
urllib3
=
"
*
"
Django
=
"
*
"
PyJWT
=
"
*
"
metagenedb
=
{
editable
=
true
,
path
=
"."
}
drf-yasg
=
"*"
packaging
=
"*"
[requires]
python_version
=
"3.7"
backend/Pipfile.lock
View file @
65eab49d
This diff is collapsed.
Click to expand it.
backend/metagenedb/api/catalog/views/gene.py
View file @
65eab49d
import
pandas
as
pd
from
drf_yasg
import
openapi
from
drf_yasg.utils
import
swagger_auto_schema
from
rest_framework.viewsets
import
GenericViewSet
from
rest_framework
import
mixins
from
rest_framework
import
status
...
...
@@ -10,6 +12,13 @@ from metagenedb.apps.catalog.models import Gene
from
metagenedb.apps.catalog.serializers
import
GeneSerializer
# Define global variable for API documentation
window_size_param
=
openapi
.
Parameter
(
'window_size'
,
in_
=
openapi
.
IN_QUERY
,
description
=
'Size of the window.'
,
type
=
openapi
.
TYPE_INTEGER
,
default
=
10000
)
gene_length_schema
=
openapi
.
Schema
(
"pouet"
,
{},
type
=
{
'hihi'
:
'haha'
})
gene_length_response
=
openapi
.
Response
(
'return JSON content'
,
schema
=
gene_length_schema
)
class
GeneViewSet
(
mixins
.
ListModelMixin
,
mixins
.
RetrieveModelMixin
,
GenericViewSet
):
...
...
@@ -36,6 +45,16 @@ class GeneViewSet(mixins.ListModelMixin,
'labels'
:
labels
}
@
swagger_auto_schema
(
manual_parameters
=
[
window_size_param
],
responses
=
{
'200'
:
gene_length_response
,
'204'
:
'no content'
},
security
=
[],
operation_id
=
'List of categories'
,
operation_description
=
'Get the distribution of gene length for a given window size.'
,
)
@
action
(
methods
=
[
'get'
],
detail
=
False
)
def
gene_length
(
self
,
request
,
window_size
=
10000
):
if
'window_size'
in
request
.
query_params
:
...
...
backend/metagenedb/settings/django.py
View file @
65eab49d
...
...
@@ -19,6 +19,7 @@ INSTALLED_APPS = [
'rest_framework'
,
'django_extensions'
,
'corsheaders'
,
'drf_yasg'
,
]
MIDDLEWARE
=
[
...
...
backend/metagenedb/urls.py
View file @
65eab49d
...
...
@@ -15,9 +15,28 @@ Including another URLconf
"""
from
django.contrib
import
admin
from
django.urls
import
include
,
path
from
django.conf.urls
import
url
from
rest_framework
import
permissions
from
drf_yasg.views
import
get_schema_view
from
drf_yasg
import
openapi
schema_view
=
get_schema_view
(
openapi
.
Info
(
title
=
"Metagenedb API"
,
default_version
=
'v1'
,
description
=
"API documentation for metagenedb"
,
contact
=
openapi
.
Contact
(
email
=
"kehillio@pasteur.fr"
),
license
=
openapi
.
License
(
name
=
"License not defined"
),
),
public
=
True
,
permission_classes
=
(
permissions
.
AllowAny
,),
)
urlpatterns
=
[
path
(
'api/'
,
include
((
'metagenedb.api.urls'
,
'api'
))),
path
(
'admin/'
,
admin
.
site
.
urls
),
url
(
r
'^swagger(?P<format>\.json|\.yaml)$'
,
schema_view
.
without_ui
(
cache_timeout
=
0
),
name
=
'schema-json'
),
url
(
r
'^swagger/$'
,
schema_view
.
with_ui
(
'swagger'
,
cache_timeout
=
0
),
name
=
'schema-swagger-ui'
),
]
ci/kubernetes/ingress.yaml
View file @
65eab49d
...
...
@@ -24,6 +24,14 @@ spec:
serviceName
:
backend
servicePort
:
8000
-
path
:
/api
backend
:
serviceName
:
backend
servicePort
:
8000
-
path
:
/swagger
backend
:
serviceName
:
backend
servicePort
:
8000
-
path
:
/redoc
backend
:
serviceName
:
backend
servicePort
:
8000
\ No newline at end of file
docker-compose.yaml
View file @
65eab49d
...
...
@@ -48,9 +48,7 @@ services:
-
NODE_ENV=development
nginx
:
build
:
context
:
.
dockerfile
:
nginx/dev/Dockerfile
image
:
nginx:1.13.12-alpine
ports
:
-
"
80:80"
depends_on
:
...
...
nginx/dev/dev.conf
View file @
65eab49d
...
...
@@ -41,18 +41,12 @@ http {
}
# backend urls
location
~ ^/(
admin
|
api
|
catalog
|
auth
) {
location
~ ^/(
admin
|
api
|
swagger
|
static
) {
proxy_redirect
off
;
proxy_pass
http
://
backend
;
proxy_set_header
X
-
Forwarded
-
For
$
proxy_add_x_forwarded_for
;
proxy_set_header
Host
$
http_host
;
}
# static files
location
/
static
{
autoindex
on
;
alias
/
usr
/
src
/
app
/
static
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment