mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-03 00:43:46 +00:00
Python flask pythonic params (#2374)
* Using connexion `pythonic_params` support while keeping OpenAPI spec file correct with reference to the original spec file. * - Add `camelCase` query parameter which shows the incorrectnes of the conversion of the OpenAPI spec file in Python server implementation(s). * Also use `pythonic_params=True` for the `python-aiohttp` implementation. * - Updated Python related samples. * The unit tests must provide the correct query parameters. * - Updated Python related samples.
This commit is contained in:
committed by
William Cheng
parent
033ab8a6f5
commit
f7943257c5
@@ -8,7 +8,9 @@ from openapi_server import encoder
|
||||
def main():
|
||||
app = connexion.App(__name__, specification_dir='./openapi/')
|
||||
app.app.json_encoder = encoder.JSONEncoder
|
||||
app.add_api('openapi.yaml', arguments={'title': 'OpenAPI Petstore'})
|
||||
app.add_api('openapi.yaml',
|
||||
arguments={'title': 'OpenAPI Petstore'},
|
||||
pythonic_params=True)
|
||||
app.run(port=8080)
|
||||
|
||||
|
||||
|
||||
@@ -49,13 +49,15 @@ def find_pets_by_status(status): # noqa: E501
|
||||
return 'do some magic!'
|
||||
|
||||
|
||||
def find_pets_by_tags(tags): # noqa: E501
|
||||
def find_pets_by_tags(tags, max_count=None): # 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]
|
||||
:param max_count: Maximum number of items to return
|
||||
:type max_count: int
|
||||
|
||||
:rtype: List[Pet]
|
||||
"""
|
||||
|
||||
@@ -114,6 +114,15 @@ paths:
|
||||
type: string
|
||||
type: array
|
||||
style: form
|
||||
- description: Maximum number of items to return
|
||||
explode: true
|
||||
in: query
|
||||
name: maxCount
|
||||
required: false
|
||||
schema:
|
||||
format: int32
|
||||
type: integer
|
||||
style: form
|
||||
responses:
|
||||
200:
|
||||
content:
|
||||
@@ -138,7 +147,7 @@ paths:
|
||||
tags:
|
||||
- pet
|
||||
x-openapi-router-controller: openapi_server.controllers.pet_controller
|
||||
/pet/{pet_id}:
|
||||
/pet/{petId}:
|
||||
delete:
|
||||
operationId: delete_pet
|
||||
parameters:
|
||||
@@ -152,7 +161,7 @@ paths:
|
||||
- description: Pet id to delete
|
||||
explode: false
|
||||
in: path
|
||||
name: pet_id
|
||||
name: petId
|
||||
required: true
|
||||
schema:
|
||||
format: int64
|
||||
@@ -176,7 +185,7 @@ paths:
|
||||
- description: ID of pet to return
|
||||
explode: false
|
||||
in: path
|
||||
name: pet_id
|
||||
name: petId
|
||||
required: true
|
||||
schema:
|
||||
format: int64
|
||||
@@ -208,7 +217,7 @@ paths:
|
||||
- description: ID of pet that needs to be updated
|
||||
explode: false
|
||||
in: path
|
||||
name: pet_id
|
||||
name: petId
|
||||
required: true
|
||||
schema:
|
||||
format: int64
|
||||
@@ -238,14 +247,14 @@ paths:
|
||||
tags:
|
||||
- pet
|
||||
x-openapi-router-controller: openapi_server.controllers.pet_controller
|
||||
/pet/{pet_id}/uploadImage:
|
||||
/pet/{petId}/uploadImage:
|
||||
post:
|
||||
operationId: upload_file
|
||||
parameters:
|
||||
- description: ID of pet to update
|
||||
explode: false
|
||||
in: path
|
||||
name: pet_id
|
||||
name: petId
|
||||
required: true
|
||||
schema:
|
||||
format: int64
|
||||
@@ -326,7 +335,7 @@ paths:
|
||||
tags:
|
||||
- store
|
||||
x-openapi-router-controller: openapi_server.controllers.store_controller
|
||||
/store/order/{order_id}:
|
||||
/store/order/{orderId}:
|
||||
delete:
|
||||
description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
operationId: delete_order
|
||||
@@ -334,7 +343,7 @@ paths:
|
||||
- description: ID of the order that needs to be deleted
|
||||
explode: false
|
||||
in: path
|
||||
name: order_id
|
||||
name: orderId
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
@@ -355,7 +364,7 @@ paths:
|
||||
- description: ID of pet that needs to be fetched
|
||||
explode: false
|
||||
in: path
|
||||
name: order_id
|
||||
name: orderId
|
||||
required: true
|
||||
schema:
|
||||
format: int64
|
||||
|
||||
@@ -12,5 +12,5 @@ class BaseTestCase(TestCase):
|
||||
logging.getLogger('connexion.operation').setLevel('ERROR')
|
||||
app = connexion.App(__name__, specification_dir='../openapi/')
|
||||
app.app.json_encoder = JSONEncoder
|
||||
app.add_api('openapi.yaml')
|
||||
app.add_api('openapi.yaml', pythonic_params=True)
|
||||
return app.app
|
||||
|
||||
@@ -89,7 +89,8 @@ class TestPetController(BaseTestCase):
|
||||
|
||||
Finds Pets by tags
|
||||
"""
|
||||
query_string = [('tags', 'tags_example')]
|
||||
query_string = [('tags', 'tags_example'),
|
||||
('maxCount', 56)]
|
||||
headers = {
|
||||
'Accept': 'application/json',
|
||||
'Authorization': 'Bearer special-key',
|
||||
|
||||
Reference in New Issue
Block a user