Use the dataType if the baseType is not set (#5372)

* Use the dataType if the baseType is not set

* add tests for passing enum as parameter

* updated requirements file in samples

* Update spec to explicitly name objects and prevent `inline_object`

* use the correct scripts to generate samples (`bin/openapi3/python-flask*`)
This commit is contained in:
Justin
2020-02-28 18:46:57 +01:00
committed by GitHub
parent 4603061c17
commit 857a4bf5d9
25 changed files with 1273 additions and 206 deletions

View File

@@ -3,6 +3,9 @@ import six
from openapi_server.models.api_response import ApiResponse # noqa: E501
from openapi_server.models.pet import Pet # noqa: E501
from openapi_server.models.pet_form import PetForm # noqa: E501
from openapi_server.models.status_enum import StatusEnum # noqa: E501
from openapi_server.models.upload_form import UploadForm # noqa: E501
from openapi_server import util
@@ -90,35 +93,52 @@ def update_pet(pet): # noqa: E501
return 'do some magic!'
def update_pet_with_form(pet_id, name=None, status=None): # noqa: E501
def update_pet_status_with_enum(pet_id, status): # noqa: E501
"""Set the status of a pet in the store using an enum
# noqa: E501
:param pet_id: ID of pet to return
:type pet_id: int
:param status: The required status
:type status: dict | bytes
:rtype: Pet
"""
if connexion.request.is_json:
status = StatusEnum.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
def update_pet_with_form(pet_id, pet_form=None): # noqa: E501
"""Updates a pet in the store with form data
# noqa: E501
: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
:param pet_form:
:type pet_form: dict | bytes
:rtype: None
"""
if connexion.request.is_json:
pet_form = PetForm.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
def upload_file(pet_id, additional_metadata=None, file=None): # noqa: E501
def upload_file(pet_id, upload_form=None): # noqa: E501
"""uploads an image
# noqa: E501
: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
:param upload_form:
:type upload_form: dict | bytes
:rtype: ApiResponse
"""
if connexion.request.is_json:
upload_form = UploadForm.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'

View File

@@ -25,7 +25,7 @@ def create_users_with_array_input(user): # noqa: E501
# noqa: E501
:param user: List of user object
:param user: List of user objects
:type user: list | bytes
:rtype: None
@@ -40,7 +40,7 @@ def create_users_with_list_input(user): # noqa: E501
# noqa: E501
:param user: List of user object
:param user: List of user objects
:type user: list | bytes
:rtype: None

View File

@@ -5,9 +5,10 @@ from __future__ import absolute_import
# import models into model package
from openapi_server.models.api_response import ApiResponse
from openapi_server.models.category import Category
from openapi_server.models.inline_object import InlineObject
from openapi_server.models.inline_object1 import InlineObject1
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

@@ -9,18 +9,18 @@ from openapi_server.models.base_model_ import Model
from openapi_server import util
class InlineObject(Model):
class PetForm(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""
def __init__(self, name=None, status=None): # noqa: E501
"""InlineObject - a model defined in OpenAPI
"""PetForm - a model defined in OpenAPI
:param name: The name of this InlineObject. # noqa: E501
:param name: The name of this PetForm. # noqa: E501
:type name: str
:param status: The status of this InlineObject. # noqa: E501
:param status: The status of this PetForm. # noqa: E501
:type status: str
"""
self.openapi_types = {
@@ -37,58 +37,62 @@ class InlineObject(Model):
self._status = status
@classmethod
def from_dict(cls, dikt) -> 'InlineObject':
def from_dict(cls, dikt) -> 'PetForm':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The inline_object of this InlineObject. # noqa: E501
:rtype: InlineObject
:return: The PetForm of this PetForm. # noqa: E501
:rtype: PetForm
"""
return util.deserialize_model(dikt, cls)
@property
def name(self):
"""Gets the name of this InlineObject.
"""Gets the name of this PetForm.
Updated name of the pet # noqa: E501
:return: The name of this InlineObject.
:return: The name of this PetForm.
:rtype: str
"""
return self._name
@name.setter
def name(self, name):
"""Sets the name of this InlineObject.
"""Sets the name of this PetForm.
Updated name of the pet # noqa: E501
:param name: The name of this InlineObject.
:param name: The name of this PetForm.
:type name: str
"""
if name is None:
raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501
self._name = name
@property
def status(self):
"""Gets the status of this InlineObject.
"""Gets the status of this PetForm.
Updated status of the pet # noqa: E501
:return: The status of this InlineObject.
:return: The status of this PetForm.
:rtype: str
"""
return self._status
@status.setter
def status(self, status):
"""Sets the status of this InlineObject.
"""Sets the status of this PetForm.
Updated status of the pet # noqa: E501
:param status: The status of this InlineObject.
:param status: The status of this PetForm.
:type status: str
"""
if status is None:
raise ValueError("Invalid value for `status`, must not be `None`") # noqa: E501
self._status = status

View File

@@ -0,0 +1,43 @@
# coding: utf-8
from __future__ import absolute_import
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 import util
class StatusEnum(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""
"""
allowed enum values
"""
AVAILABLE = "available"
PENDING = "pending"
SOLD = "sold"
def __init__(self): # noqa: E501
"""StatusEnum - a model defined in OpenAPI
"""
self.openapi_types = {
}
self.attribute_map = {
}
@classmethod
def from_dict(cls, dikt) -> 'StatusEnum':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The statusEnum of this StatusEnum. # noqa: E501
:rtype: StatusEnum
"""
return util.deserialize_model(dikt, cls)

View File

@@ -9,18 +9,18 @@ from openapi_server.models.base_model_ import Model
from openapi_server import util
class InlineObject1(Model):
class UploadForm(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""
def __init__(self, additional_metadata=None, file=None): # noqa: E501
"""InlineObject1 - a model defined in OpenAPI
"""UploadForm - a model defined in OpenAPI
:param additional_metadata: The additional_metadata of this InlineObject1. # noqa: E501
:param additional_metadata: The additional_metadata of this UploadForm. # noqa: E501
:type additional_metadata: str
:param file: The file of this InlineObject1. # noqa: E501
:param file: The file of this UploadForm. # noqa: E501
:type file: file
"""
self.openapi_types = {
@@ -37,34 +37,34 @@ class InlineObject1(Model):
self._file = file
@classmethod
def from_dict(cls, dikt) -> 'InlineObject1':
def from_dict(cls, dikt) -> 'UploadForm':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The inline_object_1 of this InlineObject1. # noqa: E501
:rtype: InlineObject1
:return: The UploadForm of this UploadForm. # noqa: E501
:rtype: UploadForm
"""
return util.deserialize_model(dikt, cls)
@property
def additional_metadata(self):
"""Gets the additional_metadata of this InlineObject1.
"""Gets the additional_metadata of this UploadForm.
Additional data to pass to server # noqa: E501
:return: The additional_metadata of this InlineObject1.
:return: The additional_metadata of this UploadForm.
:rtype: str
"""
return self._additional_metadata
@additional_metadata.setter
def additional_metadata(self, additional_metadata):
"""Sets the additional_metadata of this InlineObject1.
"""Sets the additional_metadata of this UploadForm.
Additional data to pass to server # noqa: E501
:param additional_metadata: The additional_metadata of this InlineObject1.
:param additional_metadata: The additional_metadata of this UploadForm.
:type additional_metadata: str
"""
@@ -72,23 +72,25 @@ class InlineObject1(Model):
@property
def file(self):
"""Gets the file of this InlineObject1.
"""Gets the file of this UploadForm.
file to upload # noqa: E501
:return: The file of this InlineObject1.
:return: The file of this UploadForm.
:rtype: file
"""
return self._file
@file.setter
def file(self, file):
"""Sets the file of this InlineObject1.
"""Sets the file of this UploadForm.
file to upload # noqa: E501
:param file: The file of this InlineObject1.
:param file: The file of this UploadForm.
:type file: file
"""
if file is None:
raise ValueError("Invalid value for `file`, must not be `None`") # noqa: E501
self._file = file

View File

@@ -1,4 +1,4 @@
openapi: 3.0.0
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.
@@ -220,6 +220,45 @@ paths:
tags:
- pet
x-openapi-router-controller: openapi_server.controllers.pet_controller
patch:
operationId: update_pet_status_with_enum
parameters:
- description: ID of pet to return
explode: false
in: path
name: petId
required: true
schema:
format: int64
type: integer
style: simple
- description: The required status
example: pending
explode: true
in: query
name: status
required: true
schema:
$ref: '#/components/schemas/statusEnum'
style: form
responses:
"200":
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
description: successful operation
"400":
description: Invalid ID supplied
"404":
description: Pet not found
summary: Set the status of a pet in the store using an enum
tags:
- pet
x-openapi-router-controller: openapi_server.controllers.pet_controller
post:
operationId: update_pet_with_form
parameters:
@@ -233,18 +272,7 @@ paths:
type: integer
style: simple
requestBody:
$ref: '#/components/requestBodies/inline_object'
content:
application/x-www-form-urlencoded:
schema:
properties:
name:
description: Updated name of the pet
type: string
status:
description: Updated status of the pet
type: string
type: object
$ref: '#/components/requestBodies/PetForm'
responses:
"405":
description: Invalid input
@@ -270,19 +298,7 @@ paths:
type: integer
style: simple
requestBody:
$ref: '#/components/requestBodies/inline_object_1'
content:
multipart/form-data:
schema:
properties:
additionalMetadata:
description: Additional data to pass to server
type: string
file:
description: file to upload
format: binary
type: string
type: object
$ref: '#/components/requestBodies/UploadForm'
responses:
"200":
content:
@@ -605,6 +621,17 @@ paths:
- user
x-openapi-router-controller: openapi_server.controllers.user_controller
components:
parameters:
statusEnum:
description: The required status
example: pending
explode: true
in: query
name: status
required: true
schema:
$ref: '#/components/schemas/statusEnum'
style: form
requestBodies:
UserArray:
content:
@@ -613,7 +640,7 @@ components:
items:
$ref: '#/components/schemas/User'
type: array
description: List of user object
description: List of user objects
required: true
Pet:
content:
@@ -625,16 +652,22 @@ components:
$ref: '#/components/schemas/Pet'
description: Pet object that needs to be added to the store
required: true
inline_object:
PetForm:
content:
application/x-www-form-urlencoded:
example:
name: fluffy
status: available
schema:
$ref: '#/components/schemas/inline_object'
inline_object_1:
$ref: '#/components/schemas/PetForm'
UploadForm:
content:
multipart/form-data:
example:
additionalMetadata: additional metadata example
file: c29tZSB0ZXN0IGRhdGEK
schema:
$ref: '#/components/schemas/inline_object_1'
$ref: '#/components/schemas/UploadForm'
schemas:
Order:
description: An order for a pets from the pet store
@@ -792,6 +825,34 @@ components:
type: object
xml:
name: Pet
PetForm:
description: A form for updating a pet
properties:
name:
description: Updated name of the pet
type: string
status:
description: Updated status of the pet
type: string
required:
- name
- status
title: A pet form
type: object
UploadForm:
description: A form for attaching files to a pet
properties:
additionalMetadata:
description: Additional data to pass to server
type: string
file:
description: file to upload
format: binary
type: string
required:
- file
title: An upload form
type: object
ApiResponse:
description: Describes the result of uploading an image resource
example:
@@ -808,25 +869,13 @@ components:
type: string
title: An uploaded response
type: object
inline_object:
properties:
name:
description: Updated name of the pet
type: string
status:
description: Updated status of the pet
type: string
type: object
inline_object_1:
properties:
additionalMetadata:
description: Additional data to pass to server
type: string
file:
description: file to upload
format: binary
type: string
type: object
statusEnum:
description: pet status in the store
enum:
- available
- pending
- sold
type: string
securitySchemes:
petstore_auth:
flows:

View File

@@ -8,6 +8,9 @@ from six import BytesIO
from openapi_server.models.api_response import ApiResponse # noqa: E501
from openapi_server.models.pet import Pet # noqa: E501
from openapi_server.models.pet_form import PetForm # noqa: E501
from openapi_server.models.status_enum import StatusEnum # noqa: E501
from openapi_server.models.upload_form import UploadForm # noqa: E501
from openapi_server.test import BaseTestCase
@@ -156,23 +159,39 @@ class TestPetController(BaseTestCase):
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
def test_update_pet_status_with_enum(self):
"""Test case for update_pet_status_with_enum
Set the status of a pet in the store using an enum
"""
query_string = [('status', pending)]
headers = {
'Accept': 'application/json',
}
response = self.client.open(
'/v2/pet/{pet_id}'.format(pet_id=56),
method='PATCH',
headers=headers,
query_string=query_string)
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
@unittest.skip("application/x-www-form-urlencoded not supported by Connexion")
def test_update_pet_with_form(self):
"""Test case for update_pet_with_form
Updates a pet in the store with form data
"""
pet_form = {"name":"fluffy","status":"available"}
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer special-key',
}
data = dict(name='name_example',
status='status_example')
response = self.client.open(
'/v2/pet/{pet_id}'.format(pet_id=56),
method='POST',
headers=headers,
data=data,
data=json.dumps(pet_form),
content_type='application/x-www-form-urlencoded')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
@@ -183,18 +202,17 @@ class TestPetController(BaseTestCase):
uploads an image
"""
upload_form = {"additionalMetadata":"additional metadata example","file":"c29tZSB0ZXN0IGRhdGEK"}
headers = {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data',
'Authorization': 'Bearer special-key',
}
data = dict(additional_metadata='additional_metadata_example',
file=(BytesIO(b'some file data'), 'file.txt'))
response = self.client.open(
'/v2/pet/{pet_id}/uploadImage'.format(pet_id=56),
method='POST',
headers=headers,
data=data,
data=json.dumps(upload_form),
content_type='multipart/form-data')
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))