Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
76d54f7
python server: Add pythonSrcRoot option
cognifloyd Feb 24, 2020
fd751e9
python server: update template files to support pythonSrcRoot
cognifloyd Mar 6, 2020
7df485f
python server: update docs to add pythonSrcRoot option
cognifloyd Feb 26, 2020
9e7a2a3
python server: add pythonSrcRoot sample script
cognifloyd Feb 25, 2020
a440404
python server: build sample srclayout project
cognifloyd Feb 25, 2020
0bbd2b7
[Python] copy test files preserving history
cognifloyd Apr 3, 2020
23a64a7
[Python] Make a conflict to preserve file copy history
cognifloyd Apr 3, 2020
0e32620
Merge branch to finish copying python test files
cognifloyd Apr 3, 2020
a649ac4
[Python] customize pom.xml for src layout tests
cognifloyd Apr 3, 2020
ef999c2
[Python] add python-aiohttp-srclayout tests
cognifloyd Apr 4, 2020
b03adef
[Python] Fix server tests by updating requirements
cognifloyd Apr 4, 2020
458de3f
[Python] Copy setup.py to python-aiohttp
cognifloyd Apr 4, 2020
c768797
[Python] Save history while copying setup.py to python-aiohttp
cognifloyd Apr 4, 2020
422022a
[Python] Merge copied setup.py
cognifloyd Apr 4, 2020
b791fff
[Python] Add aiohttp server setup.py
cognifloyd Apr 4, 2020
8a63a5c
[Python] Fix python server tests with src layout
cognifloyd Apr 4, 2020
0398827
[Python] bump Flask-Testing version
cognifloyd Apr 4, 2020
8dbc5f6
[Python] Pin pyyaml for py2.7 flask server
cognifloyd Apr 4, 2020
ef44596
[Python] simplify flask server requirements
cognifloyd Apr 4, 2020
743a618
consolidate server tests
cognifloyd Apr 4, 2020
2f5148b
[Python] rebuild python server samples
cognifloyd Apr 4, 2020
85665f1
[Python] Fix python server requirements for older pythons
cognifloyd Apr 7, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
python server: build sample srclayout project
  • Loading branch information
cognifloyd committed Apr 3, 2020
commit a440404e1629a066e6c6872c3c325666381a85fb
66 changes: 66 additions & 0 deletions samples/server/petstore/python-aiohttp-srclayout/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
venv/
.venv/
.python-version
.pytest_cache

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

#Ipython Notebook
.ipynb_checkpoints
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.3.0-SNAPSHOT
46 changes: 46 additions & 0 deletions samples/server/petstore/python-aiohttp-srclayout/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# OpenAPI generated server

