Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
prozorro-sale
Aiohttp Swagger
Commits
0b998b8d
Commit
0b998b8d
authored
May 27, 2021
by
Viacheslav Sukhovieiev
Browse files
feat: ci implementation
parent
95c22494
Pipeline
#22560
passed with stages
in 42 seconds
Changes
13
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.flake8
0 → 100644
View file @
0b998b8d
[flake8]
max-line-length = 120
ignore = D, VNE, E126, E123, E121, W504, W503
\ No newline at end of file
.gitignore
View file @
0b998b8d
...
...
@@ -81,6 +81,7 @@ htmlcov/
.tox/
.coverage
.coverage.*
cover-html
.cache
nosetests.xml
coverage.xml
...
...
.gitlab-ci.yml
0 → 100644
View file @
0b998b8d
include
:
-
project
:
'
prozorro-sale/ci-build-box'
file
:
'
/template-ci.yml'
stages
:
-
lint
-
build
-
test
-
publish
code-style-check
:
extends
:
.lint-template
build-wheel
:
extends
:
.build-wheel-template
test-unit-pytest
:
stage
:
test
script
:
-
make test-unit-pytest
artifacts
:
paths
:
-
.coverage
publish-wheel
:
extends
:
.publish-wheel-template
publish-coverage-report
:
extends
:
.publish-coverage-report-template
\ No newline at end of file
Makefile
View file @
0b998b8d
# Some simple testing tasks (sorry, UNIX only).
CI_COMMIT_REF_NAME
?=
''
cov
:
@
py.test
--cov
=
aiohttp_swagger
--cov-report
=
term
--cov-report
=
html tests
ifeq
($(CI_COMMIT_REF_NAME), master)
EGG_INFO
=
egg_info
--tag-date
else
ifeq
($(shell echo ${CI_COMMIT_REF_NAME} | grep -o "^epic/"), epic/)
EGG_INFO
=
egg_info
--tag-date
--tag-build
=
DEV
else
EGG_INFO
=
endif
clean
:
@
rm
-rf
`
find
.
-name
__pycache__
`
...
...
@@ -23,3 +29,24 @@ clean:
install
:
@
pip
install
-U
pip
@
pip
install
-Ur
requirements-dev.txt
## Run pytest
test-unit-pytest
:
@
pip
install
-r
requirements.txt
-r
requirements-dev.txt
@
pytest
-v
\
-W
ignore::DeprecationWarning
\
--doctest-modules
\
--cov
=
.
\
-o
testpaths
=
"tests"
\
## Build python package
build-wheel
:
@
python3 setup.py
$(EGG_INFO)
sdist bdist_wheel
## Publish python package
publish-wheel
:
twine upload
--skip-existing
dist/
*
## Publish coverage report
publish-coverage
:
coverage report
&&
coverage html
-d
cover-html
aiohttp_swagger/__init__.py
View file @
0b998b8d
...
...
@@ -96,9 +96,9 @@ async def setup_swagger(app: web.Application,
with
open
(
join
(
STATIC_PATH
,
"index.html"
),
"r"
)
as
f
:
app
[
"SWAGGER_TEMPLATE_CONTENT"
]
=
(
f
.
read
()
.
replace
(
"##SWAGGER_CONFIG##"
,
f
"
{
api_base_url
.
rstrip
(
'/'
)
}{
_swagger_def_url
}
"
)
.
replace
(
"##STATIC_PATH##"
,
f
"
{
api_base_url
.
rstrip
(
'/'
)
}{
statics_path
}
"
)
.
replace
(
"##SWAGGER_VALIDATOR_URL##"
,
swagger_validator_url
)
.
replace
(
"##SWAGGER_CONFIG##"
,
f
"
{
api_base_url
.
rstrip
(
'/'
)
}{
_swagger_def_url
}
"
)
.
replace
(
"##STATIC_PATH##"
,
f
"
{
api_base_url
.
rstrip
(
'/'
)
}{
statics_path
}
"
)
.
replace
(
"##SWAGGER_VALIDATOR_URL##"
,
swagger_validator_url
)
)
...
...
aiohttp_swagger/helpers/builders.py
View file @
0b998b8d
...
...
@@ -86,7 +86,8 @@ async def generate_doc_from_each_end_point(
contact
:
str
=
""
,
template_path
:
str
=
None
,
definitions
:
dict
=
None
,
security_definitions
:
dict
=
None
):
security_definitions
:
dict
=
None
):
# Clean description
_start_desc
=
0
for
i
,
word
in
enumerate
(
description
):
...
...
examples/example_01.py
View file @
0b998b8d
from
aiohttp
import
web
if
__name__
==
'__main__'
:
from
aiohttp_swagger
import
*
from
aiohttp_swagger
import
setup_swagger
,
swagger_path
async
def
example_1
(
request
):
"""
...
...
@@ -51,12 +50,11 @@ if __name__ == '__main__':
"""
return
web
.
Response
(
text
=
"Example"
)
@
swagger_path
(
"example_swagger_partial.yaml"
)
async
def
example_2
(
request
):
"""
Description end-point
---
tags:
- Example
...
...
@@ -78,18 +76,16 @@ if __name__ == '__main__':
description: short URL not found
"405":
description: invalid HTTP Method
"""
return
web
.
Response
(
text
=
"Example"
)
async
def
example_3
(
request
):
"""
Description end-point
"""
return
web
.
Response
(
text
=
"Example"
)
app
=
web
.
Application
()
app
.
router
.
add_route
(
'GET'
,
"/example1"
,
example_1
)
...
...
examples/example_02.py
View file @
0b998b8d
from
aiohttp
import
web
if
__name__
==
'__main__'
:
from
aiohttp_swagger
import
*
from
aiohttp_swagger
import
setup_swagger
async
def
example_1
(
request
):
"""
...
...
@@ -51,18 +50,15 @@ if __name__ == '__main__':
"""
return
web
.
Response
(
text
=
"Example"
)
async
def
example_2
(
request
):
"""
Description end-point
"""
return
web
.
Response
(
text
=
"Example"
)
async
def
wrap_setup_swagger
(
app
):
await
setup_swagger
(
app
,
swagger_from_file
=
"example_swagger.yaml"
)
app
=
web
.
Application
()
app
.
router
.
add_route
(
'GET'
,
"/example1"
,
example_1
)
...
...
examples/example_03.py
View file @
0b998b8d
from
aiohttp
import
web
if
__name__
==
'__main__'
:
from
aiohttp_swagger
import
*
from
aiohttp_swagger
import
setup_swagger
async
def
ping
(
request
):
"""
This is my usually Sphinx doc
>>> import json
>>> ping(None)
:param request: Context injected by aiohttp framework
:type request: RequestHandler
---
description: This end-point allow to test that service is up.
tags:
...
...
@@ -28,7 +27,6 @@ if __name__ == '__main__':
"""
return
web
.
Response
(
text
=
"pong"
)
app
=
web
.
Application
()
app
.
router
.
add_route
(
'GET'
,
"/ping"
,
ping
)
...
...
examples/example_04.py
View file @
0b998b8d
from
aiohttp
import
web
if
__name__
==
'__main__'
:
from
aiohttp_swagger
import
*
from
aiohttp_swagger
import
setup_swagger
async
def
ping
(
request
):
"""
This is my usually Sphinx doc
>>> import json
>>> ping(None)
:param request: Context injected by aiohttp framework
:type request: RequestHandler
"""
return
web
.
Response
(
text
=
"pong"
)
async
def
wrap_setup_swagger
(
app
):
await
setup_swagger
(
app
,
swagger_from_file
=
"example_swagger.yaml"
)
app
=
web
.
Application
()
app
.
router
.
add_route
(
'GET'
,
"/ping"
,
ping
)
...
...
examples/example_05.py
View file @
0b998b8d
from
aiohttp
import
web
if
__name__
==
'__main__'
:
from
aiohttp_swagger
import
*
from
aiohttp_swagger
import
setup_swagger
async
def
ping
(
request
):
"""
...
...
@@ -20,16 +19,15 @@ if __name__ == '__main__':
"""
return
web
.
Response
(
text
=
"pong"
)
async
def
wrap_setup_swagger
(
app
):
long_description
=
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus vehicula, metus et sodales fringilla,
purus leo aliquet odio, non tempor ante urna aliquet nibh. Integer accumsan laoreet tincidunt.
Vestibulum semper vehicula sollicitudin. Suspendisse dapibus neque vitae mattis bibendum.
Morbi eu pulvinar turpis, quis malesuada ex. Vestibulum sed maximus diam.
Proin semper fermentum suscipit. Duis at suscipit diam. Integer in augue elementum, auctor orci ac,
elementum est. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Maecenas condimentum id arcu quis volutpat. Vestibulum sit amet nibh sodales, iaculis nibh eget,
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus vehicula, metus et sodales fringilla,
purus leo aliquet odio, non tempor ante urna aliquet nibh. Integer accumsan laoreet tincidunt.
Vestibulum semper vehicula sollicitudin. Suspendisse dapibus neque vitae mattis bibendum.
Morbi eu pulvinar turpis, quis malesuada ex. Vestibulum sed maximus diam.
Proin semper fermentum suscipit. Duis at suscipit diam. Integer in augue elementum, auctor orci ac,
elementum est. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Maecenas condimentum id arcu quis volutpat. Vestibulum sit amet nibh sodales, iaculis nibh eget,
scelerisque justo.
"""
...
...
@@ -56,7 +54,6 @@ if __name__ == '__main__':
}
})
app
=
web
.
Application
()
app
.
router
.
add_route
(
'GET'
,
"/ping"
,
ping
)
...
...
tests/test_openapi.py
View file @
0b998b8d
...
...
@@ -5,7 +5,7 @@ import pytest
import
yaml
from
aiohttp
import
web
from
aiohttp_swagger
import
*
from
aiohttp_swagger
import
setup_swagger
,
swagger_path
async
def
ping
(
request
):
...
...
@@ -218,6 +218,7 @@ async def test_swagger_info(aiohttp_client, loop, swagger_info):
await
setup_swagger
(
app
,
ui_version
=
3
,
swagger_url
=
"/api/v1/doc"
,
description
=
description
,
swagger_info
=
swagger_info
)
client
=
await
aiohttp_client
(
app
)
...
...
tests/test_swagger.py
View file @
0b998b8d
...
...
@@ -241,6 +241,7 @@ async def test_swagger_info(aiohttp_client, loop, swagger_info):
description
=
"Test Custom Swagger"
await
setup_swagger
(
app
,
swagger_url
=
"/api/v1/doc"
,
description
=
description
,
swagger_info
=
swagger_info
)
client
=
await
aiohttp_client
(
app
)
...
...
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