[Python] Add enum support when building default values for model properties when using $ref (#18796)

* Add enum support when building default values for model properties

* Update enum handling for Python for enum references

* Remove unused method

* Update mustaches for FastAPI, Pydantic, and Python for default values

* Address PR feedback and rebase main

* Remove old 2_0 samples
This commit is contained in:
Mike Welsh 2024-06-08 04:18:03 -04:00 committed by GitHub
parent 5adf1ff522
commit a5a99585ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 1441 additions and 841 deletions

View File

@ -1,4 +1,4 @@
generatorName: python-flask
outputDir: samples/server/petstore/python-flask
inputSpec: modules/openapi-generator/src/test/resources/2_0/python-flask/petstore.yaml
inputSpec: modules/openapi-generator/src/test/resources/3_0/python-flask/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/python-flask

View File

@ -923,6 +923,18 @@ public class DefaultCodegen implements CodegenConfig {
return datatype + "." + value;
}
/**
* Return the enum default value in the language specified format
*
* @param property The codegen property to create the default for.
* @param value Enum variable name
* @return the default value for the enum
*/
public String toEnumDefaultValue(CodegenProperty property, String value) {
// Use the datatype with the value.
return toEnumDefaultValue(value, property.datatypeWithEnum);
}
/**
* Return the enum value in the language specified format
* e.g. status becomes "status"
@ -6645,7 +6657,7 @@ public class DefaultCodegen implements CodegenConfig {
}
}
if (enumName != null) {
var.defaultValue = toEnumDefaultValue(enumName, var.datatypeWithEnum);
var.defaultValue = toEnumDefaultValue(var, enumName);
}
}
}

View File

@ -198,6 +198,18 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co
*/
@Override
public String toDefaultValue(Schema p) {
// If the Schema is a $ref, get the default value from the reference.
String ref = ModelUtils.getSimpleRef(p.get$ref());
if (ref != null) {
Schema referencedSchema = ModelUtils.getSchemas(this.openAPI).get(ref);
if (referencedSchema != null) {
String defaultValue = toDefaultValue(referencedSchema);
if (defaultValue != null) {
return defaultValue;
}
// No default was found for the $ref, so see if one has been defined locally.
}
}
if (ModelUtils.isBooleanSchema(p)) {
if (p.getDefault() != null) {
if (!Boolean.valueOf(p.getDefault().toString()))
@ -217,6 +229,14 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co
if (p.getDefault() != null) {
return p.getDefault().toString();
}
} else if (ModelUtils.isEnumSchema(p)) {
// Enum must come before string to use enum reference!
if (p.getDefault() != null) {
String defaultValue = String.valueOf(p.getDefault());
if (defaultValue != null) {
return defaultValue;
}
}
} else if (ModelUtils.isStringSchema(p)) {
if (p.getDefault() != null) {
String defaultValue = String.valueOf(p.getDefault());
@ -237,7 +257,6 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co
return null;
}
}
return null;
}
@ -1085,7 +1104,9 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co
}
// remove quote e.g. 'abc' => abc
name = name.substring(1, name.length() - 1);
if (name.startsWith("'") && name.endsWith("'")) {
name = name.substring(1, name.length() - 1);
}
if (name.length() == 0) {
return "EMPTY";
@ -1396,7 +1417,13 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co
}
@Override
public String toEnumDefaultValue(String value, String datatype) {
public String toEnumDefaultValue(CodegenProperty property, String value) {
if (property.isEnumRef) {
// Determine if it's a string by checking if the value has already been encapsulated in single quotes.
String dataType = (value.startsWith("'") && value.endsWith("'")) ? "string" : "int";
// If the property is an enum reference, then use the fully qualified name with the data type.
return property.dataType + "." + toEnumVariableName(value, dataType);
}
return value;
}

View File

@ -351,7 +351,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
"{{{baseName}}}": {{{dataType}}}.from_dict(obj.get("{{{baseName}}}")) if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}}
{{/isEnumOrRef}}
{{#isEnumOrRef}}
"{{{baseName}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
"{{{baseName}}}": obj.get("{{{baseName}}}"){{#defaultValue}} if obj.get("{{baseName}}") is not None else {{defaultValue}}{{/defaultValue}}{{^-last}},{{/-last}}
{{/isEnumOrRef}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}

View File

@ -343,7 +343,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
"{{{name}}}": {{{dataType}}}.from_dict(obj.get("{{{baseName}}}")) if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}}
{{/isEnumOrRef}}
{{#isEnumOrRef}}
"{{{name}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
"{{{name}}}": obj.get("{{{baseName}}}"){{#defaultValue}} if obj.get("{{baseName}}") is not None else {{defaultValue}}{{/defaultValue}}{{^-last}},{{/-last}}
{{/isEnumOrRef}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}

View File

@ -363,7 +363,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
"{{{baseName}}}": {{{dataType}}}.from_dict(obj["{{{baseName}}}"]) if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}}
{{/isEnumOrRef}}
{{#isEnumOrRef}}
"{{{baseName}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
"{{{baseName}}}": obj.get("{{{baseName}}}"){{#defaultValue}} if obj.get("{{baseName}}") is not None else {{defaultValue}}{{/defaultValue}}{{^-last}},{{/-last}}
{{/isEnumOrRef}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}

View File

@ -1,703 +0,0 @@
swagger: '2.0'
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.'
version: 1.0.0
title: OpenAPI Petstore
license:
name: Apache-2.0
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
host: petstore.swagger.io
basePath: /v2
tags:
- name: pet
description: Everything about your Pets
- name: store
description: Access to Petstore orders
- name: user
description: Operations about user
schemes:
- http
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: ''
operationId: addPet
consumes:
- application/json
- application/xml
produces:
- application/xml
- application/json
parameters:
- in: body
name: body
description: Pet object that needs to be added to the store
required: true
schema:
$ref: '#/definitions/Pet'
responses:
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
put:
tags:
- pet
summary: Update an existing pet
description: ''
operationId: updatePet
consumes:
- application/json
- application/xml
produces:
- application/xml
- application/json
parameters:
- in: body
name: body
description: Pet object that needs to be added to the store
required: true
schema:
$ref: '#/definitions/Pet'
responses:
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
/pet/findByStatus:
get:
tags:
- pet
summary: Finds Pets by status
description: Multiple status values can be provided with comma separated strings
operationId: findPetsByStatus
produces:
- application/xml
- application/json
parameters:
- name: status
in: query
description: Status values that need to be considered for filter
required: true
type: array
items:
type: string
enum:
- available
- pending
- sold
default: available
collectionFormat: csv
responses:
'200':
description: successful operation
schema:
type: array
items:
$ref: '#/definitions/Pet'
'400':
description: Invalid status value
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
/pet/findByTags:
get:
tags:
- pet
summary: Finds Pets by tags
description: 'Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.'
operationId: findPetsByTags
produces:
- application/xml
- application/json
parameters:
- name: tags
in: query
description: Tags to filter by
required: true
type: array
items:
type: string
collectionFormat: csv
responses:
'200':
description: successful operation
schema:
type: array
items:
$ref: '#/definitions/Pet'
'400':
description: Invalid tag value
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
deprecated: true
'/pet/{petId}':
get:
tags:
- pet
summary: Find pet by ID
description: Returns a single pet
operationId: getPetById
produces:
- application/xml
- application/json
parameters:
- name: petId
in: path
description: ID of pet to return
required: true
type: integer
format: int64
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
security:
- api_key: []
post:
tags:
- pet
summary: Updates a pet in the store with form data
description: ''
operationId: updatePetWithForm
consumes:
- application/x-www-form-urlencoded
produces:
- application/xml
- application/json
parameters:
- name: petId
in: path
description: ID of pet that needs to be updated
required: true
type: integer
format: int64
- name: name
in: formData
description: Updated name of the pet
required: false
type: string
- name: status
in: formData
description: Updated status of the pet
required: false
type: string
responses:
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
delete:
tags:
- pet
summary: Deletes a pet
description: ''
operationId: deletePet
produces:
- application/xml
- application/json
parameters:
- name: api_key
in: header
required: false
type: string
- name: petId
in: path
description: Pet id to delete
required: true
type: integer
format: int64
responses:
'400':
description: Invalid pet value
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
'/pet/{petId}/uploadImage':
post:
tags:
- pet
summary: uploads an image
description: ''
operationId: uploadFile
consumes:
- multipart/form-data
produces:
- application/json
parameters:
- name: petId
in: path
description: ID of pet to update
required: true
type: integer
format: int64
- name: additionalMetadata
in: formData
description: Additional data to pass to server
required: false
type: string
- name: file
in: formData
description: file to upload
required: false
type: file
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/ApiResponse'
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
/store/inventory:
get:
tags:
- store
summary: Returns pet inventories by status
description: Returns a map of status codes to quantities
operationId: getInventory
produces:
- application/json
parameters: []
responses:
'200':
description: successful operation
schema:
type: object
additionalProperties:
type: integer
format: int32
security:
- api_key: []
/store/order:
post:
tags:
- store
summary: Place an order for a pet
description: ''
operationId: placeOrder
produces:
- application/xml
- application/json
parameters:
- in: body
name: body
description: order placed for purchasing the pet
required: true
schema:
$ref: '#/definitions/Order'
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/Order'
'400':
description: Invalid Order
'/store/order/{orderId}':
get:
tags:
- store
summary: Find purchase order by ID
description: 'For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions'
operationId: getOrderById
produces:
- application/xml
- application/json
parameters:
- name: orderId
in: path
description: ID of pet that needs to be fetched
required: true
type: integer
maximum: 5
minimum: 1
format: int64
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/Order'
'400':
description: Invalid ID supplied
'404':
description: Order not found
delete:
tags:
- store
summary: Delete purchase order by ID
description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
operationId: deleteOrder
produces:
- application/xml
- application/json
parameters:
- name: orderId
in: path
description: ID of the order that needs to be deleted
required: true
type: string
responses:
'400':
description: Invalid ID supplied
'404':
description: Order not found
/user:
post:
tags:
- user
summary: Create user
description: This can only be done by the logged in user.
operationId: createUser
produces:
- application/xml
- application/json
parameters:
- in: body
name: body
description: Created user object
required: true
schema:
$ref: '#/definitions/User'
responses:
default:
description: successful operation
/user/createWithArray:
post:
tags:
- user
summary: Creates list of users with given input array
description: ''
operationId: createUsersWithArrayInput
produces:
- application/xml
- application/json
parameters:
- in: body
name: body
description: List of user object
required: true
schema:
type: array
items:
$ref: '#/definitions/User'
responses:
default:
description: successful operation
/user/createWithList:
post:
tags:
- user
summary: Creates list of users with given input array
description: ''
operationId: createUsersWithListInput
produces:
- application/xml
- application/json
parameters:
- in: body
name: body
description: List of user object
required: true
schema:
type: array
items:
$ref: '#/definitions/User'
responses:
default:
description: successful operation
/user/login:
get:
tags:
- user
summary: Logs user into the system
description: ''
operationId: loginUser
produces:
- application/xml
- application/json
parameters:
- name: username
in: query
description: The user name for login
required: true
type: string
- name: password
in: query
description: The password for login in clear text
required: true
type: string
responses:
'200':
description: successful operation
schema:
type: string
headers:
X-Rate-Limit:
type: integer
format: int32
description: calls per hour allowed by the user
X-Expires-After:
type: string
format: date-time
description: date in UTC when token expires
'400':
description: Invalid username/password supplied
/user/logout:
get:
tags:
- user
summary: Logs out current logged in user session
description: ''
operationId: logoutUser
produces:
- application/xml
- application/json
parameters: []
responses:
default:
description: successful operation
'/user/{username}':
get:
tags:
- user
summary: Get user by user name
description: ''
operationId: getUserByName
produces:
- application/xml
- application/json
parameters:
- name: username
in: path
description: 'The name that needs to be fetched. Use user1 for testing.'
required: true
type: string
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/User'
'400':
description: Invalid username supplied
'404':
description: User not found
put:
tags:
- user
summary: Updated user
description: This can only be done by the logged in user.
operationId: updateUser
produces:
- application/xml
- application/json
parameters:
- name: username
in: path
description: name that need to be deleted
required: true
type: string
- in: body
name: body
description: Updated user object
required: true
schema:
$ref: '#/definitions/User'
responses:
'400':
description: Invalid user supplied
'404':
description: User not found
delete:
tags:
- user
summary: Delete user
description: This can only be done by the logged in user.
operationId: deleteUser
produces:
- application/xml
- application/json
parameters:
- name: username
in: path
description: The name that needs to be deleted
required: true
type: string
responses:
'400':
description: Invalid username supplied
'404':
description: User not found
securityDefinitions:
petstore_auth:
type: oauth2
authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog'
flow: implicit
scopes:
'write:pets': modify pets in your account
'read:pets': read your pets
api_key:
type: apiKey
name: api_key
in: header
definitions:
Order:
title: Pet Order
description: An order for a pets from the pet store
type: object
properties:
id:
type: integer
format: int64
petId:
type: integer
format: int64
quantity:
type: integer
format: int32
shipDate:
type: string
format: date-time
status:
type: string
description: Order Status
enum:
- placed
- approved
- delivered
complete:
type: boolean
default: false
xml:
name: Order
Category:
title: Pet category
description: A category for a pet
type: object
properties:
id:
type: integer
format: int64
name:
type: string
xml:
name: Category
User:
title: a User
description: A User who is purchasing from the pet store
type: object
properties:
id:
type: integer
format: int64
username:
type: string
firstName:
type: string
lastName:
type: string
email:
type: string
password:
type: string
phone:
type: string
userStatus:
type: integer
format: int32
description: User Status
xml:
name: User
Tag:
title: Pet Tag
description: A tag for a pet
type: object
properties:
id:
type: integer
format: int64
name:
type: string
xml:
name: Tag
Pet:
title: a Pet
description: A pet for sale in the pet store
type: object
required:
- name
- photoUrls
properties:
id:
type: integer
format: int64
category:
$ref: '#/definitions/Category'
name:
type: string
example: doggie
photoUrls:
type: array
xml:
name: photoUrl
wrapped: true
items:
type: string
tags:
type: array
xml:
name: tag
wrapped: true
items:
$ref: '#/definitions/Tag'
status:
type: string
description: pet status in the store
enum:
- available
- pending
- sold
xml:
name: Pet
ApiResponse:
title: An uploaded response
description: Describes the result of uploading an image resource
type: object
properties:
code:
type: integer
format: int32
type:
type: string
message:
type: string
EnumModel:
enum:
- available>
- pending<
- sold
- 1
- 2
type: string

View File

@ -0,0 +1,802 @@
openapi: 3.0.0
servers:
- url: 'http://petstore.swagger.io/v2'
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.
version: 1.0.0
title: OpenAPI Petstore
license:
name: Apache-2.0
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: pet
description: Everything about your Pets
- name: store
description: Access to Petstore orders
- name: user
description: Operations about user
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: ''
operationId: addPet
responses:
'200':
description: successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
$ref: '#/components/requestBodies/Pet'
put:
tags:
- pet
summary: Update an existing pet
description: ''
operationId: updatePet
externalDocs:
url: "http://petstore.swagger.io/v2/doc/updatePet"
description: "API documentation for the updatePet operation"
responses:
'200':
description: successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
$ref: '#/components/requestBodies/Pet'
/pet/findByStatus:
get:
tags:
- pet
summary: Finds Pets by status
description: Multiple status values can be provided with comma separated strings
operationId: findPetsByStatus
parameters:
- name: status
in: query
description: Status values that need to be considered for filter
required: true
style: form
explode: false
deprecated: true
schema:
type: array
items:
type: string
enum:
- available
- pending
- sold
default: available
responses:
'200':
description: successful operation
content:
application/xml:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid status value
security:
- petstore_auth:
- 'read:pets'
/pet/findByTags:
get:
tags:
- pet
summary: Finds Pets by tags
description: >-
Multiple tags can be provided with comma separated strings. Use tag1,
tag2, tag3 for testing.
operationId: findPetsByTags
parameters:
- name: tags
in: query
description: Tags to filter by
required: true
style: form
explode: false
schema:
type: array
items:
type: string
responses:
'200':
description: successful operation
content:
application/xml:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid tag value
security:
- petstore_auth:
- 'read:pets'
deprecated: true
'/pet/{petId}':
get:
tags:
- pet
summary: Find pet by ID
description: Returns a single pet
operationId: getPetById
parameters:
- name: petId
in: path
description: ID of pet to return
required: true
schema:
type: integer
format: int64
responses:
'200':
description: successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
security:
- api_key: []
post:
tags:
- pet
summary: Updates a pet in the store with form data
description: ''
operationId: updatePetWithForm
parameters:
- name: petId
in: path
description: ID of pet that needs to be updated
required: true
schema:
type: integer
format: int64
responses:
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
name:
description: Updated name of the pet
type: string
status:
description: Updated status of the pet
type: string
delete:
tags:
- pet
summary: Deletes a pet
description: ''
operationId: deletePet
parameters:
- name: api_key
in: header
required: false
schema:
type: string
- name: petId
in: path
description: Pet id to delete
required: true
schema:
type: integer
format: int64
responses:
'400':
description: Invalid pet value
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
'/pet/{petId}/uploadImage':
post:
tags:
- pet
summary: uploads an image
description: ''
operationId: uploadFile
parameters:
- name: petId
in: path
description: ID of pet to update
required: true
schema:
type: integer
format: int64
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
additionalMetadata:
description: Additional data to pass to server
type: string
file:
description: file to upload
type: string
format: binary
/store/inventory:
get:
tags:
- store
summary: Returns pet inventories by status
description: Returns a map of status codes to quantities
operationId: getInventory
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: object
additionalProperties:
type: integer
format: int32
security:
- api_key: []
/store/order:
post:
tags:
- store
summary: Place an order for a pet
description: ''
operationId: placeOrder
responses:
'200':
description: successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Order'
application/json:
schema:
$ref: '#/components/schemas/Order'
'400':
description: Invalid Order
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Order'
description: order placed for purchasing the pet
required: true
'/store/order/{orderId}':
get:
tags:
- store
summary: Find purchase order by ID
description: >-
For valid response try integer IDs with value <= 5 or > 10. Other values
will generate exceptions
operationId: getOrderById
parameters:
- name: orderId
in: path
description: ID of pet that needs to be fetched
required: true
schema:
type: integer
format: int64
minimum: 1
maximum: 5
responses:
'200':
description: successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Order'
application/json:
schema:
$ref: '#/components/schemas/Order'
'400':
description: Invalid ID supplied
'404':
description: Order not found
delete:
tags:
- store
summary: Delete purchase order by ID
description: >-
For valid response try integer IDs with value < 1000. Anything above
1000 or nonintegers will generate API errors
operationId: deleteOrder
parameters:
- name: orderId
in: path
description: ID of the order that needs to be deleted
required: true
schema:
type: string
responses:
'400':
description: Invalid ID supplied
'404':
description: Order not found
/user:
post:
tags:
- user
summary: Create user
description: This can only be done by the logged in user.
operationId: createUser
responses:
default:
description: successful operation
security:
- api_key: []
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/User'
description: Created user object
required: true
/user/createWithArray:
post:
tags:
- user
summary: Creates list of users with given input array
description: ''
operationId: createUsersWithArrayInput
responses:
default:
description: successful operation
security:
- api_key: []
requestBody:
$ref: '#/components/requestBodies/UserArray'
/user/createWithList:
post:
tags:
- user
summary: Creates list of users with given input array
description: ''
operationId: createUsersWithListInput
responses:
default:
description: successful operation
security:
- api_key: []
requestBody:
$ref: '#/components/requestBodies/UserArray'
/user/login:
get:
tags:
- user
summary: Logs user into the system
description: ''
operationId: loginUser
parameters:
- name: username
in: query
description: The user name for login
required: true
schema:
type: string
pattern: '^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$'
- name: password
in: query
description: The password for login in clear text
required: true
schema:
type: string
responses:
'200':
description: successful operation
headers:
Set-Cookie:
description: >-
Cookie authentication key for use with the `api_key`
apiKey authentication.
schema:
type: string
example: AUTH_KEY=abcde12345; Path=/; HttpOnly
X-Rate-Limit:
description: calls per hour allowed by the user
schema:
type: integer
format: int32
X-Expires-After:
description: date in UTC when token expires
schema:
type: string
format: date-time
content:
application/xml:
schema:
type: string
application/json:
schema:
type: string
'400':
description: Invalid username/password supplied
/user/logout:
get:
tags:
- user
summary: Logs out current logged in user session
description: ''
operationId: logoutUser
responses:
default:
description: successful operation
security:
- api_key: []
'/user/{username}':
get:
tags:
- user
summary: Get user by user name
description: ''
operationId: getUserByName
parameters:
- name: username
in: path
description: The name that needs to be fetched. Use user1 for testing.
required: true
schema:
type: string
responses:
'200':
description: successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/User'
application/json:
schema:
$ref: '#/components/schemas/User'
'400':
description: Invalid username supplied
'404':
description: User not found
put:
tags:
- user
summary: Updated user
description: This can only be done by the logged in user.
operationId: updateUser
parameters:
- name: username
in: path
description: name that need to be deleted
required: true
schema:
type: string
responses:
'400':
description: Invalid user supplied
'404':
description: User not found
security:
- api_key: []
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/User'
description: Updated user object
required: true
delete:
tags:
- user
summary: Delete user
description: This can only be done by the logged in user.
operationId: deleteUser
parameters:
- name: username
in: path
description: The name that needs to be deleted
required: true
schema:
type: string
responses:
'400':
description: Invalid username supplied
'404':
description: User not found
security:
- api_key: []
/fake/query_param_default:
get:
tags:
- fake
summary: test query parameter default value
description: ''
operationId: fake_query_param_default
parameters:
- name: hasDefault
in: query
description: has default value
schema:
type: string
default: Hello World
- name: noDefault
in: query
description: no default value
schema:
type: string
responses:
'400':
description: Invalid username supplied
'404':
description: User not found
externalDocs:
description: Find out more about Swagger
url: 'http://swagger.io'
components:
requestBodies:
UserArray:
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
description: List of user object
required: true
Pet:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
description: Pet object that needs to be added to the store
required: true
securitySchemes:
petstore_auth:
type: oauth2
flows:
implicit:
authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog'
scopes:
'write:pets': modify pets in your account
'read:pets': read your pets
api_key:
type: apiKey
name: api_key
in: header
schemas:
Order:
title: Pet Order
description: An order for a pets from the pet store
type: object
properties:
id:
type: integer
format: int64
petId:
type: integer
format: int64
quantity:
type: integer
format: int32
shipDate:
type: string
format: date-time
status:
type: string
description: Order Status
enum:
- placed
- approved
- delivered
complete:
type: boolean
default: false
xml:
name: Order
Category:
title: Pet category
description: A category for a pet
type: object
properties:
id:
type: integer
format: int64
name:
type: string
pattern: '^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$'
xml:
name: Category
User:
title: a User
description: A User who is purchasing from the pet store
type: object
properties:
id:
type: integer
format: int64
username:
type: string
firstName:
type: string
lastName:
type: string
email:
type: string
password:
type: string
phone:
type: string
userStatus:
type: integer
format: int32
description: User Status
xml:
name: User
Tag:
title: Pet Tag
description: A tag for a pet
type: object
properties:
id:
type: integer
format: int64
name:
type: string
xml:
name: Tag
Pet:
title: a Pet
description: A pet for sale in the pet store
type: object
required:
- name
- photoUrls
properties:
id:
type: integer
format: int64
category:
$ref: '#/components/schemas/Category'
name:
type: string
example: doggie
photoUrls:
type: array
xml:
name: photoUrl
wrapped: true
items:
type: string
tags:
type: array
xml:
name: tag
wrapped: true
items:
$ref: '#/components/schemas/Tag'
status:
type: string
description: pet status in the store
deprecated: true
enum:
- available
- pending
- sold
xml:
name: Pet
ApiResponse:
title: An uploaded response
description: Describes the result of uploading an image resource
type: object
properties:
code:
type: integer
format: int32
type:
type: string
message:
type: string
TestEnum:
type: string
enum:
- ONE
- TWO
- THREE
- foUr
TestEnumWithDefault:
type: string
enum:
- EIN
- ZWEI
- DREI
default: ZWEI
TestModel:
type: object
required:
- test_enum
properties:
test_enum:
$ref: "#/components/schemas/TestEnum"
test_string:
type: string
example: "Just some string"
test_enum_with_default:
$ref: "#/components/schemas/TestEnumWithDefault"
test_string_with_default:
type: string
example: "More string"
default: "ahoy matey"
test_inline_defined_enum_with_default:
type: string
enum:
- A
- B
- C
default: B

View File

@ -14,8 +14,8 @@ Name | Type | Description | Notes
**enum_string_vendor_ext** | **str** | | [optional]
**outer_enum** | [**OuterEnum**](OuterEnum.md) | | [optional]
**outer_enum_integer** | [**OuterEnumInteger**](OuterEnumInteger.md) | | [optional]
**outer_enum_default_value** | [**OuterEnumDefaultValue**](OuterEnumDefaultValue.md) | | [optional]
**outer_enum_integer_default_value** | [**OuterEnumIntegerDefaultValue**](OuterEnumIntegerDefaultValue.md) | | [optional]
**outer_enum_default_value** | [**OuterEnumDefaultValue**](OuterEnumDefaultValue.md) | | [optional] [default to OuterEnumDefaultValue.PLACED]
**outer_enum_integer_default_value** | [**OuterEnumIntegerDefaultValue**](OuterEnumIntegerDefaultValue.md) | | [optional] [default to OuterEnumIntegerDefaultValue.NUMBER_0]
## Example

View File

@ -130,7 +130,7 @@ configuration = petstore_api.Configuration(
async with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
enum_ref = petstore_api.EnumClass() # EnumClass | enum reference (optional)
enum_ref = -efg # EnumClass | enum reference (optional) (default to -efg)
try:
# test enum reference query parameter
@ -146,7 +146,7 @@ async with petstore_api.ApiClient(configuration) as api_client:
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**enum_ref** | [**EnumClass**](.md)| enum reference | [optional]
**enum_ref** | [**EnumClass**](.md)| enum reference | [optional] [default to -efg]
### Return type

View File

@ -39,8 +39,8 @@ class EnumTest(BaseModel):
enum_string_vendor_ext: Optional[StrictStr] = None
outer_enum: Optional[OuterEnum] = Field(default=None, alias="outerEnum")
outer_enum_integer: Optional[OuterEnumInteger] = Field(default=None, alias="outerEnumInteger")
outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(default=None, alias="outerEnumDefaultValue")
outer_enum_integer_default_value: Optional[OuterEnumIntegerDefaultValue] = Field(default=None, alias="outerEnumIntegerDefaultValue")
outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(default=OuterEnumDefaultValue.PLACED, alias="outerEnumDefaultValue")
outer_enum_integer_default_value: Optional[OuterEnumIntegerDefaultValue] = Field(default=OuterEnumIntegerDefaultValue.NUMBER_0, alias="outerEnumIntegerDefaultValue")
__properties: ClassVar[List[str]] = ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "enum_number_vendor_ext", "enum_string_vendor_ext", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"]
@field_validator('enum_string')
@ -175,8 +175,8 @@ class EnumTest(BaseModel):
"enum_string_vendor_ext": obj.get("enum_string_vendor_ext"),
"outerEnum": obj.get("outerEnum"),
"outerEnumInteger": obj.get("outerEnumInteger"),
"outerEnumDefaultValue": obj.get("outerEnumDefaultValue"),
"outerEnumIntegerDefaultValue": obj.get("outerEnumIntegerDefaultValue")
"outerEnumDefaultValue": obj.get("outerEnumDefaultValue") if obj.get("outerEnumDefaultValue") is not None else OuterEnumDefaultValue.PLACED,
"outerEnumIntegerDefaultValue": obj.get("outerEnumIntegerDefaultValue") if obj.get("outerEnumIntegerDefaultValue") is not None else OuterEnumIntegerDefaultValue.NUMBER_0
})
return _obj

View File

@ -14,8 +14,8 @@ Name | Type | Description | Notes
**enum_string_vendor_ext** | **str** | | [optional]
**outer_enum** | [**OuterEnum**](OuterEnum.md) | | [optional]
**outer_enum_integer** | [**OuterEnumInteger**](OuterEnumInteger.md) | | [optional]
**outer_enum_default_value** | [**OuterEnumDefaultValue**](OuterEnumDefaultValue.md) | | [optional]
**outer_enum_integer_default_value** | [**OuterEnumIntegerDefaultValue**](OuterEnumIntegerDefaultValue.md) | | [optional]
**outer_enum_default_value** | [**OuterEnumDefaultValue**](OuterEnumDefaultValue.md) | | [optional] [default to OuterEnumDefaultValue.PLACED]
**outer_enum_integer_default_value** | [**OuterEnumIntegerDefaultValue**](OuterEnumIntegerDefaultValue.md) | | [optional] [default to OuterEnumIntegerDefaultValue.NUMBER_0]
## Example

View File

@ -130,7 +130,7 @@ configuration = petstore_api.Configuration(
with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
enum_ref = petstore_api.EnumClass() # EnumClass | enum reference (optional)
enum_ref = -efg # EnumClass | enum reference (optional) (default to -efg)
try:
# test enum reference query parameter
@ -146,7 +146,7 @@ with petstore_api.ApiClient(configuration) as api_client:
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**enum_ref** | [**EnumClass**](.md)| enum reference | [optional]
**enum_ref** | [**EnumClass**](.md)| enum reference | [optional] [default to -efg]
### Return type

View File

@ -39,8 +39,8 @@ class EnumTest(BaseModel):
enum_string_vendor_ext: Optional[StrictStr] = None
outer_enum: Optional[OuterEnum] = Field(default=None, alias="outerEnum")
outer_enum_integer: Optional[OuterEnumInteger] = Field(default=None, alias="outerEnumInteger")
outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(default=None, alias="outerEnumDefaultValue")
outer_enum_integer_default_value: Optional[OuterEnumIntegerDefaultValue] = Field(default=None, alias="outerEnumIntegerDefaultValue")
outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(default=OuterEnumDefaultValue.PLACED, alias="outerEnumDefaultValue")
outer_enum_integer_default_value: Optional[OuterEnumIntegerDefaultValue] = Field(default=OuterEnumIntegerDefaultValue.NUMBER_0, alias="outerEnumIntegerDefaultValue")
additional_properties: Dict[str, Any] = {}
__properties: ClassVar[List[str]] = ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "enum_number_vendor_ext", "enum_string_vendor_ext", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"]
@ -183,8 +183,8 @@ class EnumTest(BaseModel):
"enum_string_vendor_ext": obj.get("enum_string_vendor_ext"),
"outerEnum": obj.get("outerEnum"),
"outerEnumInteger": obj.get("outerEnumInteger"),
"outerEnumDefaultValue": obj.get("outerEnumDefaultValue"),
"outerEnumIntegerDefaultValue": obj.get("outerEnumIntegerDefaultValue")
"outerEnumDefaultValue": obj.get("outerEnumDefaultValue") if obj.get("outerEnumDefaultValue") is not None else OuterEnumDefaultValue.PLACED,
"outerEnumIntegerDefaultValue": obj.get("outerEnumIntegerDefaultValue") if obj.get("outerEnumIntegerDefaultValue") is not None else OuterEnumIntegerDefaultValue.NUMBER_0
})
# store additional fields in additional_properties
for _key in obj.keys():

View File

@ -7,6 +7,7 @@ git_push.sh
openapi_server/__init__.py
openapi_server/__main__.py
openapi_server/controllers/__init__.py
openapi_server/controllers/fake_controller.py
openapi_server/controllers/pet_controller.py
openapi_server/controllers/security_controller.py
openapi_server/controllers/store_controller.py
@ -16,10 +17,12 @@ 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/enum_model.py
openapi_server/models/order.py
openapi_server/models/pet.py
openapi_server/models/tag.py
openapi_server/models/test_enum.py
openapi_server/models/test_enum_with_default.py
openapi_server/models/test_model.py
openapi_server/models/user.py
openapi_server/openapi/openapi.yaml
openapi_server/test/__init__.py

View File

@ -0,0 +1,21 @@
import connexion
from typing import Dict
from typing import Tuple
from typing import Union
from openapi_server import util
def fake_query_param_default(has_default=None, no_default=None): # noqa: E501
"""test query parameter default value
# noqa: E501
:param has_default: has default value
:type has_default: str
:param no_default: no default value
:type no_default: str
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
return 'do some magic!'

View File

@ -8,18 +8,18 @@ from openapi_server.models.pet import Pet # noqa: E501
from openapi_server import util
def add_pet(body): # noqa: E501
def add_pet(pet): # noqa: E501
"""Add a new pet to the store
# noqa: E501
:param body: Pet object that needs to be added to the store
:type body: dict | bytes
:param pet: Pet object that needs to be added to the store
:type pet: dict | bytes
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
:rtype: Union[Pet, Tuple[Pet, int], Tuple[Pet, int, Dict[str, str]]
"""
if connexion.request.is_json:
body = Pet.from_dict(connexion.request.get_json()) # noqa: E501
pet = Pet.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
@ -77,18 +77,18 @@ def get_pet_by_id(pet_id): # noqa: E501
return 'do some magic!'
def update_pet(body): # noqa: E501
def update_pet(pet): # noqa: E501
"""Update an existing pet
# noqa: E501
:param body: Pet object that needs to be added to the store
:type body: dict | bytes
:param pet: Pet object that needs to be added to the store
:type pet: dict | bytes
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
:rtype: Union[Pet, Tuple[Pet, int], Tuple[Pet, int, Dict[str, str]]
"""
if connexion.request.is_json:
body = Pet.from_dict(connexion.request.get_json()) # noqa: E501
pet = Pet.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'

View File

@ -44,16 +44,16 @@ def get_order_by_id(order_id): # noqa: E501
return 'do some magic!'
def place_order(body): # noqa: E501
def place_order(order): # noqa: E501
"""Place an order for a pet
# noqa: E501
:param body: order placed for purchasing the pet
:type body: dict | bytes
:param order: order placed for purchasing the pet
:type order: dict | bytes
:rtype: Union[Order, Tuple[Order, int], Tuple[Order, int, Dict[str, str]]
"""
if connexion.request.is_json:
body = Order.from_dict(connexion.request.get_json()) # noqa: E501
order = Order.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'

View File

@ -7,48 +7,48 @@ from openapi_server.models.user import User # noqa: E501
from openapi_server import util
def create_user(body): # noqa: E501
def create_user(user): # noqa: E501
"""Create user
This can only be done by the logged in user. # noqa: E501
:param body: Created user object
:type body: dict | bytes
:param user: Created user object
:type user: dict | bytes
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
if connexion.request.is_json:
body = User.from_dict(connexion.request.get_json()) # noqa: E501
user = User.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
def create_users_with_array_input(body): # noqa: E501
def create_users_with_array_input(user): # noqa: E501
"""Creates list of users with given input array
# noqa: E501
:param body: List of user object
:type body: list | bytes
:param user: List of user object
:type user: list | bytes
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
if connexion.request.is_json:
body = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501
user = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501
return 'do some magic!'
def create_users_with_list_input(body): # noqa: E501
def create_users_with_list_input(user): # noqa: E501
"""Creates list of users with given input array
# noqa: E501
:param body: List of user object
:type body: list | bytes
:param user: List of user object
:type user: list | bytes
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
if connexion.request.is_json:
body = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501
user = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501
return 'do some magic!'
@ -104,18 +104,18 @@ def logout_user(): # noqa: E501
return 'do some magic!'
def update_user(username, body): # noqa: E501
def update_user(username, user): # noqa: E501
"""Updated user
This can only be done by the logged in user. # noqa: E501
:param username: name that need to be deleted
:type username: str
:param body: Updated user object
:type body: dict | bytes
:param user: Updated user object
:type user: dict | bytes
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
if connexion.request.is_json:
body = User.from_dict(connexion.request.get_json()) # noqa: E501
user = User.from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'

View File

@ -2,8 +2,10 @@
# import models into model package
from openapi_server.models.api_response import ApiResponse
from openapi_server.models.category import Category
from openapi_server.models.enum_model import EnumModel
from openapi_server.models.order import Order
from openapi_server.models.pet import Pet
from openapi_server.models.tag import Tag
from openapi_server.models.test_enum import TestEnum
from openapi_server.models.test_enum_with_default import TestEnumWithDefault
from openapi_server.models.test_model import TestModel
from openapi_server.models.user import User

View File

@ -3,8 +3,10 @@ from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from openapi_server.models.base_model import Model
import re
from openapi_server import util
import re # noqa: E501
class Category(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
@ -83,5 +85,7 @@ class Category(Model):
:param name: The name of this Category.
:type name: str
"""
if name is not None and not re.search(r'^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$', name): # noqa: E501
raise ValueError("Invalid value for `name`, must be a follow pattern or equal to `/^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$/`") # noqa: E501
self._name = name

View File

@ -0,0 +1,40 @@
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

@ -0,0 +1,41 @@
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 TestEnum(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""
"""
allowed enum values
"""
ONE = 'ONE'
TWO = 'TWO'
THREE = 'THREE'
FOUR = 'foUr'
def __init__(self): # noqa: E501
"""TestEnum - a model defined in OpenAPI
"""
self.openapi_types = {
}
self.attribute_map = {
}
@classmethod
def from_dict(cls, dikt) -> 'TestEnum':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The TestEnum of this TestEnum. # noqa: E501
:rtype: TestEnum
"""
return util.deserialize_model(dikt, cls)

View File

@ -0,0 +1,40 @@
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 TestEnumWithDefault(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""
"""
allowed enum values
"""
EIN = 'EIN'
ZWEI = 'ZWEI'
DREI = 'DREI'
def __init__(self): # noqa: E501
"""TestEnumWithDefault - a model defined in OpenAPI
"""
self.openapi_types = {
}
self.attribute_map = {
}
@classmethod
def from_dict(cls, dikt) -> 'TestEnumWithDefault':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The TestEnumWithDefault of this TestEnumWithDefault. # noqa: E501
:rtype: TestEnumWithDefault
"""
return util.deserialize_model(dikt, cls)

View File

@ -0,0 +1,177 @@
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.test_enum import TestEnum
from openapi_server.models.test_enum_with_default import TestEnumWithDefault
from openapi_server import util
from openapi_server.models.test_enum import TestEnum # noqa: E501
from openapi_server.models.test_enum_with_default import TestEnumWithDefault # noqa: E501
class TestModel(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""
def __init__(self, test_enum=None, test_string=None, test_enum_with_default=TestEnumWithDefault.ZWEI, test_string_with_default='ahoy matey', test_inline_defined_enum_with_default='B'): # noqa: E501
"""TestModel - a model defined in OpenAPI
:param test_enum: The test_enum of this TestModel. # noqa: E501
:type test_enum: TestEnum
:param test_string: The test_string of this TestModel. # noqa: E501
:type test_string: str
:param test_enum_with_default: The test_enum_with_default of this TestModel. # noqa: E501
:type test_enum_with_default: TestEnumWithDefault
:param test_string_with_default: The test_string_with_default of this TestModel. # noqa: E501
:type test_string_with_default: str
:param test_inline_defined_enum_with_default: The test_inline_defined_enum_with_default of this TestModel. # noqa: E501
:type test_inline_defined_enum_with_default: str
"""
self.openapi_types = {
'test_enum': TestEnum,
'test_string': str,
'test_enum_with_default': TestEnumWithDefault,
'test_string_with_default': str,
'test_inline_defined_enum_with_default': str
}
self.attribute_map = {
'test_enum': 'test_enum',
'test_string': 'test_string',
'test_enum_with_default': 'test_enum_with_default',
'test_string_with_default': 'test_string_with_default',
'test_inline_defined_enum_with_default': 'test_inline_defined_enum_with_default'
}
self._test_enum = test_enum
self._test_string = test_string
self._test_enum_with_default = test_enum_with_default
self._test_string_with_default = test_string_with_default
self._test_inline_defined_enum_with_default = test_inline_defined_enum_with_default
@classmethod
def from_dict(cls, dikt) -> 'TestModel':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The TestModel of this TestModel. # noqa: E501
:rtype: TestModel
"""
return util.deserialize_model(dikt, cls)
@property
def test_enum(self) -> TestEnum:
"""Gets the test_enum of this TestModel.
:return: The test_enum of this TestModel.
:rtype: TestEnum
"""
return self._test_enum
@test_enum.setter
def test_enum(self, test_enum: TestEnum):
"""Sets the test_enum of this TestModel.
:param test_enum: The test_enum of this TestModel.
:type test_enum: TestEnum
"""
if test_enum is None:
raise ValueError("Invalid value for `test_enum`, must not be `None`") # noqa: E501
self._test_enum = test_enum
@property
def test_string(self) -> str:
"""Gets the test_string of this TestModel.
:return: The test_string of this TestModel.
:rtype: str
"""
return self._test_string
@test_string.setter
def test_string(self, test_string: str):
"""Sets the test_string of this TestModel.
:param test_string: The test_string of this TestModel.
:type test_string: str
"""
self._test_string = test_string
@property
def test_enum_with_default(self) -> TestEnumWithDefault:
"""Gets the test_enum_with_default of this TestModel.
:return: The test_enum_with_default of this TestModel.
:rtype: TestEnumWithDefault
"""
return self._test_enum_with_default
@test_enum_with_default.setter
def test_enum_with_default(self, test_enum_with_default: TestEnumWithDefault):
"""Sets the test_enum_with_default of this TestModel.
:param test_enum_with_default: The test_enum_with_default of this TestModel.
:type test_enum_with_default: TestEnumWithDefault
"""
self._test_enum_with_default = test_enum_with_default
@property
def test_string_with_default(self) -> str:
"""Gets the test_string_with_default of this TestModel.
:return: The test_string_with_default of this TestModel.
:rtype: str
"""
return self._test_string_with_default
@test_string_with_default.setter
def test_string_with_default(self, test_string_with_default: str):
"""Sets the test_string_with_default of this TestModel.
:param test_string_with_default: The test_string_with_default of this TestModel.
:type test_string_with_default: str
"""
self._test_string_with_default = test_string_with_default
@property
def test_inline_defined_enum_with_default(self) -> str:
"""Gets the test_inline_defined_enum_with_default of this TestModel.
:return: The test_inline_defined_enum_with_default of this TestModel.
:rtype: str
"""
return self._test_inline_defined_enum_with_default
@test_inline_defined_enum_with_default.setter
def test_inline_defined_enum_with_default(self, test_inline_defined_enum_with_default: str):
"""Sets the test_inline_defined_enum_with_default of this TestModel.
:param test_inline_defined_enum_with_default: The test_inline_defined_enum_with_default of this TestModel.
:type test_inline_defined_enum_with_default: str
"""
allowed_values = ["A", "B", "C"] # noqa: E501
if test_inline_defined_enum_with_default not in allowed_values:
raise ValueError(
"Invalid value for `test_inline_defined_enum_with_default` ({0}), must be one of {1}"
.format(test_inline_defined_enum_with_default, allowed_values)
)
self._test_inline_defined_enum_with_default = test_inline_defined_enum_with_default

View File

@ -1,4 +1,4 @@
openapi: 3.0.1
openapi: 3.0.0
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."
@ -7,6 +7,9 @@ info:
url: https://www.apache.org/licenses/LICENSE-2.0.html
title: OpenAPI Petstore
version: 1.0.0
externalDocs:
description: Find out more about Swagger
url: http://swagger.io
servers:
- url: http://petstore.swagger.io/v2
tags:
@ -17,22 +20,54 @@ tags:
- description: Operations about user
name: user
paths:
/fake/query_param_default:
get:
description: ""
operationId: fake_query_param_default
parameters:
- description: has default value
explode: true
in: query
name: hasDefault
required: false
schema:
default: Hello World
type: string
style: form
- description: no default value
explode: true
in: query
name: noDefault
required: false
schema:
type: string
style: form
responses:
"400":
description: Invalid username supplied
"404":
description: User not found
summary: test query parameter default value
tags:
- fake
x-openapi-router-controller: openapi_server.controllers.fake_controller
/pet:
post:
description: ""
operationId: add_pet
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
description: Pet object that needs to be added to the store
required: true
$ref: '#/components/requestBodies/Pet'
responses:
"200":
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
description: successful operation
"405":
content: {}
description: Invalid input
security:
- petstore_auth:
@ -41,29 +76,30 @@ paths:
summary: Add a new pet to the store
tags:
- pet
x-codegen-request-body-name: body
x-openapi-router-controller: openapi_server.controllers.pet_controller
put:
description: ""
externalDocs:
description: API documentation for the updatePet operation
url: http://petstore.swagger.io/v2/doc/updatePet
operationId: update_pet
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
description: Pet object that needs to be added to the store
required: true
$ref: '#/components/requestBodies/Pet'
responses:
"200":
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
description: successful operation
"400":
content: {}
description: Invalid ID supplied
"404":
content: {}
description: Pet not found
"405":
content: {}
description: Validation exception
security:
- petstore_auth:
@ -72,14 +108,14 @@ paths:
summary: Update an existing pet
tags:
- pet
x-codegen-request-body-name: body
x-openapi-router-controller: openapi_server.controllers.pet_controller
/pet/findByStatus:
get:
description: Multiple status values can be provided with comma separated strings
operationId: find_pets_by_status
parameters:
- description: Status values that need to be considered for filter
- deprecated: true
description: Status values that need to be considered for filter
explode: false
in: query
name: status
@ -109,11 +145,9 @@ paths:
type: array
description: successful operation
"400":
content: {}
description: Invalid status value
security:
- petstore_auth:
- write:pets
- read:pets
summary: Finds Pets by status
tags:
@ -151,11 +185,9 @@ paths:
type: array
description: successful operation
"400":
content: {}
description: Invalid tag value
security:
- petstore_auth:
- write:pets
- read:pets
summary: Finds Pets by tags
tags:
@ -163,22 +195,27 @@ paths:
x-openapi-router-controller: openapi_server.controllers.pet_controller
/pet/{petId}:
delete:
description: ""
operationId: delete_pet
parameters:
- in: header
- explode: false
in: header
name: api_key
required: false
schema:
type: string
style: simple
- description: Pet id to delete
explode: false
in: path
name: petId
required: true
schema:
format: int64
type: integer
style: simple
responses:
"400":
content: {}
description: Invalid pet value
security:
- petstore_auth:
@ -193,12 +230,14 @@ paths:
operationId: get_pet_by_id
parameters:
- description: ID of pet to return
explode: false
in: path
name: petId
required: true
schema:
format: int64
type: integer
style: simple
responses:
"200":
content:
@ -210,10 +249,8 @@ paths:
$ref: '#/components/schemas/Pet'
description: successful operation
"400":
content: {}
description: Invalid ID supplied
"404":
content: {}
description: Pet not found
security:
- api_key: []
@ -222,15 +259,18 @@ 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
explode: false
in: path
name: petId
required: true
schema:
format: int64
type: integer
style: simple
requestBody:
content:
application/x-www-form-urlencoded:
@ -238,7 +278,6 @@ paths:
$ref: '#/components/schemas/updatePetWithForm_request'
responses:
"405":
content: {}
description: Invalid input
security:
- petstore_auth:
@ -250,15 +289,18 @@ 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
explode: false
in: path
name: petId
required: true
schema:
format: int64
type: integer
style: simple
requestBody:
content:
multipart/form-data:
@ -301,10 +343,11 @@ paths:
x-openapi-router-controller: openapi_server.controllers.store_controller
/store/order:
post:
description: ""
operationId: place_order
requestBody:
content:
'*/*':
application/json:
schema:
$ref: '#/components/schemas/Order'
description: order placed for purchasing the pet
@ -320,12 +363,10 @@ paths:
$ref: '#/components/schemas/Order'
description: successful operation
"400":
content: {}
description: Invalid Order
summary: Place an order for a pet
tags:
- store
x-codegen-request-body-name: body
x-openapi-router-controller: openapi_server.controllers.store_controller
/store/order/{orderId}:
delete:
@ -334,17 +375,17 @@ paths:
operationId: delete_order
parameters:
- description: ID of the order that needs to be deleted
explode: false
in: path
name: orderId
required: true
schema:
type: string
style: simple
responses:
"400":
content: {}
description: Invalid ID supplied
"404":
content: {}
description: Order not found
summary: Delete purchase order by ID
tags:
@ -356,6 +397,7 @@ paths:
operationId: get_order_by_id
parameters:
- description: ID of pet that needs to be fetched
explode: false
in: path
name: orderId
required: true
@ -364,6 +406,7 @@ paths:
maximum: 5
minimum: 1
type: integer
style: simple
responses:
"200":
content:
@ -375,10 +418,8 @@ paths:
$ref: '#/components/schemas/Order'
description: successful operation
"400":
content: {}
description: Invalid ID supplied
"404":
content: {}
description: Order not found
summary: Find purchase order by ID
tags:
@ -390,78 +431,72 @@ paths:
operationId: create_user
requestBody:
content:
'*/*':
application/json:
schema:
$ref: '#/components/schemas/User'
description: Created user object
required: true
responses:
default:
content: {}
description: successful operation
security:
- api_key: []
summary: Create user
tags:
- user
x-codegen-request-body-name: body
x-openapi-router-controller: openapi_server.controllers.user_controller
/user/createWithArray:
post:
description: ""
operationId: create_users_with_array_input
requestBody:
content:
'*/*':
schema:
items:
$ref: '#/components/schemas/User'
type: array
description: List of user object
required: true
$ref: '#/components/requestBodies/UserArray'
responses:
default:
content: {}
description: successful operation
security:
- api_key: []
summary: Creates list of users with given input array
tags:
- user
x-codegen-request-body-name: body
x-openapi-router-controller: openapi_server.controllers.user_controller
/user/createWithList:
post:
description: ""
operationId: create_users_with_list_input
requestBody:
content:
'*/*':
schema:
items:
$ref: '#/components/schemas/User'
type: array
description: List of user object
required: true
$ref: '#/components/requestBodies/UserArray'
responses:
default:
content: {}
description: successful operation
security:
- api_key: []
summary: Creates list of users with given input array
tags:
- user
x-codegen-request-body-name: body
x-openapi-router-controller: openapi_server.controllers.user_controller
/user/login:
get:
description: ""
operationId: login_user
parameters:
- description: The user name for login
explode: true
in: query
name: username
required: true
schema:
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
explode: true
in: query
name: password
required: true
schema:
type: string
style: form
responses:
"200":
content:
@ -473,18 +508,29 @@ paths:
type: string
description: successful operation
headers:
Set-Cookie:
description: Cookie authentication key for use with the `api_key` apiKey
authentication.
explode: false
schema:
example: AUTH_KEY=abcde12345; Path=/; HttpOnly
type: string
style: simple
X-Rate-Limit:
description: calls per hour allowed by the user
explode: false
schema:
format: int32
type: integer
style: simple
X-Expires-After:
description: date in UTC when token expires
explode: false
schema:
format: date-time
type: string
style: simple
"400":
content: {}
description: Invalid username/password supplied
summary: Logs user into the system
tags:
@ -492,11 +538,13 @@ paths:
x-openapi-router-controller: openapi_server.controllers.user_controller
/user/logout:
get:
description: ""
operationId: logout_user
responses:
default:
content: {}
description: successful operation
security:
- api_key: []
summary: Logs out current logged in user session
tags:
- user
@ -507,31 +555,36 @@ paths:
operationId: delete_user
parameters:
- description: The name that needs to be deleted
explode: false
in: path
name: username
required: true
schema:
type: string
style: simple
responses:
"400":
content: {}
description: Invalid username supplied
"404":
content: {}
description: User not found
security:
- api_key: []
summary: Delete user
tags:
- 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.
explode: false
in: path
name: username
required: true
schema:
type: string
style: simple
responses:
"200":
content:
@ -543,10 +596,8 @@ paths:
$ref: '#/components/schemas/User'
description: successful operation
"400":
content: {}
description: Invalid username supplied
"404":
content: {}
description: User not found
summary: Get user by user name
tags:
@ -557,31 +608,52 @@ paths:
operationId: update_user
parameters:
- description: name that need to be deleted
explode: false
in: path
name: username
required: true
schema:
type: string
style: simple
requestBody:
content:
'*/*':
application/json:
schema:
$ref: '#/components/schemas/User'
description: Updated user object
required: true
responses:
"400":
content: {}
description: Invalid user supplied
"404":
content: {}
description: User not found
security:
- api_key: []
summary: Updated user
tags:
- user
x-codegen-request-body-name: body
x-openapi-router-controller: openapi_server.controllers.user_controller
components:
requestBodies:
UserArray:
content:
application/json:
schema:
items:
$ref: '#/components/schemas/User'
type: array
description: List of user object
required: true
Pet:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
description: Pet object that needs to be added to the store
required: true
schemas:
Order:
description: An order for a pets from the pet store
@ -636,6 +708,7 @@ components:
title: id
type: integer
name:
pattern: "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$"
title: name
type: string
title: Pet category
@ -747,6 +820,7 @@ components:
name: tag
wrapped: true
status:
deprecated: true
description: pet status in the store
enum:
- available
@ -780,14 +854,45 @@ components:
type: string
title: An uploaded response
type: object
EnumModel:
TestEnum:
enum:
- available>
- pending<
- sold
- "1"
- "2"
- ONE
- TWO
- THREE
- foUr
title: TestEnum
type: string
TestEnumWithDefault:
default: ZWEI
enum:
- EIN
- ZWEI
- DREI
title: TestEnumWithDefault
type: string
TestModel:
properties:
test_enum:
$ref: '#/components/schemas/TestEnum'
test_string:
example: Just some string
type: string
test_enum_with_default:
$ref: '#/components/schemas/TestEnumWithDefault'
test_string_with_default:
default: ahoy matey
example: More string
type: string
test_inline_defined_enum_with_default:
default: B
enum:
- A
- B
- C
type: string
required:
- test_enum
type: object
updatePetWithForm_request:
properties:
name:
@ -823,4 +928,3 @@ components:
name: api_key
type: apiKey
x-apikeyInfoFunc: openapi_server.controllers.security_controller.info_from_api_key
x-original-swagger-version: "2.0"

View File

@ -0,0 +1,30 @@
import unittest
from flask import json
from openapi_server.test import BaseTestCase
class TestFakeController(BaseTestCase):
"""FakeController integration test stubs"""
def test_fake_query_param_default(self):
"""Test case for fake_query_param_default
test query parameter default value
"""
query_string = [('hasDefault', 'Hello World'),
('noDefault', 'no_default_example')]
headers = {
}
response = self.client.open(
'/v2/fake/query_param_default',
method='GET',
headers=headers,
query_string=query_string)
self.assert200(response,
'Response body is : ' + response.data.decode('utf-8'))
if __name__ == '__main__':
unittest.main()