Clean-up - Unnecessary trailing underscores in Python Flask, AIOHttp, BluePlanet (#16249)

* Remove trailing underscore in security_controller_.py and base_model_.py

* Regenerating sample files

* Clean-up files with trailing underscore in samples

* Update security extension to use the new security_controller

* Regenerate unmaintained samples
This commit is contained in:
Yassine Ilmi
2023-08-14 07:26:24 +02:00
committed by GitHub
parent 47020f10b7
commit 931197a1cd
91 changed files with 471 additions and 281 deletions

View File

@@ -0,0 +1,31 @@
.dockerignore
.gitignore
.travis.yml
Dockerfile
README.md
git_push.sh
openapi_server/__init__.py
openapi_server/__main__.py
openapi_server/controllers/__init__.py
openapi_server/controllers/pet_controller.py
openapi_server/controllers/security_controller.py
openapi_server/controllers/store_controller.py
openapi_server/controllers/user_controller.py
openapi_server/encoder.py
openapi_server/models/__init__.py
openapi_server/models/api_response.py
openapi_server/models/base_model.py
openapi_server/models/category.py
openapi_server/models/order.py
openapi_server/models/pet.py
openapi_server/models/status_enum.py
openapi_server/models/tag.py
openapi_server/models/user.py
openapi_server/openapi/openapi.yaml
openapi_server/test/__init__.py
openapi_server/typing_utils.py
openapi_server/util.py
requirements.txt
setup.py
test-requirements.txt
tox.ini

View File

@@ -1 +1 @@
5.0.0-SNAPSHOT
7.0.0-SNAPSHOT

View File

@@ -38,14 +38,14 @@ git add .
git commit -m "$release_note"
# Sets the new remote
git_remote=`git 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://${git_host}/${git_user_id}/${git_repo_id}.git
else
git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git
git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
fi
fi
@@ -55,4 +55,3 @@ git pull origin master
# Pushes (Forces) the changes in the local repository up to the remote repository
echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
git push origin master 2>&1 | grep -v 'To https'

View File

@@ -11,6 +11,7 @@ def main():
app.add_api('openapi.yaml',
arguments={'title': 'OpenAPI Petstore'},
pythonic_params=True)
app.run(port=8080)

View File

@@ -1,5 +1,8 @@
import connexion
import six
from typing import Dict
from typing import Tuple
from typing import Union
from openapi_server.models.api_response import ApiResponse # noqa: E501
from openapi_server.models.pet import Pet # noqa: E501
@@ -17,7 +20,7 @@ def add_pet(pet): # noqa: E501
:param pet: Pet object that needs to be added to the store
:type pet: dict | bytes
:rtype: None
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
if connexion.request.is_json:
pet = Pet.from_dict(connexion.request.get_json()) # noqa: E501
@@ -34,7 +37,7 @@ def delete_pet(pet_id, api_key=None): # noqa: E501
:param api_key:
:type api_key: str
:rtype: None
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
return 'do some magic!'
@@ -47,7 +50,7 @@ def find_pets_by_status(status): # noqa: E501
:param status: Status values that need to be considered for filter
:type status: List[str]
:rtype: List[Pet]
:rtype: Union[List[Pet], Tuple[List[Pet], int], Tuple[List[Pet], int, Dict[str, str]]
"""
return 'do some magic!'
@@ -60,7 +63,7 @@ def find_pets_by_tags(tags): # noqa: E501
:param tags: Tags to filter by
:type tags: List[str]
:rtype: List[Pet]
:rtype: Union[List[Pet], Tuple[List[Pet], int], Tuple[List[Pet], int, Dict[str, str]]
"""
return 'do some magic!'
@@ -73,7 +76,7 @@ def get_pet_by_id(pet_id): # noqa: E501
:param pet_id: ID of pet to return
:type pet_id: int
:rtype: Pet
:rtype: Union[Pet, Tuple[Pet, int], Tuple[Pet, int, Dict[str, str]]
"""
return 'do some magic!'
@@ -86,7 +89,7 @@ def update_pet(pet): # noqa: E501
:param pet: Pet object that needs to be added to the store
:type pet: dict | bytes
:rtype: None
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
if connexion.request.is_json:
pet = Pet.from_dict(connexion.request.get_json()) # noqa: E501
@@ -103,7 +106,7 @@ def update_pet_status_with_enum(pet_id, status): # noqa: E501
:param status: The required status
:type status: dict | bytes
:rtype: Pet
:rtype: Union[Pet, Tuple[Pet, int], Tuple[Pet, int, Dict[str, str]]
"""
if connexion.request.is_json:
status = StatusEnum.from_dict(connexion.request.get_json()) # noqa: E501
@@ -120,7 +123,7 @@ def update_pet_with_form(pet_id, pet_form=None): # noqa: E501
:param pet_form:
:type pet_form: dict | bytes
:rtype: None
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
if connexion.request.is_json:
pet_form = PetForm.from_dict(connexion.request.get_json()) # noqa: E501
@@ -137,7 +140,7 @@ def upload_file(pet_id, upload_form=None): # noqa: E501
:param upload_form:
:type upload_form: dict | bytes
:rtype: ApiResponse
:rtype: Union[ApiResponse, Tuple[ApiResponse, int], Tuple[ApiResponse, int, Dict[str, str]]
"""
if connexion.request.is_json:
upload_form = UploadForm.from_dict(connexion.request.get_json()) # noqa: E501

View File

@@ -1,6 +1,35 @@
from typing import List
def info_from_petstore_auth(token):
"""
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.
:param token Token provided by Authorization header
:type token: str
:return: Decoded token information or None if token is invalid
:rtype: dict | None
"""
return {'scopes': ['read:pets', 'write:pets'], 'uid': 'user_id'}
def validate_scope_petstore_auth(required_scopes, token_scopes):
"""
Validate required scopes are included in token scope
:param required_scopes Required scope to access called API
:type required_scopes: List[str]
:param token_scopes Scope present in token
:type token_scopes: List[str]
:return: True if access to called API is allowed
:rtype: bool
"""
return set(required_scopes).issubset(set(token_scopes))
def info_from_api_key(api_key, required_scopes):
"""
Check and retrieve authentication information from api_key.
@@ -32,33 +61,3 @@ def info_from_auth_cookie(api_key, required_scopes):
"""
return {'uid': 'user_id'}
def info_from_petstore_auth(token):
"""
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.
:param token Token provided by Authorization header
:type token: str
:return: Decoded token information or None if token is invalid
:rtype: dict | None
"""
return {'scopes': ['read:pets', 'write:pets'], 'uid': 'user_id'}
def validate_scope_petstore_auth(required_scopes, token_scopes):
"""
Validate required scopes are included in token scope
:param required_scopes Required scope to access called API
:type required_scopes: List[str]
:param token_scopes Scope present in token
:type token_scopes: List[str]
:return: True if access to called API is allowed
:rtype: bool
"""
return set(required_scopes).issubset(set(token_scopes))

View File

@@ -1,5 +1,8 @@
import connexion
import six
from typing import Dict
from typing import Tuple
from typing import Union
from openapi_server.models.order import Order # noqa: E501
from openapi_server import util
@@ -13,7 +16,7 @@ def delete_order(order_id): # noqa: E501
:param order_id: ID of the order that needs to be deleted
:type order_id: str
:rtype: None
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
return 'do some magic!'
@@ -24,7 +27,7 @@ def get_inventory(): # noqa: E501
Returns a map of status codes to quantities # noqa: E501
:rtype: Dict[str, int]
:rtype: Union[Dict[str, int], Tuple[Dict[str, int], int], Tuple[Dict[str, int], int, Dict[str, str]]
"""
return 'do some magic!'
@@ -37,7 +40,7 @@ def get_order_by_id(order_id): # noqa: E501
:param order_id: ID of pet that needs to be fetched
:type order_id: int
:rtype: Order
:rtype: Union[Order, Tuple[Order, int], Tuple[Order, int, Dict[str, str]]
"""
return 'do some magic!'
@@ -50,7 +53,7 @@ def place_order(order): # noqa: E501
:param order: order placed for purchasing the pet
:type order: dict | bytes
:rtype: Order
:rtype: Union[Order, Tuple[Order, int], Tuple[Order, int, Dict[str, str]]
"""
if connexion.request.is_json:
order = Order.from_dict(connexion.request.get_json()) # noqa: E501

View File

@@ -1,5 +1,8 @@
import connexion
import six
from typing import Dict
from typing import Tuple
from typing import Union
from openapi_server.models.user import User # noqa: E501
from openapi_server import util
@@ -13,7 +16,7 @@ def create_user(user): # noqa: E501
:param user: Created user object
:type user: dict | bytes
:rtype: None
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
if connexion.request.is_json:
user = User.from_dict(connexion.request.get_json()) # noqa: E501
@@ -28,7 +31,7 @@ def create_users_with_array_input(user): # noqa: E501
:param user: List of user objects
:type user: list | bytes
:rtype: None
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
if connexion.request.is_json:
user = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501
@@ -43,7 +46,7 @@ def create_users_with_list_input(user): # noqa: E501
:param user: List of user objects
:type user: list | bytes
:rtype: None
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
if connexion.request.is_json:
user = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501
@@ -58,7 +61,7 @@ def delete_user(username): # noqa: E501
:param username: The name that needs to be deleted
:type username: str
:rtype: None
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
return 'do some magic!'
@@ -71,7 +74,7 @@ def get_user_by_name(username): # noqa: E501
:param username: The name that needs to be fetched. Use user1 for testing.
:type username: str
:rtype: User
:rtype: Union[User, Tuple[User, int], Tuple[User, int, Dict[str, str]]
"""
return 'do some magic!'
@@ -86,7 +89,7 @@ def login_user(username, password): # noqa: E501
:param password: The password for login in clear text
:type password: str
:rtype: str
:rtype: Union[str, Tuple[str, int], Tuple[str, int, Dict[str, str]]
"""
return 'do some magic!'
@@ -97,7 +100,7 @@ def logout_user(): # noqa: E501
# noqa: E501
:rtype: None
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
return 'do some magic!'
@@ -112,7 +115,7 @@ def update_user(username, user): # noqa: E501
:param user: Updated user object
:type user: dict | bytes
:rtype: None
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
if connexion.request.is_json:
user = User.from_dict(connexion.request.get_json()) # noqa: E501

View File

@@ -1,7 +1,7 @@
from connexion.apps.flask_app import FlaskJSONEncoder
import six
from openapi_server.models.base_model_ import Model
from openapi_server.models.base_model import Model
class JSONEncoder(FlaskJSONEncoder):

View File

@@ -7,8 +7,6 @@ from openapi_server.models.api_response import ApiResponse
from openapi_server.models.category import Category
from openapi_server.models.order import Order
from openapi_server.models.pet import Pet
from openapi_server.models.pet_form import PetForm
from openapi_server.models.status_enum import StatusEnum
from openapi_server.models.tag import Tag
from openapi_server.models.upload_form import UploadForm
from openapi_server.models.user import User

View File

@@ -5,7 +5,7 @@ from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from openapi_server.models.base_model_ import Model
from openapi_server.models.base_model import Model
from openapi_server import util

View File

@@ -11,11 +11,11 @@ T = typing.TypeVar('T')
class Model(object):
# openapiTypes: The key is attribute name and the
# value is attribute type.
openapi_types = {}
openapi_types: typing.Dict[str, type] = {}
# attributeMap: The key is attribute name and the
# value is json key in definition.
attribute_map = {}
attribute_map: typing.Dict[str, str] = {}
@classmethod
def from_dict(cls: typing.Type[T], dikt) -> T:

View File

@@ -5,7 +5,7 @@ from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from openapi_server.models.base_model_ import Model
from openapi_server.models.base_model import Model
import re
from openapi_server import util

View File

@@ -5,7 +5,7 @@ from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from openapi_server.models.base_model_ import Model
from openapi_server.models.base_model import Model
from openapi_server import util

View File

@@ -5,7 +5,7 @@ from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from openapi_server.models.base_model_ import Model
from openapi_server.models.base_model import Model
from openapi_server.models.category import Category
from openapi_server.models.tag import Tag
from openapi_server import util

View File

@@ -5,7 +5,7 @@ from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from openapi_server.models.base_model_ import Model
from openapi_server.models.base_model import Model
from openapi_server import util

View File

@@ -5,7 +5,7 @@ from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from openapi_server.models.base_model_ import Model
from openapi_server.models.base_model import Model
from openapi_server import util

View File

@@ -5,7 +5,7 @@ from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from openapi_server.models.base_model_ import Model
from openapi_server.models.base_model import Model
from openapi_server import util

View File

@@ -1,7 +1,7 @@
openapi: 3.0.1
info:
description: This is a sample server Petstore server. For this sample, you can use
the api key `special-key` to test the authorization filters.
description: "This is a sample server Petstore server. For this sample, you can\
\ use the api key `special-key` to test the authorization filters."
license:
name: Apache-2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
@@ -22,6 +22,7 @@ tags:
paths:
/pet:
post:
description: ""
operationId: add_pet
requestBody:
$ref: '#/components/requestBodies/Pet'
@@ -37,6 +38,7 @@ paths:
- pet
x-openapi-router-controller: openapi_server.controllers.pet_controller
put:
description: ""
operationId: update_pet
requestBody:
$ref: '#/components/requestBodies/Pet'
@@ -101,8 +103,8 @@ paths:
/pet/findByTags:
get:
deprecated: true
description: Multiple tags can be provided with comma separated strings. Use
tag1, tag2, tag3 for testing.
description: "Multiple tags can be provided with comma separated strings. Use\
\ tag1, tag2, tag3 for testing."
operationId: find_pets_by_tags
parameters:
- description: Tags to filter by
@@ -140,6 +142,7 @@ paths:
x-openapi-router-controller: openapi_server.controllers.pet_controller
/pet/{petId}:
delete:
description: ""
operationId: delete_pet
parameters:
- explode: false
@@ -203,6 +206,7 @@ paths:
- pet
x-openapi-router-controller: openapi_server.controllers.pet_controller
patch:
description: ""
operationId: update_pet_status_with_enum
parameters:
- description: ID of pet to return
@@ -242,6 +246,7 @@ paths:
- pet
x-openapi-router-controller: openapi_server.controllers.pet_controller
post:
description: ""
operationId: update_pet_with_form
parameters:
- description: ID of pet that needs to be updated
@@ -268,6 +273,7 @@ paths:
x-openapi-router-controller: openapi_server.controllers.pet_controller
/pet/{petId}/uploadImage:
post:
description: ""
operationId: upload_file
parameters:
- description: ID of pet to update
@@ -318,6 +324,7 @@ paths:
x-openapi-router-controller: openapi_server.controllers.store_controller
/store/order:
post:
description: ""
operationId: place_order
requestBody:
content:
@@ -421,6 +428,7 @@ paths:
x-openapi-router-controller: openapi_server.controllers.user_controller
/user/createWithArray:
post:
description: ""
operationId: create_users_with_array_input
requestBody:
$ref: '#/components/requestBodies/UserArray'
@@ -435,6 +443,7 @@ paths:
x-openapi-router-controller: openapi_server.controllers.user_controller
/user/createWithList:
post:
description: ""
operationId: create_users_with_list_input
requestBody:
$ref: '#/components/requestBodies/UserArray'
@@ -449,6 +458,7 @@ paths:
x-openapi-router-controller: openapi_server.controllers.user_controller
/user/login:
get:
description: ""
operationId: login_user
parameters:
- description: The user name for login
@@ -457,7 +467,7 @@ paths:
name: username
required: true
schema:
pattern: ^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$
pattern: "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$"
type: string
style: form
- description: The password for login in clear text
@@ -509,6 +519,7 @@ paths:
x-openapi-router-controller: openapi_server.controllers.user_controller
/user/logout:
get:
description: ""
operationId: logout_user
responses:
default:
@@ -544,6 +555,7 @@ paths:
- user
x-openapi-router-controller: openapi_server.controllers.user_controller
get:
description: ""
operationId: get_user_by_name
parameters:
- description: The name that needs to be fetched. Use user1 for testing.
@@ -663,15 +675,19 @@ components:
properties:
id:
format: int64
title: id
type: integer
petId:
format: int64
title: petId
type: integer
quantity:
format: int32
title: quantity
type: integer
shipDate:
format: date-time
title: shipDate
type: string
status:
description: Order Status
@@ -679,9 +695,11 @@ components:
- placed
- approved
- delivered
title: status
type: string
complete:
default: false
title: complete
type: boolean
title: Pet Order
type: object
@@ -695,9 +713,11 @@ components:
properties:
id:
format: int64
title: id
type: integer
name:
pattern: ^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$
pattern: "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$"
title: name
type: string
title: Pet category
type: object
@@ -717,22 +737,30 @@ components:
properties:
id:
format: int64
title: id
type: integer
username:
title: username
type: string
firstName:
title: firstName
type: string
lastName:
title: lastName
type: string
email:
title: email
type: string
password:
title: password
type: string
phone:
title: phone
type: string
userStatus:
description: User Status
format: int32
title: userStatus
type: integer
title: a User
type: object
@@ -746,8 +774,10 @@ components:
properties:
id:
format: int64
title: id
type: integer
name:
title: name
type: string
title: Pet Tag
type: object
@@ -773,15 +803,18 @@ components:
properties:
id:
format: int64
title: id
type: integer
category:
$ref: '#/components/schemas/Category'
name:
example: doggie
title: name
type: string
photoUrls:
items:
type: string
title: photoUrls
type: array
xml:
name: photoUrl
@@ -789,6 +822,7 @@ components:
tags:
items:
$ref: '#/components/schemas/Tag'
title: tags
type: array
xml:
name: tag
@@ -799,6 +833,7 @@ components:
- available
- pending
- sold
title: status
type: string
required:
- name
@@ -812,9 +847,11 @@ components:
properties:
name:
description: Updated name of the pet
title: name
type: string
status:
description: Updated status of the pet
title: status
type: string
required:
- name
@@ -826,10 +863,12 @@ components:
properties:
additionalMetadata:
description: Additional data to pass to server
title: additionalMetadata
type: string
file:
description: file to upload
format: binary
title: file
type: string
required:
- file
@@ -844,10 +883,13 @@ components:
properties:
code:
format: int32
title: code
type: integer
type:
title: type
type: string
message:
title: message
type: string
title: An uploaded response
type: object
@@ -857,6 +899,7 @@ components:
- available
- pending
- sold
title: statusEnum
type: string
securitySchemes:
petstore_auth:
@@ -867,15 +910,15 @@ components:
write:pets: modify pets in your account
read:pets: read your pets
type: oauth2
x-tokenInfoFunc: openapi_server.controllers.security_controller_.info_from_petstore_auth
x-scopeValidateFunc: openapi_server.controllers.security_controller_.validate_scope_petstore_auth
x-tokenInfoFunc: openapi_server.controllers.security_controller.info_from_petstore_auth
x-scopeValidateFunc: openapi_server.controllers.security_controller.validate_scope_petstore_auth
api_key:
in: header
name: api_key
type: apiKey
x-apikeyInfoFunc: openapi_server.controllers.security_controller_.info_from_api_key
x-apikeyInfoFunc: openapi_server.controllers.security_controller.info_from_api_key
auth_cookie:
in: cookie
name: AUTH_KEY
type: apiKey
x-apikeyInfoFunc: openapi_server.controllers.security_controller_.info_from_auth_cookie
x-apikeyInfoFunc: openapi_server.controllers.security_controller.info_from_auth_cookie

View File

@@ -67,6 +67,9 @@ def deserialize_date(string):
:return: date.
:rtype: date
"""
if string is None:
return None
try:
from dateutil.parser import parse
return parse(string).date()
@@ -84,6 +87,9 @@ def deserialize_datetime(string):
:return: datetime.
:rtype: datetime
"""
if string is None:
return None
try:
from dateutil.parser import parse
return parse(string)

View File

@@ -8,3 +8,4 @@ werkzeug == 0.16.1; python_version=="3.5" or python_version=="3.4"
swagger-ui-bundle >= 0.0.2
python_dateutil >= 2.6.0
setuptools >= 21.0.0
Flask == 2.1.1

View File

@@ -1,4 +1,4 @@
pytest~=4.6.7 # needed for python 2.7+3.4
pytest~=7.1.0
pytest-cov>=2.8.1
pytest-randomly==1.2.3 # needed for python 2.7+3.4
Flask-Testing==0.8.0
pytest-randomly>=1.2.3
Flask-Testing==0.8.1