re-generate flaskConnexion sample server with latest changes

This commit is contained in:
hjacobs 2016-01-22 22:35:37 +01:00
parent 103321d872
commit 4e9d1e8c79
3 changed files with 147 additions and 143 deletions

View File

@ -2,26 +2,27 @@
## Overview ## Overview
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
[swagger-spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This [OpenAPI-Spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This
is an example of building a swagger-enabled flask server. is an example of building a swagger-enabled Flask server.
This example uses the [connexion](https://github.com/zalando/connexion) library on top of Flask. This example uses the [Connexion](https://github.com/zalando/connexion) library on top of Flask.
To run the server, please execute the following: To run the server, please execute the following:
``` ```
sudo pip3 install -U connexion # install Connexion from PyPI
python3 app.py python3 app.py
``` ```
and open your browser to here: and open your browser to here:
``` ```
http://localhost:8080/ui http://localhost:8080/v2/ui/
``` ```
Your swagger definition lives here: Your Swagger definition lives here:
``` ```
http://localhost:8080/swagger.json http://localhost:8080/v2/swagger.json
``` ```

View File

@ -3,7 +3,6 @@
import connexion import connexion
if __name__ == '__main__': if __name__ == '__main__':
app = connexion.App(__name__, 8080, app = connexion.App(__name__, specification_dir='./swagger/')
specification_dir='./swagger/') app.add_api('swagger.yaml', arguments={'title': 'This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.'})
app.add_api('swagger.yaml', arguments={'title': 'This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters'}) app.run(port=8080)
app.run()

View File

@ -2,9 +2,9 @@
swagger: "2.0" swagger: "2.0"
info: info:
description: "This is a sample server Petstore server. You can find out more about\ description: "This is a sample server Petstore server. You can find out more about\
\ Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net,\ \ Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).\
\ #swagger. For this sample, you can use the api key \"special-key\" to test\ \ For this sample, you can use the api key `special-key` to test the authorization\
\ the authorization filters" \ filters."
version: "1.0.0" version: "1.0.0"
title: "Swagger Petstore" title: "Swagger Petstore"
termsOfService: "http://swagger.io/terms/" termsOfService: "http://swagger.io/terms/"
@ -15,6 +15,19 @@ info:
url: "http://www.apache.org/licenses/LICENSE-2.0.html" url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "petstore.swagger.io" host: "petstore.swagger.io"
basePath: "/v2" basePath: "/v2"
tags:
- name: "pet"
description: "Everything about your Pets"
externalDocs:
description: "Find out more"
url: "http://swagger.io"
- name: "store"
description: "Access to Petstore orders"
- name: "user"
description: "Operations about user"
externalDocs:
description: "Find out more about our store"
url: "http://swagger.io"
schemes: schemes:
- "http" - "http"
paths: paths:
@ -29,22 +42,18 @@ paths:
- "application/json" - "application/json"
- "application/xml" - "application/xml"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: parameters:
- in: "body" - in: "body"
name: "body" name: "body"
description: "Pet object that needs to be added to the store" description: "Pet object that needs to be added to the store"
required: false required: true
schema: schema:
$ref: "#/definitions/Pet" $ref: "#/definitions/Pet"
responses: responses:
405: 405:
description: "Invalid input" description: "Invalid input"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
x-tags: x-tags:
- tag: "pet" - tag: "pet"
put: put:
@ -57,13 +66,13 @@ paths:
- "application/json" - "application/json"
- "application/xml" - "application/xml"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: parameters:
- in: "body" - in: "body"
name: "body" name: "body"
description: "Pet object that needs to be added to the store" description: "Pet object that needs to be added to the store"
required: false required: true
schema: schema:
$ref: "#/definitions/Pet" $ref: "#/definitions/Pet"
responses: responses:
@ -73,10 +82,6 @@ paths:
description: "Pet not found" description: "Pet not found"
405: 405:
description: "Validation exception" description: "Validation exception"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
x-tags: x-tags:
- tag: "pet" - tag: "pet"
/pet/findByStatus: /pet/findByStatus:
@ -84,21 +89,25 @@ paths:
tags: tags:
- "pet" - "pet"
summary: "Finds Pets by status" summary: "Finds Pets by status"
description: "Multiple status values can be provided with comma seperated strings" description: "Multiple status values can be provided with comma separated strings"
operationId: "controllers.default_controller.find_pets_by_status" operationId: "controllers.default_controller.find_pets_by_status"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: parameters:
- name: "status" - name: "status"
in: "query" in: "query"
description: "Status values that need to be considered for filter" description: "Status values that need to be considered for filter"
required: false required: true
type: "array" type: "array"
items: items:
type: "string" type: "string"
enum:
- "available"
- "pending"
- "sold"
default: "available"
collectionFormat: "multi" collectionFormat: "multi"
default: "available"
responses: responses:
200: 200:
description: "successful operation" description: "successful operation"
@ -108,10 +117,6 @@ paths:
$ref: "#/definitions/Pet" $ref: "#/definitions/Pet"
400: 400:
description: "Invalid status value" description: "Invalid status value"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
x-tags: x-tags:
- tag: "pet" - tag: "pet"
/pet/findByTags: /pet/findByTags:
@ -119,17 +124,17 @@ paths:
tags: tags:
- "pet" - "pet"
summary: "Finds Pets by tags" summary: "Finds Pets by tags"
description: "Muliple tags can be provided with comma seperated strings. Use\ description: "Muliple tags can be provided with comma separated strings. Use\
\ tag1, tag2, tag3 for testing." \ tag1, tag2, tag3 for testing."
operationId: "controllers.default_controller.find_pets_by_tags" operationId: "controllers.default_controller.find_pets_by_tags"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: parameters:
- name: "tags" - name: "tags"
in: "query" in: "query"
description: "Tags to filter by" description: "Tags to filter by"
required: false required: true
type: "array" type: "array"
items: items:
type: "string" type: "string"
@ -143,10 +148,7 @@ paths:
$ref: "#/definitions/Pet" $ref: "#/definitions/Pet"
400: 400:
description: "Invalid tag value" description: "Invalid tag value"
security: deprecated: true
- petstore_auth:
- "write:pets"
- "read:pets"
x-tags: x-tags:
- tag: "pet" - tag: "pet"
/pet/{petId}: /pet/{petId}:
@ -154,16 +156,15 @@ paths:
tags: tags:
- "pet" - "pet"
summary: "Find pet by ID" summary: "Find pet by ID"
description: "Returns a pet when ID < 10. ID > 10 or nonintegers will simulate\ description: "Returns a single pet"
\ API error conditions"
operationId: "controllers.default_controller.get_pet_by_id" operationId: "controllers.default_controller.get_pet_by_id"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: parameters:
- name: "petId" - name: "petId"
in: "path" in: "path"
description: "ID of pet that needs to be fetched" description: "ID of pet to return"
required: true required: true
type: "integer" type: "integer"
format: "int64" format: "int64"
@ -178,9 +179,6 @@ paths:
description: "Pet not found" description: "Pet not found"
security: security:
- api_key: [] - api_key: []
- petstore_auth:
- "write:pets"
- "read:pets"
x-tags: x-tags:
- tag: "pet" - tag: "pet"
post: post:
@ -192,14 +190,15 @@ paths:
consumes: consumes:
- "application/x-www-form-urlencoded" - "application/x-www-form-urlencoded"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: parameters:
- name: "petId" - name: "petId"
in: "path" in: "path"
description: "ID of pet that needs to be updated" description: "ID of pet that needs to be updated"
required: true required: true
type: "string" type: "integer"
format: "int64"
- name: "name" - name: "name"
in: "formData" in: "formData"
description: "Updated name of the pet" description: "Updated name of the pet"
@ -213,10 +212,6 @@ paths:
responses: responses:
405: 405:
description: "Invalid input" description: "Invalid input"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
x-tags: x-tags:
- tag: "pet" - tag: "pet"
delete: delete:
@ -226,12 +221,11 @@ paths:
description: "" description: ""
operationId: "controllers.default_controller.delete_pet" operationId: "controllers.default_controller.delete_pet"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: parameters:
- name: "api_key" - name: "api_key"
in: "header" in: "header"
description: ""
required: false required: false
type: "string" type: "string"
- name: "petId" - name: "petId"
@ -242,11 +236,9 @@ paths:
format: "int64" format: "int64"
responses: responses:
400: 400:
description: "Invalid pet value" description: "Invalid ID supplied"
security: 404:
- petstore_auth: description: "Pet not found"
- "write:pets"
- "read:pets"
x-tags: x-tags:
- tag: "pet" - tag: "pet"
/pet/{petId}/uploadImage: /pet/{petId}/uploadImage:
@ -260,7 +252,6 @@ paths:
- "multipart/form-data" - "multipart/form-data"
produces: produces:
- "application/json" - "application/json"
- "application/xml"
parameters: parameters:
- name: "petId" - name: "petId"
in: "path" in: "path"
@ -279,12 +270,10 @@ paths:
required: false required: false
type: "file" type: "file"
responses: responses:
default: 200:
description: "successful operation" description: "successful operation"
security: schema:
- petstore_auth: $ref: "#/definitions/ApiResponse"
- "write:pets"
- "read:pets"
x-tags: x-tags:
- tag: "pet" - tag: "pet"
/store/inventory: /store/inventory:
@ -296,7 +285,6 @@ paths:
operationId: "controllers.default_controller.get_inventory" operationId: "controllers.default_controller.get_inventory"
produces: produces:
- "application/json" - "application/json"
- "application/xml"
parameters: [] parameters: []
responses: responses:
200: 200:
@ -318,13 +306,13 @@ paths:
description: "" description: ""
operationId: "controllers.default_controller.place_order" operationId: "controllers.default_controller.place_order"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: parameters:
- in: "body" - in: "body"
name: "body" name: "body"
description: "order placed for purchasing the pet" description: "order placed for purchasing the pet"
required: false required: true
schema: schema:
$ref: "#/definitions/Order" $ref: "#/definitions/Order"
responses: responses:
@ -341,18 +329,21 @@ paths:
tags: tags:
- "store" - "store"
summary: "Find purchase order by ID" summary: "Find purchase order by ID"
description: "For valid response try integer IDs with value <= 5 or > 10. Other\ description: "For valid response try integer IDs with value >= 1 and <= 10.\
\ values will generated exceptions" \ Other values will generated exceptions"
operationId: "controllers.default_controller.get_order_by_id" operationId: "controllers.default_controller.get_order_by_id"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: parameters:
- name: "orderId" - name: "orderId"
in: "path" in: "path"
description: "ID of pet that needs to be fetched" description: "ID of pet that needs to be fetched"
required: true required: true
type: "string" type: "integer"
maximum: 10.0
minimum: 1.0
format: "int64"
responses: responses:
200: 200:
description: "successful operation" description: "successful operation"
@ -368,18 +359,20 @@ paths:
tags: tags:
- "store" - "store"
summary: "Delete purchase order by ID" summary: "Delete purchase order by ID"
description: "For valid response try integer IDs with value < 1000. Anything\ description: "For valid response try integer IDs with positive integer value.\
\ above 1000 or nonintegers will generate API errors" \ Negative or non-integer values will generate API errors"
operationId: "controllers.default_controller.delete_order" operationId: "controllers.default_controller.delete_order"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: parameters:
- name: "orderId" - name: "orderId"
in: "path" in: "path"
description: "ID of the order that needs to be deleted" description: "ID of the order that needs to be deleted"
required: true required: true
type: "string" type: "integer"
minimum: 1.0
format: "int64"
responses: responses:
400: 400:
description: "Invalid ID supplied" description: "Invalid ID supplied"
@ -395,13 +388,13 @@ paths:
description: "This can only be done by the logged in user." description: "This can only be done by the logged in user."
operationId: "controllers.default_controller.create_user" operationId: "controllers.default_controller.create_user"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: parameters:
- in: "body" - in: "body"
name: "body" name: "body"
description: "Created user object" description: "Created user object"
required: false required: true
schema: schema:
$ref: "#/definitions/User" $ref: "#/definitions/User"
responses: responses:
@ -417,13 +410,13 @@ paths:
description: "" description: ""
operationId: "controllers.default_controller.create_users_with_array_input" operationId: "controllers.default_controller.create_users_with_array_input"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: parameters:
- in: "body" - in: "body"
name: "body" name: "body"
description: "List of user object" description: "List of user object"
required: false required: true
schema: schema:
type: "array" type: "array"
items: items:
@ -441,13 +434,13 @@ paths:
description: "" description: ""
operationId: "controllers.default_controller.create_users_with_list_input" operationId: "controllers.default_controller.create_users_with_list_input"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: parameters:
- in: "body" - in: "body"
name: "body" name: "body"
description: "List of user object" description: "List of user object"
required: false required: true
schema: schema:
type: "array" type: "array"
items: items:
@ -465,24 +458,33 @@ paths:
description: "" description: ""
operationId: "controllers.default_controller.login_user" operationId: "controllers.default_controller.login_user"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: parameters:
- name: "username" - name: "username"
in: "query" in: "query"
description: "The user name for login" description: "The user name for login"
required: false required: true
type: "string" type: "string"
- name: "password" - name: "password"
in: "query" in: "query"
description: "The password for login in clear text" description: "The password for login in clear text"
required: false required: true
type: "string" type: "string"
responses: responses:
200: 200:
description: "successful operation" description: "successful operation"
schema: schema:
type: "string" 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: 400:
description: "Invalid username/password supplied" description: "Invalid username/password supplied"
x-tags: x-tags:
@ -495,8 +497,8 @@ paths:
description: "" description: ""
operationId: "controllers.default_controller.logout_user" operationId: "controllers.default_controller.logout_user"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: [] parameters: []
responses: responses:
default: default:
@ -511,8 +513,8 @@ paths:
description: "" description: ""
operationId: "controllers.default_controller.get_user_by_name" operationId: "controllers.default_controller.get_user_by_name"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: parameters:
- name: "username" - name: "username"
in: "path" in: "path"
@ -524,16 +526,6 @@ paths:
description: "successful operation" description: "successful operation"
schema: schema:
$ref: "#/definitions/User" $ref: "#/definitions/User"
examples:
application/json:
id: 1
username: "johnp"
firstName: "John"
lastName: "Public"
email: "johnp@swagger.io"
password: "-secret-"
phone: "0123456789"
userStatus: 0
400: 400:
description: "Invalid username supplied" description: "Invalid username supplied"
404: 404:
@ -547,18 +539,18 @@ paths:
description: "This can only be done by the logged in user." description: "This can only be done by the logged in user."
operationId: "controllers.default_controller.update_user" operationId: "controllers.default_controller.update_user"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: parameters:
- name: "username" - name: "username"
in: "path" in: "path"
description: "name that need to be deleted" description: "name that need to be updated"
required: true required: true
type: "string" type: "string"
- in: "body" - in: "body"
name: "body" name: "body"
description: "Updated user object" description: "Updated user object"
required: false required: true
schema: schema:
$ref: "#/definitions/User" $ref: "#/definitions/User"
responses: responses:
@ -575,8 +567,8 @@ paths:
description: "This can only be done by the logged in user." description: "This can only be done by the logged in user."
operationId: "controllers.default_controller.delete_user" operationId: "controllers.default_controller.delete_user"
produces: produces:
- "application/json"
- "application/xml" - "application/xml"
- "application/json"
parameters: parameters:
- name: "username" - name: "username"
in: "path" in: "path"
@ -591,19 +583,40 @@ paths:
x-tags: x-tags:
- tag: "user" - tag: "user"
securityDefinitions: 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: api_key:
type: "apiKey" type: "apiKey"
name: "api_key" name: "api_key"
in: "header" in: "header"
definitions: definitions:
Order:
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"
User: User:
type: "object"
properties: properties:
id: id:
type: "integer" type: "integer"
@ -627,6 +640,7 @@ definitions:
xml: xml:
name: "User" name: "User"
Category: Category:
type: "object"
properties: properties:
id: id:
type: "integer" type: "integer"
@ -635,7 +649,28 @@ definitions:
type: "string" type: "string"
xml: xml:
name: "Category" name: "Category"
Tag:
type: "object"
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
xml:
name: "Tag"
ApiResponse:
type: "object"
properties:
code:
type: "integer"
format: "int32"
type:
type: "string"
message:
type: "string"
Pet: Pet:
type: "object"
required: required:
- "name" - "name"
- "photoUrls" - "photoUrls"
@ -671,37 +706,6 @@ definitions:
- "sold" - "sold"
xml: xml:
name: "Pet" name: "Pet"
Tag: externalDocs:
properties: description: "Find out more about Swagger"
id: url: "http://swagger.io"
type: "integer"
format: "int64"
name:
type: "string"
xml:
name: "Tag"
Order:
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"
xml:
name: "Order"