Skip to content

Commit c63e9d3

Browse files
committed
samples updates - python/flask and html2 samples update
1 parent 9b0fb52 commit c63e9d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+12816
-9617
lines changed

samples/html2/index.html

Lines changed: 7212 additions & 9617 deletions
Large diffs are not rendered by default.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM python:2-alpine
2+
3+
RUN mkdir -p /usr/src/app
4+
WORKDIR /usr/src/app
5+
6+
COPY requirements.txt /usr/src/app/
7+
8+
RUN pip install --no-cache-dir -r requirements.txt
9+
10+
COPY . /usr/src/app
11+
12+
EXPOSE 8080
13+
14+
ENTRYPOINT ["python"]
15+
16+
CMD ["-m", "swagger_server"]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Swagger generated server
2+
3+
## Overview
4+
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
5+
[OpenAPI-Spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This
6+
is an example of building a swagger-enabled Flask server.
7+
8+
This example uses the [Connexion](https://github.com/zalando/connexion) library on top of Flask.
9+
10+
## Requirements
11+
Python 2.7+
12+
13+
## Usage
14+
To run the server, please execute the following from the root directory:
15+
16+
```
17+
pip install -r requirements.txt
18+
python -m swagger_server
19+
```
20+
21+
and open your browser to here:
22+
23+
```
24+
http://localhost:8080/v2/ui/
25+
```
26+
27+
Your Swagger definition lives here:
28+
29+
```
30+
http://localhost:8080/v2/swagger.json
31+
```
32+
33+
To launch the integration tests, use tox:
34+
```
35+
sudo pip install tox
36+
tox
37+
```
38+
39+
## Running with Docker
40+
41+
To run the server on a Docker container, please execute the following from the root directory:
42+
43+
```bash
44+
# building the image
45+
docker build -t swagger_server .
46+
47+
# starting up a container
48+
docker run -p 8080:8080 swagger_server
49+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
3+
#
4+
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
5+
6+
git_user_id=$1
7+
git_repo_id=$2
8+
release_note=$3
9+
10+
if [ "$git_user_id" = "" ]; then
11+
git_user_id="GIT_USER_ID"
12+
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
13+
fi
14+
15+
if [ "$git_repo_id" = "" ]; then
16+
git_repo_id="GIT_REPO_ID"
17+
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
18+
fi
19+
20+
if [ "$release_note" = "" ]; then
21+
release_note="Minor update"
22+
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
23+
fi
24+
25+
# Initialize the local directory as a Git repository
26+
git init
27+
28+
# Adds the files in the local repository and stages them for commit.
29+
git add .
30+
31+
# Commits the tracked changes and prepares them to be pushed to a remote repository.
32+
git commit -m "$release_note"
33+
34+
# Sets the new remote
35+
git_remote=`git remote`
36+
if [ "$git_remote" = "" ]; then # git remote not defined
37+
38+
if [ "$GIT_TOKEN" = "" ]; then
39+
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
40+
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
41+
else
42+
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
43+
fi
44+
45+
fi
46+
47+
git pull origin master
48+
49+
# Pushes (Forces) the changes in the local repository up to the remote repository
50+
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
51+
git push origin master 2>&1 | grep -v 'To https'
52+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
connexion == 1.1.15
2+
python_dateutil == 2.6.0
3+
typing == 3.5.2.2
4+
setuptools >= 21.0.0
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# coding: utf-8
2+
3+
import sys
4+
from setuptools import setup, find_packages
5+
6+
NAME = "swagger_server"
7+
VERSION = "1.0.0"
8+
9+
# To install the library, run the following
10+
#
11+
# python setup.py install
12+
#
13+
# prerequisite: setuptools
14+
# http://pypi.python.org/pypi/setuptools
15+
16+
REQUIRES = ["connexion"]
17+
18+
setup(
19+
name=NAME,
20+
version=VERSION,
21+
description="Swagger Petstore",
22+
author_email="[email protected]",
23+
url="",
24+
keywords=["Swagger", "Swagger Petstore"],
25+
install_requires=REQUIRES,
26+
packages=find_packages(),
27+
package_data={'': ['swagger/swagger.yaml']},
28+
include_package_data=True,
29+
entry_points={
30+
'console_scripts': ['swagger_server=swagger_server.__main__:main']},
31+
long_description="""\
32+
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
33+
"""
34+
)
35+

samples/server/petstore/flaskConnexion-python2/swagger_server/__init__.py

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
3+
import connexion
4+
5+
from swagger_server import encoder
6+
7+
8+
def main():
9+
app = connexion.App(__name__, specification_dir='./swagger/')
10+
app.app.json_encoder = encoder.JSONEncoder
11+
app.add_api('swagger.yaml', arguments={'title': 'Swagger Petstore'})
12+
app.run(port=8080)
13+
14+
15+
if __name__ == '__main__':
16+
main()

samples/server/petstore/flaskConnexion-python2/swagger_server/controllers/__init__.py

Whitespace-only changes.
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import connexion
2+
import six
3+
4+
from swagger_server.models.api_response import ApiResponse # noqa: E501
5+
from swagger_server.models.pet import Pet # noqa: E501
6+
from swagger_server import util
7+
8+
9+
def add_pet(body): # noqa: E501
10+
"""Add a new pet to the store
11+
12+
# noqa: E501
13+
14+
:param body: Pet object that needs to be added to the store
15+
:type body: dict | bytes
16+
17+
:rtype: None
18+
"""
19+
if connexion.request.is_json:
20+
body = Pet.from_dict(connexion.request.get_json()) # noqa: E501
21+
return 'do some magic!'
22+
23+
24+
def delete_pet(petId, api_key=None): # noqa: E501
25+
"""Deletes a pet
26+
27+
# noqa: E501
28+
29+
:param petId: Pet id to delete
30+
:type petId: int
31+
:param api_key:
32+
:type api_key: str
33+
34+
:rtype: None
35+
"""
36+
return 'do some magic!'
37+
38+
39+
def find_pets_by_status(status): # noqa: E501
40+
"""Finds Pets by status
41+
42+
Multiple status values can be provided with comma separated strings # noqa: E501
43+
44+
:param status: Status values that need to be considered for filter
45+
:type status: List[str]
46+
47+
:rtype: List[Pet]
48+
"""
49+
return 'do some magic!'
50+
51+
52+
def find_pets_by_tags(tags): # noqa: E501
53+
"""Finds Pets by tags
54+
55+
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. # noqa: E501
56+
57+
:param tags: Tags to filter by
58+
:type tags: List[str]
59+
60+
:rtype: List[Pet]
61+
"""
62+
return 'do some magic!'
63+
64+
65+
def get_pet_by_id(petId): # noqa: E501
66+
"""Find pet by ID
67+
68+
Returns a single pet # noqa: E501
69+
70+
:param petId: ID of pet to return
71+
:type petId: int
72+
73+
:rtype: Pet
74+
"""
75+
return 'do some magic!'
76+
77+
78+
def update_pet(body): # noqa: E501
79+
"""Update an existing pet
80+
81+
# noqa: E501
82+
83+
:param body: Pet object that needs to be added to the store
84+
:type body: dict | bytes
85+
86+
:rtype: None
87+
"""
88+
if connexion.request.is_json:
89+
body = Pet.from_dict(connexion.request.get_json()) # noqa: E501
90+
return 'do some magic!'
91+
92+
93+
def update_pet_with_form(petId, name=None, status=None): # noqa: E501
94+
"""Updates a pet in the store with form data
95+
96+
# noqa: E501
97+
98+
:param petId: ID of pet that needs to be updated
99+
:type petId: int
100+
:param name: Updated name of the pet
101+
:type name: str
102+
:param status: Updated status of the pet
103+
:type status: str
104+
105+
:rtype: None
106+
"""
107+
return 'do some magic!'
108+
109+
110+
def upload_file(petId, additionalMetadata=None, file=None): # noqa: E501
111+
"""uploads an image
112+
113+
# noqa: E501
114+
115+
:param petId: ID of pet to update
116+
:type petId: int
117+
:param additionalMetadata: Additional data to pass to server
118+
:type additionalMetadata: str
119+
:param file: file to upload
120+
:type file: werkzeug.datastructures.FileStorage
121+
122+
:rtype: ApiResponse
123+
"""
124+
return 'do some magic!'

0 commit comments

Comments
 (0)