[Python] fix numeric enum in python flask, aiohttp (#5019)

* minor code format fix

* fix numeric enum in python flask and aiohttp

* add python-server-all.sh to ensure-up-to-date
This commit is contained in:
William Cheng 2020-01-19 15:25:20 +08:00 committed by GitHub
parent 6a34706a9b
commit fff759b79c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 109 additions and 103 deletions

View File

@ -39,6 +39,7 @@ declare -a samples=(
"${root}/bin/mysql-schema-petstore.sh"
"${root}/bin/nim-client-petstore.sh"
"${root}/bin/python-petstore-all.sh"
"${root}/bin/python-server-all.sh"
"${root}/bin/openapi3/python-petstore.sh"
"${root}/bin/php-petstore.sh"
"${root}/bin/php-silex-petstore-server.sh"

View File

@ -649,6 +649,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
/**
* Return the default value of the property
*
* @param p OpenAPI property object
* @return string presentation of the default value of the property
*/

View File

@ -89,8 +89,8 @@ class {{classname}}(Model):
:type {{name}}: {{dataType}}
"""
{{#isEnum}}
allowed_values = [{{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]
{{#isContainer}}
allowed_values = [{{#isNullable}}None,{{/isNullable}}{{#allowableValues}}{{#values}}{{#items.isString}}"{{/items.isString}}{{{this}}}{{#items.isString}}"{{/items.isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501
{{#isListContainer}}
if not set({{{name}}}).issubset(set(allowed_values)):
raise ValueError(
@ -109,6 +109,7 @@ class {{classname}}(Model):
{{/isMapContainer}}
{{/isContainer}}
{{^isContainer}}
allowed_values = [{{#isNullable}}None,{{/isNullable}}{{#allowableValues}}{{#values}}{{#isString}}"{{/isString}}{{{this}}}{{#isString}}"{{/isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501
if {{{name}}} not in allowed_values:
raise ValueError(
"Invalid value for `{{{name}}}` ({0}), must be one of {1}"

View File

@ -25,7 +25,8 @@ class {{classname}}(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""{{#allowableValues}}
"""
{{#allowableValues}}
"""
allowed enum values
@ -33,7 +34,8 @@ class {{classname}}(Model):
{{#enumVars}}
{{name}} = {{{value}}}{{^-last}}
{{/-last}}
{{/enumVars}}{{/allowableValues}}
{{/enumVars}}
{{/allowableValues}}
def __init__(self{{#vars}}, {{name}}={{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{/vars}}): # noqa: E501
"""{{classname}} - a model defined in OpenAPI
@ -96,8 +98,8 @@ class {{classname}}(Model):
:type {{name}}: {{dataType}}
"""
{{#isEnum}}
allowed_values = [{{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501
{{#isContainer}}
allowed_values = [{{#isNullable}}None,{{/isNullable}}{{#allowableValues}}{{#values}}{{#items.isString}}"{{/items.isString}}{{{this}}}{{#items.isString}}"{{/items.isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501
{{#isListContainer}}
if not set({{{name}}}).issubset(set(allowed_values)):
raise ValueError(
@ -116,6 +118,7 @@ class {{classname}}(Model):
{{/isMapContainer}}
{{/isContainer}}
{{^isContainer}}
allowed_values = [{{#isNullable}}None,{{/isNullable}}{{#allowableValues}}{{#values}}{{#isString}}"{{/isString}}{{{this}}}{{#isString}}"{{/isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501
if {{{name}}} not in allowed_values:
raise ValueError(
"Invalid value for `{{{name}}}` ({0}), must be one of {1}"

View File

@ -162,7 +162,7 @@ class Order(Model):
:param status: The status of this Order.
:type status: str
"""
allowed_values = ["placed", "approved", "delivered"]
allowed_values = ["placed", "approved", "delivered"] # noqa: E501
if status not in allowed_values:
raise ValueError(
"Invalid value for `status` ({0}), must be one of {1}"

View File

@ -189,7 +189,7 @@ class Pet(Model):
:param status: The status of this Pet.
:type status: str
"""
allowed_values = ["available", "pending", "sold"]
allowed_values = ["available", "pending", "sold"] # noqa: E501
if status not in allowed_values:
raise ValueError(
"Invalid value for `status` ({0}), must be one of {1}"

View File

@ -32,7 +32,7 @@ paths:
required: true
x-body-name: body
responses:
405:
"405":
content: {}
description: Invalid input
security:
@ -58,13 +58,13 @@ paths:
required: true
x-body-name: body
responses:
400:
"400":
content: {}
description: Invalid ID supplied
404:
"404":
content: {}
description: Pet not found
405:
"405":
content: {}
description: Validation exception
security:
@ -97,7 +97,7 @@ paths:
type: array
style: form
responses:
200:
"200":
content:
application/xml:
schema:
@ -110,7 +110,7 @@ paths:
$ref: '#/components/schemas/Pet'
type: array
description: successful operation
400:
"400":
content: {}
description: Invalid status value
security:
@ -139,7 +139,7 @@ paths:
type: array
style: form
responses:
200:
"200":
content:
application/xml:
schema:
@ -152,7 +152,7 @@ paths:
$ref: '#/components/schemas/Pet'
type: array
description: successful operation
400:
"400":
content: {}
description: Invalid tag value
security:
@ -179,7 +179,7 @@ paths:
format: int64
type: integer
responses:
400:
"400":
content: {}
description: Invalid pet value
security:
@ -202,7 +202,7 @@ paths:
format: int64
type: integer
responses:
200:
"200":
content:
application/xml:
schema:
@ -211,10 +211,10 @@ paths:
schema:
$ref: '#/components/schemas/Pet'
description: successful operation
400:
"400":
content: {}
description: Invalid ID supplied
404:
"404":
content: {}
description: Pet not found
security:
@ -246,7 +246,7 @@ paths:
type: string
x-body-name: body
responses:
405:
"405":
content: {}
description: Invalid input
security:
@ -283,7 +283,7 @@ paths:
type: string
x-body-name: body
responses:
200:
"200":
content:
application/json:
schema:
@ -303,7 +303,7 @@ paths:
description: Returns a map of status codes to quantities
operationId: get_inventory
responses:
200:
"200":
content:
application/json:
schema:
@ -330,7 +330,7 @@ paths:
required: true
x-body-name: body
responses:
200:
"200":
content:
application/xml:
schema:
@ -339,7 +339,7 @@ paths:
schema:
$ref: '#/components/schemas/Order'
description: successful operation
400:
"400":
content: {}
description: Invalid Order
summary: Place an order for a pet
@ -360,10 +360,10 @@ paths:
schema:
type: string
responses:
400:
"400":
content: {}
description: Invalid ID supplied
404:
"404":
content: {}
description: Order not found
summary: Delete purchase order by ID
@ -385,7 +385,7 @@ paths:
minimum: 1
type: integer
responses:
200:
"200":
content:
application/xml:
schema:
@ -394,10 +394,10 @@ paths:
schema:
$ref: '#/components/schemas/Order'
description: successful operation
400:
"400":
content: {}
description: Invalid ID supplied
404:
"404":
content: {}
description: Order not found
summary: Find purchase order by ID
@ -486,7 +486,7 @@ paths:
schema:
type: string
responses:
200:
"200":
content:
application/xml:
schema:
@ -506,7 +506,7 @@ paths:
schema:
format: date-time
type: string
400:
"400":
content: {}
description: Invalid username/password supplied
summary: Logs user into the system
@ -536,10 +536,10 @@ paths:
schema:
type: string
responses:
400:
"400":
content: {}
description: Invalid username supplied
404:
"404":
content: {}
description: User not found
summary: Delete user
@ -556,7 +556,7 @@ paths:
schema:
type: string
responses:
200:
"200":
content:
application/xml:
schema:
@ -565,10 +565,10 @@ paths:
schema:
$ref: '#/components/schemas/User'
description: successful operation
400:
"400":
content: {}
description: Invalid username supplied
404:
"404":
content: {}
description: User not found
summary: Get user by user name
@ -594,10 +594,10 @@ paths:
required: true
x-body-name: body
responses:
400:
"400":
content: {}
description: Invalid user supplied
404:
"404":
content: {}
description: User not found
summary: Updated user

View File

@ -31,7 +31,7 @@ paths:
description: Pet object that needs to be added to the store
required: true
responses:
405:
"405":
content: {}
description: Invalid input
security:
@ -56,13 +56,13 @@ paths:
description: Pet object that needs to be added to the store
required: true
responses:
400:
"400":
content: {}
description: Invalid ID supplied
404:
"404":
content: {}
description: Pet not found
405:
"405":
content: {}
description: Validation exception
security:
@ -95,7 +95,7 @@ paths:
type: array
style: form
responses:
200:
"200":
content:
application/xml:
schema:
@ -108,7 +108,7 @@ paths:
$ref: '#/components/schemas/Pet'
type: array
description: successful operation
400:
"400":
content: {}
description: Invalid status value
security:
@ -137,7 +137,7 @@ paths:
type: array
style: form
responses:
200:
"200":
content:
application/xml:
schema:
@ -150,7 +150,7 @@ paths:
$ref: '#/components/schemas/Pet'
type: array
description: successful operation
400:
"400":
content: {}
description: Invalid tag value
security:
@ -177,7 +177,7 @@ paths:
format: int64
type: integer
responses:
400:
"400":
content: {}
description: Invalid pet value
security:
@ -200,7 +200,7 @@ paths:
format: int64
type: integer
responses:
200:
"200":
content:
application/xml:
schema:
@ -209,10 +209,10 @@ paths:
schema:
$ref: '#/components/schemas/Pet'
description: successful operation
400:
"400":
content: {}
description: Invalid ID supplied
404:
"404":
content: {}
description: Pet not found
security:
@ -243,7 +243,7 @@ paths:
description: Updated status of the pet
type: string
responses:
405:
"405":
content: {}
description: Invalid input
security:
@ -278,7 +278,7 @@ paths:
format: binary
type: string
responses:
200:
"200":
content:
application/json:
schema:
@ -297,7 +297,7 @@ paths:
description: Returns a map of status codes to quantities
operationId: get_inventory
responses:
200:
"200":
content:
application/json:
schema:
@ -323,7 +323,7 @@ paths:
description: order placed for purchasing the pet
required: true
responses:
200:
"200":
content:
application/xml:
schema:
@ -332,7 +332,7 @@ paths:
schema:
$ref: '#/components/schemas/Order'
description: successful operation
400:
"400":
content: {}
description: Invalid Order
summary: Place an order for a pet
@ -353,10 +353,10 @@ paths:
schema:
type: string
responses:
400:
"400":
content: {}
description: Invalid ID supplied
404:
"404":
content: {}
description: Order not found
summary: Delete purchase order by ID
@ -378,7 +378,7 @@ paths:
minimum: 1
type: integer
responses:
200:
"200":
content:
application/xml:
schema:
@ -387,10 +387,10 @@ paths:
schema:
$ref: '#/components/schemas/Order'
description: successful operation
400:
"400":
content: {}
description: Invalid ID supplied
404:
"404":
content: {}
description: Order not found
summary: Find purchase order by ID
@ -476,7 +476,7 @@ paths:
schema:
type: string
responses:
200:
"200":
content:
application/xml:
schema:
@ -496,7 +496,7 @@ paths:
schema:
format: date-time
type: string
400:
"400":
content: {}
description: Invalid username/password supplied
summary: Logs user into the system
@ -526,10 +526,10 @@ paths:
schema:
type: string
responses:
400:
"400":
content: {}
description: Invalid username supplied
404:
"404":
content: {}
description: User not found
summary: Delete user
@ -546,7 +546,7 @@ paths:
schema:
type: string
responses:
200:
"200":
content:
application/xml:
schema:
@ -555,10 +555,10 @@ paths:
schema:
$ref: '#/components/schemas/User'
description: successful operation
400:
"400":
content: {}
description: Invalid username supplied
404:
"404":
content: {}
description: User not found
summary: Get user by user name
@ -583,10 +583,10 @@ paths:
description: Updated user object
required: true
responses:
400:
"400":
content: {}
description: Invalid user supplied
404:
"404":
content: {}
description: User not found
summary: Updated user

View File

@ -31,7 +31,7 @@ paths:
description: Pet object that needs to be added to the store
required: true
responses:
405:
"405":
content: {}
description: Invalid input
security:
@ -56,13 +56,13 @@ paths:
description: Pet object that needs to be added to the store
required: true
responses:
400:
"400":
content: {}
description: Invalid ID supplied
404:
"404":
content: {}
description: Pet not found
405:
"405":
content: {}
description: Validation exception
security:
@ -95,7 +95,7 @@ paths:
type: array
style: form
responses:
200:
"200":
content:
application/xml:
schema:
@ -108,7 +108,7 @@ paths:
$ref: '#/components/schemas/Pet'
type: array
description: successful operation
400:
"400":
content: {}
description: Invalid status value
security:
@ -137,7 +137,7 @@ paths:
type: array
style: form
responses:
200:
"200":
content:
application/xml:
schema:
@ -150,7 +150,7 @@ paths:
$ref: '#/components/schemas/Pet'
type: array
description: successful operation
400:
"400":
content: {}
description: Invalid tag value
security:
@ -177,7 +177,7 @@ paths:
format: int64
type: integer
responses:
400:
"400":
content: {}
description: Invalid pet value
security:
@ -200,7 +200,7 @@ paths:
format: int64
type: integer
responses:
200:
"200":
content:
application/xml:
schema:
@ -209,10 +209,10 @@ paths:
schema:
$ref: '#/components/schemas/Pet'
description: successful operation
400:
"400":
content: {}
description: Invalid ID supplied
404:
"404":
content: {}
description: Pet not found
security:
@ -243,7 +243,7 @@ paths:
description: Updated status of the pet
type: string
responses:
405:
"405":
content: {}
description: Invalid input
security:
@ -278,7 +278,7 @@ paths:
format: binary
type: string
responses:
200:
"200":
content:
application/json:
schema:
@ -297,7 +297,7 @@ paths:
description: Returns a map of status codes to quantities
operationId: get_inventory
responses:
200:
"200":
content:
application/json:
schema:
@ -323,7 +323,7 @@ paths:
description: order placed for purchasing the pet
required: true
responses:
200:
"200":
content:
application/xml:
schema:
@ -332,7 +332,7 @@ paths:
schema:
$ref: '#/components/schemas/Order'
description: successful operation
400:
"400":
content: {}
description: Invalid Order
summary: Place an order for a pet
@ -353,10 +353,10 @@ paths:
schema:
type: string
responses:
400:
"400":
content: {}
description: Invalid ID supplied
404:
"404":
content: {}
description: Order not found
summary: Delete purchase order by ID
@ -378,7 +378,7 @@ paths:
minimum: 1
type: integer
responses:
200:
"200":
content:
application/xml:
schema:
@ -387,10 +387,10 @@ paths:
schema:
$ref: '#/components/schemas/Order'
description: successful operation
400:
"400":
content: {}
description: Invalid ID supplied
404:
"404":
content: {}
description: Order not found
summary: Find purchase order by ID
@ -476,7 +476,7 @@ paths:
schema:
type: string
responses:
200:
"200":
content:
application/xml:
schema:
@ -496,7 +496,7 @@ paths:
schema:
format: date-time
type: string
400:
"400":
content: {}
description: Invalid username/password supplied
summary: Logs user into the system
@ -526,10 +526,10 @@ paths:
schema:
type: string
responses:
400:
"400":
content: {}
description: Invalid username supplied
404:
"404":
content: {}
description: User not found
summary: Delete user
@ -546,7 +546,7 @@ paths:
schema:
type: string
responses:
200:
"200":
content:
application/xml:
schema:
@ -555,10 +555,10 @@ paths:
schema:
$ref: '#/components/schemas/User'
description: successful operation
400:
"400":
content: {}
description: Invalid username supplied
404:
"404":
content: {}
description: User not found
summary: Get user by user name
@ -583,10 +583,10 @@ paths:
description: Updated user object
required: true
responses:
400:
"400":
content: {}
description: Invalid user supplied
404:
"404":
content: {}
description: User not found
summary: Updated user