From 925c7c59a1f1f8dde8e9f8c62b7193c9d56757e2 Mon Sep 17 00:00:00 2001 From: Justin Busschau Date: Wed, 19 Feb 2020 15:20:20 +0000 Subject: [PATCH 1/5] Use the dataType if the baseType is not set --- .../src/main/resources/python-flask/controller.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/python-flask/controller.mustache b/modules/openapi-generator/src/main/resources/python-flask/controller.mustache index 243da33e5709..9b7fdb198743 100644 --- a/modules/openapi-generator/src/main/resources/python-flask/controller.mustache +++ b/modules/openapi-generator/src/main/resources/python-flask/controller.mustache @@ -69,7 +69,7 @@ def {{operationId}}({{#allParams}}{{paramName}}{{^required}}=None{{/required}}{{ {{^isFile}} {{^isUuid}} if connexion.request.is_json: - {{paramName}} = {{baseType}}.from_dict(connexion.request.get_json()) # noqa: E501 + {{paramName}} = {{#baseType}}{{baseType}}{{/baseType}}{{^baseType}}{{#dataType}} {{dataType}}{{/dataType}}{{/baseType}}.from_dict(connexion.request.get_json()) # noqa: E501 {{/isUuid}} {{/isFile}} {{/isPrimitiveType}} From afd24520e349f2168baac2db4c7e4cf4ae80bbbc Mon Sep 17 00:00:00 2001 From: Justin Busschau Date: Thu, 20 Feb 2020 17:05:59 +0000 Subject: [PATCH 2/5] add tests for passing enum as parameter --- bin/python-server-all.sh | 1 + bin/python-server-flask-petstore-openapi.sh | 50 + .../python-flask/requirements.mustache | 2 +- .../petstore-with-object-as-parameter.yaml | 770 +++++++++++++++ .../python-flask-openapi/.dockerignore | 72 ++ .../petstore/python-flask-openapi/.gitignore | 66 ++ .../.openapi-generator-ignore | 23 + .../.openapi-generator/VERSION | 1 + .../petstore/python-flask-openapi/.travis.yml | 14 + .../petstore/python-flask-openapi/Dockerfile | 16 + .../petstore/python-flask-openapi/README.md | 49 + .../petstore/python-flask-openapi/git_push.sh | 58 ++ .../openapi_server/__init__.py | 0 .../openapi_server/__main__.py | 18 + .../openapi_server/controllers/__init__.py | 0 .../controllers/pet_controller.py | 142 +++ .../controllers/security_controller_.py | 64 ++ .../controllers/store_controller.py | 57 ++ .../controllers/user_controller.py | 119 +++ .../openapi_server/encoder.py | 20 + .../openapi_server/models/__init__.py | 14 + .../openapi_server/models/api_response.py | 116 +++ .../openapi_server/models/base_model_.py | 69 ++ .../openapi_server/models/category.py | 94 ++ .../openapi_server/models/inline_object.py | 94 ++ .../openapi_server/models/inline_object1.py | 94 ++ .../openapi_server/models/order.py | 202 ++++ .../openapi_server/models/pet.py | 210 +++++ .../openapi_server/models/status_enum.py | 43 + .../openapi_server/models/tag.py | 90 ++ .../openapi_server/models/user.py | 248 +++++ .../openapi_server/openapi/openapi.yaml | 889 ++++++++++++++++++ .../openapi_server/test/__init__.py | 16 + .../test/test_pet_controller.py | 220 +++++ .../test/test_store_controller.py | 89 ++ .../test/test_user_controller.py | 193 ++++ .../openapi_server/typing_utils.py | 32 + .../openapi_server/util.py | 142 +++ .../python-flask-openapi/requirements.txt | 7 + .../petstore/python-flask-openapi/setup.py | 39 + .../test-requirements.txt | 4 + .../petstore/python-flask-openapi/tox.ini | 9 + 42 files changed, 4455 insertions(+), 1 deletion(-) create mode 100755 bin/python-server-flask-petstore-openapi.sh create mode 100644 modules/openapi-generator/src/test/resources/3_0/petstore-with-object-as-parameter.yaml create mode 100644 samples/server/petstore/python-flask-openapi/.dockerignore create mode 100644 samples/server/petstore/python-flask-openapi/.gitignore create mode 100644 samples/server/petstore/python-flask-openapi/.openapi-generator-ignore create mode 100644 samples/server/petstore/python-flask-openapi/.openapi-generator/VERSION create mode 100644 samples/server/petstore/python-flask-openapi/.travis.yml create mode 100644 samples/server/petstore/python-flask-openapi/Dockerfile create mode 100644 samples/server/petstore/python-flask-openapi/README.md create mode 100644 samples/server/petstore/python-flask-openapi/git_push.sh create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/__init__.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/__main__.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/controllers/__init__.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/controllers/pet_controller.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/controllers/security_controller_.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/controllers/store_controller.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/controllers/user_controller.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/encoder.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/__init__.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/api_response.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/base_model_.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/category.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/inline_object.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/inline_object1.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/order.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/pet.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/status_enum.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/tag.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/user.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/openapi/openapi.yaml create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/test/__init__.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/test/test_pet_controller.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/test/test_store_controller.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/test/test_user_controller.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/typing_utils.py create mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/util.py create mode 100644 samples/server/petstore/python-flask-openapi/requirements.txt create mode 100644 samples/server/petstore/python-flask-openapi/setup.py create mode 100644 samples/server/petstore/python-flask-openapi/test-requirements.txt create mode 100644 samples/server/petstore/python-flask-openapi/tox.ini diff --git a/bin/python-server-all.sh b/bin/python-server-all.sh index 5fe3176eed9e..8d0b9b4424a6 100755 --- a/bin/python-server-all.sh +++ b/bin/python-server-all.sh @@ -3,4 +3,5 @@ ./bin/python-server-aiohttp-petstore.sh ./bin/python-server-flask-petstore.sh ./bin/python-server-flask-petstore-python2.sh +./bin/python-server-flask-petstore-openapi.sh ./bin/python-server-blueplanet-petstore.sh diff --git a/bin/python-server-flask-petstore-openapi.sh b/bin/python-server-flask-petstore-openapi.sh new file mode 100755 index 000000000000..fc432d4aeda9 --- /dev/null +++ b/bin/python-server-flask-petstore-openapi.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +SCRIPT="$0" +echo "# START SCRIPT: $SCRIPT" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" + +if [ ! -f "$executable" ] +then + mvn -B clean package +fi + +generator=python-flask +input=modules/openapi-generator/src/test/resources/3_0/petstore-with-object-as-parameter.yaml +out_folder=samples/server/petstore/$generator-openapi +resources=modules/openapi-generator/src/main/resources/$generator + +# if you've executed sbt assembly previously it will use that instead. +export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties -Dservice" +ags="generate -t $resources -i $input -g $generator -o $out_folder $@" + +rm -rf $out_folder/.openapi* +rm -rf $out_folder/openapi_server +rm $out_folder/.dockerignore +rm $out_folder/.gitignore +rm $out_folder/.travis.yml +rm $out_folder/Dockerfile +rm $out_folder/git_push.sh +rm $out_folder/README.md +rm $out_folder/requirements.txt +rm $out_folder/setup.py +rm $out_folder/test-requirements.txt +rm $out_folder/tox.ini + +java $JAVA_OPTS -jar $executable $ags diff --git a/modules/openapi-generator/src/main/resources/python-flask/requirements.mustache b/modules/openapi-generator/src/main/resources/python-flask/requirements.mustache index 921d67d029a2..b5dab7b9af0b 100644 --- a/modules/openapi-generator/src/main/resources/python-flask/requirements.mustache +++ b/modules/openapi-generator/src/main/resources/python-flask/requirements.mustache @@ -1,4 +1,4 @@ -connexion >= 2.5.0; python_version>="3.6" +connexion >= 2.6.0; python_version>="3.6" connexion >= 2.3.0; python_version=="3.5" connexion >= 2.3.0; python_version=="3.4" connexion == 2.4.0; python_version<="2.7" diff --git a/modules/openapi-generator/src/test/resources/3_0/petstore-with-object-as-parameter.yaml b/modules/openapi-generator/src/test/resources/3_0/petstore-with-object-as-parameter.yaml new file mode 100644 index 000000000000..5ccae3bf52a2 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/petstore-with-object-as-parameter.yaml @@ -0,0 +1,770 @@ +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: + '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 + responses: + '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 + 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: [] + patch: + tags: + - pet + summary: Set the status of a pet in the store using an enum + description: '' + operationId: updatePetStatusWithEnum + parameters: + - name: petId + in: path + description: ID of pet to return + required: true + schema: + type: integer + format: int64 + - $ref: '#/components/parameters/statusEnum' + 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 + 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 generated 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: + - auth_cookie: [] + 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: + - auth_cookie: [] + 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: + - auth_cookie: [] + 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 `auth_cookie` + 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 toekn 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: + - auth_cookie: [] + '/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: + - auth_cookie: [] + 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: + - auth_cookie: [] +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 + auth_cookie: + type: apiKey + name: AUTH_KEY + in: cookie + 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 + 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 + statusEnum: + type: string + description: pet status in the store + enum: + - available + - pending + - sold + parameters: + statusEnum: + description: The required status + explode: true + in: query + name: status + required: true + schema: + $ref: '#/components/schemas/statusEnum' + example: + pending + style: form diff --git a/samples/server/petstore/python-flask-openapi/.dockerignore b/samples/server/petstore/python-flask-openapi/.dockerignore new file mode 100644 index 000000000000..f9619601908b --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/.dockerignore @@ -0,0 +1,72 @@ +.travis.yaml +.openapi-generator-ignore +README.md +tox.ini +git_push.sh +test-requirements.txt +setup.py + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ +venv/ +.python-version + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +#Ipython Notebook +.ipynb_checkpoints diff --git a/samples/server/petstore/python-flask-openapi/.gitignore b/samples/server/petstore/python-flask-openapi/.gitignore new file mode 100644 index 000000000000..43995bd42fa2 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/.gitignore @@ -0,0 +1,66 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ +venv/ +.venv/ +.python-version +.pytest_cache + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +#Ipython Notebook +.ipynb_checkpoints diff --git a/samples/server/petstore/python-flask-openapi/.openapi-generator-ignore b/samples/server/petstore/python-flask-openapi/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/server/petstore/python-flask-openapi/.openapi-generator/VERSION b/samples/server/petstore/python-flask-openapi/.openapi-generator/VERSION new file mode 100644 index 000000000000..58592f031f65 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/.openapi-generator/VERSION @@ -0,0 +1 @@ +4.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/python-flask-openapi/.travis.yml b/samples/server/petstore/python-flask-openapi/.travis.yml new file mode 100644 index 000000000000..ad71ee5ca083 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/.travis.yml @@ -0,0 +1,14 @@ +# ref: https://docs.travis-ci.com/user/languages/python +language: python +python: + - "3.2" + - "3.3" + - "3.4" + - "3.5" + - "3.6" + - "3.7" + - "3.8" +# command to install dependencies +install: "pip install -r requirements.txt" +# command to run tests +script: nosetests diff --git a/samples/server/petstore/python-flask-openapi/Dockerfile b/samples/server/petstore/python-flask-openapi/Dockerfile new file mode 100644 index 000000000000..4857637c3799 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/Dockerfile @@ -0,0 +1,16 @@ +FROM python:3-alpine + +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app + +COPY requirements.txt /usr/src/app/ + +RUN pip3 install --no-cache-dir -r requirements.txt + +COPY . /usr/src/app + +EXPOSE 8080 + +ENTRYPOINT ["python3"] + +CMD ["-m", "openapi_server"] \ No newline at end of file diff --git a/samples/server/petstore/python-flask-openapi/README.md b/samples/server/petstore/python-flask-openapi/README.md new file mode 100644 index 000000000000..673c8b3b5a01 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/README.md @@ -0,0 +1,49 @@ +# OpenAPI generated server + +## Overview +This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the +[OpenAPI-Spec](https://openapis.org) from a remote server, you can easily generate a server stub. This +is an example of building a OpenAPI-enabled Flask server. + +This example uses the [Connexion](https://github.com/zalando/connexion) library on top of Flask. + +## Requirements +Python 3.5.2+ + +## Usage +To run the server, please execute the following from the root directory: + +``` +pip3 install -r requirements.txt +python3 -m openapi_server +``` + +and open your browser to here: + +``` +http://localhost:8080/v2/ui/ +``` + +Your OpenAPI definition lives here: + +``` +http://localhost:8080/v2/openapi.json +``` + +To launch the integration tests, use tox: +``` +sudo pip install tox +tox +``` + +## Running with Docker + +To run the server on a Docker container, please execute the following from the root directory: + +```bash +# building the image +docker build -t openapi_server . + +# starting up a container +docker run -p 8080:8080 openapi_server +``` \ No newline at end of file diff --git a/samples/server/petstore/python-flask-openapi/git_push.sh b/samples/server/petstore/python-flask-openapi/git_push.sh new file mode 100644 index 000000000000..ced3be2b0c7b --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/git_push.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 +git_host=$4 + +if [ "$git_host" = "" ]; then + git_host="github.com" + echo "[INFO] No command line input provided. Set \$git_host to $git_host" +fi + +if [ "$git_user_id" = "" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=`git remote` +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' + diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/__init__.py b/samples/server/petstore/python-flask-openapi/openapi_server/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/__main__.py b/samples/server/petstore/python-flask-openapi/openapi_server/__main__.py new file mode 100644 index 000000000000..24b2141e14de --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/__main__.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +import connexion + +from openapi_server import encoder + + +def main(): + app = connexion.App(__name__, specification_dir='./openapi/') + app.app.json_encoder = encoder.JSONEncoder + app.add_api('openapi.yaml', + arguments={'title': 'OpenAPI Petstore'}, + pythonic_params=True) + app.run(port=8080) + + +if __name__ == '__main__': + main() diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/__init__.py b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/pet_controller.py b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/pet_controller.py new file mode 100644 index 000000000000..883ac6e5655f --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/pet_controller.py @@ -0,0 +1,142 @@ +import connexion +import six + +from openapi_server.models.api_response import ApiResponse # noqa: E501 +from openapi_server.models.pet import Pet # noqa: E501 +from openapi_server.models.status_enum import StatusEnum # noqa: E501 +from openapi_server import util + + +def add_pet(pet): # noqa: E501 + """Add a new pet to the store + + # noqa: E501 + + :param pet: Pet object that needs to be added to the store + :type pet: dict | bytes + + :rtype: None + """ + if connexion.request.is_json: + pet = Pet.from_dict(connexion.request.get_json()) # noqa: E501 + return 'do some magic!' + + +def delete_pet(pet_id, api_key=None): # noqa: E501 + """Deletes a pet + + # noqa: E501 + + :param pet_id: Pet id to delete + :type pet_id: int + :param api_key: + :type api_key: str + + :rtype: None + """ + return 'do some magic!' + + +def find_pets_by_status(status): # noqa: E501 + """Finds Pets by status + + Multiple status values can be provided with comma separated strings # noqa: E501 + + :param status: Status values that need to be considered for filter + :type status: List[str] + + :rtype: List[Pet] + """ + return 'do some magic!' + + +def find_pets_by_tags(tags): # noqa: E501 + """Finds Pets by tags + + Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. # noqa: E501 + + :param tags: Tags to filter by + :type tags: List[str] + + :rtype: List[Pet] + """ + return 'do some magic!' + + +def get_pet_by_id(pet_id): # noqa: E501 + """Find pet by ID + + Returns a single pet # noqa: E501 + + :param pet_id: ID of pet to return + :type pet_id: int + + :rtype: Pet + """ + return 'do some magic!' + + +def update_pet(pet): # noqa: E501 + """Update an existing pet + + # noqa: E501 + + :param pet: Pet object that needs to be added to the store + :type pet: dict | bytes + + :rtype: None + """ + if connexion.request.is_json: + pet = Pet.from_dict(connexion.request.get_json()) # noqa: E501 + return 'do some magic!' + + +def update_pet_status_with_enum(pet_id, status): # noqa: E501 + """Set the status of a pet in the store using an enum + + # noqa: E501 + + :param pet_id: ID of pet to return + :type pet_id: int + :param status: The required status + :type status: dict | bytes + + :rtype: Pet + """ + if connexion.request.is_json: + status = StatusEnum.from_dict(connexion.request.get_json()) # noqa: E501 + return 'do some magic!' + + +def update_pet_with_form(pet_id, name=None, status=None): # noqa: E501 + """Updates a pet in the store with form data + + # noqa: E501 + + :param pet_id: ID of pet that needs to be updated + :type pet_id: int + :param name: Updated name of the pet + :type name: str + :param status: Updated status of the pet + :type status: str + + :rtype: None + """ + return 'do some magic!' + + +def upload_file(pet_id, additional_metadata=None, file=None): # noqa: E501 + """uploads an image + + # noqa: E501 + + :param pet_id: ID of pet to update + :type pet_id: int + :param additional_metadata: Additional data to pass to server + :type additional_metadata: str + :param file: file to upload + :type file: str + + :rtype: ApiResponse + """ + return 'do some magic!' diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/security_controller_.py b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/security_controller_.py new file mode 100644 index 000000000000..b4bd85dd1a71 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/security_controller_.py @@ -0,0 +1,64 @@ +from typing import List + + +def info_from_api_key(api_key, required_scopes): + """ + Check and retrieve authentication information from api_key. + Returned value will be passed in 'token_info' parameter of your operation function, if there is one. + 'sub' or 'uid' will be set in 'user' parameter of your operation function, if there is one. + + :param api_key API key provided by Authorization header + :type api_key: str + :param required_scopes Always None. Used for other authentication method + :type required_scopes: None + :return: Information attached to provided api_key or None if api_key is invalid or does not allow access to called API + :rtype: dict | None + """ + return {'uid': 'user_id'} + + +def info_from_auth_cookie(api_key, required_scopes): + """ + Check and retrieve authentication information from api_key. + Returned value will be passed in 'token_info' parameter of your operation function, if there is one. + 'sub' or 'uid' will be set in 'user' parameter of your operation function, if there is one. + + :param api_key API key provided by Authorization header + :type api_key: str + :param required_scopes Always None. Used for other authentication method + :type required_scopes: None + :return: Information attached to provided api_key or None if api_key is invalid or does not allow access to called API + :rtype: dict | None + """ + return {'uid': 'user_id'} + + +def info_from_petstore_auth(token): + """ + Validate and decode token. + Returned value will be passed in 'token_info' parameter of your operation function, if there is one. + 'sub' or 'uid' will be set in 'user' parameter of your operation function, if there is one. + 'scope' or 'scopes' will be passed to scope validation function. + + :param token Token provided by Authorization header + :type token: str + :return: Decoded token information or None if token is invalid + :rtype: dict | None + """ + return {'scopes': ['read:pets', 'write:pets'], 'uid': 'user_id'} + + +def validate_scope_petstore_auth(required_scopes, token_scopes): + """ + Validate required scopes are included in token scope + + :param required_scopes Required scope to access called API + :type required_scopes: List[str] + :param token_scopes Scope present in token + :type token_scopes: List[str] + :return: True if access to called API is allowed + :rtype: bool + """ + return set(required_scopes).issubset(set(token_scopes)) + + diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/store_controller.py b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/store_controller.py new file mode 100644 index 000000000000..3d16d99859e7 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/store_controller.py @@ -0,0 +1,57 @@ +import connexion +import six + +from openapi_server.models.order import Order # noqa: E501 +from openapi_server import util + + +def delete_order(order_id): # noqa: E501 + """Delete purchase order by ID + + For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors # noqa: E501 + + :param order_id: ID of the order that needs to be deleted + :type order_id: str + + :rtype: None + """ + return 'do some magic!' + + +def get_inventory(): # noqa: E501 + """Returns pet inventories by status + + Returns a map of status codes to quantities # noqa: E501 + + + :rtype: Dict[str, int] + """ + return 'do some magic!' + + +def get_order_by_id(order_id): # noqa: E501 + """Find purchase order by ID + + For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions # noqa: E501 + + :param order_id: ID of pet that needs to be fetched + :type order_id: int + + :rtype: Order + """ + return 'do some magic!' + + +def place_order(order): # noqa: E501 + """Place an order for a pet + + # noqa: E501 + + :param order: order placed for purchasing the pet + :type order: dict | bytes + + :rtype: Order + """ + if connexion.request.is_json: + order = Order.from_dict(connexion.request.get_json()) # noqa: E501 + return 'do some magic!' diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/user_controller.py b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/user_controller.py new file mode 100644 index 000000000000..9b9706262121 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/user_controller.py @@ -0,0 +1,119 @@ +import connexion +import six + +from openapi_server.models.user import User # noqa: E501 +from openapi_server import util + + +def create_user(user): # noqa: E501 + """Create user + + This can only be done by the logged in user. # noqa: E501 + + :param user: Created user object + :type user: dict | bytes + + :rtype: None + """ + if connexion.request.is_json: + user = User.from_dict(connexion.request.get_json()) # noqa: E501 + return 'do some magic!' + + +def create_users_with_array_input(user): # noqa: E501 + """Creates list of users with given input array + + # noqa: E501 + + :param user: List of user object + :type user: list | bytes + + :rtype: None + """ + if connexion.request.is_json: + user = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501 + return 'do some magic!' + + +def create_users_with_list_input(user): # noqa: E501 + """Creates list of users with given input array + + # noqa: E501 + + :param user: List of user object + :type user: list | bytes + + :rtype: None + """ + if connexion.request.is_json: + user = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501 + return 'do some magic!' + + +def delete_user(username): # noqa: E501 + """Delete user + + This can only be done by the logged in user. # noqa: E501 + + :param username: The name that needs to be deleted + :type username: str + + :rtype: None + """ + return 'do some magic!' + + +def get_user_by_name(username): # noqa: E501 + """Get user by user name + + # noqa: E501 + + :param username: The name that needs to be fetched. Use user1 for testing. + :type username: str + + :rtype: User + """ + return 'do some magic!' + + +def login_user(username, password): # noqa: E501 + """Logs user into the system + + # noqa: E501 + + :param username: The user name for login + :type username: str + :param password: The password for login in clear text + :type password: str + + :rtype: str + """ + return 'do some magic!' + + +def logout_user(): # noqa: E501 + """Logs out current logged in user session + + # noqa: E501 + + + :rtype: None + """ + return 'do some magic!' + + +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 user: Updated user object + :type user: dict | bytes + + :rtype: None + """ + if connexion.request.is_json: + user = User.from_dict(connexion.request.get_json()) # noqa: E501 + return 'do some magic!' diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/encoder.py b/samples/server/petstore/python-flask-openapi/openapi_server/encoder.py new file mode 100644 index 000000000000..3bbef854f3b8 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/encoder.py @@ -0,0 +1,20 @@ +from connexion.apps.flask_app import FlaskJSONEncoder +import six + +from openapi_server.models.base_model_ import Model + + +class JSONEncoder(FlaskJSONEncoder): + include_nulls = False + + def default(self, o): + if isinstance(o, Model): + dikt = {} + for attr, _ in six.iteritems(o.openapi_types): + value = getattr(o, attr) + if value is None and not self.include_nulls: + continue + attr = o.attribute_map[attr] + dikt[attr] = value + return dikt + return FlaskJSONEncoder.default(self, o) diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/__init__.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/__init__.py new file mode 100644 index 000000000000..3788dd080cb1 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/models/__init__.py @@ -0,0 +1,14 @@ +# coding: utf-8 + +# flake8: noqa +from __future__ import absolute_import +# import models into model package +from openapi_server.models.api_response import ApiResponse +from openapi_server.models.category import Category +from openapi_server.models.inline_object import InlineObject +from openapi_server.models.inline_object1 import InlineObject1 +from openapi_server.models.order import Order +from openapi_server.models.pet import Pet +from openapi_server.models.status_enum import StatusEnum +from openapi_server.models.tag import Tag +from openapi_server.models.user import User diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/api_response.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/api_response.py new file mode 100644 index 000000000000..1e23da9c2304 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/models/api_response.py @@ -0,0 +1,116 @@ +# coding: utf-8 + +from __future__ import absolute_import +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from openapi_server.models.base_model_ import Model +from openapi_server import util + + +class ApiResponse(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + def __init__(self, code=None, type=None, message=None): # noqa: E501 + """ApiResponse - a model defined in OpenAPI + + :param code: The code of this ApiResponse. # noqa: E501 + :type code: int + :param type: The type of this ApiResponse. # noqa: E501 + :type type: str + :param message: The message of this ApiResponse. # noqa: E501 + :type message: str + """ + self.openapi_types = { + 'code': int, + 'type': str, + 'message': str + } + + self.attribute_map = { + 'code': 'code', + 'type': 'type', + 'message': 'message' + } + + self._code = code + self._type = type + self._message = message + + @classmethod + def from_dict(cls, dikt) -> 'ApiResponse': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The ApiResponse of this ApiResponse. # noqa: E501 + :rtype: ApiResponse + """ + return util.deserialize_model(dikt, cls) + + @property + def code(self): + """Gets the code of this ApiResponse. + + + :return: The code of this ApiResponse. + :rtype: int + """ + return self._code + + @code.setter + def code(self, code): + """Sets the code of this ApiResponse. + + + :param code: The code of this ApiResponse. + :type code: int + """ + + self._code = code + + @property + def type(self): + """Gets the type of this ApiResponse. + + + :return: The type of this ApiResponse. + :rtype: str + """ + return self._type + + @type.setter + def type(self, type): + """Sets the type of this ApiResponse. + + + :param type: The type of this ApiResponse. + :type type: str + """ + + self._type = type + + @property + def message(self): + """Gets the message of this ApiResponse. + + + :return: The message of this ApiResponse. + :rtype: str + """ + return self._message + + @message.setter + def message(self, message): + """Sets the message of this ApiResponse. + + + :param message: The message of this ApiResponse. + :type message: str + """ + + self._message = message diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/base_model_.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/base_model_.py new file mode 100644 index 000000000000..ec33e3ba3cff --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/models/base_model_.py @@ -0,0 +1,69 @@ +import pprint + +import six +import typing + +from openapi_server import util + +T = typing.TypeVar('T') + + +class Model(object): + # openapiTypes: The key is attribute name and the + # value is attribute type. + openapi_types = {} + + # attributeMap: The key is attribute name and the + # value is json key in definition. + attribute_map = {} + + @classmethod + def from_dict(cls: typing.Type[T], dikt) -> T: + """Returns the dict as a model""" + return util.deserialize_model(dikt, cls) + + def to_dict(self): + """Returns the model properties as a dict + + :rtype: dict + """ + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model + + :rtype: str + """ + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/category.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/category.py new file mode 100644 index 000000000000..8511752bafb9 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/models/category.py @@ -0,0 +1,94 @@ +# coding: utf-8 + +from __future__ import absolute_import +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from openapi_server.models.base_model_ import Model +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). + + Do not edit the class manually. + """ + + def __init__(self, id=None, name=None): # noqa: E501 + """Category - a model defined in OpenAPI + + :param id: The id of this Category. # noqa: E501 + :type id: int + :param name: The name of this Category. # noqa: E501 + :type name: str + """ + self.openapi_types = { + 'id': int, + 'name': str + } + + self.attribute_map = { + 'id': 'id', + 'name': 'name' + } + + self._id = id + self._name = name + + @classmethod + def from_dict(cls, dikt) -> 'Category': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The Category of this Category. # noqa: E501 + :rtype: Category + """ + return util.deserialize_model(dikt, cls) + + @property + def id(self): + """Gets the id of this Category. + + + :return: The id of this Category. + :rtype: int + """ + return self._id + + @id.setter + def id(self, id): + """Sets the id of this Category. + + + :param id: The id of this Category. + :type id: int + """ + + self._id = id + + @property + def name(self): + """Gets the name of this Category. + + + :return: The name of this Category. + :rtype: str + """ + return self._name + + @name.setter + def name(self, name): + """Sets the name of this Category. + + + :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 diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/inline_object.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/inline_object.py new file mode 100644 index 000000000000..1178d560625c --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/models/inline_object.py @@ -0,0 +1,94 @@ +# coding: utf-8 + +from __future__ import absolute_import +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from openapi_server.models.base_model_ import Model +from openapi_server import util + + +class InlineObject(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + def __init__(self, name=None, status=None): # noqa: E501 + """InlineObject - a model defined in OpenAPI + + :param name: The name of this InlineObject. # noqa: E501 + :type name: str + :param status: The status of this InlineObject. # noqa: E501 + :type status: str + """ + self.openapi_types = { + 'name': str, + 'status': str + } + + self.attribute_map = { + 'name': 'name', + 'status': 'status' + } + + self._name = name + self._status = status + + @classmethod + def from_dict(cls, dikt) -> 'InlineObject': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The inline_object of this InlineObject. # noqa: E501 + :rtype: InlineObject + """ + return util.deserialize_model(dikt, cls) + + @property + def name(self): + """Gets the name of this InlineObject. + + Updated name of the pet # noqa: E501 + + :return: The name of this InlineObject. + :rtype: str + """ + return self._name + + @name.setter + def name(self, name): + """Sets the name of this InlineObject. + + Updated name of the pet # noqa: E501 + + :param name: The name of this InlineObject. + :type name: str + """ + + self._name = name + + @property + def status(self): + """Gets the status of this InlineObject. + + Updated status of the pet # noqa: E501 + + :return: The status of this InlineObject. + :rtype: str + """ + return self._status + + @status.setter + def status(self, status): + """Sets the status of this InlineObject. + + Updated status of the pet # noqa: E501 + + :param status: The status of this InlineObject. + :type status: str + """ + + self._status = status diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/inline_object1.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/inline_object1.py new file mode 100644 index 000000000000..349041c0c8fc --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/models/inline_object1.py @@ -0,0 +1,94 @@ +# coding: utf-8 + +from __future__ import absolute_import +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from openapi_server.models.base_model_ import Model +from openapi_server import util + + +class InlineObject1(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + def __init__(self, additional_metadata=None, file=None): # noqa: E501 + """InlineObject1 - a model defined in OpenAPI + + :param additional_metadata: The additional_metadata of this InlineObject1. # noqa: E501 + :type additional_metadata: str + :param file: The file of this InlineObject1. # noqa: E501 + :type file: file + """ + self.openapi_types = { + 'additional_metadata': str, + 'file': file + } + + self.attribute_map = { + 'additional_metadata': 'additionalMetadata', + 'file': 'file' + } + + self._additional_metadata = additional_metadata + self._file = file + + @classmethod + def from_dict(cls, dikt) -> 'InlineObject1': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The inline_object_1 of this InlineObject1. # noqa: E501 + :rtype: InlineObject1 + """ + return util.deserialize_model(dikt, cls) + + @property + def additional_metadata(self): + """Gets the additional_metadata of this InlineObject1. + + Additional data to pass to server # noqa: E501 + + :return: The additional_metadata of this InlineObject1. + :rtype: str + """ + return self._additional_metadata + + @additional_metadata.setter + def additional_metadata(self, additional_metadata): + """Sets the additional_metadata of this InlineObject1. + + Additional data to pass to server # noqa: E501 + + :param additional_metadata: The additional_metadata of this InlineObject1. + :type additional_metadata: str + """ + + self._additional_metadata = additional_metadata + + @property + def file(self): + """Gets the file of this InlineObject1. + + file to upload # noqa: E501 + + :return: The file of this InlineObject1. + :rtype: file + """ + return self._file + + @file.setter + def file(self, file): + """Sets the file of this InlineObject1. + + file to upload # noqa: E501 + + :param file: The file of this InlineObject1. + :type file: file + """ + + self._file = file diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/order.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/order.py new file mode 100644 index 000000000000..aa8a7a71c393 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/models/order.py @@ -0,0 +1,202 @@ +# coding: utf-8 + +from __future__ import absolute_import +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from openapi_server.models.base_model_ import Model +from openapi_server import util + + +class Order(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + def __init__(self, id=None, pet_id=None, quantity=None, ship_date=None, status=None, complete=False): # noqa: E501 + """Order - a model defined in OpenAPI + + :param id: The id of this Order. # noqa: E501 + :type id: int + :param pet_id: The pet_id of this Order. # noqa: E501 + :type pet_id: int + :param quantity: The quantity of this Order. # noqa: E501 + :type quantity: int + :param ship_date: The ship_date of this Order. # noqa: E501 + :type ship_date: datetime + :param status: The status of this Order. # noqa: E501 + :type status: str + :param complete: The complete of this Order. # noqa: E501 + :type complete: bool + """ + self.openapi_types = { + 'id': int, + 'pet_id': int, + 'quantity': int, + 'ship_date': datetime, + 'status': str, + 'complete': bool + } + + self.attribute_map = { + 'id': 'id', + 'pet_id': 'petId', + 'quantity': 'quantity', + 'ship_date': 'shipDate', + 'status': 'status', + 'complete': 'complete' + } + + self._id = id + self._pet_id = pet_id + self._quantity = quantity + self._ship_date = ship_date + self._status = status + self._complete = complete + + @classmethod + def from_dict(cls, dikt) -> 'Order': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The Order of this Order. # noqa: E501 + :rtype: Order + """ + return util.deserialize_model(dikt, cls) + + @property + def id(self): + """Gets the id of this Order. + + + :return: The id of this Order. + :rtype: int + """ + return self._id + + @id.setter + def id(self, id): + """Sets the id of this Order. + + + :param id: The id of this Order. + :type id: int + """ + + self._id = id + + @property + def pet_id(self): + """Gets the pet_id of this Order. + + + :return: The pet_id of this Order. + :rtype: int + """ + return self._pet_id + + @pet_id.setter + def pet_id(self, pet_id): + """Sets the pet_id of this Order. + + + :param pet_id: The pet_id of this Order. + :type pet_id: int + """ + + self._pet_id = pet_id + + @property + def quantity(self): + """Gets the quantity of this Order. + + + :return: The quantity of this Order. + :rtype: int + """ + return self._quantity + + @quantity.setter + def quantity(self, quantity): + """Sets the quantity of this Order. + + + :param quantity: The quantity of this Order. + :type quantity: int + """ + + self._quantity = quantity + + @property + def ship_date(self): + """Gets the ship_date of this Order. + + + :return: The ship_date of this Order. + :rtype: datetime + """ + return self._ship_date + + @ship_date.setter + def ship_date(self, ship_date): + """Sets the ship_date of this Order. + + + :param ship_date: The ship_date of this Order. + :type ship_date: datetime + """ + + self._ship_date = ship_date + + @property + def status(self): + """Gets the status of this Order. + + Order Status # noqa: E501 + + :return: The status of this Order. + :rtype: str + """ + return self._status + + @status.setter + def status(self, status): + """Sets the status of this Order. + + Order Status # noqa: E501 + + :param status: The status of this Order. + :type status: str + """ + 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}" + .format(status, allowed_values) + ) + + self._status = status + + @property + def complete(self): + """Gets the complete of this Order. + + + :return: The complete of this Order. + :rtype: bool + """ + return self._complete + + @complete.setter + def complete(self, complete): + """Sets the complete of this Order. + + + :param complete: The complete of this Order. + :type complete: bool + """ + + self._complete = complete diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/pet.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/pet.py new file mode 100644 index 000000000000..e61674165e1c --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/models/pet.py @@ -0,0 +1,210 @@ +# coding: utf-8 + +from __future__ import absolute_import +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from openapi_server.models.base_model_ import Model +from openapi_server.models.category import Category +from openapi_server.models.tag import Tag +from openapi_server import util + +from openapi_server.models.category import Category # noqa: E501 +from openapi_server.models.tag import Tag # noqa: E501 + +class Pet(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + def __init__(self, id=None, category=None, name=None, photo_urls=None, tags=None, status=None): # noqa: E501 + """Pet - a model defined in OpenAPI + + :param id: The id of this Pet. # noqa: E501 + :type id: int + :param category: The category of this Pet. # noqa: E501 + :type category: Category + :param name: The name of this Pet. # noqa: E501 + :type name: str + :param photo_urls: The photo_urls of this Pet. # noqa: E501 + :type photo_urls: List[str] + :param tags: The tags of this Pet. # noqa: E501 + :type tags: List[Tag] + :param status: The status of this Pet. # noqa: E501 + :type status: str + """ + self.openapi_types = { + 'id': int, + 'category': Category, + 'name': str, + 'photo_urls': List[str], + 'tags': List[Tag], + 'status': str + } + + self.attribute_map = { + 'id': 'id', + 'category': 'category', + 'name': 'name', + 'photo_urls': 'photoUrls', + 'tags': 'tags', + 'status': 'status' + } + + self._id = id + self._category = category + self._name = name + self._photo_urls = photo_urls + self._tags = tags + self._status = status + + @classmethod + def from_dict(cls, dikt) -> 'Pet': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The Pet of this Pet. # noqa: E501 + :rtype: Pet + """ + return util.deserialize_model(dikt, cls) + + @property + def id(self): + """Gets the id of this Pet. + + + :return: The id of this Pet. + :rtype: int + """ + return self._id + + @id.setter + def id(self, id): + """Sets the id of this Pet. + + + :param id: The id of this Pet. + :type id: int + """ + + self._id = id + + @property + def category(self): + """Gets the category of this Pet. + + + :return: The category of this Pet. + :rtype: Category + """ + return self._category + + @category.setter + def category(self, category): + """Sets the category of this Pet. + + + :param category: The category of this Pet. + :type category: Category + """ + + self._category = category + + @property + def name(self): + """Gets the name of this Pet. + + + :return: The name of this Pet. + :rtype: str + """ + return self._name + + @name.setter + def name(self, name): + """Sets the name of this Pet. + + + :param name: The name of this Pet. + :type name: str + """ + if name is None: + raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + + self._name = name + + @property + def photo_urls(self): + """Gets the photo_urls of this Pet. + + + :return: The photo_urls of this Pet. + :rtype: List[str] + """ + return self._photo_urls + + @photo_urls.setter + def photo_urls(self, photo_urls): + """Sets the photo_urls of this Pet. + + + :param photo_urls: The photo_urls of this Pet. + :type photo_urls: List[str] + """ + if photo_urls is None: + raise ValueError("Invalid value for `photo_urls`, must not be `None`") # noqa: E501 + + self._photo_urls = photo_urls + + @property + def tags(self): + """Gets the tags of this Pet. + + + :return: The tags of this Pet. + :rtype: List[Tag] + """ + return self._tags + + @tags.setter + def tags(self, tags): + """Sets the tags of this Pet. + + + :param tags: The tags of this Pet. + :type tags: List[Tag] + """ + + self._tags = tags + + @property + def status(self): + """Gets the status of this Pet. + + pet status in the store # noqa: E501 + + :return: The status of this Pet. + :rtype: str + """ + return self._status + + @status.setter + def status(self, status): + """Sets the status of this Pet. + + pet status in the store # noqa: E501 + + :param status: The status of this Pet. + :type status: str + """ + 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}" + .format(status, allowed_values) + ) + + self._status = status diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/status_enum.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/status_enum.py new file mode 100644 index 000000000000..653c1684396f --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/models/status_enum.py @@ -0,0 +1,43 @@ +# coding: utf-8 + +from __future__ import absolute_import +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from openapi_server.models.base_model_ import Model +from openapi_server import util + + +class StatusEnum(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + """ + allowed enum values + """ + AVAILABLE = "available" + PENDING = "pending" + SOLD = "sold" + def __init__(self): # noqa: E501 + """StatusEnum - a model defined in OpenAPI + + """ + self.openapi_types = { + } + + self.attribute_map = { + } + + @classmethod + def from_dict(cls, dikt) -> 'StatusEnum': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The statusEnum of this StatusEnum. # noqa: E501 + :rtype: StatusEnum + """ + return util.deserialize_model(dikt, cls) diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/tag.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/tag.py new file mode 100644 index 000000000000..bd6fff169078 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/models/tag.py @@ -0,0 +1,90 @@ +# coding: utf-8 + +from __future__ import absolute_import +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from openapi_server.models.base_model_ import Model +from openapi_server import util + + +class Tag(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + def __init__(self, id=None, name=None): # noqa: E501 + """Tag - a model defined in OpenAPI + + :param id: The id of this Tag. # noqa: E501 + :type id: int + :param name: The name of this Tag. # noqa: E501 + :type name: str + """ + self.openapi_types = { + 'id': int, + 'name': str + } + + self.attribute_map = { + 'id': 'id', + 'name': 'name' + } + + self._id = id + self._name = name + + @classmethod + def from_dict(cls, dikt) -> 'Tag': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The Tag of this Tag. # noqa: E501 + :rtype: Tag + """ + return util.deserialize_model(dikt, cls) + + @property + def id(self): + """Gets the id of this Tag. + + + :return: The id of this Tag. + :rtype: int + """ + return self._id + + @id.setter + def id(self, id): + """Sets the id of this Tag. + + + :param id: The id of this Tag. + :type id: int + """ + + self._id = id + + @property + def name(self): + """Gets the name of this Tag. + + + :return: The name of this Tag. + :rtype: str + """ + return self._name + + @name.setter + def name(self, name): + """Sets the name of this Tag. + + + :param name: The name of this Tag. + :type name: str + """ + + self._name = name diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/user.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/user.py new file mode 100644 index 000000000000..1b1f4bdae726 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/models/user.py @@ -0,0 +1,248 @@ +# coding: utf-8 + +from __future__ import absolute_import +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from openapi_server.models.base_model_ import Model +from openapi_server import util + + +class User(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + def __init__(self, id=None, username=None, first_name=None, last_name=None, email=None, password=None, phone=None, user_status=None): # noqa: E501 + """User - a model defined in OpenAPI + + :param id: The id of this User. # noqa: E501 + :type id: int + :param username: The username of this User. # noqa: E501 + :type username: str + :param first_name: The first_name of this User. # noqa: E501 + :type first_name: str + :param last_name: The last_name of this User. # noqa: E501 + :type last_name: str + :param email: The email of this User. # noqa: E501 + :type email: str + :param password: The password of this User. # noqa: E501 + :type password: str + :param phone: The phone of this User. # noqa: E501 + :type phone: str + :param user_status: The user_status of this User. # noqa: E501 + :type user_status: int + """ + self.openapi_types = { + 'id': int, + 'username': str, + 'first_name': str, + 'last_name': str, + 'email': str, + 'password': str, + 'phone': str, + 'user_status': int + } + + self.attribute_map = { + 'id': 'id', + 'username': 'username', + 'first_name': 'firstName', + 'last_name': 'lastName', + 'email': 'email', + 'password': 'password', + 'phone': 'phone', + 'user_status': 'userStatus' + } + + self._id = id + self._username = username + self._first_name = first_name + self._last_name = last_name + self._email = email + self._password = password + self._phone = phone + self._user_status = user_status + + @classmethod + def from_dict(cls, dikt) -> 'User': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The User of this User. # noqa: E501 + :rtype: User + """ + return util.deserialize_model(dikt, cls) + + @property + def id(self): + """Gets the id of this User. + + + :return: The id of this User. + :rtype: int + """ + return self._id + + @id.setter + def id(self, id): + """Sets the id of this User. + + + :param id: The id of this User. + :type id: int + """ + + self._id = id + + @property + def username(self): + """Gets the username of this User. + + + :return: The username of this User. + :rtype: str + """ + return self._username + + @username.setter + def username(self, username): + """Sets the username of this User. + + + :param username: The username of this User. + :type username: str + """ + + self._username = username + + @property + def first_name(self): + """Gets the first_name of this User. + + + :return: The first_name of this User. + :rtype: str + """ + return self._first_name + + @first_name.setter + def first_name(self, first_name): + """Sets the first_name of this User. + + + :param first_name: The first_name of this User. + :type first_name: str + """ + + self._first_name = first_name + + @property + def last_name(self): + """Gets the last_name of this User. + + + :return: The last_name of this User. + :rtype: str + """ + return self._last_name + + @last_name.setter + def last_name(self, last_name): + """Sets the last_name of this User. + + + :param last_name: The last_name of this User. + :type last_name: str + """ + + self._last_name = last_name + + @property + def email(self): + """Gets the email of this User. + + + :return: The email of this User. + :rtype: str + """ + return self._email + + @email.setter + def email(self, email): + """Sets the email of this User. + + + :param email: The email of this User. + :type email: str + """ + + self._email = email + + @property + def password(self): + """Gets the password of this User. + + + :return: The password of this User. + :rtype: str + """ + return self._password + + @password.setter + def password(self, password): + """Sets the password of this User. + + + :param password: The password of this User. + :type password: str + """ + + self._password = password + + @property + def phone(self): + """Gets the phone of this User. + + + :return: The phone of this User. + :rtype: str + """ + return self._phone + + @phone.setter + def phone(self, phone): + """Sets the phone of this User. + + + :param phone: The phone of this User. + :type phone: str + """ + + self._phone = phone + + @property + def user_status(self): + """Gets the user_status of this User. + + User Status # noqa: E501 + + :return: The user_status of this User. + :rtype: int + """ + return self._user_status + + @user_status.setter + def user_status(self, user_status): + """Sets the user_status of this User. + + User Status # noqa: E501 + + :param user_status: The user_status of this User. + :type user_status: int + """ + + self._user_status = user_status diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/openapi/openapi.yaml b/samples/server/petstore/python-flask-openapi/openapi_server/openapi/openapi.yaml new file mode 100644 index 000000000000..e5d1465dccb5 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/openapi/openapi.yaml @@ -0,0 +1,889 @@ +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. + license: + name: Apache-2.0 + 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: +- description: Everything about your Pets + name: pet +- description: Access to Petstore orders + name: store +- description: Operations about user + name: user +paths: + /pet: + post: + operationId: add_pet + requestBody: + $ref: '#/components/requestBodies/Pet' + responses: + "405": + description: Invalid input + security: + - petstore_auth: + - write:pets + - read:pets + summary: Add a new pet to the store + tags: + - pet + x-openapi-router-controller: openapi_server.controllers.pet_controller + put: + operationId: update_pet + requestBody: + $ref: '#/components/requestBodies/Pet' + responses: + "400": + description: Invalid ID supplied + "404": + description: Pet not found + "405": + description: Validation exception + security: + - petstore_auth: + - write:pets + - read:pets + summary: Update an existing pet + tags: + - pet + 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 + explode: false + in: query + name: status + required: true + schema: + items: + default: available + enum: + - available + - pending + - sold + type: string + type: array + style: form + responses: + "200": + content: + application/xml: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + application/json: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + description: successful operation + "400": + description: Invalid status value + security: + - petstore_auth: + - read:pets + summary: Finds Pets by status + tags: + - pet + x-openapi-router-controller: openapi_server.controllers.pet_controller + /pet/findByTags: + get: + deprecated: true + description: Multiple tags can be provided with comma separated strings. Use + tag1, tag2, tag3 for testing. + operationId: find_pets_by_tags + parameters: + - description: Tags to filter by + explode: false + in: query + name: tags + required: true + schema: + items: + type: string + type: array + style: form + responses: + "200": + content: + application/xml: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + application/json: + schema: + items: + $ref: '#/components/schemas/Pet' + type: array + description: successful operation + "400": + description: Invalid tag value + security: + - petstore_auth: + - read:pets + summary: Finds Pets by tags + tags: + - pet + x-openapi-router-controller: openapi_server.controllers.pet_controller + /pet/{petId}: + delete: + operationId: delete_pet + parameters: + - 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": + description: Invalid pet value + security: + - petstore_auth: + - write:pets + - read:pets + summary: Deletes a pet + tags: + - pet + x-openapi-router-controller: openapi_server.controllers.pet_controller + get: + description: Returns a single pet + 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: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation + "400": + description: Invalid ID supplied + "404": + description: Pet not found + security: + - api_key: [] + summary: Find pet by ID + tags: + - pet + x-openapi-router-controller: openapi_server.controllers.pet_controller + patch: + operationId: update_pet_status_with_enum + parameters: + - description: ID of pet to return + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + - description: The required status + example: pending + explode: true + in: query + name: status + required: true + schema: + $ref: '#/components/schemas/statusEnum' + style: form + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation + "400": + description: Invalid ID supplied + "404": + description: Pet not found + summary: Set the status of a pet in the store using an enum + tags: + - pet + x-openapi-router-controller: openapi_server.controllers.pet_controller + post: + operationId: update_pet_with_form + parameters: + - 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: + $ref: '#/components/requestBodies/inline_object' + content: + application/x-www-form-urlencoded: + schema: + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + type: object + responses: + "405": + description: Invalid input + security: + - petstore_auth: + - write:pets + - read:pets + summary: Updates a pet in the store with form data + tags: + - pet + x-openapi-router-controller: openapi_server.controllers.pet_controller + /pet/{petId}/uploadImage: + post: + 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: + $ref: '#/components/requestBodies/inline_object_1' + content: + multipart/form-data: + schema: + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + format: binary + type: string + type: object + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + description: successful operation + security: + - petstore_auth: + - write:pets + - read:pets + summary: uploads an image + tags: + - pet + x-openapi-router-controller: openapi_server.controllers.pet_controller + /store/inventory: + get: + description: Returns a map of status codes to quantities + operationId: get_inventory + responses: + "200": + content: + application/json: + schema: + additionalProperties: + format: int32 + type: integer + type: object + description: successful operation + security: + - api_key: [] + summary: Returns pet inventories by status + tags: + - store + x-openapi-router-controller: openapi_server.controllers.store_controller + /store/order: + post: + operationId: place_order + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Order' + description: order placed for purchasing the pet + required: true + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + description: successful operation + "400": + description: Invalid Order + summary: Place an order for a pet + tags: + - store + x-openapi-router-controller: openapi_server.controllers.store_controller + /store/order/{orderId}: + delete: + description: For valid response try integer IDs with value < 1000. Anything + above 1000 or nonintegers will generate API errors + operationId: delete_order + 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": + description: Invalid ID supplied + "404": + description: Order not found + summary: Delete purchase order by ID + tags: + - store + x-openapi-router-controller: openapi_server.controllers.store_controller + get: + description: For valid response try integer IDs with value <= 5 or > 10. Other + values will generated exceptions + operationId: get_order_by_id + parameters: + - description: ID of pet that needs to be fetched + explode: false + in: path + name: orderId + required: true + schema: + format: int64 + maximum: 5 + minimum: 1 + type: integer + style: simple + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + description: successful operation + "400": + description: Invalid ID supplied + "404": + description: Order not found + summary: Find purchase order by ID + tags: + - store + x-openapi-router-controller: openapi_server.controllers.store_controller + /user: + post: + description: This can only be done by the logged in user. + operationId: create_user + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Created user object + required: true + responses: + default: + description: successful operation + security: + - auth_cookie: [] + summary: Create user + tags: + - user + x-openapi-router-controller: openapi_server.controllers.user_controller + /user/createWithArray: + post: + operationId: create_users_with_array_input + requestBody: + $ref: '#/components/requestBodies/UserArray' + responses: + default: + description: successful operation + security: + - auth_cookie: [] + summary: Creates list of users with given input array + tags: + - user + x-openapi-router-controller: openapi_server.controllers.user_controller + /user/createWithList: + post: + operationId: create_users_with_list_input + requestBody: + $ref: '#/components/requestBodies/UserArray' + responses: + default: + description: successful operation + security: + - auth_cookie: [] + summary: Creates list of users with given input array + tags: + - user + x-openapi-router-controller: openapi_server.controllers.user_controller + /user/login: + get: + 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: + application/xml: + schema: + type: string + application/json: + schema: + type: string + description: successful operation + headers: + Set-Cookie: + description: Cookie authentication key for use with the `auth_cookie` + 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 toekn expires + explode: false + schema: + format: date-time + type: string + style: simple + "400": + description: Invalid username/password supplied + summary: Logs user into the system + tags: + - user + x-openapi-router-controller: openapi_server.controllers.user_controller + /user/logout: + get: + operationId: logout_user + responses: + default: + description: successful operation + security: + - auth_cookie: [] + summary: Logs out current logged in user session + tags: + - user + x-openapi-router-controller: openapi_server.controllers.user_controller + /user/{username}: + delete: + description: This can only be done by the logged in user. + 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": + description: Invalid username supplied + "404": + description: User not found + security: + - auth_cookie: [] + summary: Delete user + tags: + - user + x-openapi-router-controller: openapi_server.controllers.user_controller + get: + 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: + application/xml: + schema: + $ref: '#/components/schemas/User' + application/json: + schema: + $ref: '#/components/schemas/User' + description: successful operation + "400": + description: Invalid username supplied + "404": + description: User not found + summary: Get user by user name + tags: + - user + x-openapi-router-controller: openapi_server.controllers.user_controller + put: + description: This can only be done by the logged in user. + 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": + description: Invalid user supplied + "404": + description: User not found + security: + - auth_cookie: [] + summary: Updated user + tags: + - user + x-openapi-router-controller: openapi_server.controllers.user_controller +components: + parameters: + statusEnum: + description: The required status + example: pending + explode: true + in: query + name: status + required: true + schema: + $ref: '#/components/schemas/statusEnum' + style: form + requestBodies: + UserArray: + content: + 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 + inline_object: + content: + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/inline_object' + inline_object_1: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/inline_object_1' + schemas: + Order: + description: An order for a pets from the pet store + example: + petId: 6 + quantity: 1 + id: 0 + shipDate: 2000-01-23T04:56:07.000+00:00 + complete: false + status: placed + properties: + id: + format: int64 + type: integer + petId: + format: int64 + type: integer + quantity: + format: int32 + type: integer + shipDate: + format: date-time + type: string + status: + description: Order Status + enum: + - placed + - approved + - delivered + type: string + complete: + default: false + type: boolean + title: Pet Order + type: object + xml: + name: Order + Category: + description: A category for a pet + example: + name: name + id: 6 + properties: + id: + format: int64 + type: integer + name: + pattern: ^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$ + type: string + title: Pet category + type: object + xml: + name: Category + User: + description: A User who is purchasing from the pet store + example: + firstName: firstName + lastName: lastName + password: password + userStatus: 6 + phone: phone + id: 0 + email: email + username: username + properties: + id: + format: int64 + type: integer + username: + type: string + firstName: + type: string + lastName: + type: string + email: + type: string + password: + type: string + phone: + type: string + userStatus: + description: User Status + format: int32 + type: integer + title: a User + type: object + xml: + name: User + Tag: + description: A tag for a pet + example: + name: name + id: 1 + properties: + id: + format: int64 + type: integer + name: + type: string + title: Pet Tag + type: object + xml: + name: Tag + Pet: + description: A pet for sale in the pet store + example: + photoUrls: + - photoUrls + - photoUrls + name: doggie + id: 0 + category: + name: name + id: 6 + tags: + - name: name + id: 1 + - name: name + id: 1 + status: available + properties: + id: + format: int64 + type: integer + category: + $ref: '#/components/schemas/Category' + name: + example: doggie + type: string + photoUrls: + items: + type: string + type: array + xml: + name: photoUrl + wrapped: true + tags: + items: + $ref: '#/components/schemas/Tag' + type: array + xml: + name: tag + wrapped: true + status: + description: pet status in the store + enum: + - available + - pending + - sold + type: string + required: + - name + - photoUrls + title: a Pet + type: object + xml: + name: Pet + ApiResponse: + description: Describes the result of uploading an image resource + example: + code: 0 + type: type + message: message + properties: + code: + format: int32 + type: integer + type: + type: string + message: + type: string + title: An uploaded response + type: object + statusEnum: + description: pet status in the store + enum: + - available + - pending + - sold + type: string + inline_object: + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + type: object + inline_object_1: + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + format: binary + type: string + type: object + securitySchemes: + petstore_auth: + flows: + implicit: + authorizationUrl: http://petstore.swagger.io/api/oauth/dialog + scopes: + write:pets: modify pets in your account + read:pets: read your pets + type: oauth2 + x-tokenInfoFunc: openapi_server.controllers.security_controller_.info_from_petstore_auth + x-scopeValidateFunc: openapi_server.controllers.security_controller_.validate_scope_petstore_auth + api_key: + in: header + name: api_key + type: apiKey + x-apikeyInfoFunc: openapi_server.controllers.security_controller_.info_from_api_key + auth_cookie: + in: cookie + name: AUTH_KEY + type: apiKey + x-apikeyInfoFunc: openapi_server.controllers.security_controller_.info_from_auth_cookie diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/test/__init__.py b/samples/server/petstore/python-flask-openapi/openapi_server/test/__init__.py new file mode 100644 index 000000000000..364aba9fbf88 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/test/__init__.py @@ -0,0 +1,16 @@ +import logging + +import connexion +from flask_testing import TestCase + +from openapi_server.encoder import JSONEncoder + + +class BaseTestCase(TestCase): + + def create_app(self): + logging.getLogger('connexion.operation').setLevel('ERROR') + app = connexion.App(__name__, specification_dir='../openapi/') + app.app.json_encoder = JSONEncoder + app.add_api('openapi.yaml', pythonic_params=True) + return app.app diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/test/test_pet_controller.py b/samples/server/petstore/python-flask-openapi/openapi_server/test/test_pet_controller.py new file mode 100644 index 000000000000..3a40329cdc82 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/test/test_pet_controller.py @@ -0,0 +1,220 @@ +# coding: utf-8 + +from __future__ import absolute_import +import unittest + +from flask import json +from six import BytesIO + +from openapi_server.models.api_response import ApiResponse # noqa: E501 +from openapi_server.models.pet import Pet # noqa: E501 +from openapi_server.models.status_enum import StatusEnum # noqa: E501 +from openapi_server.test import BaseTestCase + + +class TestPetController(BaseTestCase): + """PetController integration test stubs""" + + @unittest.skip("Connexion does not support multiple consummes. See https://github.com/zalando/connexion/pull/760") + def test_add_pet(self): + """Test case for add_pet + + Add a new pet to the store + """ + pet = { + "photoUrls" : [ "photoUrls", "photoUrls" ], + "name" : "doggie", + "id" : 0, + "category" : { + "name" : "name", + "id" : 6 + }, + "tags" : [ { + "name" : "name", + "id" : 1 + }, { + "name" : "name", + "id" : 1 + } ], + "status" : "available" +} + headers = { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer special-key', + } + response = self.client.open( + '/v2/pet', + method='POST', + headers=headers, + data=json.dumps(pet), + content_type='application/json') + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + def test_delete_pet(self): + """Test case for delete_pet + + Deletes a pet + """ + headers = { + 'api_key': 'api_key_example', + 'Authorization': 'Bearer special-key', + } + response = self.client.open( + '/v2/pet/{pet_id}'.format(pet_id=56), + method='DELETE', + headers=headers) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + def test_find_pets_by_status(self): + """Test case for find_pets_by_status + + Finds Pets by status + """ + query_string = [('status', 'available')] + headers = { + 'Accept': 'application/json', + 'Authorization': 'Bearer special-key', + } + response = self.client.open( + '/v2/pet/findByStatus', + method='GET', + headers=headers, + query_string=query_string) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + def test_find_pets_by_tags(self): + """Test case for find_pets_by_tags + + Finds Pets by tags + """ + query_string = [('tags', 'tags_example')] + headers = { + 'Accept': 'application/json', + 'Authorization': 'Bearer special-key', + } + response = self.client.open( + '/v2/pet/findByTags', + method='GET', + headers=headers, + query_string=query_string) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + def test_get_pet_by_id(self): + """Test case for get_pet_by_id + + Find pet by ID + """ + headers = { + 'Accept': 'application/json', + 'api_key': 'special-key', + } + response = self.client.open( + '/v2/pet/{pet_id}'.format(pet_id=56), + method='GET', + headers=headers) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + @unittest.skip("Connexion does not support multiple consummes. See https://github.com/zalando/connexion/pull/760") + def test_update_pet(self): + """Test case for update_pet + + Update an existing pet + """ + pet = { + "photoUrls" : [ "photoUrls", "photoUrls" ], + "name" : "doggie", + "id" : 0, + "category" : { + "name" : "name", + "id" : 6 + }, + "tags" : [ { + "name" : "name", + "id" : 1 + }, { + "name" : "name", + "id" : 1 + } ], + "status" : "available" +} + headers = { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer special-key', + } + response = self.client.open( + '/v2/pet', + method='PUT', + headers=headers, + data=json.dumps(pet), + content_type='application/json') + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + def test_update_pet_status_with_enum(self): + """Test case for update_pet_status_with_enum + + Set the status of a pet in the store using an enum + """ + query_string = [('status', pending)] + headers = { + 'Accept': 'application/json', + } + response = self.client.open( + '/v2/pet/{pet_id}'.format(pet_id=56), + method='PATCH', + headers=headers, + query_string=query_string) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + @unittest.skip("application/x-www-form-urlencoded not supported by Connexion") + def test_update_pet_with_form(self): + """Test case for update_pet_with_form + + Updates a pet in the store with form data + """ + headers = { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Authorization': 'Bearer special-key', + } + data = dict(name='name_example', + status='status_example') + response = self.client.open( + '/v2/pet/{pet_id}'.format(pet_id=56), + method='POST', + headers=headers, + data=data, + content_type='application/x-www-form-urlencoded') + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + @unittest.skip("multipart/form-data not supported by Connexion") + def test_upload_file(self): + """Test case for upload_file + + uploads an image + """ + headers = { + 'Accept': 'application/json', + 'Content-Type': 'multipart/form-data', + 'Authorization': 'Bearer special-key', + } + data = dict(additional_metadata='additional_metadata_example', + file=(BytesIO(b'some file data'), 'file.txt')) + response = self.client.open( + '/v2/pet/{pet_id}/uploadImage'.format(pet_id=56), + method='POST', + headers=headers, + data=data, + content_type='multipart/form-data') + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/test/test_store_controller.py b/samples/server/petstore/python-flask-openapi/openapi_server/test/test_store_controller.py new file mode 100644 index 000000000000..e232ef3aad48 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/test/test_store_controller.py @@ -0,0 +1,89 @@ +# coding: utf-8 + +from __future__ import absolute_import +import unittest + +from flask import json +from six import BytesIO + +from openapi_server.models.order import Order # noqa: E501 +from openapi_server.test import BaseTestCase + + +class TestStoreController(BaseTestCase): + """StoreController integration test stubs""" + + def test_delete_order(self): + """Test case for delete_order + + Delete purchase order by ID + """ + headers = { + } + response = self.client.open( + '/v2/store/order/{order_id}'.format(order_id='order_id_example'), + method='DELETE', + headers=headers) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + def test_get_inventory(self): + """Test case for get_inventory + + Returns pet inventories by status + """ + headers = { + 'Accept': 'application/json', + 'api_key': 'special-key', + } + response = self.client.open( + '/v2/store/inventory', + method='GET', + headers=headers) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + def test_get_order_by_id(self): + """Test case for get_order_by_id + + Find purchase order by ID + """ + headers = { + 'Accept': 'application/json', + } + response = self.client.open( + '/v2/store/order/{order_id}'.format(order_id=5), + method='GET', + headers=headers) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + def test_place_order(self): + """Test case for place_order + + Place an order for a pet + """ + order = { + "petId" : 6, + "quantity" : 1, + "id" : 0, + "shipDate" : "2000-01-23T04:56:07.000+00:00", + "complete" : false, + "status" : "placed" +} + headers = { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + } + response = self.client.open( + '/v2/store/order', + method='POST', + headers=headers, + data=json.dumps(order), + content_type='application/json') + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/test/test_user_controller.py b/samples/server/petstore/python-flask-openapi/openapi_server/test/test_user_controller.py new file mode 100644 index 000000000000..8f634b7cd6bf --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/test/test_user_controller.py @@ -0,0 +1,193 @@ +# coding: utf-8 + +from __future__ import absolute_import +import unittest + +from flask import json +from six import BytesIO + +from openapi_server.models.user import User # noqa: E501 +from openapi_server.test import BaseTestCase + + +class TestUserController(BaseTestCase): + """UserController integration test stubs""" + + def test_create_user(self): + """Test case for create_user + + Create user + """ + user = { + "firstName" : "firstName", + "lastName" : "lastName", + "password" : "password", + "userStatus" : 6, + "phone" : "phone", + "id" : 0, + "email" : "email", + "username" : "username" +} + headers = { + 'Content-Type': 'application/json', + 'auth_cookie': 'special-key', + } + response = self.client.open( + '/v2/user', + method='POST', + headers=headers, + data=json.dumps(user), + content_type='application/json') + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + def test_create_users_with_array_input(self): + """Test case for create_users_with_array_input + + Creates list of users with given input array + """ + user = { + "firstName" : "firstName", + "lastName" : "lastName", + "password" : "password", + "userStatus" : 6, + "phone" : "phone", + "id" : 0, + "email" : "email", + "username" : "username" +} + headers = { + 'Content-Type': 'application/json', + 'auth_cookie': 'special-key', + } + response = self.client.open( + '/v2/user/createWithArray', + method='POST', + headers=headers, + data=json.dumps(user), + content_type='application/json') + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + def test_create_users_with_list_input(self): + """Test case for create_users_with_list_input + + Creates list of users with given input array + """ + user = { + "firstName" : "firstName", + "lastName" : "lastName", + "password" : "password", + "userStatus" : 6, + "phone" : "phone", + "id" : 0, + "email" : "email", + "username" : "username" +} + headers = { + 'Content-Type': 'application/json', + 'auth_cookie': 'special-key', + } + response = self.client.open( + '/v2/user/createWithList', + method='POST', + headers=headers, + data=json.dumps(user), + content_type='application/json') + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + def test_delete_user(self): + """Test case for delete_user + + Delete user + """ + headers = { + 'auth_cookie': 'special-key', + } + response = self.client.open( + '/v2/user/{username}'.format(username='username_example'), + method='DELETE', + headers=headers) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + def test_get_user_by_name(self): + """Test case for get_user_by_name + + Get user by user name + """ + headers = { + 'Accept': 'application/json', + } + response = self.client.open( + '/v2/user/{username}'.format(username='username_example'), + method='GET', + headers=headers) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + def test_login_user(self): + """Test case for login_user + + Logs user into the system + """ + query_string = [('username', 'username_example'), + ('password', 'password_example')] + headers = { + 'Accept': 'application/json', + } + response = self.client.open( + '/v2/user/login', + method='GET', + headers=headers, + query_string=query_string) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + def test_logout_user(self): + """Test case for logout_user + + Logs out current logged in user session + """ + headers = { + 'auth_cookie': 'special-key', + } + response = self.client.open( + '/v2/user/logout', + method='GET', + headers=headers) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + def test_update_user(self): + """Test case for update_user + + Updated user + """ + user = { + "firstName" : "firstName", + "lastName" : "lastName", + "password" : "password", + "userStatus" : 6, + "phone" : "phone", + "id" : 0, + "email" : "email", + "username" : "username" +} + headers = { + 'Content-Type': 'application/json', + 'auth_cookie': 'special-key', + } + response = self.client.open( + '/v2/user/{username}'.format(username='username_example'), + method='PUT', + headers=headers, + data=json.dumps(user), + content_type='application/json') + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/typing_utils.py b/samples/server/petstore/python-flask-openapi/openapi_server/typing_utils.py new file mode 100644 index 000000000000..0563f81fd534 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/typing_utils.py @@ -0,0 +1,32 @@ +# coding: utf-8 + +import sys + +if sys.version_info < (3, 7): + import typing + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return type(klass) == typing.GenericMeta + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__extra__ == dict + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__extra__ == list + +else: + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return hasattr(klass, '__origin__') + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__origin__ == dict + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__origin__ == list diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/util.py b/samples/server/petstore/python-flask-openapi/openapi_server/util.py new file mode 100644 index 000000000000..e1185a713ec9 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/openapi_server/util.py @@ -0,0 +1,142 @@ +import datetime + +import six +import typing +from openapi_server import typing_utils + + +def _deserialize(data, klass): + """Deserializes dict, list, str into an object. + + :param data: dict, list or str. + :param klass: class literal, or string of class name. + + :return: object. + """ + if data is None: + return None + + if klass in six.integer_types or klass in (float, str, bool, bytearray): + return _deserialize_primitive(data, klass) + elif klass == object: + return _deserialize_object(data) + elif klass == datetime.date: + return deserialize_date(data) + elif klass == datetime.datetime: + return deserialize_datetime(data) + elif typing_utils.is_generic(klass): + if typing_utils.is_list(klass): + return _deserialize_list(data, klass.__args__[0]) + if typing_utils.is_dict(klass): + return _deserialize_dict(data, klass.__args__[1]) + else: + return deserialize_model(data, klass) + + +def _deserialize_primitive(data, klass): + """Deserializes to primitive type. + + :param data: data to deserialize. + :param klass: class literal. + + :return: int, long, float, str, bool. + :rtype: int | long | float | str | bool + """ + try: + value = klass(data) + except UnicodeEncodeError: + value = six.u(data) + except TypeError: + value = data + return value + + +def _deserialize_object(value): + """Return an original value. + + :return: object. + """ + return value + + +def deserialize_date(string): + """Deserializes string to date. + + :param string: str. + :type string: str + :return: date. + :rtype: date + """ + try: + from dateutil.parser import parse + return parse(string).date() + except ImportError: + return string + + +def deserialize_datetime(string): + """Deserializes string to datetime. + + The string should be in iso8601 datetime format. + + :param string: str. + :type string: str + :return: datetime. + :rtype: datetime + """ + try: + from dateutil.parser import parse + return parse(string) + except ImportError: + return string + + +def deserialize_model(data, klass): + """Deserializes list or dict to model. + + :param data: dict, list. + :type data: dict | list + :param klass: class literal. + :return: model object. + """ + instance = klass() + + if not instance.openapi_types: + return data + + for attr, attr_type in six.iteritems(instance.openapi_types): + if data is not None \ + and instance.attribute_map[attr] in data \ + and isinstance(data, (list, dict)): + value = data[instance.attribute_map[attr]] + setattr(instance, attr, _deserialize(value, attr_type)) + + return instance + + +def _deserialize_list(data, boxed_type): + """Deserializes a list and its elements. + + :param data: list to deserialize. + :type data: list + :param boxed_type: class literal. + + :return: deserialized list. + :rtype: list + """ + return [_deserialize(sub_data, boxed_type) + for sub_data in data] + + +def _deserialize_dict(data, boxed_type): + """Deserializes a dict and its elements. + + :param data: dict to deserialize. + :type data: dict + :param boxed_type: class literal. + + :return: deserialized dict. + :rtype: dict + """ + return {k: _deserialize(v, boxed_type) + for k, v in six.iteritems(data)} diff --git a/samples/server/petstore/python-flask-openapi/requirements.txt b/samples/server/petstore/python-flask-openapi/requirements.txt new file mode 100644 index 000000000000..2639eedf1361 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/requirements.txt @@ -0,0 +1,7 @@ +connexion >= 2.6.0; python_version>="3.6" +connexion >= 2.3.0; python_version=="3.5" +connexion >= 2.3.0; python_version=="3.4" +connexion == 2.4.0; python_version<="2.7" +swagger-ui-bundle >= 0.0.2 +python_dateutil >= 2.6.0 +setuptools >= 21.0.0 diff --git a/samples/server/petstore/python-flask-openapi/setup.py b/samples/server/petstore/python-flask-openapi/setup.py new file mode 100644 index 000000000000..1cd2660efd67 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/setup.py @@ -0,0 +1,39 @@ +# coding: utf-8 + +import sys +from setuptools import setup, find_packages + +NAME = "openapi_server" +VERSION = "1.0.0" + +# To install the library, run the following +# +# python setup.py install +# +# prerequisite: setuptools +# http://pypi.python.org/pypi/setuptools + +REQUIRES = [ + "connexion>=2.0.2", + "swagger-ui-bundle>=0.0.2", + "python_dateutil>=2.6.0" +] + +setup( + name=NAME, + version=VERSION, + description="OpenAPI Petstore", + author_email="", + url="", + keywords=["OpenAPI", "OpenAPI Petstore"], + install_requires=REQUIRES, + packages=find_packages(), + package_data={'': ['openapi/openapi.yaml']}, + include_package_data=True, + entry_points={ + 'console_scripts': ['openapi_server=openapi_server.__main__:main']}, + long_description="""\ + This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + """ +) + diff --git a/samples/server/petstore/python-flask-openapi/test-requirements.txt b/samples/server/petstore/python-flask-openapi/test-requirements.txt new file mode 100644 index 000000000000..a2626d875ff4 --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/test-requirements.txt @@ -0,0 +1,4 @@ +pytest~=4.6.7 # needed for python 2.7+3.4 +pytest-cov>=2.8.1 +pytest-randomly==1.2.3 # needed for python 2.7+3.4 +flask_testing==0.6.1 \ No newline at end of file diff --git a/samples/server/petstore/python-flask-openapi/tox.ini b/samples/server/petstore/python-flask-openapi/tox.ini new file mode 100644 index 000000000000..cff71191e6cb --- /dev/null +++ b/samples/server/petstore/python-flask-openapi/tox.ini @@ -0,0 +1,9 @@ +[tox] +envlist = py3 + +[testenv] +deps=-r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt + +commands= + pytest --cov=openapi_server \ No newline at end of file From a24a4dabd6d68f5eee4c9607892a01c9b542b759 Mon Sep 17 00:00:00 2001 From: Justin Busschau Date: Thu, 20 Feb 2020 19:59:51 +0000 Subject: [PATCH 3/5] updated requirements file in samples --- samples/server/petstore/python-flask-python2/requirements.txt | 2 +- samples/server/petstore/python-flask/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/server/petstore/python-flask-python2/requirements.txt b/samples/server/petstore/python-flask-python2/requirements.txt index 5c5ce2a1a269..47350085aa10 100644 --- a/samples/server/petstore/python-flask-python2/requirements.txt +++ b/samples/server/petstore/python-flask-python2/requirements.txt @@ -1,4 +1,4 @@ -connexion >= 2.5.0; python_version>="3.6" +connexion >= 2.6.0; python_version>="3.6" connexion >= 2.3.0; python_version=="3.5" connexion >= 2.3.0; python_version=="3.4" connexion == 2.4.0; python_version<="2.7" diff --git a/samples/server/petstore/python-flask/requirements.txt b/samples/server/petstore/python-flask/requirements.txt index 029a9dae4cdf..2639eedf1361 100644 --- a/samples/server/petstore/python-flask/requirements.txt +++ b/samples/server/petstore/python-flask/requirements.txt @@ -1,4 +1,4 @@ -connexion >= 2.5.0; python_version>="3.6" +connexion >= 2.6.0; python_version>="3.6" connexion >= 2.3.0; python_version=="3.5" connexion >= 2.3.0; python_version=="3.4" connexion == 2.4.0; python_version<="2.7" From b141d2535ec848b5befd9e37741409ec5f7917f1 Mon Sep 17 00:00:00 2001 From: Justin Busschau Date: Fri, 21 Feb 2020 10:35:15 +0000 Subject: [PATCH 4/5] Update spec to explicitly name objects and prevent `inline_object` --- .../petstore-with-object-as-parameter.yaml | 73 ++++++++++----- .../controllers/pet_controller.py | 22 +++-- .../controllers/user_controller.py | 4 +- .../openapi_server/models/__init__.py | 4 +- .../models/{inline_object.py => pet_form.py} | 34 ++++--- .../{inline_object1.py => upload_form.py} | 32 ++++--- .../openapi_server/openapi/openapi.yaml | 92 +++++++++---------- .../test/test_pet_controller.py | 12 +-- 8 files changed, 148 insertions(+), 125 deletions(-) rename samples/server/petstore/python-flask-openapi/openapi_server/models/{inline_object.py => pet_form.py} (62%) rename samples/server/petstore/python-flask-openapi/openapi_server/models/{inline_object1.py => upload_form.py} (69%) diff --git a/modules/openapi-generator/src/test/resources/3_0/petstore-with-object-as-parameter.yaml b/modules/openapi-generator/src/test/resources/3_0/petstore-with-object-as-parameter.yaml index 5ccae3bf52a2..0cfbd1b0f9d3 100644 --- a/modules/openapi-generator/src/test/resources/3_0/petstore-with-object-as-parameter.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/petstore-with-object-as-parameter.yaml @@ -1,4 +1,4 @@ -openapi: 3.0.0 +openapi: 3.0.1 servers: - url: 'http://petstore.swagger.io/v2' info: @@ -217,17 +217,7 @@ paths: - '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 + $ref: '#/components/requestBodies/PetForm' delete: tags: - pet @@ -281,18 +271,7 @@ paths: - '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 + $ref: '#/components/requestBodies/UploadForm' /store/inventory: get: tags: @@ -588,7 +567,7 @@ components: type: array items: $ref: '#/components/schemas/User' - description: List of user object + description: List of user objects required: true Pet: content: @@ -600,6 +579,22 @@ components: $ref: '#/components/schemas/Pet' description: Pet object that needs to be added to the store required: true + PetForm: + content: + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/PetForm' + example: + name: fluffy + status: available + UploadForm: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/UploadForm' + example: + additionalMetadata: additional metadata example + file: c29tZSB0ZXN0IGRhdGEK securitySchemes: petstore_auth: type: oauth2 @@ -737,6 +732,34 @@ components: - sold xml: name: Pet + PetForm: + title: A pet form + description: A form for updating a pet + type: object + required: + - name + - status + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + UploadForm: + title: An upload form + description: A form for attaching files to a pet + type: object + required: + - file + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + type: string + format: binary ApiResponse: title: An uploaded response description: Describes the result of uploading an image resource diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/pet_controller.py b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/pet_controller.py index 883ac6e5655f..5ae8f380ee38 100644 --- a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/pet_controller.py +++ b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/pet_controller.py @@ -3,7 +3,9 @@ from openapi_server.models.api_response import ApiResponse # noqa: E501 from openapi_server.models.pet import Pet # noqa: E501 +from openapi_server.models.pet_form import PetForm # noqa: E501 from openapi_server.models.status_enum import StatusEnum # noqa: E501 +from openapi_server.models.upload_form import UploadForm # noqa: E501 from openapi_server import util @@ -108,35 +110,35 @@ def update_pet_status_with_enum(pet_id, status): # noqa: E501 return 'do some magic!' -def update_pet_with_form(pet_id, name=None, status=None): # noqa: E501 +def update_pet_with_form(pet_id, pet_form=None): # noqa: E501 """Updates a pet in the store with form data # noqa: E501 :param pet_id: ID of pet that needs to be updated :type pet_id: int - :param name: Updated name of the pet - :type name: str - :param status: Updated status of the pet - :type status: str + :param pet_form: + :type pet_form: dict | bytes :rtype: None """ + if connexion.request.is_json: + pet_form = PetForm.from_dict(connexion.request.get_json()) # noqa: E501 return 'do some magic!' -def upload_file(pet_id, additional_metadata=None, file=None): # noqa: E501 +def upload_file(pet_id, upload_form=None): # noqa: E501 """uploads an image # noqa: E501 :param pet_id: ID of pet to update :type pet_id: int - :param additional_metadata: Additional data to pass to server - :type additional_metadata: str - :param file: file to upload - :type file: str + :param upload_form: + :type upload_form: dict | bytes :rtype: ApiResponse """ + if connexion.request.is_json: + upload_form = UploadForm.from_dict(connexion.request.get_json()) # noqa: E501 return 'do some magic!' diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/user_controller.py b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/user_controller.py index 9b9706262121..e897814d4b0d 100644 --- a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/user_controller.py +++ b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/user_controller.py @@ -25,7 +25,7 @@ def create_users_with_array_input(user): # noqa: E501 # noqa: E501 - :param user: List of user object + :param user: List of user objects :type user: list | bytes :rtype: None @@ -40,7 +40,7 @@ def create_users_with_list_input(user): # noqa: E501 # noqa: E501 - :param user: List of user object + :param user: List of user objects :type user: list | bytes :rtype: None diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/__init__.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/__init__.py index 3788dd080cb1..bb6f70f1569b 100644 --- a/samples/server/petstore/python-flask-openapi/openapi_server/models/__init__.py +++ b/samples/server/petstore/python-flask-openapi/openapi_server/models/__init__.py @@ -5,10 +5,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.inline_object import InlineObject -from openapi_server.models.inline_object1 import InlineObject1 from openapi_server.models.order import Order from openapi_server.models.pet import Pet +from openapi_server.models.pet_form import PetForm from openapi_server.models.status_enum import StatusEnum from openapi_server.models.tag import Tag +from openapi_server.models.upload_form import UploadForm from openapi_server.models.user import User diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/inline_object.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/pet_form.py similarity index 62% rename from samples/server/petstore/python-flask-openapi/openapi_server/models/inline_object.py rename to samples/server/petstore/python-flask-openapi/openapi_server/models/pet_form.py index 1178d560625c..1f682346e4fb 100644 --- a/samples/server/petstore/python-flask-openapi/openapi_server/models/inline_object.py +++ b/samples/server/petstore/python-flask-openapi/openapi_server/models/pet_form.py @@ -9,18 +9,18 @@ from openapi_server import util -class InlineObject(Model): +class PetForm(Model): """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). Do not edit the class manually. """ def __init__(self, name=None, status=None): # noqa: E501 - """InlineObject - a model defined in OpenAPI + """PetForm - a model defined in OpenAPI - :param name: The name of this InlineObject. # noqa: E501 + :param name: The name of this PetForm. # noqa: E501 :type name: str - :param status: The status of this InlineObject. # noqa: E501 + :param status: The status of this PetForm. # noqa: E501 :type status: str """ self.openapi_types = { @@ -37,58 +37,62 @@ def __init__(self, name=None, status=None): # noqa: E501 self._status = status @classmethod - def from_dict(cls, dikt) -> 'InlineObject': + def from_dict(cls, dikt) -> 'PetForm': """Returns the dict as a model :param dikt: A dict. :type: dict - :return: The inline_object of this InlineObject. # noqa: E501 - :rtype: InlineObject + :return: The PetForm of this PetForm. # noqa: E501 + :rtype: PetForm """ return util.deserialize_model(dikt, cls) @property def name(self): - """Gets the name of this InlineObject. + """Gets the name of this PetForm. Updated name of the pet # noqa: E501 - :return: The name of this InlineObject. + :return: The name of this PetForm. :rtype: str """ return self._name @name.setter def name(self, name): - """Sets the name of this InlineObject. + """Sets the name of this PetForm. Updated name of the pet # noqa: E501 - :param name: The name of this InlineObject. + :param name: The name of this PetForm. :type name: str """ + if name is None: + raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 self._name = name @property def status(self): - """Gets the status of this InlineObject. + """Gets the status of this PetForm. Updated status of the pet # noqa: E501 - :return: The status of this InlineObject. + :return: The status of this PetForm. :rtype: str """ return self._status @status.setter def status(self, status): - """Sets the status of this InlineObject. + """Sets the status of this PetForm. Updated status of the pet # noqa: E501 - :param status: The status of this InlineObject. + :param status: The status of this PetForm. :type status: str """ + if status is None: + raise ValueError("Invalid value for `status`, must not be `None`") # noqa: E501 self._status = status diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/inline_object1.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/upload_form.py similarity index 69% rename from samples/server/petstore/python-flask-openapi/openapi_server/models/inline_object1.py rename to samples/server/petstore/python-flask-openapi/openapi_server/models/upload_form.py index 349041c0c8fc..3e566f6837aa 100644 --- a/samples/server/petstore/python-flask-openapi/openapi_server/models/inline_object1.py +++ b/samples/server/petstore/python-flask-openapi/openapi_server/models/upload_form.py @@ -9,18 +9,18 @@ from openapi_server import util -class InlineObject1(Model): +class UploadForm(Model): """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). Do not edit the class manually. """ def __init__(self, additional_metadata=None, file=None): # noqa: E501 - """InlineObject1 - a model defined in OpenAPI + """UploadForm - a model defined in OpenAPI - :param additional_metadata: The additional_metadata of this InlineObject1. # noqa: E501 + :param additional_metadata: The additional_metadata of this UploadForm. # noqa: E501 :type additional_metadata: str - :param file: The file of this InlineObject1. # noqa: E501 + :param file: The file of this UploadForm. # noqa: E501 :type file: file """ self.openapi_types = { @@ -37,34 +37,34 @@ def __init__(self, additional_metadata=None, file=None): # noqa: E501 self._file = file @classmethod - def from_dict(cls, dikt) -> 'InlineObject1': + def from_dict(cls, dikt) -> 'UploadForm': """Returns the dict as a model :param dikt: A dict. :type: dict - :return: The inline_object_1 of this InlineObject1. # noqa: E501 - :rtype: InlineObject1 + :return: The UploadForm of this UploadForm. # noqa: E501 + :rtype: UploadForm """ return util.deserialize_model(dikt, cls) @property def additional_metadata(self): - """Gets the additional_metadata of this InlineObject1. + """Gets the additional_metadata of this UploadForm. Additional data to pass to server # noqa: E501 - :return: The additional_metadata of this InlineObject1. + :return: The additional_metadata of this UploadForm. :rtype: str """ return self._additional_metadata @additional_metadata.setter def additional_metadata(self, additional_metadata): - """Sets the additional_metadata of this InlineObject1. + """Sets the additional_metadata of this UploadForm. Additional data to pass to server # noqa: E501 - :param additional_metadata: The additional_metadata of this InlineObject1. + :param additional_metadata: The additional_metadata of this UploadForm. :type additional_metadata: str """ @@ -72,23 +72,25 @@ def additional_metadata(self, additional_metadata): @property def file(self): - """Gets the file of this InlineObject1. + """Gets the file of this UploadForm. file to upload # noqa: E501 - :return: The file of this InlineObject1. + :return: The file of this UploadForm. :rtype: file """ return self._file @file.setter def file(self, file): - """Sets the file of this InlineObject1. + """Sets the file of this UploadForm. file to upload # noqa: E501 - :param file: The file of this InlineObject1. + :param file: The file of this UploadForm. :type file: file """ + if file is None: + raise ValueError("Invalid value for `file`, must not be `None`") # noqa: E501 self._file = file diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/openapi/openapi.yaml b/samples/server/petstore/python-flask-openapi/openapi_server/openapi/openapi.yaml index e5d1465dccb5..31100fda5278 100644 --- a/samples/server/petstore/python-flask-openapi/openapi_server/openapi/openapi.yaml +++ b/samples/server/petstore/python-flask-openapi/openapi_server/openapi/openapi.yaml @@ -1,4 +1,4 @@ -openapi: 3.0.0 +openapi: 3.0.1 info: description: This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. @@ -254,18 +254,7 @@ paths: type: integer style: simple requestBody: - $ref: '#/components/requestBodies/inline_object' - content: - application/x-www-form-urlencoded: - schema: - properties: - name: - description: Updated name of the pet - type: string - status: - description: Updated status of the pet - type: string - type: object + $ref: '#/components/requestBodies/PetForm' responses: "405": description: Invalid input @@ -291,19 +280,7 @@ paths: type: integer style: simple requestBody: - $ref: '#/components/requestBodies/inline_object_1' - content: - multipart/form-data: - schema: - properties: - additionalMetadata: - description: Additional data to pass to server - type: string - file: - description: file to upload - format: binary - type: string - type: object + $ref: '#/components/requestBodies/UploadForm' responses: "200": content: @@ -645,7 +622,7 @@ components: items: $ref: '#/components/schemas/User' type: array - description: List of user object + description: List of user objects required: true Pet: content: @@ -657,16 +634,22 @@ components: $ref: '#/components/schemas/Pet' description: Pet object that needs to be added to the store required: true - inline_object: + PetForm: content: application/x-www-form-urlencoded: + example: + name: fluffy + status: available schema: - $ref: '#/components/schemas/inline_object' - inline_object_1: + $ref: '#/components/schemas/PetForm' + UploadForm: content: multipart/form-data: + example: + additionalMetadata: additional metadata example + file: c29tZSB0ZXN0IGRhdGEK schema: - $ref: '#/components/schemas/inline_object_1' + $ref: '#/components/schemas/UploadForm' schemas: Order: description: An order for a pets from the pet store @@ -824,6 +807,34 @@ components: type: object xml: name: Pet + PetForm: + description: A form for updating a pet + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + required: + - name + - status + title: A pet form + type: object + UploadForm: + description: A form for attaching files to a pet + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + format: binary + type: string + required: + - file + title: An upload form + type: object ApiResponse: description: Describes the result of uploading an image resource example: @@ -847,25 +858,6 @@ components: - pending - sold type: string - inline_object: - properties: - name: - description: Updated name of the pet - type: string - status: - description: Updated status of the pet - type: string - type: object - inline_object_1: - properties: - additionalMetadata: - description: Additional data to pass to server - type: string - file: - description: file to upload - format: binary - type: string - type: object securitySchemes: petstore_auth: flows: diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/test/test_pet_controller.py b/samples/server/petstore/python-flask-openapi/openapi_server/test/test_pet_controller.py index 3a40329cdc82..2e9944b3cc33 100644 --- a/samples/server/petstore/python-flask-openapi/openapi_server/test/test_pet_controller.py +++ b/samples/server/petstore/python-flask-openapi/openapi_server/test/test_pet_controller.py @@ -8,7 +8,9 @@ from openapi_server.models.api_response import ApiResponse # noqa: E501 from openapi_server.models.pet import Pet # noqa: E501 +from openapi_server.models.pet_form import PetForm # noqa: E501 from openapi_server.models.status_enum import StatusEnum # noqa: E501 +from openapi_server.models.upload_form import UploadForm # noqa: E501 from openapi_server.test import BaseTestCase @@ -178,17 +180,16 @@ def test_update_pet_with_form(self): Updates a pet in the store with form data """ + pet_form = {"name":"fluffy","status":"available"} headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Bearer special-key', } - data = dict(name='name_example', - status='status_example') response = self.client.open( '/v2/pet/{pet_id}'.format(pet_id=56), method='POST', headers=headers, - data=data, + data=json.dumps(pet_form), content_type='application/x-www-form-urlencoded') self.assert200(response, 'Response body is : ' + response.data.decode('utf-8')) @@ -199,18 +200,17 @@ def test_upload_file(self): uploads an image """ + upload_form = {"additionalMetadata":"additional metadata example","file":"c29tZSB0ZXN0IGRhdGEK"} headers = { 'Accept': 'application/json', 'Content-Type': 'multipart/form-data', 'Authorization': 'Bearer special-key', } - data = dict(additional_metadata='additional_metadata_example', - file=(BytesIO(b'some file data'), 'file.txt')) response = self.client.open( '/v2/pet/{pet_id}/uploadImage'.format(pet_id=56), method='POST', headers=headers, - data=data, + data=json.dumps(upload_form), content_type='multipart/form-data') self.assert200(response, 'Response body is : ' + response.data.decode('utf-8')) From aa66efcbec65d860708d558e6f0fb151959fe832 Mon Sep 17 00:00:00 2001 From: Justin Busschau Date: Sat, 22 Feb 2020 17:35:51 +0000 Subject: [PATCH 5/5] use the correct scripts to generate samples (`bin/openapi3/python-flask*`) --- bin/openapi3/python-flask-petstore-python2.sh | 2 +- bin/openapi3/python-flask-petstore.sh | 2 +- bin/python-server-all.sh | 1 - bin/python-server-flask-petstore-openapi.sh | 50 - .../controllers/pet_controller.py | 40 +- .../controllers/user_controller.py | 4 +- .../openapi_server/models/__init__.py | 5 +- .../models/{inline_object.py => pet_form.py} | 32 +- .../openapi_server/models/status_enum.py | 43 + .../{inline_object1.py => upload_form.py} | 30 +- .../openapi_server/openapi/openapi.yaml | 147 ++- .../test/test_pet_controller.py | 30 +- .../python-flask-python2/requirements.txt | 2 +- .../controllers/pet_controller.py | 40 +- .../controllers/user_controller.py | 4 +- .../openapi_server/models/__init__.py | 5 +- .../openapi_server/models/inline_object.py | 94 -- .../openapi_server/models/inline_object1.py | 94 -- .../openapi_server/models/pet_form.py | 0 .../openapi_server/models/status_enum.py | 0 .../openapi_server/models/upload_form.py | 0 .../openapi_server/openapi/openapi.yaml | 147 ++- .../test/test_pet_controller.py | 30 +- .../petstore/python-flask/requirements.txt | 2 +- .../python-flask-openapi/.dockerignore | 72 -- .../petstore/python-flask-openapi/.gitignore | 66 -- .../.openapi-generator-ignore | 23 - .../.openapi-generator/VERSION | 1 - .../petstore/python-flask-openapi/.travis.yml | 14 - .../petstore/python-flask-openapi/Dockerfile | 16 - .../petstore/python-flask-openapi/README.md | 49 - .../petstore/python-flask-openapi/git_push.sh | 58 -- .../openapi_server/__init__.py | 0 .../openapi_server/__main__.py | 18 - .../openapi_server/controllers/__init__.py | 0 .../controllers/pet_controller.py | 144 --- .../controllers/security_controller_.py | 64 -- .../controllers/store_controller.py | 57 -- .../controllers/user_controller.py | 119 --- .../openapi_server/encoder.py | 20 - .../openapi_server/models/__init__.py | 14 - .../openapi_server/models/api_response.py | 116 --- .../openapi_server/models/base_model_.py | 69 -- .../openapi_server/models/category.py | 94 -- .../openapi_server/models/order.py | 202 ---- .../openapi_server/models/pet.py | 210 ----- .../openapi_server/models/tag.py | 90 -- .../openapi_server/models/user.py | 248 ----- .../openapi_server/openapi/openapi.yaml | 881 ------------------ .../openapi_server/test/__init__.py | 16 - .../test/test_pet_controller.py | 220 ----- .../test/test_store_controller.py | 89 -- .../test/test_user_controller.py | 193 ---- .../openapi_server/typing_utils.py | 32 - .../openapi_server/util.py | 142 --- .../python-flask-openapi/requirements.txt | 7 - .../petstore/python-flask-openapi/setup.py | 39 - .../test-requirements.txt | 4 - .../petstore/python-flask-openapi/tox.ini | 9 - 59 files changed, 395 insertions(+), 3805 deletions(-) delete mode 100755 bin/python-server-flask-petstore-openapi.sh rename samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/{inline_object.py => pet_form.py} (64%) create mode 100644 samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/status_enum.py rename samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/{inline_object1.py => upload_form.py} (71%) delete mode 100644 samples/openapi3/server/petstore/python-flask/openapi_server/models/inline_object.py delete mode 100644 samples/openapi3/server/petstore/python-flask/openapi_server/models/inline_object1.py rename samples/{server/petstore/python-flask-openapi => openapi3/server/petstore/python-flask}/openapi_server/models/pet_form.py (100%) rename samples/{server/petstore/python-flask-openapi => openapi3/server/petstore/python-flask}/openapi_server/models/status_enum.py (100%) rename samples/{server/petstore/python-flask-openapi => openapi3/server/petstore/python-flask}/openapi_server/models/upload_form.py (100%) delete mode 100644 samples/server/petstore/python-flask-openapi/.dockerignore delete mode 100644 samples/server/petstore/python-flask-openapi/.gitignore delete mode 100644 samples/server/petstore/python-flask-openapi/.openapi-generator-ignore delete mode 100644 samples/server/petstore/python-flask-openapi/.openapi-generator/VERSION delete mode 100644 samples/server/petstore/python-flask-openapi/.travis.yml delete mode 100644 samples/server/petstore/python-flask-openapi/Dockerfile delete mode 100644 samples/server/petstore/python-flask-openapi/README.md delete mode 100644 samples/server/petstore/python-flask-openapi/git_push.sh delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/__init__.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/__main__.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/controllers/__init__.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/controllers/pet_controller.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/controllers/security_controller_.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/controllers/store_controller.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/controllers/user_controller.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/encoder.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/__init__.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/api_response.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/base_model_.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/category.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/order.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/pet.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/tag.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/models/user.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/openapi/openapi.yaml delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/test/__init__.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/test/test_pet_controller.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/test/test_store_controller.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/test/test_user_controller.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/typing_utils.py delete mode 100644 samples/server/petstore/python-flask-openapi/openapi_server/util.py delete mode 100644 samples/server/petstore/python-flask-openapi/requirements.txt delete mode 100644 samples/server/petstore/python-flask-openapi/setup.py delete mode 100644 samples/server/petstore/python-flask-openapi/test-requirements.txt delete mode 100644 samples/server/petstore/python-flask-openapi/tox.ini diff --git a/bin/openapi3/python-flask-petstore-python2.sh b/bin/openapi3/python-flask-petstore-python2.sh index e33183e3a218..b9afa34fcd63 100755 --- a/bin/openapi3/python-flask-petstore-python2.sh +++ b/bin/openapi3/python-flask-petstore-python2.sh @@ -26,7 +26,7 @@ then fi # if you've executed sbt assembly previously it will use that instead. -input=modules/openapi-generator/src/test/resources/3_0/petstore.yaml +input=modules/openapi-generator/src/test/resources/3_0/petstore-with-object-as-parameter.yaml out_folder=samples/openapi3/server/petstore/python-flask-python2 resources=modules/openapi-generator/src/main/resources/python-flask diff --git a/bin/openapi3/python-flask-petstore.sh b/bin/openapi3/python-flask-petstore.sh index b2422ba069b3..6b0f03aa3d28 100755 --- a/bin/openapi3/python-flask-petstore.sh +++ b/bin/openapi3/python-flask-petstore.sh @@ -26,7 +26,7 @@ then fi # if you've executed sbt assembly previously it will use that instead. -input=modules/openapi-generator/src/test/resources/3_0/petstore.yaml +input=modules/openapi-generator/src/test/resources/3_0/petstore-with-object-as-parameter.yaml out_folder=samples/openapi3/server/petstore/python-flask resources=modules/openapi-generator/src/main/resources/python-flask diff --git a/bin/python-server-all.sh b/bin/python-server-all.sh index 8d0b9b4424a6..5fe3176eed9e 100755 --- a/bin/python-server-all.sh +++ b/bin/python-server-all.sh @@ -3,5 +3,4 @@ ./bin/python-server-aiohttp-petstore.sh ./bin/python-server-flask-petstore.sh ./bin/python-server-flask-petstore-python2.sh -./bin/python-server-flask-petstore-openapi.sh ./bin/python-server-blueplanet-petstore.sh diff --git a/bin/python-server-flask-petstore-openapi.sh b/bin/python-server-flask-petstore-openapi.sh deleted file mode 100755 index fc432d4aeda9..000000000000 --- a/bin/python-server-flask-petstore-openapi.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/sh - -SCRIPT="$0" -echo "# START SCRIPT: $SCRIPT" - -while [ -h "$SCRIPT" ] ; do - ls=`ls -ld "$SCRIPT"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - SCRIPT="$link" - else - SCRIPT=`dirname "$SCRIPT"`/"$link" - fi -done - -if [ ! -d "${APP_DIR}" ]; then - APP_DIR=`dirname "$SCRIPT"`/.. - APP_DIR=`cd "${APP_DIR}"; pwd` -fi - -executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" - -if [ ! -f "$executable" ] -then - mvn -B clean package -fi - -generator=python-flask -input=modules/openapi-generator/src/test/resources/3_0/petstore-with-object-as-parameter.yaml -out_folder=samples/server/petstore/$generator-openapi -resources=modules/openapi-generator/src/main/resources/$generator - -# if you've executed sbt assembly previously it will use that instead. -export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties -Dservice" -ags="generate -t $resources -i $input -g $generator -o $out_folder $@" - -rm -rf $out_folder/.openapi* -rm -rf $out_folder/openapi_server -rm $out_folder/.dockerignore -rm $out_folder/.gitignore -rm $out_folder/.travis.yml -rm $out_folder/Dockerfile -rm $out_folder/git_push.sh -rm $out_folder/README.md -rm $out_folder/requirements.txt -rm $out_folder/setup.py -rm $out_folder/test-requirements.txt -rm $out_folder/tox.ini - -java $JAVA_OPTS -jar $executable $ags diff --git a/samples/openapi3/server/petstore/python-flask-python2/openapi_server/controllers/pet_controller.py b/samples/openapi3/server/petstore/python-flask-python2/openapi_server/controllers/pet_controller.py index 125820f00549..5ae8f380ee38 100644 --- a/samples/openapi3/server/petstore/python-flask-python2/openapi_server/controllers/pet_controller.py +++ b/samples/openapi3/server/petstore/python-flask-python2/openapi_server/controllers/pet_controller.py @@ -3,6 +3,9 @@ from openapi_server.models.api_response import ApiResponse # noqa: E501 from openapi_server.models.pet import Pet # noqa: E501 +from openapi_server.models.pet_form import PetForm # noqa: E501 +from openapi_server.models.status_enum import StatusEnum # noqa: E501 +from openapi_server.models.upload_form import UploadForm # noqa: E501 from openapi_server import util @@ -90,35 +93,52 @@ def update_pet(pet): # noqa: E501 return 'do some magic!' -def update_pet_with_form(pet_id, name=None, status=None): # noqa: E501 +def update_pet_status_with_enum(pet_id, status): # noqa: E501 + """Set the status of a pet in the store using an enum + + # noqa: E501 + + :param pet_id: ID of pet to return + :type pet_id: int + :param status: The required status + :type status: dict | bytes + + :rtype: Pet + """ + if connexion.request.is_json: + status = StatusEnum.from_dict(connexion.request.get_json()) # noqa: E501 + return 'do some magic!' + + +def update_pet_with_form(pet_id, pet_form=None): # noqa: E501 """Updates a pet in the store with form data # noqa: E501 :param pet_id: ID of pet that needs to be updated :type pet_id: int - :param name: Updated name of the pet - :type name: str - :param status: Updated status of the pet - :type status: str + :param pet_form: + :type pet_form: dict | bytes :rtype: None """ + if connexion.request.is_json: + pet_form = PetForm.from_dict(connexion.request.get_json()) # noqa: E501 return 'do some magic!' -def upload_file(pet_id, additional_metadata=None, file=None): # noqa: E501 +def upload_file(pet_id, upload_form=None): # noqa: E501 """uploads an image # noqa: E501 :param pet_id: ID of pet to update :type pet_id: int - :param additional_metadata: Additional data to pass to server - :type additional_metadata: str - :param file: file to upload - :type file: str + :param upload_form: + :type upload_form: dict | bytes :rtype: ApiResponse """ + if connexion.request.is_json: + upload_form = UploadForm.from_dict(connexion.request.get_json()) # noqa: E501 return 'do some magic!' diff --git a/samples/openapi3/server/petstore/python-flask-python2/openapi_server/controllers/user_controller.py b/samples/openapi3/server/petstore/python-flask-python2/openapi_server/controllers/user_controller.py index 9b9706262121..e897814d4b0d 100644 --- a/samples/openapi3/server/petstore/python-flask-python2/openapi_server/controllers/user_controller.py +++ b/samples/openapi3/server/petstore/python-flask-python2/openapi_server/controllers/user_controller.py @@ -25,7 +25,7 @@ def create_users_with_array_input(user): # noqa: E501 # noqa: E501 - :param user: List of user object + :param user: List of user objects :type user: list | bytes :rtype: None @@ -40,7 +40,7 @@ def create_users_with_list_input(user): # noqa: E501 # noqa: E501 - :param user: List of user object + :param user: List of user objects :type user: list | bytes :rtype: None diff --git a/samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/__init__.py b/samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/__init__.py index 689233630d14..bb6f70f1569b 100644 --- a/samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/__init__.py +++ b/samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/__init__.py @@ -5,9 +5,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.inline_object import InlineObject -from openapi_server.models.inline_object1 import InlineObject1 from openapi_server.models.order import Order from openapi_server.models.pet import Pet +from openapi_server.models.pet_form import PetForm +from openapi_server.models.status_enum import StatusEnum from openapi_server.models.tag import Tag +from openapi_server.models.upload_form import UploadForm from openapi_server.models.user import User diff --git a/samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/inline_object.py b/samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/pet_form.py similarity index 64% rename from samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/inline_object.py rename to samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/pet_form.py index f8fe9cb4af8f..0eac9c1c2696 100644 --- a/samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/inline_object.py +++ b/samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/pet_form.py @@ -9,18 +9,18 @@ from openapi_server import util -class InlineObject(Model): +class PetForm(Model): """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). Do not edit the class manually. """ def __init__(self, name=None, status=None): # noqa: E501 - """InlineObject - a model defined in OpenAPI + """PetForm - a model defined in OpenAPI - :param name: The name of this InlineObject. # noqa: E501 + :param name: The name of this PetForm. # noqa: E501 :type name: str - :param status: The status of this InlineObject. # noqa: E501 + :param status: The status of this PetForm. # noqa: E501 :type status: str """ self.openapi_types = { @@ -42,53 +42,57 @@ def from_dict(cls, dikt): :param dikt: A dict. :type: dict - :return: The inline_object of this InlineObject. # noqa: E501 - :rtype: InlineObject + :return: The PetForm of this PetForm. # noqa: E501 + :rtype: PetForm """ return util.deserialize_model(dikt, cls) @property def name(self): - """Gets the name of this InlineObject. + """Gets the name of this PetForm. Updated name of the pet # noqa: E501 - :return: The name of this InlineObject. + :return: The name of this PetForm. :rtype: str """ return self._name @name.setter def name(self, name): - """Sets the name of this InlineObject. + """Sets the name of this PetForm. Updated name of the pet # noqa: E501 - :param name: The name of this InlineObject. + :param name: The name of this PetForm. :type name: str """ + if name is None: + raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 self._name = name @property def status(self): - """Gets the status of this InlineObject. + """Gets the status of this PetForm. Updated status of the pet # noqa: E501 - :return: The status of this InlineObject. + :return: The status of this PetForm. :rtype: str """ return self._status @status.setter def status(self, status): - """Sets the status of this InlineObject. + """Sets the status of this PetForm. Updated status of the pet # noqa: E501 - :param status: The status of this InlineObject. + :param status: The status of this PetForm. :type status: str """ + if status is None: + raise ValueError("Invalid value for `status`, must not be `None`") # noqa: E501 self._status = status diff --git a/samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/status_enum.py b/samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/status_enum.py new file mode 100644 index 000000000000..08bebbe6242f --- /dev/null +++ b/samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/status_enum.py @@ -0,0 +1,43 @@ +# coding: utf-8 + +from __future__ import absolute_import +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from openapi_server.models.base_model_ import Model +from openapi_server import util + + +class StatusEnum(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + """ + allowed enum values + """ + AVAILABLE = "available" + PENDING = "pending" + SOLD = "sold" + def __init__(self): # noqa: E501 + """StatusEnum - a model defined in OpenAPI + + """ + self.openapi_types = { + } + + self.attribute_map = { + } + + @classmethod + def from_dict(cls, dikt): + """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) diff --git a/samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/inline_object1.py b/samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/upload_form.py similarity index 71% rename from samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/inline_object1.py rename to samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/upload_form.py index a3517cf57982..7e91468ae988 100644 --- a/samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/inline_object1.py +++ b/samples/openapi3/server/petstore/python-flask-python2/openapi_server/models/upload_form.py @@ -9,18 +9,18 @@ from openapi_server import util -class InlineObject1(Model): +class UploadForm(Model): """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). Do not edit the class manually. """ def __init__(self, additional_metadata=None, file=None): # noqa: E501 - """InlineObject1 - a model defined in OpenAPI + """UploadForm - a model defined in OpenAPI - :param additional_metadata: The additional_metadata of this InlineObject1. # noqa: E501 + :param additional_metadata: The additional_metadata of this UploadForm. # noqa: E501 :type additional_metadata: str - :param file: The file of this InlineObject1. # noqa: E501 + :param file: The file of this UploadForm. # noqa: E501 :type file: file """ self.openapi_types = { @@ -42,29 +42,29 @@ def from_dict(cls, dikt): :param dikt: A dict. :type: dict - :return: The inline_object_1 of this InlineObject1. # noqa: E501 - :rtype: InlineObject1 + :return: The UploadForm of this UploadForm. # noqa: E501 + :rtype: UploadForm """ return util.deserialize_model(dikt, cls) @property def additional_metadata(self): - """Gets the additional_metadata of this InlineObject1. + """Gets the additional_metadata of this UploadForm. Additional data to pass to server # noqa: E501 - :return: The additional_metadata of this InlineObject1. + :return: The additional_metadata of this UploadForm. :rtype: str """ return self._additional_metadata @additional_metadata.setter def additional_metadata(self, additional_metadata): - """Sets the additional_metadata of this InlineObject1. + """Sets the additional_metadata of this UploadForm. Additional data to pass to server # noqa: E501 - :param additional_metadata: The additional_metadata of this InlineObject1. + :param additional_metadata: The additional_metadata of this UploadForm. :type additional_metadata: str """ @@ -72,23 +72,25 @@ def additional_metadata(self, additional_metadata): @property def file(self): - """Gets the file of this InlineObject1. + """Gets the file of this UploadForm. file to upload # noqa: E501 - :return: The file of this InlineObject1. + :return: The file of this UploadForm. :rtype: file """ return self._file @file.setter def file(self, file): - """Sets the file of this InlineObject1. + """Sets the file of this UploadForm. file to upload # noqa: E501 - :param file: The file of this InlineObject1. + :param file: The file of this UploadForm. :type file: file """ + if file is None: + raise ValueError("Invalid value for `file`, must not be `None`") # noqa: E501 self._file = file diff --git a/samples/openapi3/server/petstore/python-flask-python2/openapi_server/openapi/openapi.yaml b/samples/openapi3/server/petstore/python-flask-python2/openapi_server/openapi/openapi.yaml index 922e0b4af696..31100fda5278 100644 --- a/samples/openapi3/server/petstore/python-flask-python2/openapi_server/openapi/openapi.yaml +++ b/samples/openapi3/server/petstore/python-flask-python2/openapi_server/openapi/openapi.yaml @@ -1,4 +1,4 @@ -openapi: 3.0.0 +openapi: 3.0.1 info: description: This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. @@ -202,6 +202,45 @@ paths: tags: - pet x-openapi-router-controller: openapi_server.controllers.pet_controller + patch: + operationId: update_pet_status_with_enum + parameters: + - description: ID of pet to return + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + - description: The required status + example: pending + explode: true + in: query + name: status + required: true + schema: + $ref: '#/components/schemas/statusEnum' + style: form + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation + "400": + description: Invalid ID supplied + "404": + description: Pet not found + summary: Set the status of a pet in the store using an enum + tags: + - pet + x-openapi-router-controller: openapi_server.controllers.pet_controller post: operationId: update_pet_with_form parameters: @@ -215,18 +254,7 @@ paths: type: integer style: simple requestBody: - $ref: '#/components/requestBodies/inline_object' - content: - application/x-www-form-urlencoded: - schema: - properties: - name: - description: Updated name of the pet - type: string - status: - description: Updated status of the pet - type: string - type: object + $ref: '#/components/requestBodies/PetForm' responses: "405": description: Invalid input @@ -252,19 +280,7 @@ paths: type: integer style: simple requestBody: - $ref: '#/components/requestBodies/inline_object_1' - content: - multipart/form-data: - schema: - properties: - additionalMetadata: - description: Additional data to pass to server - type: string - file: - description: file to upload - format: binary - type: string - type: object + $ref: '#/components/requestBodies/UploadForm' responses: "200": content: @@ -587,6 +603,17 @@ paths: - user x-openapi-router-controller: openapi_server.controllers.user_controller components: + parameters: + statusEnum: + description: The required status + example: pending + explode: true + in: query + name: status + required: true + schema: + $ref: '#/components/schemas/statusEnum' + style: form requestBodies: UserArray: content: @@ -595,7 +622,7 @@ components: items: $ref: '#/components/schemas/User' type: array - description: List of user object + description: List of user objects required: true Pet: content: @@ -607,16 +634,22 @@ components: $ref: '#/components/schemas/Pet' description: Pet object that needs to be added to the store required: true - inline_object: + PetForm: content: application/x-www-form-urlencoded: + example: + name: fluffy + status: available schema: - $ref: '#/components/schemas/inline_object' - inline_object_1: + $ref: '#/components/schemas/PetForm' + UploadForm: content: multipart/form-data: + example: + additionalMetadata: additional metadata example + file: c29tZSB0ZXN0IGRhdGEK schema: - $ref: '#/components/schemas/inline_object_1' + $ref: '#/components/schemas/UploadForm' schemas: Order: description: An order for a pets from the pet store @@ -774,23 +807,8 @@ components: type: object xml: name: Pet - ApiResponse: - description: Describes the result of uploading an image resource - example: - code: 0 - type: type - message: message - properties: - code: - format: int32 - type: integer - type: - type: string - message: - type: string - title: An uploaded response - type: object - inline_object: + PetForm: + description: A form for updating a pet properties: name: description: Updated name of the pet @@ -798,8 +816,13 @@ components: status: description: Updated status of the pet type: string + required: + - name + - status + title: A pet form type: object - inline_object_1: + UploadForm: + description: A form for attaching files to a pet properties: additionalMetadata: description: Additional data to pass to server @@ -808,7 +831,33 @@ components: description: file to upload format: binary type: string + required: + - file + title: An upload form + type: object + ApiResponse: + description: Describes the result of uploading an image resource + example: + code: 0 + type: type + message: message + properties: + code: + format: int32 + type: integer + type: + type: string + message: + type: string + title: An uploaded response type: object + statusEnum: + description: pet status in the store + enum: + - available + - pending + - sold + type: string securitySchemes: petstore_auth: flows: diff --git a/samples/openapi3/server/petstore/python-flask-python2/openapi_server/test/test_pet_controller.py b/samples/openapi3/server/petstore/python-flask-python2/openapi_server/test/test_pet_controller.py index 230ac4a4b607..6c031e9f4b10 100644 --- a/samples/openapi3/server/petstore/python-flask-python2/openapi_server/test/test_pet_controller.py +++ b/samples/openapi3/server/petstore/python-flask-python2/openapi_server/test/test_pet_controller.py @@ -8,6 +8,9 @@ from openapi_server.models.api_response import ApiResponse # noqa: E501 from openapi_server.models.pet import Pet # noqa: E501 +from openapi_server.models.pet_form import PetForm # noqa: E501 +from openapi_server.models.status_enum import StatusEnum # noqa: E501 +from openapi_server.models.upload_form import UploadForm # noqa: E501 from openapi_server.test import BaseTestCase @@ -154,23 +157,39 @@ def test_update_pet(self): self.assert200(response, 'Response body is : ' + response.data.decode('utf-8')) + def test_update_pet_status_with_enum(self): + """Test case for update_pet_status_with_enum + + Set the status of a pet in the store using an enum + """ + query_string = [('status', pending)] + headers = { + 'Accept': 'application/json', + } + response = self.client.open( + '/v2/pet/{pet_id}'.format(pet_id=789), + method='PATCH', + headers=headers, + query_string=query_string) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + @unittest.skip("application/x-www-form-urlencoded not supported by Connexion") def test_update_pet_with_form(self): """Test case for update_pet_with_form Updates a pet in the store with form data """ + pet_form = {"name":"fluffy","status":"available"} headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Bearer special-key', } - data = dict(name='name_example', - status='status_example') response = self.client.open( '/v2/pet/{pet_id}'.format(pet_id=789), method='POST', headers=headers, - data=data, + data=json.dumps(pet_form), content_type='application/x-www-form-urlencoded') self.assert200(response, 'Response body is : ' + response.data.decode('utf-8')) @@ -181,18 +200,17 @@ def test_upload_file(self): uploads an image """ + upload_form = {"additionalMetadata":"additional metadata example","file":"c29tZSB0ZXN0IGRhdGEK"} headers = { 'Accept': 'application/json', 'Content-Type': 'multipart/form-data', 'Authorization': 'Bearer special-key', } - data = dict(additional_metadata='additional_metadata_example', - file=(BytesIO(b'some file data'), 'file.txt')) response = self.client.open( '/v2/pet/{pet_id}/uploadImage'.format(pet_id=789), method='POST', headers=headers, - data=data, + data=json.dumps(upload_form), content_type='multipart/form-data') self.assert200(response, 'Response body is : ' + response.data.decode('utf-8')) diff --git a/samples/openapi3/server/petstore/python-flask-python2/requirements.txt b/samples/openapi3/server/petstore/python-flask-python2/requirements.txt index 5c5ce2a1a269..47350085aa10 100644 --- a/samples/openapi3/server/petstore/python-flask-python2/requirements.txt +++ b/samples/openapi3/server/petstore/python-flask-python2/requirements.txt @@ -1,4 +1,4 @@ -connexion >= 2.5.0; python_version>="3.6" +connexion >= 2.6.0; python_version>="3.6" connexion >= 2.3.0; python_version=="3.5" connexion >= 2.3.0; python_version=="3.4" connexion == 2.4.0; python_version<="2.7" diff --git a/samples/openapi3/server/petstore/python-flask/openapi_server/controllers/pet_controller.py b/samples/openapi3/server/petstore/python-flask/openapi_server/controllers/pet_controller.py index 125820f00549..5ae8f380ee38 100644 --- a/samples/openapi3/server/petstore/python-flask/openapi_server/controllers/pet_controller.py +++ b/samples/openapi3/server/petstore/python-flask/openapi_server/controllers/pet_controller.py @@ -3,6 +3,9 @@ from openapi_server.models.api_response import ApiResponse # noqa: E501 from openapi_server.models.pet import Pet # noqa: E501 +from openapi_server.models.pet_form import PetForm # noqa: E501 +from openapi_server.models.status_enum import StatusEnum # noqa: E501 +from openapi_server.models.upload_form import UploadForm # noqa: E501 from openapi_server import util @@ -90,35 +93,52 @@ def update_pet(pet): # noqa: E501 return 'do some magic!' -def update_pet_with_form(pet_id, name=None, status=None): # noqa: E501 +def update_pet_status_with_enum(pet_id, status): # noqa: E501 + """Set the status of a pet in the store using an enum + + # noqa: E501 + + :param pet_id: ID of pet to return + :type pet_id: int + :param status: The required status + :type status: dict | bytes + + :rtype: Pet + """ + if connexion.request.is_json: + status = StatusEnum.from_dict(connexion.request.get_json()) # noqa: E501 + return 'do some magic!' + + +def update_pet_with_form(pet_id, pet_form=None): # noqa: E501 """Updates a pet in the store with form data # noqa: E501 :param pet_id: ID of pet that needs to be updated :type pet_id: int - :param name: Updated name of the pet - :type name: str - :param status: Updated status of the pet - :type status: str + :param pet_form: + :type pet_form: dict | bytes :rtype: None """ + if connexion.request.is_json: + pet_form = PetForm.from_dict(connexion.request.get_json()) # noqa: E501 return 'do some magic!' -def upload_file(pet_id, additional_metadata=None, file=None): # noqa: E501 +def upload_file(pet_id, upload_form=None): # noqa: E501 """uploads an image # noqa: E501 :param pet_id: ID of pet to update :type pet_id: int - :param additional_metadata: Additional data to pass to server - :type additional_metadata: str - :param file: file to upload - :type file: str + :param upload_form: + :type upload_form: dict | bytes :rtype: ApiResponse """ + if connexion.request.is_json: + upload_form = UploadForm.from_dict(connexion.request.get_json()) # noqa: E501 return 'do some magic!' diff --git a/samples/openapi3/server/petstore/python-flask/openapi_server/controllers/user_controller.py b/samples/openapi3/server/petstore/python-flask/openapi_server/controllers/user_controller.py index 9b9706262121..e897814d4b0d 100644 --- a/samples/openapi3/server/petstore/python-flask/openapi_server/controllers/user_controller.py +++ b/samples/openapi3/server/petstore/python-flask/openapi_server/controllers/user_controller.py @@ -25,7 +25,7 @@ def create_users_with_array_input(user): # noqa: E501 # noqa: E501 - :param user: List of user object + :param user: List of user objects :type user: list | bytes :rtype: None @@ -40,7 +40,7 @@ def create_users_with_list_input(user): # noqa: E501 # noqa: E501 - :param user: List of user object + :param user: List of user objects :type user: list | bytes :rtype: None diff --git a/samples/openapi3/server/petstore/python-flask/openapi_server/models/__init__.py b/samples/openapi3/server/petstore/python-flask/openapi_server/models/__init__.py index 689233630d14..bb6f70f1569b 100644 --- a/samples/openapi3/server/petstore/python-flask/openapi_server/models/__init__.py +++ b/samples/openapi3/server/petstore/python-flask/openapi_server/models/__init__.py @@ -5,9 +5,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.inline_object import InlineObject -from openapi_server.models.inline_object1 import InlineObject1 from openapi_server.models.order import Order from openapi_server.models.pet import Pet +from openapi_server.models.pet_form import PetForm +from openapi_server.models.status_enum import StatusEnum from openapi_server.models.tag import Tag +from openapi_server.models.upload_form import UploadForm from openapi_server.models.user import User diff --git a/samples/openapi3/server/petstore/python-flask/openapi_server/models/inline_object.py b/samples/openapi3/server/petstore/python-flask/openapi_server/models/inline_object.py deleted file mode 100644 index 1178d560625c..000000000000 --- a/samples/openapi3/server/petstore/python-flask/openapi_server/models/inline_object.py +++ /dev/null @@ -1,94 +0,0 @@ -# coding: utf-8 - -from __future__ import absolute_import -from datetime import date, datetime # noqa: F401 - -from typing import List, Dict # noqa: F401 - -from openapi_server.models.base_model_ import Model -from openapi_server import util - - -class InlineObject(Model): - """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - - Do not edit the class manually. - """ - - def __init__(self, name=None, status=None): # noqa: E501 - """InlineObject - a model defined in OpenAPI - - :param name: The name of this InlineObject. # noqa: E501 - :type name: str - :param status: The status of this InlineObject. # noqa: E501 - :type status: str - """ - self.openapi_types = { - 'name': str, - 'status': str - } - - self.attribute_map = { - 'name': 'name', - 'status': 'status' - } - - self._name = name - self._status = status - - @classmethod - def from_dict(cls, dikt) -> 'InlineObject': - """Returns the dict as a model - - :param dikt: A dict. - :type: dict - :return: The inline_object of this InlineObject. # noqa: E501 - :rtype: InlineObject - """ - return util.deserialize_model(dikt, cls) - - @property - def name(self): - """Gets the name of this InlineObject. - - Updated name of the pet # noqa: E501 - - :return: The name of this InlineObject. - :rtype: str - """ - return self._name - - @name.setter - def name(self, name): - """Sets the name of this InlineObject. - - Updated name of the pet # noqa: E501 - - :param name: The name of this InlineObject. - :type name: str - """ - - self._name = name - - @property - def status(self): - """Gets the status of this InlineObject. - - Updated status of the pet # noqa: E501 - - :return: The status of this InlineObject. - :rtype: str - """ - return self._status - - @status.setter - def status(self, status): - """Sets the status of this InlineObject. - - Updated status of the pet # noqa: E501 - - :param status: The status of this InlineObject. - :type status: str - """ - - self._status = status diff --git a/samples/openapi3/server/petstore/python-flask/openapi_server/models/inline_object1.py b/samples/openapi3/server/petstore/python-flask/openapi_server/models/inline_object1.py deleted file mode 100644 index 349041c0c8fc..000000000000 --- a/samples/openapi3/server/petstore/python-flask/openapi_server/models/inline_object1.py +++ /dev/null @@ -1,94 +0,0 @@ -# coding: utf-8 - -from __future__ import absolute_import -from datetime import date, datetime # noqa: F401 - -from typing import List, Dict # noqa: F401 - -from openapi_server.models.base_model_ import Model -from openapi_server import util - - -class InlineObject1(Model): - """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - - Do not edit the class manually. - """ - - def __init__(self, additional_metadata=None, file=None): # noqa: E501 - """InlineObject1 - a model defined in OpenAPI - - :param additional_metadata: The additional_metadata of this InlineObject1. # noqa: E501 - :type additional_metadata: str - :param file: The file of this InlineObject1. # noqa: E501 - :type file: file - """ - self.openapi_types = { - 'additional_metadata': str, - 'file': file - } - - self.attribute_map = { - 'additional_metadata': 'additionalMetadata', - 'file': 'file' - } - - self._additional_metadata = additional_metadata - self._file = file - - @classmethod - def from_dict(cls, dikt) -> 'InlineObject1': - """Returns the dict as a model - - :param dikt: A dict. - :type: dict - :return: The inline_object_1 of this InlineObject1. # noqa: E501 - :rtype: InlineObject1 - """ - return util.deserialize_model(dikt, cls) - - @property - def additional_metadata(self): - """Gets the additional_metadata of this InlineObject1. - - Additional data to pass to server # noqa: E501 - - :return: The additional_metadata of this InlineObject1. - :rtype: str - """ - return self._additional_metadata - - @additional_metadata.setter - def additional_metadata(self, additional_metadata): - """Sets the additional_metadata of this InlineObject1. - - Additional data to pass to server # noqa: E501 - - :param additional_metadata: The additional_metadata of this InlineObject1. - :type additional_metadata: str - """ - - self._additional_metadata = additional_metadata - - @property - def file(self): - """Gets the file of this InlineObject1. - - file to upload # noqa: E501 - - :return: The file of this InlineObject1. - :rtype: file - """ - return self._file - - @file.setter - def file(self, file): - """Sets the file of this InlineObject1. - - file to upload # noqa: E501 - - :param file: The file of this InlineObject1. - :type file: file - """ - - self._file = file diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/pet_form.py b/samples/openapi3/server/petstore/python-flask/openapi_server/models/pet_form.py similarity index 100% rename from samples/server/petstore/python-flask-openapi/openapi_server/models/pet_form.py rename to samples/openapi3/server/petstore/python-flask/openapi_server/models/pet_form.py diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/status_enum.py b/samples/openapi3/server/petstore/python-flask/openapi_server/models/status_enum.py similarity index 100% rename from samples/server/petstore/python-flask-openapi/openapi_server/models/status_enum.py rename to samples/openapi3/server/petstore/python-flask/openapi_server/models/status_enum.py diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/upload_form.py b/samples/openapi3/server/petstore/python-flask/openapi_server/models/upload_form.py similarity index 100% rename from samples/server/petstore/python-flask-openapi/openapi_server/models/upload_form.py rename to samples/openapi3/server/petstore/python-flask/openapi_server/models/upload_form.py diff --git a/samples/openapi3/server/petstore/python-flask/openapi_server/openapi/openapi.yaml b/samples/openapi3/server/petstore/python-flask/openapi_server/openapi/openapi.yaml index 922e0b4af696..31100fda5278 100644 --- a/samples/openapi3/server/petstore/python-flask/openapi_server/openapi/openapi.yaml +++ b/samples/openapi3/server/petstore/python-flask/openapi_server/openapi/openapi.yaml @@ -1,4 +1,4 @@ -openapi: 3.0.0 +openapi: 3.0.1 info: description: This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. @@ -202,6 +202,45 @@ paths: tags: - pet x-openapi-router-controller: openapi_server.controllers.pet_controller + patch: + operationId: update_pet_status_with_enum + parameters: + - description: ID of pet to return + explode: false + in: path + name: petId + required: true + schema: + format: int64 + type: integer + style: simple + - description: The required status + example: pending + explode: true + in: query + name: status + required: true + schema: + $ref: '#/components/schemas/statusEnum' + style: form + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation + "400": + description: Invalid ID supplied + "404": + description: Pet not found + summary: Set the status of a pet in the store using an enum + tags: + - pet + x-openapi-router-controller: openapi_server.controllers.pet_controller post: operationId: update_pet_with_form parameters: @@ -215,18 +254,7 @@ paths: type: integer style: simple requestBody: - $ref: '#/components/requestBodies/inline_object' - content: - application/x-www-form-urlencoded: - schema: - properties: - name: - description: Updated name of the pet - type: string - status: - description: Updated status of the pet - type: string - type: object + $ref: '#/components/requestBodies/PetForm' responses: "405": description: Invalid input @@ -252,19 +280,7 @@ paths: type: integer style: simple requestBody: - $ref: '#/components/requestBodies/inline_object_1' - content: - multipart/form-data: - schema: - properties: - additionalMetadata: - description: Additional data to pass to server - type: string - file: - description: file to upload - format: binary - type: string - type: object + $ref: '#/components/requestBodies/UploadForm' responses: "200": content: @@ -587,6 +603,17 @@ paths: - user x-openapi-router-controller: openapi_server.controllers.user_controller components: + parameters: + statusEnum: + description: The required status + example: pending + explode: true + in: query + name: status + required: true + schema: + $ref: '#/components/schemas/statusEnum' + style: form requestBodies: UserArray: content: @@ -595,7 +622,7 @@ components: items: $ref: '#/components/schemas/User' type: array - description: List of user object + description: List of user objects required: true Pet: content: @@ -607,16 +634,22 @@ components: $ref: '#/components/schemas/Pet' description: Pet object that needs to be added to the store required: true - inline_object: + PetForm: content: application/x-www-form-urlencoded: + example: + name: fluffy + status: available schema: - $ref: '#/components/schemas/inline_object' - inline_object_1: + $ref: '#/components/schemas/PetForm' + UploadForm: content: multipart/form-data: + example: + additionalMetadata: additional metadata example + file: c29tZSB0ZXN0IGRhdGEK schema: - $ref: '#/components/schemas/inline_object_1' + $ref: '#/components/schemas/UploadForm' schemas: Order: description: An order for a pets from the pet store @@ -774,23 +807,8 @@ components: type: object xml: name: Pet - ApiResponse: - description: Describes the result of uploading an image resource - example: - code: 0 - type: type - message: message - properties: - code: - format: int32 - type: integer - type: - type: string - message: - type: string - title: An uploaded response - type: object - inline_object: + PetForm: + description: A form for updating a pet properties: name: description: Updated name of the pet @@ -798,8 +816,13 @@ components: status: description: Updated status of the pet type: string + required: + - name + - status + title: A pet form type: object - inline_object_1: + UploadForm: + description: A form for attaching files to a pet properties: additionalMetadata: description: Additional data to pass to server @@ -808,7 +831,33 @@ components: description: file to upload format: binary type: string + required: + - file + title: An upload form + type: object + ApiResponse: + description: Describes the result of uploading an image resource + example: + code: 0 + type: type + message: message + properties: + code: + format: int32 + type: integer + type: + type: string + message: + type: string + title: An uploaded response type: object + statusEnum: + description: pet status in the store + enum: + - available + - pending + - sold + type: string securitySchemes: petstore_auth: flows: diff --git a/samples/openapi3/server/petstore/python-flask/openapi_server/test/test_pet_controller.py b/samples/openapi3/server/petstore/python-flask/openapi_server/test/test_pet_controller.py index c756d7bb2ca1..2e9944b3cc33 100644 --- a/samples/openapi3/server/petstore/python-flask/openapi_server/test/test_pet_controller.py +++ b/samples/openapi3/server/petstore/python-flask/openapi_server/test/test_pet_controller.py @@ -8,6 +8,9 @@ from openapi_server.models.api_response import ApiResponse # noqa: E501 from openapi_server.models.pet import Pet # noqa: E501 +from openapi_server.models.pet_form import PetForm # noqa: E501 +from openapi_server.models.status_enum import StatusEnum # noqa: E501 +from openapi_server.models.upload_form import UploadForm # noqa: E501 from openapi_server.test import BaseTestCase @@ -154,23 +157,39 @@ def test_update_pet(self): self.assert200(response, 'Response body is : ' + response.data.decode('utf-8')) + def test_update_pet_status_with_enum(self): + """Test case for update_pet_status_with_enum + + Set the status of a pet in the store using an enum + """ + query_string = [('status', pending)] + headers = { + 'Accept': 'application/json', + } + response = self.client.open( + '/v2/pet/{pet_id}'.format(pet_id=56), + method='PATCH', + headers=headers, + query_string=query_string) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + @unittest.skip("application/x-www-form-urlencoded not supported by Connexion") def test_update_pet_with_form(self): """Test case for update_pet_with_form Updates a pet in the store with form data """ + pet_form = {"name":"fluffy","status":"available"} headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Bearer special-key', } - data = dict(name='name_example', - status='status_example') response = self.client.open( '/v2/pet/{pet_id}'.format(pet_id=56), method='POST', headers=headers, - data=data, + data=json.dumps(pet_form), content_type='application/x-www-form-urlencoded') self.assert200(response, 'Response body is : ' + response.data.decode('utf-8')) @@ -181,18 +200,17 @@ def test_upload_file(self): uploads an image """ + upload_form = {"additionalMetadata":"additional metadata example","file":"c29tZSB0ZXN0IGRhdGEK"} headers = { 'Accept': 'application/json', 'Content-Type': 'multipart/form-data', 'Authorization': 'Bearer special-key', } - data = dict(additional_metadata='additional_metadata_example', - file=(BytesIO(b'some file data'), 'file.txt')) response = self.client.open( '/v2/pet/{pet_id}/uploadImage'.format(pet_id=56), method='POST', headers=headers, - data=data, + data=json.dumps(upload_form), content_type='multipart/form-data') self.assert200(response, 'Response body is : ' + response.data.decode('utf-8')) diff --git a/samples/openapi3/server/petstore/python-flask/requirements.txt b/samples/openapi3/server/petstore/python-flask/requirements.txt index 029a9dae4cdf..2639eedf1361 100644 --- a/samples/openapi3/server/petstore/python-flask/requirements.txt +++ b/samples/openapi3/server/petstore/python-flask/requirements.txt @@ -1,4 +1,4 @@ -connexion >= 2.5.0; python_version>="3.6" +connexion >= 2.6.0; python_version>="3.6" connexion >= 2.3.0; python_version=="3.5" connexion >= 2.3.0; python_version=="3.4" connexion == 2.4.0; python_version<="2.7" diff --git a/samples/server/petstore/python-flask-openapi/.dockerignore b/samples/server/petstore/python-flask-openapi/.dockerignore deleted file mode 100644 index f9619601908b..000000000000 --- a/samples/server/petstore/python-flask-openapi/.dockerignore +++ /dev/null @@ -1,72 +0,0 @@ -.travis.yaml -.openapi-generator-ignore -README.md -tox.ini -git_push.sh -test-requirements.txt -setup.py - -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -env/ -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -*.egg-info/ -.installed.cfg -*.egg - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*,cover -.hypothesis/ -venv/ -.python-version - -# Translations -*.mo -*.pot - -# Django stuff: -*.log - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -#Ipython Notebook -.ipynb_checkpoints diff --git a/samples/server/petstore/python-flask-openapi/.gitignore b/samples/server/petstore/python-flask-openapi/.gitignore deleted file mode 100644 index 43995bd42fa2..000000000000 --- a/samples/server/petstore/python-flask-openapi/.gitignore +++ /dev/null @@ -1,66 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -env/ -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -*.egg-info/ -.installed.cfg -*.egg - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*,cover -.hypothesis/ -venv/ -.venv/ -.python-version -.pytest_cache - -# Translations -*.mo -*.pot - -# Django stuff: -*.log - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -#Ipython Notebook -.ipynb_checkpoints diff --git a/samples/server/petstore/python-flask-openapi/.openapi-generator-ignore b/samples/server/petstore/python-flask-openapi/.openapi-generator-ignore deleted file mode 100644 index 7484ee590a38..000000000000 --- a/samples/server/petstore/python-flask-openapi/.openapi-generator-ignore +++ /dev/null @@ -1,23 +0,0 @@ -# OpenAPI Generator Ignore -# Generated by openapi-generator https://github.com/openapitools/openapi-generator - -# Use this file to prevent files from being overwritten by the generator. -# The patterns follow closely to .gitignore or .dockerignore. - -# As an example, the C# client generator defines ApiClient.cs. -# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: -#ApiClient.cs - -# You can match any string of characters against a directory, file or extension with a single asterisk (*): -#foo/*/qux -# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux - -# You can recursively match patterns against a directory, file or extension with a double asterisk (**): -#foo/**/qux -# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux - -# You can also negate patterns with an exclamation (!). -# For example, you can ignore all files in a docs folder with the file extension .md: -#docs/*.md -# Then explicitly reverse the ignore rule for a single file: -#!docs/README.md diff --git a/samples/server/petstore/python-flask-openapi/.openapi-generator/VERSION b/samples/server/petstore/python-flask-openapi/.openapi-generator/VERSION deleted file mode 100644 index 58592f031f65..000000000000 --- a/samples/server/petstore/python-flask-openapi/.openapi-generator/VERSION +++ /dev/null @@ -1 +0,0 @@ -4.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/python-flask-openapi/.travis.yml b/samples/server/petstore/python-flask-openapi/.travis.yml deleted file mode 100644 index ad71ee5ca083..000000000000 --- a/samples/server/petstore/python-flask-openapi/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -# ref: https://docs.travis-ci.com/user/languages/python -language: python -python: - - "3.2" - - "3.3" - - "3.4" - - "3.5" - - "3.6" - - "3.7" - - "3.8" -# command to install dependencies -install: "pip install -r requirements.txt" -# command to run tests -script: nosetests diff --git a/samples/server/petstore/python-flask-openapi/Dockerfile b/samples/server/petstore/python-flask-openapi/Dockerfile deleted file mode 100644 index 4857637c3799..000000000000 --- a/samples/server/petstore/python-flask-openapi/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM python:3-alpine - -RUN mkdir -p /usr/src/app -WORKDIR /usr/src/app - -COPY requirements.txt /usr/src/app/ - -RUN pip3 install --no-cache-dir -r requirements.txt - -COPY . /usr/src/app - -EXPOSE 8080 - -ENTRYPOINT ["python3"] - -CMD ["-m", "openapi_server"] \ No newline at end of file diff --git a/samples/server/petstore/python-flask-openapi/README.md b/samples/server/petstore/python-flask-openapi/README.md deleted file mode 100644 index 673c8b3b5a01..000000000000 --- a/samples/server/petstore/python-flask-openapi/README.md +++ /dev/null @@ -1,49 +0,0 @@ -# OpenAPI generated server - -## Overview -This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the -[OpenAPI-Spec](https://openapis.org) from a remote server, you can easily generate a server stub. This -is an example of building a OpenAPI-enabled Flask server. - -This example uses the [Connexion](https://github.com/zalando/connexion) library on top of Flask. - -## Requirements -Python 3.5.2+ - -## Usage -To run the server, please execute the following from the root directory: - -``` -pip3 install -r requirements.txt -python3 -m openapi_server -``` - -and open your browser to here: - -``` -http://localhost:8080/v2/ui/ -``` - -Your OpenAPI definition lives here: - -``` -http://localhost:8080/v2/openapi.json -``` - -To launch the integration tests, use tox: -``` -sudo pip install tox -tox -``` - -## Running with Docker - -To run the server on a Docker container, please execute the following from the root directory: - -```bash -# building the image -docker build -t openapi_server . - -# starting up a container -docker run -p 8080:8080 openapi_server -``` \ No newline at end of file diff --git a/samples/server/petstore/python-flask-openapi/git_push.sh b/samples/server/petstore/python-flask-openapi/git_push.sh deleted file mode 100644 index ced3be2b0c7b..000000000000 --- a/samples/server/petstore/python-flask-openapi/git_push.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/sh -# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ -# -# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com" - -git_user_id=$1 -git_repo_id=$2 -release_note=$3 -git_host=$4 - -if [ "$git_host" = "" ]; then - git_host="github.com" - echo "[INFO] No command line input provided. Set \$git_host to $git_host" -fi - -if [ "$git_user_id" = "" ]; then - git_user_id="GIT_USER_ID" - echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" -fi - -if [ "$git_repo_id" = "" ]; then - git_repo_id="GIT_REPO_ID" - echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" -fi - -if [ "$release_note" = "" ]; then - release_note="Minor update" - echo "[INFO] No command line input provided. Set \$release_note to $release_note" -fi - -# Initialize the local directory as a Git repository -git init - -# Adds the files in the local repository and stages them for commit. -git add . - -# Commits the tracked changes and prepares them to be pushed to a remote repository. -git commit -m "$release_note" - -# Sets the new remote -git_remote=`git remote` -if [ "$git_remote" = "" ]; then # git remote not defined - - if [ "$GIT_TOKEN" = "" ]; then - echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." - git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git - else - git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git - fi - -fi - -git pull origin master - -# Pushes (Forces) the changes in the local repository up to the remote repository -echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" -git push origin master 2>&1 | grep -v 'To https' - diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/__init__.py b/samples/server/petstore/python-flask-openapi/openapi_server/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/__main__.py b/samples/server/petstore/python-flask-openapi/openapi_server/__main__.py deleted file mode 100644 index 24b2141e14de..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/__main__.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env python3 - -import connexion - -from openapi_server import encoder - - -def main(): - app = connexion.App(__name__, specification_dir='./openapi/') - app.app.json_encoder = encoder.JSONEncoder - app.add_api('openapi.yaml', - arguments={'title': 'OpenAPI Petstore'}, - pythonic_params=True) - app.run(port=8080) - - -if __name__ == '__main__': - main() diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/__init__.py b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/pet_controller.py b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/pet_controller.py deleted file mode 100644 index 5ae8f380ee38..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/pet_controller.py +++ /dev/null @@ -1,144 +0,0 @@ -import connexion -import six - -from openapi_server.models.api_response import ApiResponse # noqa: E501 -from openapi_server.models.pet import Pet # noqa: E501 -from openapi_server.models.pet_form import PetForm # noqa: E501 -from openapi_server.models.status_enum import StatusEnum # noqa: E501 -from openapi_server.models.upload_form import UploadForm # noqa: E501 -from openapi_server import util - - -def add_pet(pet): # noqa: E501 - """Add a new pet to the store - - # noqa: E501 - - :param pet: Pet object that needs to be added to the store - :type pet: dict | bytes - - :rtype: None - """ - if connexion.request.is_json: - pet = Pet.from_dict(connexion.request.get_json()) # noqa: E501 - return 'do some magic!' - - -def delete_pet(pet_id, api_key=None): # noqa: E501 - """Deletes a pet - - # noqa: E501 - - :param pet_id: Pet id to delete - :type pet_id: int - :param api_key: - :type api_key: str - - :rtype: None - """ - return 'do some magic!' - - -def find_pets_by_status(status): # noqa: E501 - """Finds Pets by status - - Multiple status values can be provided with comma separated strings # noqa: E501 - - :param status: Status values that need to be considered for filter - :type status: List[str] - - :rtype: List[Pet] - """ - return 'do some magic!' - - -def find_pets_by_tags(tags): # noqa: E501 - """Finds Pets by tags - - Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. # noqa: E501 - - :param tags: Tags to filter by - :type tags: List[str] - - :rtype: List[Pet] - """ - return 'do some magic!' - - -def get_pet_by_id(pet_id): # noqa: E501 - """Find pet by ID - - Returns a single pet # noqa: E501 - - :param pet_id: ID of pet to return - :type pet_id: int - - :rtype: Pet - """ - return 'do some magic!' - - -def update_pet(pet): # noqa: E501 - """Update an existing pet - - # noqa: E501 - - :param pet: Pet object that needs to be added to the store - :type pet: dict | bytes - - :rtype: None - """ - if connexion.request.is_json: - pet = Pet.from_dict(connexion.request.get_json()) # noqa: E501 - return 'do some magic!' - - -def update_pet_status_with_enum(pet_id, status): # noqa: E501 - """Set the status of a pet in the store using an enum - - # noqa: E501 - - :param pet_id: ID of pet to return - :type pet_id: int - :param status: The required status - :type status: dict | bytes - - :rtype: Pet - """ - if connexion.request.is_json: - status = StatusEnum.from_dict(connexion.request.get_json()) # noqa: E501 - return 'do some magic!' - - -def update_pet_with_form(pet_id, pet_form=None): # noqa: E501 - """Updates a pet in the store with form data - - # noqa: E501 - - :param pet_id: ID of pet that needs to be updated - :type pet_id: int - :param pet_form: - :type pet_form: dict | bytes - - :rtype: None - """ - if connexion.request.is_json: - pet_form = PetForm.from_dict(connexion.request.get_json()) # noqa: E501 - return 'do some magic!' - - -def upload_file(pet_id, upload_form=None): # noqa: E501 - """uploads an image - - # noqa: E501 - - :param pet_id: ID of pet to update - :type pet_id: int - :param upload_form: - :type upload_form: dict | bytes - - :rtype: ApiResponse - """ - if connexion.request.is_json: - upload_form = UploadForm.from_dict(connexion.request.get_json()) # noqa: E501 - return 'do some magic!' diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/security_controller_.py b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/security_controller_.py deleted file mode 100644 index b4bd85dd1a71..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/security_controller_.py +++ /dev/null @@ -1,64 +0,0 @@ -from typing import List - - -def info_from_api_key(api_key, required_scopes): - """ - Check and retrieve authentication information from api_key. - Returned value will be passed in 'token_info' parameter of your operation function, if there is one. - 'sub' or 'uid' will be set in 'user' parameter of your operation function, if there is one. - - :param api_key API key provided by Authorization header - :type api_key: str - :param required_scopes Always None. Used for other authentication method - :type required_scopes: None - :return: Information attached to provided api_key or None if api_key is invalid or does not allow access to called API - :rtype: dict | None - """ - return {'uid': 'user_id'} - - -def info_from_auth_cookie(api_key, required_scopes): - """ - Check and retrieve authentication information from api_key. - Returned value will be passed in 'token_info' parameter of your operation function, if there is one. - 'sub' or 'uid' will be set in 'user' parameter of your operation function, if there is one. - - :param api_key API key provided by Authorization header - :type api_key: str - :param required_scopes Always None. Used for other authentication method - :type required_scopes: None - :return: Information attached to provided api_key or None if api_key is invalid or does not allow access to called API - :rtype: dict | None - """ - return {'uid': 'user_id'} - - -def info_from_petstore_auth(token): - """ - Validate and decode token. - Returned value will be passed in 'token_info' parameter of your operation function, if there is one. - 'sub' or 'uid' will be set in 'user' parameter of your operation function, if there is one. - 'scope' or 'scopes' will be passed to scope validation function. - - :param token Token provided by Authorization header - :type token: str - :return: Decoded token information or None if token is invalid - :rtype: dict | None - """ - return {'scopes': ['read:pets', 'write:pets'], 'uid': 'user_id'} - - -def validate_scope_petstore_auth(required_scopes, token_scopes): - """ - Validate required scopes are included in token scope - - :param required_scopes Required scope to access called API - :type required_scopes: List[str] - :param token_scopes Scope present in token - :type token_scopes: List[str] - :return: True if access to called API is allowed - :rtype: bool - """ - return set(required_scopes).issubset(set(token_scopes)) - - diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/store_controller.py b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/store_controller.py deleted file mode 100644 index 3d16d99859e7..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/store_controller.py +++ /dev/null @@ -1,57 +0,0 @@ -import connexion -import six - -from openapi_server.models.order import Order # noqa: E501 -from openapi_server import util - - -def delete_order(order_id): # noqa: E501 - """Delete purchase order by ID - - For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors # noqa: E501 - - :param order_id: ID of the order that needs to be deleted - :type order_id: str - - :rtype: None - """ - return 'do some magic!' - - -def get_inventory(): # noqa: E501 - """Returns pet inventories by status - - Returns a map of status codes to quantities # noqa: E501 - - - :rtype: Dict[str, int] - """ - return 'do some magic!' - - -def get_order_by_id(order_id): # noqa: E501 - """Find purchase order by ID - - For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions # noqa: E501 - - :param order_id: ID of pet that needs to be fetched - :type order_id: int - - :rtype: Order - """ - return 'do some magic!' - - -def place_order(order): # noqa: E501 - """Place an order for a pet - - # noqa: E501 - - :param order: order placed for purchasing the pet - :type order: dict | bytes - - :rtype: Order - """ - if connexion.request.is_json: - order = Order.from_dict(connexion.request.get_json()) # noqa: E501 - return 'do some magic!' diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/user_controller.py b/samples/server/petstore/python-flask-openapi/openapi_server/controllers/user_controller.py deleted file mode 100644 index e897814d4b0d..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/controllers/user_controller.py +++ /dev/null @@ -1,119 +0,0 @@ -import connexion -import six - -from openapi_server.models.user import User # noqa: E501 -from openapi_server import util - - -def create_user(user): # noqa: E501 - """Create user - - This can only be done by the logged in user. # noqa: E501 - - :param user: Created user object - :type user: dict | bytes - - :rtype: None - """ - if connexion.request.is_json: - user = User.from_dict(connexion.request.get_json()) # noqa: E501 - return 'do some magic!' - - -def create_users_with_array_input(user): # noqa: E501 - """Creates list of users with given input array - - # noqa: E501 - - :param user: List of user objects - :type user: list | bytes - - :rtype: None - """ - if connexion.request.is_json: - user = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501 - return 'do some magic!' - - -def create_users_with_list_input(user): # noqa: E501 - """Creates list of users with given input array - - # noqa: E501 - - :param user: List of user objects - :type user: list | bytes - - :rtype: None - """ - if connexion.request.is_json: - user = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501 - return 'do some magic!' - - -def delete_user(username): # noqa: E501 - """Delete user - - This can only be done by the logged in user. # noqa: E501 - - :param username: The name that needs to be deleted - :type username: str - - :rtype: None - """ - return 'do some magic!' - - -def get_user_by_name(username): # noqa: E501 - """Get user by user name - - # noqa: E501 - - :param username: The name that needs to be fetched. Use user1 for testing. - :type username: str - - :rtype: User - """ - return 'do some magic!' - - -def login_user(username, password): # noqa: E501 - """Logs user into the system - - # noqa: E501 - - :param username: The user name for login - :type username: str - :param password: The password for login in clear text - :type password: str - - :rtype: str - """ - return 'do some magic!' - - -def logout_user(): # noqa: E501 - """Logs out current logged in user session - - # noqa: E501 - - - :rtype: None - """ - return 'do some magic!' - - -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 user: Updated user object - :type user: dict | bytes - - :rtype: None - """ - if connexion.request.is_json: - user = User.from_dict(connexion.request.get_json()) # noqa: E501 - return 'do some magic!' diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/encoder.py b/samples/server/petstore/python-flask-openapi/openapi_server/encoder.py deleted file mode 100644 index 3bbef854f3b8..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/encoder.py +++ /dev/null @@ -1,20 +0,0 @@ -from connexion.apps.flask_app import FlaskJSONEncoder -import six - -from openapi_server.models.base_model_ import Model - - -class JSONEncoder(FlaskJSONEncoder): - include_nulls = False - - def default(self, o): - if isinstance(o, Model): - dikt = {} - for attr, _ in six.iteritems(o.openapi_types): - value = getattr(o, attr) - if value is None and not self.include_nulls: - continue - attr = o.attribute_map[attr] - dikt[attr] = value - return dikt - return FlaskJSONEncoder.default(self, o) diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/__init__.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/__init__.py deleted file mode 100644 index bb6f70f1569b..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/models/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -# coding: utf-8 - -# flake8: noqa -from __future__ import absolute_import -# import models into model package -from openapi_server.models.api_response import ApiResponse -from openapi_server.models.category import Category -from openapi_server.models.order import Order -from openapi_server.models.pet import Pet -from openapi_server.models.pet_form import PetForm -from openapi_server.models.status_enum import StatusEnum -from openapi_server.models.tag import Tag -from openapi_server.models.upload_form import UploadForm -from openapi_server.models.user import User diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/api_response.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/api_response.py deleted file mode 100644 index 1e23da9c2304..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/models/api_response.py +++ /dev/null @@ -1,116 +0,0 @@ -# coding: utf-8 - -from __future__ import absolute_import -from datetime import date, datetime # noqa: F401 - -from typing import List, Dict # noqa: F401 - -from openapi_server.models.base_model_ import Model -from openapi_server import util - - -class ApiResponse(Model): - """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - - Do not edit the class manually. - """ - - def __init__(self, code=None, type=None, message=None): # noqa: E501 - """ApiResponse - a model defined in OpenAPI - - :param code: The code of this ApiResponse. # noqa: E501 - :type code: int - :param type: The type of this ApiResponse. # noqa: E501 - :type type: str - :param message: The message of this ApiResponse. # noqa: E501 - :type message: str - """ - self.openapi_types = { - 'code': int, - 'type': str, - 'message': str - } - - self.attribute_map = { - 'code': 'code', - 'type': 'type', - 'message': 'message' - } - - self._code = code - self._type = type - self._message = message - - @classmethod - def from_dict(cls, dikt) -> 'ApiResponse': - """Returns the dict as a model - - :param dikt: A dict. - :type: dict - :return: The ApiResponse of this ApiResponse. # noqa: E501 - :rtype: ApiResponse - """ - return util.deserialize_model(dikt, cls) - - @property - def code(self): - """Gets the code of this ApiResponse. - - - :return: The code of this ApiResponse. - :rtype: int - """ - return self._code - - @code.setter - def code(self, code): - """Sets the code of this ApiResponse. - - - :param code: The code of this ApiResponse. - :type code: int - """ - - self._code = code - - @property - def type(self): - """Gets the type of this ApiResponse. - - - :return: The type of this ApiResponse. - :rtype: str - """ - return self._type - - @type.setter - def type(self, type): - """Sets the type of this ApiResponse. - - - :param type: The type of this ApiResponse. - :type type: str - """ - - self._type = type - - @property - def message(self): - """Gets the message of this ApiResponse. - - - :return: The message of this ApiResponse. - :rtype: str - """ - return self._message - - @message.setter - def message(self, message): - """Sets the message of this ApiResponse. - - - :param message: The message of this ApiResponse. - :type message: str - """ - - self._message = message diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/base_model_.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/base_model_.py deleted file mode 100644 index ec33e3ba3cff..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/models/base_model_.py +++ /dev/null @@ -1,69 +0,0 @@ -import pprint - -import six -import typing - -from openapi_server import util - -T = typing.TypeVar('T') - - -class Model(object): - # openapiTypes: The key is attribute name and the - # value is attribute type. - openapi_types = {} - - # attributeMap: The key is attribute name and the - # value is json key in definition. - attribute_map = {} - - @classmethod - def from_dict(cls: typing.Type[T], dikt) -> T: - """Returns the dict as a model""" - return util.deserialize_model(dikt, cls) - - def to_dict(self): - """Returns the model properties as a dict - - :rtype: dict - """ - result = {} - - for attr, _ in six.iteritems(self.openapi_types): - value = getattr(self, attr) - if isinstance(value, list): - result[attr] = list(map( - lambda x: x.to_dict() if hasattr(x, "to_dict") else x, - value - )) - elif hasattr(value, "to_dict"): - result[attr] = value.to_dict() - elif isinstance(value, dict): - result[attr] = dict(map( - lambda item: (item[0], item[1].to_dict()) - if hasattr(item[1], "to_dict") else item, - value.items() - )) - else: - result[attr] = value - - return result - - def to_str(self): - """Returns the string representation of the model - - :rtype: str - """ - return pprint.pformat(self.to_dict()) - - def __repr__(self): - """For `print` and `pprint`""" - return self.to_str() - - def __eq__(self, other): - """Returns true if both objects are equal""" - return self.__dict__ == other.__dict__ - - def __ne__(self, other): - """Returns true if both objects are not equal""" - return not self == other diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/category.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/category.py deleted file mode 100644 index 8511752bafb9..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/models/category.py +++ /dev/null @@ -1,94 +0,0 @@ -# coding: utf-8 - -from __future__ import absolute_import -from datetime import date, datetime # noqa: F401 - -from typing import List, Dict # noqa: F401 - -from openapi_server.models.base_model_ import Model -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). - - Do not edit the class manually. - """ - - def __init__(self, id=None, name=None): # noqa: E501 - """Category - a model defined in OpenAPI - - :param id: The id of this Category. # noqa: E501 - :type id: int - :param name: The name of this Category. # noqa: E501 - :type name: str - """ - self.openapi_types = { - 'id': int, - 'name': str - } - - self.attribute_map = { - 'id': 'id', - 'name': 'name' - } - - self._id = id - self._name = name - - @classmethod - def from_dict(cls, dikt) -> 'Category': - """Returns the dict as a model - - :param dikt: A dict. - :type: dict - :return: The Category of this Category. # noqa: E501 - :rtype: Category - """ - return util.deserialize_model(dikt, cls) - - @property - def id(self): - """Gets the id of this Category. - - - :return: The id of this Category. - :rtype: int - """ - return self._id - - @id.setter - def id(self, id): - """Sets the id of this Category. - - - :param id: The id of this Category. - :type id: int - """ - - self._id = id - - @property - def name(self): - """Gets the name of this Category. - - - :return: The name of this Category. - :rtype: str - """ - return self._name - - @name.setter - def name(self, name): - """Sets the name of this Category. - - - :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 diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/order.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/order.py deleted file mode 100644 index aa8a7a71c393..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/models/order.py +++ /dev/null @@ -1,202 +0,0 @@ -# coding: utf-8 - -from __future__ import absolute_import -from datetime import date, datetime # noqa: F401 - -from typing import List, Dict # noqa: F401 - -from openapi_server.models.base_model_ import Model -from openapi_server import util - - -class Order(Model): - """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - - Do not edit the class manually. - """ - - def __init__(self, id=None, pet_id=None, quantity=None, ship_date=None, status=None, complete=False): # noqa: E501 - """Order - a model defined in OpenAPI - - :param id: The id of this Order. # noqa: E501 - :type id: int - :param pet_id: The pet_id of this Order. # noqa: E501 - :type pet_id: int - :param quantity: The quantity of this Order. # noqa: E501 - :type quantity: int - :param ship_date: The ship_date of this Order. # noqa: E501 - :type ship_date: datetime - :param status: The status of this Order. # noqa: E501 - :type status: str - :param complete: The complete of this Order. # noqa: E501 - :type complete: bool - """ - self.openapi_types = { - 'id': int, - 'pet_id': int, - 'quantity': int, - 'ship_date': datetime, - 'status': str, - 'complete': bool - } - - self.attribute_map = { - 'id': 'id', - 'pet_id': 'petId', - 'quantity': 'quantity', - 'ship_date': 'shipDate', - 'status': 'status', - 'complete': 'complete' - } - - self._id = id - self._pet_id = pet_id - self._quantity = quantity - self._ship_date = ship_date - self._status = status - self._complete = complete - - @classmethod - def from_dict(cls, dikt) -> 'Order': - """Returns the dict as a model - - :param dikt: A dict. - :type: dict - :return: The Order of this Order. # noqa: E501 - :rtype: Order - """ - return util.deserialize_model(dikt, cls) - - @property - def id(self): - """Gets the id of this Order. - - - :return: The id of this Order. - :rtype: int - """ - return self._id - - @id.setter - def id(self, id): - """Sets the id of this Order. - - - :param id: The id of this Order. - :type id: int - """ - - self._id = id - - @property - def pet_id(self): - """Gets the pet_id of this Order. - - - :return: The pet_id of this Order. - :rtype: int - """ - return self._pet_id - - @pet_id.setter - def pet_id(self, pet_id): - """Sets the pet_id of this Order. - - - :param pet_id: The pet_id of this Order. - :type pet_id: int - """ - - self._pet_id = pet_id - - @property - def quantity(self): - """Gets the quantity of this Order. - - - :return: The quantity of this Order. - :rtype: int - """ - return self._quantity - - @quantity.setter - def quantity(self, quantity): - """Sets the quantity of this Order. - - - :param quantity: The quantity of this Order. - :type quantity: int - """ - - self._quantity = quantity - - @property - def ship_date(self): - """Gets the ship_date of this Order. - - - :return: The ship_date of this Order. - :rtype: datetime - """ - return self._ship_date - - @ship_date.setter - def ship_date(self, ship_date): - """Sets the ship_date of this Order. - - - :param ship_date: The ship_date of this Order. - :type ship_date: datetime - """ - - self._ship_date = ship_date - - @property - def status(self): - """Gets the status of this Order. - - Order Status # noqa: E501 - - :return: The status of this Order. - :rtype: str - """ - return self._status - - @status.setter - def status(self, status): - """Sets the status of this Order. - - Order Status # noqa: E501 - - :param status: The status of this Order. - :type status: str - """ - 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}" - .format(status, allowed_values) - ) - - self._status = status - - @property - def complete(self): - """Gets the complete of this Order. - - - :return: The complete of this Order. - :rtype: bool - """ - return self._complete - - @complete.setter - def complete(self, complete): - """Sets the complete of this Order. - - - :param complete: The complete of this Order. - :type complete: bool - """ - - self._complete = complete diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/pet.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/pet.py deleted file mode 100644 index e61674165e1c..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/models/pet.py +++ /dev/null @@ -1,210 +0,0 @@ -# coding: utf-8 - -from __future__ import absolute_import -from datetime import date, datetime # noqa: F401 - -from typing import List, Dict # noqa: F401 - -from openapi_server.models.base_model_ import Model -from openapi_server.models.category import Category -from openapi_server.models.tag import Tag -from openapi_server import util - -from openapi_server.models.category import Category # noqa: E501 -from openapi_server.models.tag import Tag # noqa: E501 - -class Pet(Model): - """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - - Do not edit the class manually. - """ - - def __init__(self, id=None, category=None, name=None, photo_urls=None, tags=None, status=None): # noqa: E501 - """Pet - a model defined in OpenAPI - - :param id: The id of this Pet. # noqa: E501 - :type id: int - :param category: The category of this Pet. # noqa: E501 - :type category: Category - :param name: The name of this Pet. # noqa: E501 - :type name: str - :param photo_urls: The photo_urls of this Pet. # noqa: E501 - :type photo_urls: List[str] - :param tags: The tags of this Pet. # noqa: E501 - :type tags: List[Tag] - :param status: The status of this Pet. # noqa: E501 - :type status: str - """ - self.openapi_types = { - 'id': int, - 'category': Category, - 'name': str, - 'photo_urls': List[str], - 'tags': List[Tag], - 'status': str - } - - self.attribute_map = { - 'id': 'id', - 'category': 'category', - 'name': 'name', - 'photo_urls': 'photoUrls', - 'tags': 'tags', - 'status': 'status' - } - - self._id = id - self._category = category - self._name = name - self._photo_urls = photo_urls - self._tags = tags - self._status = status - - @classmethod - def from_dict(cls, dikt) -> 'Pet': - """Returns the dict as a model - - :param dikt: A dict. - :type: dict - :return: The Pet of this Pet. # noqa: E501 - :rtype: Pet - """ - return util.deserialize_model(dikt, cls) - - @property - def id(self): - """Gets the id of this Pet. - - - :return: The id of this Pet. - :rtype: int - """ - return self._id - - @id.setter - def id(self, id): - """Sets the id of this Pet. - - - :param id: The id of this Pet. - :type id: int - """ - - self._id = id - - @property - def category(self): - """Gets the category of this Pet. - - - :return: The category of this Pet. - :rtype: Category - """ - return self._category - - @category.setter - def category(self, category): - """Sets the category of this Pet. - - - :param category: The category of this Pet. - :type category: Category - """ - - self._category = category - - @property - def name(self): - """Gets the name of this Pet. - - - :return: The name of this Pet. - :rtype: str - """ - return self._name - - @name.setter - def name(self, name): - """Sets the name of this Pet. - - - :param name: The name of this Pet. - :type name: str - """ - if name is None: - raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 - - self._name = name - - @property - def photo_urls(self): - """Gets the photo_urls of this Pet. - - - :return: The photo_urls of this Pet. - :rtype: List[str] - """ - return self._photo_urls - - @photo_urls.setter - def photo_urls(self, photo_urls): - """Sets the photo_urls of this Pet. - - - :param photo_urls: The photo_urls of this Pet. - :type photo_urls: List[str] - """ - if photo_urls is None: - raise ValueError("Invalid value for `photo_urls`, must not be `None`") # noqa: E501 - - self._photo_urls = photo_urls - - @property - def tags(self): - """Gets the tags of this Pet. - - - :return: The tags of this Pet. - :rtype: List[Tag] - """ - return self._tags - - @tags.setter - def tags(self, tags): - """Sets the tags of this Pet. - - - :param tags: The tags of this Pet. - :type tags: List[Tag] - """ - - self._tags = tags - - @property - def status(self): - """Gets the status of this Pet. - - pet status in the store # noqa: E501 - - :return: The status of this Pet. - :rtype: str - """ - return self._status - - @status.setter - def status(self, status): - """Sets the status of this Pet. - - pet status in the store # noqa: E501 - - :param status: The status of this Pet. - :type status: str - """ - 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}" - .format(status, allowed_values) - ) - - self._status = status diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/tag.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/tag.py deleted file mode 100644 index bd6fff169078..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/models/tag.py +++ /dev/null @@ -1,90 +0,0 @@ -# coding: utf-8 - -from __future__ import absolute_import -from datetime import date, datetime # noqa: F401 - -from typing import List, Dict # noqa: F401 - -from openapi_server.models.base_model_ import Model -from openapi_server import util - - -class Tag(Model): - """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - - Do not edit the class manually. - """ - - def __init__(self, id=None, name=None): # noqa: E501 - """Tag - a model defined in OpenAPI - - :param id: The id of this Tag. # noqa: E501 - :type id: int - :param name: The name of this Tag. # noqa: E501 - :type name: str - """ - self.openapi_types = { - 'id': int, - 'name': str - } - - self.attribute_map = { - 'id': 'id', - 'name': 'name' - } - - self._id = id - self._name = name - - @classmethod - def from_dict(cls, dikt) -> 'Tag': - """Returns the dict as a model - - :param dikt: A dict. - :type: dict - :return: The Tag of this Tag. # noqa: E501 - :rtype: Tag - """ - return util.deserialize_model(dikt, cls) - - @property - def id(self): - """Gets the id of this Tag. - - - :return: The id of this Tag. - :rtype: int - """ - return self._id - - @id.setter - def id(self, id): - """Sets the id of this Tag. - - - :param id: The id of this Tag. - :type id: int - """ - - self._id = id - - @property - def name(self): - """Gets the name of this Tag. - - - :return: The name of this Tag. - :rtype: str - """ - return self._name - - @name.setter - def name(self, name): - """Sets the name of this Tag. - - - :param name: The name of this Tag. - :type name: str - """ - - self._name = name diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/models/user.py b/samples/server/petstore/python-flask-openapi/openapi_server/models/user.py deleted file mode 100644 index 1b1f4bdae726..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/models/user.py +++ /dev/null @@ -1,248 +0,0 @@ -# coding: utf-8 - -from __future__ import absolute_import -from datetime import date, datetime # noqa: F401 - -from typing import List, Dict # noqa: F401 - -from openapi_server.models.base_model_ import Model -from openapi_server import util - - -class User(Model): - """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - - Do not edit the class manually. - """ - - def __init__(self, id=None, username=None, first_name=None, last_name=None, email=None, password=None, phone=None, user_status=None): # noqa: E501 - """User - a model defined in OpenAPI - - :param id: The id of this User. # noqa: E501 - :type id: int - :param username: The username of this User. # noqa: E501 - :type username: str - :param first_name: The first_name of this User. # noqa: E501 - :type first_name: str - :param last_name: The last_name of this User. # noqa: E501 - :type last_name: str - :param email: The email of this User. # noqa: E501 - :type email: str - :param password: The password of this User. # noqa: E501 - :type password: str - :param phone: The phone of this User. # noqa: E501 - :type phone: str - :param user_status: The user_status of this User. # noqa: E501 - :type user_status: int - """ - self.openapi_types = { - 'id': int, - 'username': str, - 'first_name': str, - 'last_name': str, - 'email': str, - 'password': str, - 'phone': str, - 'user_status': int - } - - self.attribute_map = { - 'id': 'id', - 'username': 'username', - 'first_name': 'firstName', - 'last_name': 'lastName', - 'email': 'email', - 'password': 'password', - 'phone': 'phone', - 'user_status': 'userStatus' - } - - self._id = id - self._username = username - self._first_name = first_name - self._last_name = last_name - self._email = email - self._password = password - self._phone = phone - self._user_status = user_status - - @classmethod - def from_dict(cls, dikt) -> 'User': - """Returns the dict as a model - - :param dikt: A dict. - :type: dict - :return: The User of this User. # noqa: E501 - :rtype: User - """ - return util.deserialize_model(dikt, cls) - - @property - def id(self): - """Gets the id of this User. - - - :return: The id of this User. - :rtype: int - """ - return self._id - - @id.setter - def id(self, id): - """Sets the id of this User. - - - :param id: The id of this User. - :type id: int - """ - - self._id = id - - @property - def username(self): - """Gets the username of this User. - - - :return: The username of this User. - :rtype: str - """ - return self._username - - @username.setter - def username(self, username): - """Sets the username of this User. - - - :param username: The username of this User. - :type username: str - """ - - self._username = username - - @property - def first_name(self): - """Gets the first_name of this User. - - - :return: The first_name of this User. - :rtype: str - """ - return self._first_name - - @first_name.setter - def first_name(self, first_name): - """Sets the first_name of this User. - - - :param first_name: The first_name of this User. - :type first_name: str - """ - - self._first_name = first_name - - @property - def last_name(self): - """Gets the last_name of this User. - - - :return: The last_name of this User. - :rtype: str - """ - return self._last_name - - @last_name.setter - def last_name(self, last_name): - """Sets the last_name of this User. - - - :param last_name: The last_name of this User. - :type last_name: str - """ - - self._last_name = last_name - - @property - def email(self): - """Gets the email of this User. - - - :return: The email of this User. - :rtype: str - """ - return self._email - - @email.setter - def email(self, email): - """Sets the email of this User. - - - :param email: The email of this User. - :type email: str - """ - - self._email = email - - @property - def password(self): - """Gets the password of this User. - - - :return: The password of this User. - :rtype: str - """ - return self._password - - @password.setter - def password(self, password): - """Sets the password of this User. - - - :param password: The password of this User. - :type password: str - """ - - self._password = password - - @property - def phone(self): - """Gets the phone of this User. - - - :return: The phone of this User. - :rtype: str - """ - return self._phone - - @phone.setter - def phone(self, phone): - """Sets the phone of this User. - - - :param phone: The phone of this User. - :type phone: str - """ - - self._phone = phone - - @property - def user_status(self): - """Gets the user_status of this User. - - User Status # noqa: E501 - - :return: The user_status of this User. - :rtype: int - """ - return self._user_status - - @user_status.setter - def user_status(self, user_status): - """Sets the user_status of this User. - - User Status # noqa: E501 - - :param user_status: The user_status of this User. - :type user_status: int - """ - - self._user_status = user_status diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/openapi/openapi.yaml b/samples/server/petstore/python-flask-openapi/openapi_server/openapi/openapi.yaml deleted file mode 100644 index 31100fda5278..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/openapi/openapi.yaml +++ /dev/null @@ -1,881 +0,0 @@ -openapi: 3.0.1 -info: - description: This is a sample server Petstore server. For this sample, you can use - the api key `special-key` to test the authorization filters. - license: - name: Apache-2.0 - 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: -- description: Everything about your Pets - name: pet -- description: Access to Petstore orders - name: store -- description: Operations about user - name: user -paths: - /pet: - post: - operationId: add_pet - requestBody: - $ref: '#/components/requestBodies/Pet' - responses: - "405": - description: Invalid input - security: - - petstore_auth: - - write:pets - - read:pets - summary: Add a new pet to the store - tags: - - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller - put: - operationId: update_pet - requestBody: - $ref: '#/components/requestBodies/Pet' - responses: - "400": - description: Invalid ID supplied - "404": - description: Pet not found - "405": - description: Validation exception - security: - - petstore_auth: - - write:pets - - read:pets - summary: Update an existing pet - tags: - - pet - 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 - explode: false - in: query - name: status - required: true - schema: - items: - default: available - enum: - - available - - pending - - sold - type: string - type: array - style: form - responses: - "200": - content: - application/xml: - schema: - items: - $ref: '#/components/schemas/Pet' - type: array - application/json: - schema: - items: - $ref: '#/components/schemas/Pet' - type: array - description: successful operation - "400": - description: Invalid status value - security: - - petstore_auth: - - read:pets - summary: Finds Pets by status - tags: - - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller - /pet/findByTags: - get: - deprecated: true - description: Multiple tags can be provided with comma separated strings. Use - tag1, tag2, tag3 for testing. - operationId: find_pets_by_tags - parameters: - - description: Tags to filter by - explode: false - in: query - name: tags - required: true - schema: - items: - type: string - type: array - style: form - responses: - "200": - content: - application/xml: - schema: - items: - $ref: '#/components/schemas/Pet' - type: array - application/json: - schema: - items: - $ref: '#/components/schemas/Pet' - type: array - description: successful operation - "400": - description: Invalid tag value - security: - - petstore_auth: - - read:pets - summary: Finds Pets by tags - tags: - - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller - /pet/{petId}: - delete: - operationId: delete_pet - parameters: - - 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": - description: Invalid pet value - security: - - petstore_auth: - - write:pets - - read:pets - summary: Deletes a pet - tags: - - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller - get: - description: Returns a single pet - 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: - application/xml: - schema: - $ref: '#/components/schemas/Pet' - application/json: - schema: - $ref: '#/components/schemas/Pet' - description: successful operation - "400": - description: Invalid ID supplied - "404": - description: Pet not found - security: - - api_key: [] - summary: Find pet by ID - tags: - - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller - patch: - operationId: update_pet_status_with_enum - parameters: - - description: ID of pet to return - explode: false - in: path - name: petId - required: true - schema: - format: int64 - type: integer - style: simple - - description: The required status - example: pending - explode: true - in: query - name: status - required: true - schema: - $ref: '#/components/schemas/statusEnum' - style: form - responses: - "200": - content: - application/xml: - schema: - $ref: '#/components/schemas/Pet' - application/json: - schema: - $ref: '#/components/schemas/Pet' - description: successful operation - "400": - description: Invalid ID supplied - "404": - description: Pet not found - summary: Set the status of a pet in the store using an enum - tags: - - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller - post: - operationId: update_pet_with_form - parameters: - - 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: - $ref: '#/components/requestBodies/PetForm' - responses: - "405": - description: Invalid input - security: - - petstore_auth: - - write:pets - - read:pets - summary: Updates a pet in the store with form data - tags: - - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller - /pet/{petId}/uploadImage: - post: - 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: - $ref: '#/components/requestBodies/UploadForm' - responses: - "200": - content: - application/json: - schema: - $ref: '#/components/schemas/ApiResponse' - description: successful operation - security: - - petstore_auth: - - write:pets - - read:pets - summary: uploads an image - tags: - - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller - /store/inventory: - get: - description: Returns a map of status codes to quantities - operationId: get_inventory - responses: - "200": - content: - application/json: - schema: - additionalProperties: - format: int32 - type: integer - type: object - description: successful operation - security: - - api_key: [] - summary: Returns pet inventories by status - tags: - - store - x-openapi-router-controller: openapi_server.controllers.store_controller - /store/order: - post: - operationId: place_order - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/Order' - description: order placed for purchasing the pet - required: true - responses: - "200": - content: - application/xml: - schema: - $ref: '#/components/schemas/Order' - application/json: - schema: - $ref: '#/components/schemas/Order' - description: successful operation - "400": - description: Invalid Order - summary: Place an order for a pet - tags: - - store - x-openapi-router-controller: openapi_server.controllers.store_controller - /store/order/{orderId}: - delete: - description: For valid response try integer IDs with value < 1000. Anything - above 1000 or nonintegers will generate API errors - operationId: delete_order - 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": - description: Invalid ID supplied - "404": - description: Order not found - summary: Delete purchase order by ID - tags: - - store - x-openapi-router-controller: openapi_server.controllers.store_controller - get: - description: For valid response try integer IDs with value <= 5 or > 10. Other - values will generated exceptions - operationId: get_order_by_id - parameters: - - description: ID of pet that needs to be fetched - explode: false - in: path - name: orderId - required: true - schema: - format: int64 - maximum: 5 - minimum: 1 - type: integer - style: simple - responses: - "200": - content: - application/xml: - schema: - $ref: '#/components/schemas/Order' - application/json: - schema: - $ref: '#/components/schemas/Order' - description: successful operation - "400": - description: Invalid ID supplied - "404": - description: Order not found - summary: Find purchase order by ID - tags: - - store - x-openapi-router-controller: openapi_server.controllers.store_controller - /user: - post: - description: This can only be done by the logged in user. - operationId: create_user - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/User' - description: Created user object - required: true - responses: - default: - description: successful operation - security: - - auth_cookie: [] - summary: Create user - tags: - - user - x-openapi-router-controller: openapi_server.controllers.user_controller - /user/createWithArray: - post: - operationId: create_users_with_array_input - requestBody: - $ref: '#/components/requestBodies/UserArray' - responses: - default: - description: successful operation - security: - - auth_cookie: [] - summary: Creates list of users with given input array - tags: - - user - x-openapi-router-controller: openapi_server.controllers.user_controller - /user/createWithList: - post: - operationId: create_users_with_list_input - requestBody: - $ref: '#/components/requestBodies/UserArray' - responses: - default: - description: successful operation - security: - - auth_cookie: [] - summary: Creates list of users with given input array - tags: - - user - x-openapi-router-controller: openapi_server.controllers.user_controller - /user/login: - get: - 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: - application/xml: - schema: - type: string - application/json: - schema: - type: string - description: successful operation - headers: - Set-Cookie: - description: Cookie authentication key for use with the `auth_cookie` - 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 toekn expires - explode: false - schema: - format: date-time - type: string - style: simple - "400": - description: Invalid username/password supplied - summary: Logs user into the system - tags: - - user - x-openapi-router-controller: openapi_server.controllers.user_controller - /user/logout: - get: - operationId: logout_user - responses: - default: - description: successful operation - security: - - auth_cookie: [] - summary: Logs out current logged in user session - tags: - - user - x-openapi-router-controller: openapi_server.controllers.user_controller - /user/{username}: - delete: - description: This can only be done by the logged in user. - 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": - description: Invalid username supplied - "404": - description: User not found - security: - - auth_cookie: [] - summary: Delete user - tags: - - user - x-openapi-router-controller: openapi_server.controllers.user_controller - get: - 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: - application/xml: - schema: - $ref: '#/components/schemas/User' - application/json: - schema: - $ref: '#/components/schemas/User' - description: successful operation - "400": - description: Invalid username supplied - "404": - description: User not found - summary: Get user by user name - tags: - - user - x-openapi-router-controller: openapi_server.controllers.user_controller - put: - description: This can only be done by the logged in user. - 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": - description: Invalid user supplied - "404": - description: User not found - security: - - auth_cookie: [] - summary: Updated user - tags: - - user - x-openapi-router-controller: openapi_server.controllers.user_controller -components: - parameters: - statusEnum: - description: The required status - example: pending - explode: true - in: query - name: status - required: true - schema: - $ref: '#/components/schemas/statusEnum' - style: form - requestBodies: - UserArray: - content: - application/json: - schema: - items: - $ref: '#/components/schemas/User' - type: array - description: List of user objects - 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 - PetForm: - content: - application/x-www-form-urlencoded: - example: - name: fluffy - status: available - schema: - $ref: '#/components/schemas/PetForm' - UploadForm: - content: - multipart/form-data: - example: - additionalMetadata: additional metadata example - file: c29tZSB0ZXN0IGRhdGEK - schema: - $ref: '#/components/schemas/UploadForm' - schemas: - Order: - description: An order for a pets from the pet store - example: - petId: 6 - quantity: 1 - id: 0 - shipDate: 2000-01-23T04:56:07.000+00:00 - complete: false - status: placed - properties: - id: - format: int64 - type: integer - petId: - format: int64 - type: integer - quantity: - format: int32 - type: integer - shipDate: - format: date-time - type: string - status: - description: Order Status - enum: - - placed - - approved - - delivered - type: string - complete: - default: false - type: boolean - title: Pet Order - type: object - xml: - name: Order - Category: - description: A category for a pet - example: - name: name - id: 6 - properties: - id: - format: int64 - type: integer - name: - pattern: ^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$ - type: string - title: Pet category - type: object - xml: - name: Category - User: - description: A User who is purchasing from the pet store - example: - firstName: firstName - lastName: lastName - password: password - userStatus: 6 - phone: phone - id: 0 - email: email - username: username - properties: - id: - format: int64 - type: integer - username: - type: string - firstName: - type: string - lastName: - type: string - email: - type: string - password: - type: string - phone: - type: string - userStatus: - description: User Status - format: int32 - type: integer - title: a User - type: object - xml: - name: User - Tag: - description: A tag for a pet - example: - name: name - id: 1 - properties: - id: - format: int64 - type: integer - name: - type: string - title: Pet Tag - type: object - xml: - name: Tag - Pet: - description: A pet for sale in the pet store - example: - photoUrls: - - photoUrls - - photoUrls - name: doggie - id: 0 - category: - name: name - id: 6 - tags: - - name: name - id: 1 - - name: name - id: 1 - status: available - properties: - id: - format: int64 - type: integer - category: - $ref: '#/components/schemas/Category' - name: - example: doggie - type: string - photoUrls: - items: - type: string - type: array - xml: - name: photoUrl - wrapped: true - tags: - items: - $ref: '#/components/schemas/Tag' - type: array - xml: - name: tag - wrapped: true - status: - description: pet status in the store - enum: - - available - - pending - - sold - type: string - required: - - name - - photoUrls - title: a Pet - type: object - xml: - name: Pet - PetForm: - description: A form for updating a pet - properties: - name: - description: Updated name of the pet - type: string - status: - description: Updated status of the pet - type: string - required: - - name - - status - title: A pet form - type: object - UploadForm: - description: A form for attaching files to a pet - properties: - additionalMetadata: - description: Additional data to pass to server - type: string - file: - description: file to upload - format: binary - type: string - required: - - file - title: An upload form - type: object - ApiResponse: - description: Describes the result of uploading an image resource - example: - code: 0 - type: type - message: message - properties: - code: - format: int32 - type: integer - type: - type: string - message: - type: string - title: An uploaded response - type: object - statusEnum: - description: pet status in the store - enum: - - available - - pending - - sold - type: string - securitySchemes: - petstore_auth: - flows: - implicit: - authorizationUrl: http://petstore.swagger.io/api/oauth/dialog - scopes: - write:pets: modify pets in your account - read:pets: read your pets - type: oauth2 - x-tokenInfoFunc: openapi_server.controllers.security_controller_.info_from_petstore_auth - x-scopeValidateFunc: openapi_server.controllers.security_controller_.validate_scope_petstore_auth - api_key: - in: header - name: api_key - type: apiKey - x-apikeyInfoFunc: openapi_server.controllers.security_controller_.info_from_api_key - auth_cookie: - in: cookie - name: AUTH_KEY - type: apiKey - x-apikeyInfoFunc: openapi_server.controllers.security_controller_.info_from_auth_cookie diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/test/__init__.py b/samples/server/petstore/python-flask-openapi/openapi_server/test/__init__.py deleted file mode 100644 index 364aba9fbf88..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/test/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ -import logging - -import connexion -from flask_testing import TestCase - -from openapi_server.encoder import JSONEncoder - - -class BaseTestCase(TestCase): - - def create_app(self): - logging.getLogger('connexion.operation').setLevel('ERROR') - app = connexion.App(__name__, specification_dir='../openapi/') - app.app.json_encoder = JSONEncoder - app.add_api('openapi.yaml', pythonic_params=True) - return app.app diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/test/test_pet_controller.py b/samples/server/petstore/python-flask-openapi/openapi_server/test/test_pet_controller.py deleted file mode 100644 index 2e9944b3cc33..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/test/test_pet_controller.py +++ /dev/null @@ -1,220 +0,0 @@ -# coding: utf-8 - -from __future__ import absolute_import -import unittest - -from flask import json -from six import BytesIO - -from openapi_server.models.api_response import ApiResponse # noqa: E501 -from openapi_server.models.pet import Pet # noqa: E501 -from openapi_server.models.pet_form import PetForm # noqa: E501 -from openapi_server.models.status_enum import StatusEnum # noqa: E501 -from openapi_server.models.upload_form import UploadForm # noqa: E501 -from openapi_server.test import BaseTestCase - - -class TestPetController(BaseTestCase): - """PetController integration test stubs""" - - @unittest.skip("Connexion does not support multiple consummes. See https://github.com/zalando/connexion/pull/760") - def test_add_pet(self): - """Test case for add_pet - - Add a new pet to the store - """ - pet = { - "photoUrls" : [ "photoUrls", "photoUrls" ], - "name" : "doggie", - "id" : 0, - "category" : { - "name" : "name", - "id" : 6 - }, - "tags" : [ { - "name" : "name", - "id" : 1 - }, { - "name" : "name", - "id" : 1 - } ], - "status" : "available" -} - headers = { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer special-key', - } - response = self.client.open( - '/v2/pet', - method='POST', - headers=headers, - data=json.dumps(pet), - content_type='application/json') - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - def test_delete_pet(self): - """Test case for delete_pet - - Deletes a pet - """ - headers = { - 'api_key': 'api_key_example', - 'Authorization': 'Bearer special-key', - } - response = self.client.open( - '/v2/pet/{pet_id}'.format(pet_id=56), - method='DELETE', - headers=headers) - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - def test_find_pets_by_status(self): - """Test case for find_pets_by_status - - Finds Pets by status - """ - query_string = [('status', 'available')] - headers = { - 'Accept': 'application/json', - 'Authorization': 'Bearer special-key', - } - response = self.client.open( - '/v2/pet/findByStatus', - method='GET', - headers=headers, - query_string=query_string) - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - def test_find_pets_by_tags(self): - """Test case for find_pets_by_tags - - Finds Pets by tags - """ - query_string = [('tags', 'tags_example')] - headers = { - 'Accept': 'application/json', - 'Authorization': 'Bearer special-key', - } - response = self.client.open( - '/v2/pet/findByTags', - method='GET', - headers=headers, - query_string=query_string) - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - def test_get_pet_by_id(self): - """Test case for get_pet_by_id - - Find pet by ID - """ - headers = { - 'Accept': 'application/json', - 'api_key': 'special-key', - } - response = self.client.open( - '/v2/pet/{pet_id}'.format(pet_id=56), - method='GET', - headers=headers) - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - @unittest.skip("Connexion does not support multiple consummes. See https://github.com/zalando/connexion/pull/760") - def test_update_pet(self): - """Test case for update_pet - - Update an existing pet - """ - pet = { - "photoUrls" : [ "photoUrls", "photoUrls" ], - "name" : "doggie", - "id" : 0, - "category" : { - "name" : "name", - "id" : 6 - }, - "tags" : [ { - "name" : "name", - "id" : 1 - }, { - "name" : "name", - "id" : 1 - } ], - "status" : "available" -} - headers = { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer special-key', - } - response = self.client.open( - '/v2/pet', - method='PUT', - headers=headers, - data=json.dumps(pet), - content_type='application/json') - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - def test_update_pet_status_with_enum(self): - """Test case for update_pet_status_with_enum - - Set the status of a pet in the store using an enum - """ - query_string = [('status', pending)] - headers = { - 'Accept': 'application/json', - } - response = self.client.open( - '/v2/pet/{pet_id}'.format(pet_id=56), - method='PATCH', - headers=headers, - query_string=query_string) - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - @unittest.skip("application/x-www-form-urlencoded not supported by Connexion") - def test_update_pet_with_form(self): - """Test case for update_pet_with_form - - Updates a pet in the store with form data - """ - pet_form = {"name":"fluffy","status":"available"} - headers = { - 'Content-Type': 'application/x-www-form-urlencoded', - 'Authorization': 'Bearer special-key', - } - response = self.client.open( - '/v2/pet/{pet_id}'.format(pet_id=56), - method='POST', - headers=headers, - data=json.dumps(pet_form), - content_type='application/x-www-form-urlencoded') - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - @unittest.skip("multipart/form-data not supported by Connexion") - def test_upload_file(self): - """Test case for upload_file - - uploads an image - """ - upload_form = {"additionalMetadata":"additional metadata example","file":"c29tZSB0ZXN0IGRhdGEK"} - headers = { - 'Accept': 'application/json', - 'Content-Type': 'multipart/form-data', - 'Authorization': 'Bearer special-key', - } - response = self.client.open( - '/v2/pet/{pet_id}/uploadImage'.format(pet_id=56), - method='POST', - headers=headers, - data=json.dumps(upload_form), - content_type='multipart/form-data') - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - -if __name__ == '__main__': - unittest.main() diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/test/test_store_controller.py b/samples/server/petstore/python-flask-openapi/openapi_server/test/test_store_controller.py deleted file mode 100644 index e232ef3aad48..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/test/test_store_controller.py +++ /dev/null @@ -1,89 +0,0 @@ -# coding: utf-8 - -from __future__ import absolute_import -import unittest - -from flask import json -from six import BytesIO - -from openapi_server.models.order import Order # noqa: E501 -from openapi_server.test import BaseTestCase - - -class TestStoreController(BaseTestCase): - """StoreController integration test stubs""" - - def test_delete_order(self): - """Test case for delete_order - - Delete purchase order by ID - """ - headers = { - } - response = self.client.open( - '/v2/store/order/{order_id}'.format(order_id='order_id_example'), - method='DELETE', - headers=headers) - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - def test_get_inventory(self): - """Test case for get_inventory - - Returns pet inventories by status - """ - headers = { - 'Accept': 'application/json', - 'api_key': 'special-key', - } - response = self.client.open( - '/v2/store/inventory', - method='GET', - headers=headers) - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - def test_get_order_by_id(self): - """Test case for get_order_by_id - - Find purchase order by ID - """ - headers = { - 'Accept': 'application/json', - } - response = self.client.open( - '/v2/store/order/{order_id}'.format(order_id=5), - method='GET', - headers=headers) - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - def test_place_order(self): - """Test case for place_order - - Place an order for a pet - """ - order = { - "petId" : 6, - "quantity" : 1, - "id" : 0, - "shipDate" : "2000-01-23T04:56:07.000+00:00", - "complete" : false, - "status" : "placed" -} - headers = { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - } - response = self.client.open( - '/v2/store/order', - method='POST', - headers=headers, - data=json.dumps(order), - content_type='application/json') - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - -if __name__ == '__main__': - unittest.main() diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/test/test_user_controller.py b/samples/server/petstore/python-flask-openapi/openapi_server/test/test_user_controller.py deleted file mode 100644 index 8f634b7cd6bf..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/test/test_user_controller.py +++ /dev/null @@ -1,193 +0,0 @@ -# coding: utf-8 - -from __future__ import absolute_import -import unittest - -from flask import json -from six import BytesIO - -from openapi_server.models.user import User # noqa: E501 -from openapi_server.test import BaseTestCase - - -class TestUserController(BaseTestCase): - """UserController integration test stubs""" - - def test_create_user(self): - """Test case for create_user - - Create user - """ - user = { - "firstName" : "firstName", - "lastName" : "lastName", - "password" : "password", - "userStatus" : 6, - "phone" : "phone", - "id" : 0, - "email" : "email", - "username" : "username" -} - headers = { - 'Content-Type': 'application/json', - 'auth_cookie': 'special-key', - } - response = self.client.open( - '/v2/user', - method='POST', - headers=headers, - data=json.dumps(user), - content_type='application/json') - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - def test_create_users_with_array_input(self): - """Test case for create_users_with_array_input - - Creates list of users with given input array - """ - user = { - "firstName" : "firstName", - "lastName" : "lastName", - "password" : "password", - "userStatus" : 6, - "phone" : "phone", - "id" : 0, - "email" : "email", - "username" : "username" -} - headers = { - 'Content-Type': 'application/json', - 'auth_cookie': 'special-key', - } - response = self.client.open( - '/v2/user/createWithArray', - method='POST', - headers=headers, - data=json.dumps(user), - content_type='application/json') - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - def test_create_users_with_list_input(self): - """Test case for create_users_with_list_input - - Creates list of users with given input array - """ - user = { - "firstName" : "firstName", - "lastName" : "lastName", - "password" : "password", - "userStatus" : 6, - "phone" : "phone", - "id" : 0, - "email" : "email", - "username" : "username" -} - headers = { - 'Content-Type': 'application/json', - 'auth_cookie': 'special-key', - } - response = self.client.open( - '/v2/user/createWithList', - method='POST', - headers=headers, - data=json.dumps(user), - content_type='application/json') - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - def test_delete_user(self): - """Test case for delete_user - - Delete user - """ - headers = { - 'auth_cookie': 'special-key', - } - response = self.client.open( - '/v2/user/{username}'.format(username='username_example'), - method='DELETE', - headers=headers) - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - def test_get_user_by_name(self): - """Test case for get_user_by_name - - Get user by user name - """ - headers = { - 'Accept': 'application/json', - } - response = self.client.open( - '/v2/user/{username}'.format(username='username_example'), - method='GET', - headers=headers) - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - def test_login_user(self): - """Test case for login_user - - Logs user into the system - """ - query_string = [('username', 'username_example'), - ('password', 'password_example')] - headers = { - 'Accept': 'application/json', - } - response = self.client.open( - '/v2/user/login', - method='GET', - headers=headers, - query_string=query_string) - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - def test_logout_user(self): - """Test case for logout_user - - Logs out current logged in user session - """ - headers = { - 'auth_cookie': 'special-key', - } - response = self.client.open( - '/v2/user/logout', - method='GET', - headers=headers) - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - def test_update_user(self): - """Test case for update_user - - Updated user - """ - user = { - "firstName" : "firstName", - "lastName" : "lastName", - "password" : "password", - "userStatus" : 6, - "phone" : "phone", - "id" : 0, - "email" : "email", - "username" : "username" -} - headers = { - 'Content-Type': 'application/json', - 'auth_cookie': 'special-key', - } - response = self.client.open( - '/v2/user/{username}'.format(username='username_example'), - method='PUT', - headers=headers, - data=json.dumps(user), - content_type='application/json') - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - -if __name__ == '__main__': - unittest.main() diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/typing_utils.py b/samples/server/petstore/python-flask-openapi/openapi_server/typing_utils.py deleted file mode 100644 index 0563f81fd534..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/typing_utils.py +++ /dev/null @@ -1,32 +0,0 @@ -# coding: utf-8 - -import sys - -if sys.version_info < (3, 7): - import typing - - def is_generic(klass): - """ Determine whether klass is a generic class """ - return type(klass) == typing.GenericMeta - - def is_dict(klass): - """ Determine whether klass is a Dict """ - return klass.__extra__ == dict - - def is_list(klass): - """ Determine whether klass is a List """ - return klass.__extra__ == list - -else: - - def is_generic(klass): - """ Determine whether klass is a generic class """ - return hasattr(klass, '__origin__') - - def is_dict(klass): - """ Determine whether klass is a Dict """ - return klass.__origin__ == dict - - def is_list(klass): - """ Determine whether klass is a List """ - return klass.__origin__ == list diff --git a/samples/server/petstore/python-flask-openapi/openapi_server/util.py b/samples/server/petstore/python-flask-openapi/openapi_server/util.py deleted file mode 100644 index e1185a713ec9..000000000000 --- a/samples/server/petstore/python-flask-openapi/openapi_server/util.py +++ /dev/null @@ -1,142 +0,0 @@ -import datetime - -import six -import typing -from openapi_server import typing_utils - - -def _deserialize(data, klass): - """Deserializes dict, list, str into an object. - - :param data: dict, list or str. - :param klass: class literal, or string of class name. - - :return: object. - """ - if data is None: - return None - - if klass in six.integer_types or klass in (float, str, bool, bytearray): - return _deserialize_primitive(data, klass) - elif klass == object: - return _deserialize_object(data) - elif klass == datetime.date: - return deserialize_date(data) - elif klass == datetime.datetime: - return deserialize_datetime(data) - elif typing_utils.is_generic(klass): - if typing_utils.is_list(klass): - return _deserialize_list(data, klass.__args__[0]) - if typing_utils.is_dict(klass): - return _deserialize_dict(data, klass.__args__[1]) - else: - return deserialize_model(data, klass) - - -def _deserialize_primitive(data, klass): - """Deserializes to primitive type. - - :param data: data to deserialize. - :param klass: class literal. - - :return: int, long, float, str, bool. - :rtype: int | long | float | str | bool - """ - try: - value = klass(data) - except UnicodeEncodeError: - value = six.u(data) - except TypeError: - value = data - return value - - -def _deserialize_object(value): - """Return an original value. - - :return: object. - """ - return value - - -def deserialize_date(string): - """Deserializes string to date. - - :param string: str. - :type string: str - :return: date. - :rtype: date - """ - try: - from dateutil.parser import parse - return parse(string).date() - except ImportError: - return string - - -def deserialize_datetime(string): - """Deserializes string to datetime. - - The string should be in iso8601 datetime format. - - :param string: str. - :type string: str - :return: datetime. - :rtype: datetime - """ - try: - from dateutil.parser import parse - return parse(string) - except ImportError: - return string - - -def deserialize_model(data, klass): - """Deserializes list or dict to model. - - :param data: dict, list. - :type data: dict | list - :param klass: class literal. - :return: model object. - """ - instance = klass() - - if not instance.openapi_types: - return data - - for attr, attr_type in six.iteritems(instance.openapi_types): - if data is not None \ - and instance.attribute_map[attr] in data \ - and isinstance(data, (list, dict)): - value = data[instance.attribute_map[attr]] - setattr(instance, attr, _deserialize(value, attr_type)) - - return instance - - -def _deserialize_list(data, boxed_type): - """Deserializes a list and its elements. - - :param data: list to deserialize. - :type data: list - :param boxed_type: class literal. - - :return: deserialized list. - :rtype: list - """ - return [_deserialize(sub_data, boxed_type) - for sub_data in data] - - -def _deserialize_dict(data, boxed_type): - """Deserializes a dict and its elements. - - :param data: dict to deserialize. - :type data: dict - :param boxed_type: class literal. - - :return: deserialized dict. - :rtype: dict - """ - return {k: _deserialize(v, boxed_type) - for k, v in six.iteritems(data)} diff --git a/samples/server/petstore/python-flask-openapi/requirements.txt b/samples/server/petstore/python-flask-openapi/requirements.txt deleted file mode 100644 index 2639eedf1361..000000000000 --- a/samples/server/petstore/python-flask-openapi/requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -connexion >= 2.6.0; python_version>="3.6" -connexion >= 2.3.0; python_version=="3.5" -connexion >= 2.3.0; python_version=="3.4" -connexion == 2.4.0; python_version<="2.7" -swagger-ui-bundle >= 0.0.2 -python_dateutil >= 2.6.0 -setuptools >= 21.0.0 diff --git a/samples/server/petstore/python-flask-openapi/setup.py b/samples/server/petstore/python-flask-openapi/setup.py deleted file mode 100644 index 1cd2660efd67..000000000000 --- a/samples/server/petstore/python-flask-openapi/setup.py +++ /dev/null @@ -1,39 +0,0 @@ -# coding: utf-8 - -import sys -from setuptools import setup, find_packages - -NAME = "openapi_server" -VERSION = "1.0.0" - -# To install the library, run the following -# -# python setup.py install -# -# prerequisite: setuptools -# http://pypi.python.org/pypi/setuptools - -REQUIRES = [ - "connexion>=2.0.2", - "swagger-ui-bundle>=0.0.2", - "python_dateutil>=2.6.0" -] - -setup( - name=NAME, - version=VERSION, - description="OpenAPI Petstore", - author_email="", - url="", - keywords=["OpenAPI", "OpenAPI Petstore"], - install_requires=REQUIRES, - packages=find_packages(), - package_data={'': ['openapi/openapi.yaml']}, - include_package_data=True, - entry_points={ - 'console_scripts': ['openapi_server=openapi_server.__main__:main']}, - long_description="""\ - This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - """ -) - diff --git a/samples/server/petstore/python-flask-openapi/test-requirements.txt b/samples/server/petstore/python-flask-openapi/test-requirements.txt deleted file mode 100644 index a2626d875ff4..000000000000 --- a/samples/server/petstore/python-flask-openapi/test-requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -pytest~=4.6.7 # needed for python 2.7+3.4 -pytest-cov>=2.8.1 -pytest-randomly==1.2.3 # needed for python 2.7+3.4 -flask_testing==0.6.1 \ No newline at end of file diff --git a/samples/server/petstore/python-flask-openapi/tox.ini b/samples/server/petstore/python-flask-openapi/tox.ini deleted file mode 100644 index cff71191e6cb..000000000000 --- a/samples/server/petstore/python-flask-openapi/tox.ini +++ /dev/null @@ -1,9 +0,0 @@ -[tox] -envlist = py3 - -[testenv] -deps=-r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt - -commands= - pytest --cov=openapi_server \ No newline at end of file