## Overview
This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the
[OpenAPI-Spec](https://openapis.org) from a remote server, you can easily generate a server stub. This
is an example of building a OpenAPI-enabled aiohttp server.

This example uses the [Connexion](https://github.com/zalando/connexion) library on top of aiohttp.

## Requirements
Python 3.5.2+

## Usage
To run the server, please execute the following from the root directory:

```
pip3 install -r requirements.txt
python3 -m openapi_server
```

and open your browser to here:

```
http://localhost:8080/v2/ui/
```

Your OpenAPI definition lives here:

```
http://localhost:8080/v2/openapi.json
```

To launch the integration tests, use pytest:
```
sudo pip install -r test-requirements.txt
pytest
```

## Prevent file overriding

After first generation, add edited files to _.openapi-generator-ignore_ to prevent generator to overwrite them. Typically:
```
server/controllers/*
test/*
*.txt
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
connexion[aiohttp,swagger-ui] == 2.0.2
swagger-ui-bundle == 0.0.2
aiohttp_jinja2 == 1.1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import connexion


def main():
options = {
"swagger_ui": True
}
specification_dir = os.path.join(os.path.dirname(__file__), 'openapi')
app = connexion.AioHttpApp(__name__, specification_dir=specification_dir, options=options)
app.add_api('openapi.yaml',
arguments={'title': 'OpenAPI Petstore'},
pythonic_params=True,
pass_context_arg_name='request')
app.run(port=8080)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env python3

from . import main

if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
from typing import List, Dict
from aiohttp import web

from openapi_server.models.api_response import ApiResponse
from openapi_server.models.pet import Pet
from openapi_server import util


async def add_pet(request: web.Request, body) -> web.Response:
"""Add a new pet to the store



:param body: Pet object that needs to be added to the store
:type body: dict | bytes

"""
body = Pet.from_dict(body)
return web.Response(status=200)


async def delete_pet(request: web.Request, pet_id, api_key=None) -> web.Response:
"""Deletes a pet



:param pet_id: Pet id to delete
:type pet_id: int
:param api_key:
:type api_key: str

"""
return web.Response(status=200)


async def find_pets_by_status(request: web.Request, status) -> web.Response:
"""Finds Pets by status

Multiple status values can be provided with comma separated strings

:param status: Status values that need to be considered for filter
:type status: List[str]

"""
return web.Response(status=200)


async def find_pets_by_tags(request: web.Request, tags) -> web.Response:
"""Finds Pets by tags

Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.

:param tags: Tags to filter by
:type tags: List[str]

"""
return web.Response(status=200)


async def get_pet_by_id(request: web.Request, pet_id) -> web.Response:
"""Find pet by ID

Returns a single pet

:param pet_id: ID of pet to return
:type pet_id: int

"""
return web.Response(status=200)


async def update_pet(request: web.Request, body) -> web.Response:
"""Update an existing pet



:param body: Pet object that needs to be added to the store
:type body: dict | bytes

"""
body = Pet.from_dict(body)
return web.Response(status=200)


async def update_pet_with_form(request: web.Request, pet_id, name=None, status=None) -> web.Response:
"""Updates a pet in the store with form data



:param pet_id: ID of pet that needs to be updated
:type pet_id: int
:param name: Updated name of the pet
:type name: str
:param status: Updated status of the pet
:type status: str

"""
return web.Response(status=200)


async def upload_file(request: web.Request, pet_id, additional_metadata=None, file=None) -> web.Response:
"""uploads an image



:param pet_id: ID of pet to update
:type pet_id: int
:param additional_metadata: Additional data to pass to server
:type additional_metadata: str
:param file: file to upload
:type file: str

"""
return web.Response(status=200)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from typing import List


def info_from_api_key(api_key: str, required_scopes: None) -> dict:
"""
Check and retrieve authentication information from api_key.
Returned value will be passed in 'token_info' parameter of your operation function, if there is one.
'sub' or 'uid' will be set in 'user' parameter of your operation function, if there is one.
Should return None if api_key is invalid or does not allow access to called API.
"""
return {'uid': 'user_id'}


def info_from_petstore_auth(token: str) -> dict:
"""
Validate and decode token.
Returned value will be passed in 'token_info' parameter of your operation function, if there is one.
'sub' or 'uid' will be set in 'user' parameter of your operation function, if there is one.
'scope' or 'scopes' will be passed to scope validation function.
Should return None if token is invalid or does not allow access to called API.
"""
return {'scopes': ['read:pets', 'write:pets'], 'uid': 'user_id'}


def validate_scope_petstore_auth(required_scopes: List[str], token_scopes: List[str]) -> bool:
""" Validate required scopes are included in token scope """
return set(required_scopes).issubset(set(token_scopes))


Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from typing import List, Dict
from aiohttp import web

from openapi_server.models.order import Order
from openapi_server import util


async def delete_order(request: web.Request, order_id) -> web.Response:
"""Delete purchase order by ID

For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors

:param order_id: ID of the order that needs to be deleted
:type order_id: str

"""
return web.Response(status=200)


async def get_inventory(request: web.Request, ) -> web.Response:
"""Returns pet inventories by status

Returns a map of status codes to quantities


"""
return web.Response(status=200)


async def get_order_by_id(request: web.Request, order_id) -> web.Response:
"""Find purchase order by ID

For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions

:param order_id: ID of pet that needs to be fetched
:type order_id: int

"""
return web.Response(status=200)


async def place_order(request: web.Request, body) -> web.Response:
"""Place an order for a pet



:param body: order placed for purchasing the pet
:type body: dict | bytes

"""
body = Order.from_dict(body)
return web.Response(status=200)
Loading