-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples updates - python/flask and html2 samples update
- Loading branch information
Showing
57 changed files
with
12,816 additions
and
9,617 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM python:2-alpine | ||
|
||
RUN mkdir -p /usr/src/app | ||
WORKDIR /usr/src/app | ||
|
||
COPY requirements.txt /usr/src/app/ | ||
|
||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
COPY . /usr/src/app | ||
|
||
EXPOSE 8080 | ||
|
||
ENTRYPOINT ["python"] | ||
|
||
CMD ["-m", "swagger_server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Swagger generated server | ||
|
||
## Overview | ||
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the | ||
[OpenAPI-Spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This | ||
is an example of building a swagger-enabled Flask server. | ||
|
||
This example uses the [Connexion](https://github.com/zalando/connexion) library on top of Flask. | ||
|
||
## Requirements | ||
Python 2.7+ | ||
|
||
## Usage | ||
To run the server, please execute the following from the root directory: | ||
|
||
``` | ||
pip install -r requirements.txt | ||
python -m swagger_server | ||
``` | ||
|
||
and open your browser to here: | ||
|
||
``` | ||
http:https://localhost:8080/v2/ui/ | ||
``` | ||
|
||
Your Swagger definition lives here: | ||
|
||
``` | ||
http:https://localhost:8080/v2/swagger.json | ||
``` | ||
|
||
To launch the integration tests, use tox: | ||
``` | ||
sudo pip install tox | ||
tox | ||
``` | ||
|
||
## Running with Docker | ||
|
||
To run the server on a Docker container, please execute the following from the root directory: | ||
|
||
```bash | ||
# building the image | ||
docker build -t swagger_server . | ||
|
||
# starting up a container | ||
docker run -p 8080:8080 swagger_server | ||
``` |
52 changes: 52 additions & 0 deletions
52
samples/server/petstore/flaskConnexion-python2/git_push.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/sh | ||
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ | ||
# | ||
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update" | ||
|
||
git_user_id=$1 | ||
git_repo_id=$2 | ||
release_note=$3 | ||
|
||
if [ "$git_user_id" = "" ]; then | ||
git_user_id="GIT_USER_ID" | ||
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" | ||
fi | ||
|
||
if [ "$git_repo_id" = "" ]; then | ||
git_repo_id="GIT_REPO_ID" | ||
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" | ||
fi | ||
|
||
if [ "$release_note" = "" ]; then | ||
release_note="Minor update" | ||
echo "[INFO] No command line input provided. Set \$release_note to $release_note" | ||
fi | ||
|
||
# Initialize the local directory as a Git repository | ||
git init | ||
|
||
# Adds the files in the local repository and stages them for commit. | ||
git add . | ||
|
||
# Commits the tracked changes and prepares them to be pushed to a remote repository. | ||
git commit -m "$release_note" | ||
|
||
# Sets the new remote | ||
git_remote=`git remote` | ||
if [ "$git_remote" = "" ]; then # git remote not defined | ||
|
||
if [ "$GIT_TOKEN" = "" ]; then | ||
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." | ||
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git | ||
else | ||
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git | ||
fi | ||
|
||
fi | ||
|
||
git pull origin master | ||
|
||
# Pushes (Forces) the changes in the local repository up to the remote repository | ||
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git" | ||
git push origin master 2>&1 | grep -v 'To https' | ||
|
4 changes: 4 additions & 0 deletions
4
samples/server/petstore/flaskConnexion-python2/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
connexion == 1.1.15 | ||
python_dateutil == 2.6.0 | ||
typing == 3.5.2.2 | ||
setuptools >= 21.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# coding: utf-8 | ||
|
||
import sys | ||
from setuptools import setup, find_packages | ||
|
||
NAME = "swagger_server" | ||
VERSION = "1.0.0" | ||
|
||
# To install the library, run the following | ||
# | ||
# python setup.py install | ||
# | ||
# prerequisite: setuptools | ||
# http:https://pypi.python.org/pypi/setuptools | ||
|
||
REQUIRES = ["connexion"] | ||
|
||
setup( | ||
name=NAME, | ||
version=VERSION, | ||
description="Swagger Petstore", | ||
author_email="[email protected]", | ||
url="", | ||
keywords=["Swagger", "Swagger Petstore"], | ||
install_requires=REQUIRES, | ||
packages=find_packages(), | ||
package_data={'': ['swagger/swagger.yaml']}, | ||
include_package_data=True, | ||
entry_points={ | ||
'console_scripts': ['swagger_server=swagger_server.__main__:main']}, | ||
long_description="""\ | ||
This is a sample server Petstore server. You can find out more about Swagger at [http:https://swagger.io](http:https://swagger.io) or on [irc.freenode.net, #swagger](http:https://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. | ||
""" | ||
) | ||
|
Empty file.
16 changes: 16 additions & 0 deletions
16
samples/server/petstore/flaskConnexion-python2/swagger_server/__main__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env python | ||
|
||
import connexion | ||
|
||
from swagger_server import encoder | ||
|
||
|
||
def main(): | ||
app = connexion.App(__name__, specification_dir='./swagger/') | ||
app.app.json_encoder = encoder.JSONEncoder | ||
app.add_api('swagger.yaml', arguments={'title': 'Swagger Petstore'}) | ||
app.run(port=8080) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Empty file.
124 changes: 124 additions & 0 deletions
124
samples/server/petstore/flaskConnexion-python2/swagger_server/controllers/pet_controller.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import connexion | ||
import six | ||
|
||
from swagger_server.models.api_response import ApiResponse # noqa: E501 | ||
from swagger_server.models.pet import Pet # noqa: E501 | ||
from swagger_server import util | ||
|
||
|
||
def add_pet(body): # noqa: E501 | ||
"""Add a new pet to the store | ||
# noqa: E501 | ||
:param body: Pet object that needs to be added to the store | ||
:type body: dict | bytes | ||
:rtype: None | ||
""" | ||
if connexion.request.is_json: | ||
body = Pet.from_dict(connexion.request.get_json()) # noqa: E501 | ||
return 'do some magic!' | ||
|
||
|
||
def delete_pet(petId, api_key=None): # noqa: E501 | ||
"""Deletes a pet | ||
# noqa: E501 | ||
:param petId: Pet id to delete | ||
:type petId: int | ||
:param api_key: | ||
:type api_key: str | ||
:rtype: None | ||
""" | ||
return 'do some magic!' | ||
|
||
|
||
def find_pets_by_status(status): # noqa: E501 | ||
"""Finds Pets by status | ||
Multiple status values can be provided with comma separated strings # noqa: E501 | ||
:param status: Status values that need to be considered for filter | ||
:type status: List[str] | ||
:rtype: List[Pet] | ||
""" | ||
return 'do some magic!' | ||
|
||
|
||
def find_pets_by_tags(tags): # noqa: E501 | ||
"""Finds Pets by tags | ||
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. # noqa: E501 | ||
:param tags: Tags to filter by | ||
:type tags: List[str] | ||
:rtype: List[Pet] | ||
""" | ||
return 'do some magic!' | ||
|
||
|
||
def get_pet_by_id(petId): # noqa: E501 | ||
"""Find pet by ID | ||
Returns a single pet # noqa: E501 | ||
:param petId: ID of pet to return | ||
:type petId: int | ||
:rtype: Pet | ||
""" | ||
return 'do some magic!' | ||
|
||
|
||
def update_pet(body): # noqa: E501 | ||
"""Update an existing pet | ||
# noqa: E501 | ||
:param body: Pet object that needs to be added to the store | ||
:type body: dict | bytes | ||
:rtype: None | ||
""" | ||
if connexion.request.is_json: | ||
body = Pet.from_dict(connexion.request.get_json()) # noqa: E501 | ||
return 'do some magic!' | ||
|
||
|
||
def update_pet_with_form(petId, name=None, status=None): # noqa: E501 | ||
"""Updates a pet in the store with form data | ||
# noqa: E501 | ||
:param petId: ID of pet that needs to be updated | ||
:type petId: int | ||
:param name: Updated name of the pet | ||
:type name: str | ||
:param status: Updated status of the pet | ||
:type status: str | ||
:rtype: None | ||
""" | ||
return 'do some magic!' | ||
|
||
|
||
def upload_file(petId, additionalMetadata=None, file=None): # noqa: E501 | ||
"""uploads an image | ||
# noqa: E501 | ||
:param petId: ID of pet to update | ||
:type petId: int | ||
:param additionalMetadata: Additional data to pass to server | ||
:type additionalMetadata: str | ||
:param file: file to upload | ||
:type file: werkzeug.datastructures.FileStorage | ||
:rtype: ApiResponse | ||
""" | ||
return 'do some magic!' |
57 changes: 57 additions & 0 deletions
57
...les/server/petstore/flaskConnexion-python2/swagger_server/controllers/store_controller.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import connexion | ||
import six | ||
|
||
from swagger_server.models.order import Order # noqa: E501 | ||
from swagger_server import util | ||
|
||
|
||
def delete_order(orderId): # noqa: E501 | ||
"""Delete purchase order by ID | ||
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors # noqa: E501 | ||
:param orderId: ID of the order that needs to be deleted | ||
:type orderId: str | ||
:rtype: None | ||
""" | ||
return 'do some magic!' | ||
|
||
|
||
def get_inventory(): # noqa: E501 | ||
"""Returns pet inventories by status | ||
Returns a map of status codes to quantities # noqa: E501 | ||
:rtype: Dict[str, int] | ||
""" | ||
return 'do some magic!' | ||
|
||
|
||
def get_order_by_id(orderId): # noqa: E501 | ||
"""Find purchase order by ID | ||
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions # noqa: E501 | ||
:param orderId: ID of pet that needs to be fetched | ||
:type orderId: int | ||
:rtype: Order | ||
""" | ||
return 'do some magic!' | ||
|
||
|
||
def place_order(body): # noqa: E501 | ||
"""Place an order for a pet | ||
# noqa: E501 | ||
:param body: order placed for purchasing the pet | ||
:type body: dict | bytes | ||
:rtype: Order | ||
""" | ||
if connexion.request.is_json: | ||
body = Order.from_dict(connexion.request.get_json()) # noqa: E501 | ||
return 'do some magic!' |
Oops, something went wrong.