From a949edced7b705b6e75f99164ace27ff924ed166 Mon Sep 17 00:00:00 2001 From: welshm Date: Thu, 30 May 2024 06:38:59 -0400 Subject: [PATCH 1/8] Add enum support when building default values for model properties --- .../codegen/languages/AbstractPythonCodegen.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java index 386a40557bde..e34721ec122d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java @@ -236,6 +236,13 @@ public String toDefaultValue(Schema p) { } else { return null; } + } else if (ModelUtils.isEnumSchema(p)) { + if (p.getDefault() != null) { + String defaultValue = String.valueOf(p.getDefault()); + if (defaultValue != null) { + return p.getDataType().toString() + "." + defaultValue; + } + } } return null; From 96034a804c10033e58b55411311a191fde81e19c Mon Sep 17 00:00:00 2001 From: welshm Date: Thu, 30 May 2024 09:33:49 -0400 Subject: [PATCH 2/8] Update enum handling for Python for enum references --- bin/configs/python-flask-enum-handling.yaml | 4 + bin/configs/python-flask.yaml | 2 +- .../openapitools/codegen/DefaultCodegen.java | 14 +- .../languages/AbstractPythonCodegen.java | 46 +- .../resources/3_0/python-flask/petstore.yaml | 802 +++++++++++++++++ .../petstore/python-aiohttp/docs/EnumTest.md | 4 +- .../petstore/python-aiohttp/docs/FakeApi.md | 4 +- .../petstore_api/models/enum_test.py | 4 +- .../client/petstore/python/docs/EnumTest.md | 4 +- .../client/petstore/python/docs/FakeApi.md | 4 +- .../python/petstore_api/models/enum_test.py | 4 +- .../petstore/2_0/python-flask/.dockerignore | 72 ++ .../petstore/2_0/python-flask/.gitignore | 66 ++ .../python-flask/.openapi-generator-ignore | 23 + .../2_0/python-flask/.openapi-generator/FILES | 31 + .../python-flask/.openapi-generator/VERSION | 1 + .../petstore/2_0/python-flask/.travis.yml | 14 + .../petstore/2_0/python-flask/Dockerfile | 16 + .../petstore/2_0/python-flask/README.md | 49 ++ .../petstore/2_0/python-flask/git_push.sh | 57 ++ .../python-flask/openapi_server/__init__.py | 0 .../python-flask/openapi_server/__main__.py | 19 + .../openapi_server/controllers/__init__.py | 0 .../controllers/pet_controller.py | 126 +++ .../controllers/security_controller.py | 47 + .../controllers/store_controller.py | 59 ++ .../controllers/user_controller.py | 121 +++ .../python-flask/openapi_server/encoder.py | 19 + .../openapi_server/models/__init__.py | 9 + .../openapi_server/models/api_response.py | 113 +++ .../openapi_server/models/base_model.py | 68 ++ .../openapi_server/models/category.py | 87 ++ .../openapi_server/models/enum_model.py | 42 + .../openapi_server/models/order.py | 199 +++++ .../python-flask/openapi_server/models/pet.py | 207 +++++ .../python-flask/openapi_server/models/tag.py | 87 ++ .../openapi_server/models/user.py | 245 ++++++ .../openapi_server/openapi/openapi.yaml | 826 ++++++++++++++++++ .../openapi_server/test/__init__.py | 16 + .../test/test_pet_controller.py | 166 ++++ .../test/test_store_controller.py | 79 ++ .../test/test_user_controller.py | 151 ++++ .../openapi_server/typing_utils.py | 30 + .../2_0/python-flask/openapi_server/util.py | 147 ++++ .../2_0/python-flask/requirements.txt | 13 + .../server/petstore/2_0/python-flask/setup.py | 37 + .../2_0/python-flask/test-requirements.txt | 4 + .../server/petstore/2_0/python-flask/tox.ini | 11 + .../python-flask/.openapi-generator/FILES | 5 +- .../controllers/fake_controller.py | 21 + .../controllers/pet_controller.py | 20 +- .../controllers/store_controller.py | 8 +- .../controllers/user_controller.py | 32 +- .../openapi_server/models/__init__.py | 4 +- .../openapi_server/models/category.py | 4 + .../openapi_server/models/status_enum.py | 40 + .../openapi_server/models/test_enum.py | 41 + .../models/test_enum_with_default.py | 40 + .../openapi_server/models/test_model.py | 177 ++++ .../openapi_server/openapi/openapi.yaml | 268 ++++-- .../test/test_fake_controller.py | 30 + 61 files changed, 4701 insertions(+), 138 deletions(-) create mode 100644 bin/configs/python-flask-enum-handling.yaml create mode 100644 modules/openapi-generator/src/test/resources/3_0/python-flask/petstore.yaml create mode 100644 samples/server/petstore/2_0/python-flask/.dockerignore create mode 100644 samples/server/petstore/2_0/python-flask/.gitignore create mode 100644 samples/server/petstore/2_0/python-flask/.openapi-generator-ignore create mode 100644 samples/server/petstore/2_0/python-flask/.openapi-generator/FILES create mode 100644 samples/server/petstore/2_0/python-flask/.openapi-generator/VERSION create mode 100644 samples/server/petstore/2_0/python-flask/.travis.yml create mode 100644 samples/server/petstore/2_0/python-flask/Dockerfile create mode 100644 samples/server/petstore/2_0/python-flask/README.md create mode 100644 samples/server/petstore/2_0/python-flask/git_push.sh create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/__init__.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/__main__.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/controllers/__init__.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/controllers/pet_controller.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/controllers/security_controller.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/controllers/store_controller.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/controllers/user_controller.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/encoder.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/__init__.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/api_response.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/base_model.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/category.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/enum_model.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/order.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/pet.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/tag.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/user.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/openapi/openapi.yaml create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/test/__init__.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/test/test_pet_controller.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/test/test_store_controller.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/test/test_user_controller.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/typing_utils.py create mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/util.py create mode 100644 samples/server/petstore/2_0/python-flask/requirements.txt create mode 100644 samples/server/petstore/2_0/python-flask/setup.py create mode 100644 samples/server/petstore/2_0/python-flask/test-requirements.txt create mode 100644 samples/server/petstore/2_0/python-flask/tox.ini create mode 100644 samples/server/petstore/python-flask/openapi_server/controllers/fake_controller.py create mode 100644 samples/server/petstore/python-flask/openapi_server/models/status_enum.py create mode 100644 samples/server/petstore/python-flask/openapi_server/models/test_enum.py create mode 100644 samples/server/petstore/python-flask/openapi_server/models/test_enum_with_default.py create mode 100644 samples/server/petstore/python-flask/openapi_server/models/test_model.py create mode 100644 samples/server/petstore/python-flask/openapi_server/test/test_fake_controller.py diff --git a/bin/configs/python-flask-enum-handling.yaml b/bin/configs/python-flask-enum-handling.yaml new file mode 100644 index 000000000000..32c5659ab43f --- /dev/null +++ b/bin/configs/python-flask-enum-handling.yaml @@ -0,0 +1,4 @@ +generatorName: python-flask +outputDir: samples/server/petstore/python-flask +inputSpec: modules/openapi-generator/src/test/resources/3_0/python-flask/petstore.yaml +templateDir: modules/openapi-generator/src/main/resources/python-flask diff --git a/bin/configs/python-flask.yaml b/bin/configs/python-flask.yaml index 570206be2bc1..5afe28bc1df9 100644 --- a/bin/configs/python-flask.yaml +++ b/bin/configs/python-flask.yaml @@ -1,4 +1,4 @@ generatorName: python-flask -outputDir: samples/server/petstore/python-flask +outputDir: samples/server/petstore/2_0/python-flask inputSpec: modules/openapi-generator/src/test/resources/2_0/python-flask/petstore.yaml templateDir: modules/openapi-generator/src/main/resources/python-flask diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 2954b06c8d8e..9dd6b2f210a3 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -923,6 +923,18 @@ public String toEnumDefaultValue(String value, String datatype) { return datatype + "." + value; } + /** + * Return the enum default value in the language specified format + * + * @param property The codegen property to create the default for. + * @param value Enum variable name + * @return the default value for the enum + */ + public String toEnumDefaultValue(CodegenProperty property, String value) { + // Use the datatype with the value. + return toEnumDefaultValue(value, property.datatypeWithEnum); + } + /** * Return the enum value in the language specified format * e.g. status becomes "status" @@ -6645,7 +6657,7 @@ public void updateCodegenPropertyEnum(CodegenProperty var) { } } if (enumName != null) { - var.defaultValue = toEnumDefaultValue(enumName, var.datatypeWithEnum); + var.defaultValue = toEnumDefaultValue(var, enumName); } } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java index e34721ec122d..b842d43ea359 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java @@ -198,6 +198,18 @@ public String escapeReservedWord(String name) { */ @Override public String toDefaultValue(Schema p) { + // If the Schema is a $ref, get the default value from the reference. + String ref = ModelUtils.getSimpleRef(p.get$ref()); + if (ref != null) { + Schema referencedSchema = ModelUtils.getSchemas(this.openAPI).get(ref); + if (referencedSchema != null) { + String defaultValue = toDefaultValue(referencedSchema); + if (defaultValue != null) { + return defaultValue; + } + // No default was found for the $ref, so see if one has been defined locally. + } + } if (ModelUtils.isBooleanSchema(p)) { if (p.getDefault() != null) { if (!Boolean.valueOf(p.getDefault().toString())) @@ -217,6 +229,14 @@ public String toDefaultValue(Schema p) { if (p.getDefault() != null) { return p.getDefault().toString(); } + } else if (ModelUtils.isEnumSchema(p)) { + // Enum must come before string to use enum reference! + if (p.getDefault() != null) { + String defaultValue = String.valueOf(p.getDefault()); + if (defaultValue != null) { + return defaultValue; + } + } } else if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { String defaultValue = String.valueOf(p.getDefault()); @@ -236,15 +256,7 @@ public String toDefaultValue(Schema p) { } else { return null; } - } else if (ModelUtils.isEnumSchema(p)) { - if (p.getDefault() != null) { - String defaultValue = String.valueOf(p.getDefault()); - if (defaultValue != null) { - return p.getDataType().toString() + "." + defaultValue; - } - } } - return null; } @@ -1092,7 +1104,9 @@ public String toEnumVariableName(String name, String datatype) { } // remove quote e.g. 'abc' => abc - name = name.substring(1, name.length() - 1); + if (name.startsWith("'") && name.endsWith("'")) { + name = name.substring(1, name.length() - 1); + } if (name.length() == 0) { return "EMPTY"; @@ -1403,10 +1417,22 @@ public String toEnumValue(String value, String datatype) { } @Override - public String toEnumDefaultValue(String value, String datatype) { + public String toEnumDefaultValue(CodegenProperty property, String value) { + if (property.isEnumRef) { + // Determine if it's a string by checking if the value has already been encapsulated in single quotes. + String dataType = (value.startsWith("'") && value.endsWith("'")) ? "string" : "int"; + // If the property is an enum reference, then use the fully qualified name with the data type. + return property.dataType + "." + toEnumVariableName(value, dataType); + } return value; } + @Override + public String toEnumDefaultValue(String value, String datatype) { + // Remove the string encapsulating the value and prefix with the datatype. + return datatype + "." + toEnumVariableName(value, datatype); + } + /** * checks if the data should be classified as "string" in enum * e.g. double in C# needs to be double-quoted (e.g. "2.8") by treating it as a string diff --git a/modules/openapi-generator/src/test/resources/3_0/python-flask/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/python-flask/petstore.yaml new file mode 100644 index 000000000000..49a6c04654bb --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/python-flask/petstore.yaml @@ -0,0 +1,802 @@ +openapi: 3.0.0 +servers: + - url: 'http://petstore.swagger.io/v2' +info: + description: >- + This is a sample server Petstore server. For this sample, you can use the api key + `special-key` to test the authorization filters. + version: 1.0.0 + title: OpenAPI Petstore + license: + name: Apache-2.0 + url: 'https://www.apache.org/licenses/LICENSE-2.0.html' +tags: + - name: pet + description: Everything about your Pets + - name: store + description: Access to Petstore orders + - name: user + description: Operations about user +paths: + /pet: + post: + tags: + - pet + summary: Add a new pet to the store + description: '' + operationId: addPet + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '405': + description: Invalid input + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + $ref: '#/components/requestBodies/Pet' + put: + tags: + - pet + summary: Update an existing pet + description: '' + operationId: updatePet + externalDocs: + url: "http://petstore.swagger.io/v2/doc/updatePet" + description: "API documentation for the updatePet operation" + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid ID supplied + '404': + description: Pet not found + '405': + description: Validation exception + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + $ref: '#/components/requestBodies/Pet' + /pet/findByStatus: + get: + tags: + - pet + summary: Finds Pets by status + description: Multiple status values can be provided with comma separated strings + operationId: findPetsByStatus + parameters: + - name: status + in: query + description: Status values that need to be considered for filter + required: true + style: form + explode: false + deprecated: true + schema: + type: array + items: + type: string + enum: + - available + - pending + - sold + default: available + responses: + '200': + description: successful operation + content: + application/xml: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid status value + security: + - petstore_auth: + - 'read:pets' + /pet/findByTags: + get: + tags: + - pet + summary: Finds Pets by tags + description: >- + Multiple tags can be provided with comma separated strings. Use tag1, + tag2, tag3 for testing. + operationId: findPetsByTags + parameters: + - name: tags + in: query + description: Tags to filter by + required: true + style: form + explode: false + schema: + type: array + items: + type: string + responses: + '200': + description: successful operation + content: + application/xml: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid tag value + security: + - petstore_auth: + - 'read:pets' + deprecated: true + '/pet/{petId}': + get: + tags: + - pet + summary: Find pet by ID + description: Returns a single pet + operationId: getPetById + parameters: + - name: petId + in: path + description: ID of pet to return + required: true + schema: + type: integer + format: int64 + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + '400': + description: Invalid ID supplied + '404': + description: Pet not found + security: + - api_key: [] + post: + tags: + - pet + summary: Updates a pet in the store with form data + description: '' + operationId: updatePetWithForm + parameters: + - name: petId + in: path + description: ID of pet that needs to be updated + required: true + schema: + type: integer + format: int64 + responses: + '405': + description: Invalid input + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + application/x-www-form-urlencoded: + schema: + type: object + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + delete: + tags: + - pet + summary: Deletes a pet + description: '' + operationId: deletePet + parameters: + - name: api_key + in: header + required: false + schema: + type: string + - name: petId + in: path + description: Pet id to delete + required: true + schema: + type: integer + format: int64 + responses: + '400': + description: Invalid pet value + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + '/pet/{petId}/uploadImage': + post: + tags: + - pet + summary: uploads an image + description: '' + operationId: uploadFile + parameters: + - name: petId + in: path + description: ID of pet to update + required: true + schema: + type: integer + format: int64 + responses: + '200': + description: successful operation + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' + requestBody: + content: + multipart/form-data: + schema: + type: object + properties: + additionalMetadata: + description: Additional data to pass to server + type: string + file: + description: file to upload + type: string + format: binary + /store/inventory: + get: + tags: + - store + summary: Returns pet inventories by status + description: Returns a map of status codes to quantities + operationId: getInventory + responses: + '200': + description: successful operation + content: + application/json: + schema: + type: object + additionalProperties: + type: integer + format: int32 + security: + - api_key: [] + /store/order: + post: + tags: + - store + summary: Place an order for a pet + description: '' + operationId: placeOrder + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + '400': + description: Invalid Order + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Order' + description: order placed for purchasing the pet + required: true + '/store/order/{orderId}': + get: + tags: + - store + summary: Find purchase order by ID + description: >- + For valid response try integer IDs with value <= 5 or > 10. Other values + will generate exceptions + operationId: getOrderById + parameters: + - name: orderId + in: path + description: ID of pet that needs to be fetched + required: true + schema: + type: integer + format: int64 + minimum: 1 + maximum: 5 + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + '400': + description: Invalid ID supplied + '404': + description: Order not found + delete: + tags: + - store + summary: Delete purchase order by ID + description: >- + For valid response try integer IDs with value < 1000. Anything above + 1000 or nonintegers will generate API errors + operationId: deleteOrder + parameters: + - name: orderId + in: path + description: ID of the order that needs to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid ID supplied + '404': + description: Order not found + /user: + post: + tags: + - user + summary: Create user + description: This can only be done by the logged in user. + operationId: createUser + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Created user object + required: true + /user/createWithArray: + post: + tags: + - user + summary: Creates list of users with given input array + description: '' + operationId: createUsersWithArrayInput + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + $ref: '#/components/requestBodies/UserArray' + /user/createWithList: + post: + tags: + - user + summary: Creates list of users with given input array + description: '' + operationId: createUsersWithListInput + responses: + default: + description: successful operation + security: + - api_key: [] + requestBody: + $ref: '#/components/requestBodies/UserArray' + /user/login: + get: + tags: + - user + summary: Logs user into the system + description: '' + operationId: loginUser + parameters: + - name: username + in: query + description: The user name for login + required: true + schema: + type: string + pattern: '^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$' + - name: password + in: query + description: The password for login in clear text + required: true + schema: + type: string + responses: + '200': + description: successful operation + headers: + Set-Cookie: + description: >- + Cookie authentication key for use with the `api_key` + apiKey authentication. + schema: + type: string + example: AUTH_KEY=abcde12345; Path=/; HttpOnly + X-Rate-Limit: + description: calls per hour allowed by the user + schema: + type: integer + format: int32 + X-Expires-After: + description: date in UTC when token expires + schema: + type: string + format: date-time + content: + application/xml: + schema: + type: string + application/json: + schema: + type: string + '400': + description: Invalid username/password supplied + /user/logout: + get: + tags: + - user + summary: Logs out current logged in user session + description: '' + operationId: logoutUser + responses: + default: + description: successful operation + security: + - api_key: [] + '/user/{username}': + get: + tags: + - user + summary: Get user by user name + description: '' + operationId: getUserByName + parameters: + - name: username + in: path + description: The name that needs to be fetched. Use user1 for testing. + required: true + schema: + type: string + responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/User' + application/json: + schema: + $ref: '#/components/schemas/User' + '400': + description: Invalid username supplied + '404': + description: User not found + put: + tags: + - user + summary: Updated user + description: This can only be done by the logged in user. + operationId: updateUser + parameters: + - name: username + in: path + description: name that need to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid user supplied + '404': + description: User not found + security: + - api_key: [] + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: Updated user object + required: true + delete: + tags: + - user + summary: Delete user + description: This can only be done by the logged in user. + operationId: deleteUser + parameters: + - name: username + in: path + description: The name that needs to be deleted + required: true + schema: + type: string + responses: + '400': + description: Invalid username supplied + '404': + description: User not found + security: + - api_key: [] + /fake/query_param_default: + get: + tags: + - fake + summary: test query parameter default value + description: '' + operationId: fake_query_param_default + parameters: + - name: hasDefault + in: query + description: has default value + schema: + type: string + default: Hello World + - name: noDefault + in: query + description: no default value + schema: + type: string + responses: + '400': + description: Invalid username supplied + '404': + description: User not found +externalDocs: + description: Find out more about Swagger + url: 'http://swagger.io' +components: + requestBodies: + UserArray: + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/User' + description: List of user object + required: true + Pet: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store + required: true + securitySchemes: + petstore_auth: + type: oauth2 + flows: + implicit: + authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog' + scopes: + 'write:pets': modify pets in your account + 'read:pets': read your pets + api_key: + type: apiKey + name: api_key + in: header + schemas: + Order: + title: Pet Order + description: An order for a pets from the pet store + type: object + properties: + id: + type: integer + format: int64 + petId: + type: integer + format: int64 + quantity: + type: integer + format: int32 + shipDate: + type: string + format: date-time + status: + type: string + description: Order Status + enum: + - placed + - approved + - delivered + complete: + type: boolean + default: false + xml: + name: Order + Category: + title: Pet category + description: A category for a pet + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + pattern: '^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$' + xml: + name: Category + User: + title: a User + description: A User who is purchasing from the pet store + type: object + properties: + id: + type: integer + format: int64 + username: + type: string + firstName: + type: string + lastName: + type: string + email: + type: string + password: + type: string + phone: + type: string + userStatus: + type: integer + format: int32 + description: User Status + xml: + name: User + Tag: + title: Pet Tag + description: A tag for a pet + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + xml: + name: Tag + Pet: + title: a Pet + description: A pet for sale in the pet store + type: object + required: + - name + - photoUrls + properties: + id: + type: integer + format: int64 + category: + $ref: '#/components/schemas/Category' + name: + type: string + example: doggie + photoUrls: + type: array + xml: + name: photoUrl + wrapped: true + items: + type: string + tags: + type: array + xml: + name: tag + wrapped: true + items: + $ref: '#/components/schemas/Tag' + status: + type: string + description: pet status in the store + deprecated: true + enum: + - available + - pending + - sold + xml: + name: Pet + ApiResponse: + title: An uploaded response + description: Describes the result of uploading an image resource + type: object + properties: + code: + type: integer + format: int32 + type: + type: string + message: + type: string + TestEnum: + type: string + enum: + - ONE + - TWO + - THREE + - foUr + TestEnumWithDefault: + type: string + enum: + - EIN + - ZWEI + - DREI + default: ZWEI + TestModel: + type: object + required: + - test_enum + properties: + test_enum: + $ref: "#/components/schemas/TestEnum" + test_string: + type: string + example: "Just some string" + test_enum_with_default: + $ref: "#/components/schemas/TestEnumWithDefault" + test_string_with_default: + type: string + example: "More string" + default: "ahoy matey" + test_inline_defined_enum_with_default: + type: string + enum: + - A + - B + - C + default: B diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/EnumTest.md b/samples/openapi3/client/petstore/python-aiohttp/docs/EnumTest.md index dd37f9cc7b4c..72f5fbdae230 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/EnumTest.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/EnumTest.md @@ -14,8 +14,8 @@ Name | Type | Description | Notes **enum_string_vendor_ext** | **str** | | [optional] **outer_enum** | [**OuterEnum**](OuterEnum.md) | | [optional] **outer_enum_integer** | [**OuterEnumInteger**](OuterEnumInteger.md) | | [optional] -**outer_enum_default_value** | [**OuterEnumDefaultValue**](OuterEnumDefaultValue.md) | | [optional] -**outer_enum_integer_default_value** | [**OuterEnumIntegerDefaultValue**](OuterEnumIntegerDefaultValue.md) | | [optional] +**outer_enum_default_value** | [**OuterEnumDefaultValue**](OuterEnumDefaultValue.md) | | [optional] [default to OuterEnumDefaultValue.PLACED] +**outer_enum_integer_default_value** | [**OuterEnumIntegerDefaultValue**](OuterEnumIntegerDefaultValue.md) | | [optional] [default to OuterEnumIntegerDefaultValue.NUMBER_0] ## Example diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/FakeApi.md b/samples/openapi3/client/petstore/python-aiohttp/docs/FakeApi.md index a04e01c3df64..7d895e650b3a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/FakeApi.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/FakeApi.md @@ -130,7 +130,7 @@ configuration = petstore_api.Configuration( async with petstore_api.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = petstore_api.FakeApi(api_client) - enum_ref = petstore_api.EnumClass() # EnumClass | enum reference (optional) + enum_ref = -efg # EnumClass | enum reference (optional) (default to -efg) try: # test enum reference query parameter @@ -146,7 +146,7 @@ async with petstore_api.ApiClient(configuration) as api_client: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **enum_ref** | [**EnumClass**](.md)| enum reference | [optional] + **enum_ref** | [**EnumClass**](.md)| enum reference | [optional] [default to -efg] ### Return type diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py index 1e65d8a80185..f7e053b23db8 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py @@ -39,8 +39,8 @@ class EnumTest(BaseModel): enum_string_vendor_ext: Optional[StrictStr] = None outer_enum: Optional[OuterEnum] = Field(default=None, alias="outerEnum") outer_enum_integer: Optional[OuterEnumInteger] = Field(default=None, alias="outerEnumInteger") - outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(default=None, alias="outerEnumDefaultValue") - outer_enum_integer_default_value: Optional[OuterEnumIntegerDefaultValue] = Field(default=None, alias="outerEnumIntegerDefaultValue") + outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(default=OuterEnumDefaultValue.PLACED, alias="outerEnumDefaultValue") + outer_enum_integer_default_value: Optional[OuterEnumIntegerDefaultValue] = Field(default=OuterEnumIntegerDefaultValue.NUMBER_0, alias="outerEnumIntegerDefaultValue") __properties: ClassVar[List[str]] = ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "enum_number_vendor_ext", "enum_string_vendor_ext", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"] @field_validator('enum_string') diff --git a/samples/openapi3/client/petstore/python/docs/EnumTest.md b/samples/openapi3/client/petstore/python/docs/EnumTest.md index dd37f9cc7b4c..72f5fbdae230 100644 --- a/samples/openapi3/client/petstore/python/docs/EnumTest.md +++ b/samples/openapi3/client/petstore/python/docs/EnumTest.md @@ -14,8 +14,8 @@ Name | Type | Description | Notes **enum_string_vendor_ext** | **str** | | [optional] **outer_enum** | [**OuterEnum**](OuterEnum.md) | | [optional] **outer_enum_integer** | [**OuterEnumInteger**](OuterEnumInteger.md) | | [optional] -**outer_enum_default_value** | [**OuterEnumDefaultValue**](OuterEnumDefaultValue.md) | | [optional] -**outer_enum_integer_default_value** | [**OuterEnumIntegerDefaultValue**](OuterEnumIntegerDefaultValue.md) | | [optional] +**outer_enum_default_value** | [**OuterEnumDefaultValue**](OuterEnumDefaultValue.md) | | [optional] [default to OuterEnumDefaultValue.PLACED] +**outer_enum_integer_default_value** | [**OuterEnumIntegerDefaultValue**](OuterEnumIntegerDefaultValue.md) | | [optional] [default to OuterEnumIntegerDefaultValue.NUMBER_0] ## Example diff --git a/samples/openapi3/client/petstore/python/docs/FakeApi.md b/samples/openapi3/client/petstore/python/docs/FakeApi.md index b5183d1123a8..a45bd7670a8c 100644 --- a/samples/openapi3/client/petstore/python/docs/FakeApi.md +++ b/samples/openapi3/client/petstore/python/docs/FakeApi.md @@ -130,7 +130,7 @@ configuration = petstore_api.Configuration( with petstore_api.ApiClient(configuration) as api_client: # Create an instance of the API class api_instance = petstore_api.FakeApi(api_client) - enum_ref = petstore_api.EnumClass() # EnumClass | enum reference (optional) + enum_ref = -efg # EnumClass | enum reference (optional) (default to -efg) try: # test enum reference query parameter @@ -146,7 +146,7 @@ with petstore_api.ApiClient(configuration) as api_client: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **enum_ref** | [**EnumClass**](.md)| enum reference | [optional] + **enum_ref** | [**EnumClass**](.md)| enum reference | [optional] [default to -efg] ### Return type diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py index bd4e77461346..918b080940a2 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py @@ -39,8 +39,8 @@ class EnumTest(BaseModel): enum_string_vendor_ext: Optional[StrictStr] = None outer_enum: Optional[OuterEnum] = Field(default=None, alias="outerEnum") outer_enum_integer: Optional[OuterEnumInteger] = Field(default=None, alias="outerEnumInteger") - outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(default=None, alias="outerEnumDefaultValue") - outer_enum_integer_default_value: Optional[OuterEnumIntegerDefaultValue] = Field(default=None, alias="outerEnumIntegerDefaultValue") + outer_enum_default_value: Optional[OuterEnumDefaultValue] = Field(default=OuterEnumDefaultValue.PLACED, alias="outerEnumDefaultValue") + outer_enum_integer_default_value: Optional[OuterEnumIntegerDefaultValue] = Field(default=OuterEnumIntegerDefaultValue.NUMBER_0, alias="outerEnumIntegerDefaultValue") additional_properties: Dict[str, Any] = {} __properties: ClassVar[List[str]] = ["enum_string", "enum_string_required", "enum_integer_default", "enum_integer", "enum_number", "enum_number_vendor_ext", "enum_string_vendor_ext", "outerEnum", "outerEnumInteger", "outerEnumDefaultValue", "outerEnumIntegerDefaultValue"] diff --git a/samples/server/petstore/2_0/python-flask/.dockerignore b/samples/server/petstore/2_0/python-flask/.dockerignore new file mode 100644 index 000000000000..f9619601908b --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/.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/2_0/python-flask/.gitignore b/samples/server/petstore/2_0/python-flask/.gitignore new file mode 100644 index 000000000000..43995bd42fa2 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/.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/2_0/python-flask/.openapi-generator-ignore b/samples/server/petstore/2_0/python-flask/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/.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/2_0/python-flask/.openapi-generator/FILES b/samples/server/petstore/2_0/python-flask/.openapi-generator/FILES new file mode 100644 index 000000000000..c08d341ed532 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/.openapi-generator/FILES @@ -0,0 +1,31 @@ +.dockerignore +.gitignore +.travis.yml +Dockerfile +README.md +git_push.sh +openapi_server/__init__.py +openapi_server/__main__.py +openapi_server/controllers/__init__.py +openapi_server/controllers/pet_controller.py +openapi_server/controllers/security_controller.py +openapi_server/controllers/store_controller.py +openapi_server/controllers/user_controller.py +openapi_server/encoder.py +openapi_server/models/__init__.py +openapi_server/models/api_response.py +openapi_server/models/base_model.py +openapi_server/models/category.py +openapi_server/models/enum_model.py +openapi_server/models/order.py +openapi_server/models/pet.py +openapi_server/models/tag.py +openapi_server/models/user.py +openapi_server/openapi/openapi.yaml +openapi_server/test/__init__.py +openapi_server/typing_utils.py +openapi_server/util.py +requirements.txt +setup.py +test-requirements.txt +tox.ini diff --git a/samples/server/petstore/2_0/python-flask/.openapi-generator/VERSION b/samples/server/petstore/2_0/python-flask/.openapi-generator/VERSION new file mode 100644 index 000000000000..7e7b8b9bc733 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.7.0-SNAPSHOT diff --git a/samples/server/petstore/2_0/python-flask/.travis.yml b/samples/server/petstore/2_0/python-flask/.travis.yml new file mode 100644 index 000000000000..ad71ee5ca083 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/.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/2_0/python-flask/Dockerfile b/samples/server/petstore/2_0/python-flask/Dockerfile new file mode 100644 index 000000000000..4857637c3799 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/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/2_0/python-flask/README.md b/samples/server/petstore/2_0/python-flask/README.md new file mode 100644 index 000000000000..673c8b3b5a01 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/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/2_0/python-flask/git_push.sh b/samples/server/petstore/2_0/python-flask/git_push.sh new file mode 100644 index 000000000000..f53a75d4fabe --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/git_push.sh @@ -0,0 +1,57 @@ +#!/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-petstore-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/2_0/python-flask/openapi_server/__init__.py b/samples/server/petstore/2_0/python-flask/openapi_server/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/__main__.py b/samples/server/petstore/2_0/python-flask/openapi_server/__main__.py new file mode 100644 index 000000000000..6045d0156f05 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/__main__.py @@ -0,0 +1,19 @@ +#!/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/2_0/python-flask/openapi_server/controllers/__init__.py b/samples/server/petstore/2_0/python-flask/openapi_server/controllers/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/controllers/pet_controller.py b/samples/server/petstore/2_0/python-flask/openapi_server/controllers/pet_controller.py new file mode 100644 index 000000000000..89086c54bd41 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/controllers/pet_controller.py @@ -0,0 +1,126 @@ +import connexion +from typing import Dict +from typing import Tuple +from typing import Union + +from openapi_server.models.api_response import ApiResponse # noqa: E501 +from openapi_server.models.pet import Pet # noqa: E501 +from openapi_server import util + + +def add_pet(body): # noqa: E501 + """Add a new pet to the store + + # noqa: E501 + + :param body: Pet object that needs to be added to the store + :type body: dict | bytes + + :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] + """ + if connexion.request.is_json: + body = 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: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] + """ + 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: Union[List[Pet], Tuple[List[Pet], int], Tuple[List[Pet], int, Dict[str, str]] + """ + 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: Union[List[Pet], Tuple[List[Pet], int], Tuple[List[Pet], int, Dict[str, str]] + """ + 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: Union[Pet, Tuple[Pet, int], Tuple[Pet, int, Dict[str, str]] + """ + return 'do some magic!' + + +def update_pet(body): # noqa: E501 + """Update an existing pet + + # noqa: E501 + + :param body: Pet object that needs to be added to the store + :type body: dict | bytes + + :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] + """ + if connexion.request.is_json: + body = Pet.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: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] + """ + 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: Union[ApiResponse, Tuple[ApiResponse, int], Tuple[ApiResponse, int, Dict[str, str]] + """ + return 'do some magic!' diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/controllers/security_controller.py b/samples/server/petstore/2_0/python-flask/openapi_server/controllers/security_controller.py new file mode 100644 index 000000000000..aae1a19e84aa --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/controllers/security_controller.py @@ -0,0 +1,47 @@ +from typing import List + + +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)) + + +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'} + diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/controllers/store_controller.py b/samples/server/petstore/2_0/python-flask/openapi_server/controllers/store_controller.py new file mode 100644 index 000000000000..62887e7adac0 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/controllers/store_controller.py @@ -0,0 +1,59 @@ +import connexion +from typing import Dict +from typing import Tuple +from typing import Union + +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: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] + """ + 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: Union[Dict[str, int], Tuple[Dict[str, int], int], Tuple[Dict[str, int], int, Dict[str, str]] + """ + 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 generate exceptions # noqa: E501 + + :param order_id: ID of pet that needs to be fetched + :type order_id: int + + :rtype: Union[Order, Tuple[Order, int], Tuple[Order, int, Dict[str, str]] + """ + return 'do some magic!' + + +def place_order(body): # noqa: E501 + """Place an order for a pet + + # noqa: E501 + + :param body: order placed for purchasing the pet + :type body: dict | bytes + + :rtype: Union[Order, Tuple[Order, int], Tuple[Order, int, Dict[str, str]] + """ + if connexion.request.is_json: + body = Order.from_dict(connexion.request.get_json()) # noqa: E501 + return 'do some magic!' diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/controllers/user_controller.py b/samples/server/petstore/2_0/python-flask/openapi_server/controllers/user_controller.py new file mode 100644 index 000000000000..0acef4751501 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/controllers/user_controller.py @@ -0,0 +1,121 @@ +import connexion +from typing import Dict +from typing import Tuple +from typing import Union + +from openapi_server.models.user import User # noqa: E501 +from openapi_server import util + + +def create_user(body): # noqa: E501 + """Create user + + This can only be done by the logged in user. # noqa: E501 + + :param body: Created user object + :type body: dict | bytes + + :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] + """ + if connexion.request.is_json: + body = User.from_dict(connexion.request.get_json()) # noqa: E501 + return 'do some magic!' + + +def create_users_with_array_input(body): # noqa: E501 + """Creates list of users with given input array + + # noqa: E501 + + :param body: List of user object + :type body: list | bytes + + :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] + """ + if connexion.request.is_json: + body = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501 + return 'do some magic!' + + +def create_users_with_list_input(body): # noqa: E501 + """Creates list of users with given input array + + # noqa: E501 + + :param body: List of user object + :type body: list | bytes + + :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] + """ + if connexion.request.is_json: + body = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501 + 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: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] + """ + 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: Union[User, Tuple[User, int], Tuple[User, int, Dict[str, str]] + """ + 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: Union[str, Tuple[str, int], Tuple[str, int, Dict[str, str]] + """ + return 'do some magic!' + + +def logout_user(): # noqa: E501 + """Logs out current logged in user session + + # noqa: E501 + + + :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] + """ + return 'do some magic!' + + +def update_user(username, body): # noqa: E501 + """Updated user + + This can only be done by the logged in user. # noqa: E501 + + :param username: name that need to be deleted + :type username: str + :param body: Updated user object + :type body: dict | bytes + + :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] + """ + if connexion.request.is_json: + body = User.from_dict(connexion.request.get_json()) # noqa: E501 + return 'do some magic!' diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/encoder.py b/samples/server/petstore/2_0/python-flask/openapi_server/encoder.py new file mode 100644 index 000000000000..60f4fa67e7dc --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/encoder.py @@ -0,0 +1,19 @@ +from connexion.apps.flask_app import FlaskJSONEncoder + +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 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/2_0/python-flask/openapi_server/models/__init__.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/__init__.py new file mode 100644 index 000000000000..21d4d1aeb93d --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/models/__init__.py @@ -0,0 +1,9 @@ +# flake8: noqa +# import models into model package +from openapi_server.models.api_response import ApiResponse +from openapi_server.models.category import Category +from openapi_server.models.enum_model import EnumModel +from openapi_server.models.order import Order +from openapi_server.models.pet import Pet +from openapi_server.models.tag import Tag +from openapi_server.models.user import User diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/models/api_response.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/api_response.py new file mode 100644 index 000000000000..983e11cc4ea2 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/models/api_response.py @@ -0,0 +1,113 @@ +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) -> int: + """Gets the code of this ApiResponse. + + + :return: The code of this ApiResponse. + :rtype: int + """ + return self._code + + @code.setter + def code(self, code: int): + """Sets the code of this ApiResponse. + + + :param code: The code of this ApiResponse. + :type code: int + """ + + self._code = code + + @property + def type(self) -> str: + """Gets the type of this ApiResponse. + + + :return: The type of this ApiResponse. + :rtype: str + """ + return self._type + + @type.setter + def type(self, type: str): + """Sets the type of this ApiResponse. + + + :param type: The type of this ApiResponse. + :type type: str + """ + + self._type = type + + @property + def message(self) -> str: + """Gets the message of this ApiResponse. + + + :return: The message of this ApiResponse. + :rtype: str + """ + return self._message + + @message.setter + def message(self, message: str): + """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/2_0/python-flask/openapi_server/models/base_model.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/base_model.py new file mode 100644 index 000000000000..c01b423a7432 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/models/base_model.py @@ -0,0 +1,68 @@ +import pprint + +import typing + +from openapi_server import util + +T = typing.TypeVar('T') + + +class Model: + # openapiTypes: The key is attribute name and the + # value is attribute type. + openapi_types: typing.Dict[str, type] = {} + + # attributeMap: The key is attribute name and the + # value is json key in definition. + attribute_map: typing.Dict[str, str] = {} + + @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 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/2_0/python-flask/openapi_server/models/category.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/category.py new file mode 100644 index 000000000000..4bdec5b25c4f --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/models/category.py @@ -0,0 +1,87 @@ +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 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) -> int: + """Gets the id of this Category. + + + :return: The id of this Category. + :rtype: int + """ + return self._id + + @id.setter + def id(self, id: int): + """Sets the id of this Category. + + + :param id: The id of this Category. + :type id: int + """ + + self._id = id + + @property + def name(self) -> str: + """Gets the name of this Category. + + + :return: The name of this Category. + :rtype: str + """ + return self._name + + @name.setter + def name(self, name: str): + """Sets the name of this Category. + + + :param name: The name of this Category. + :type name: str + """ + + self._name = name diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/models/enum_model.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/enum_model.py new file mode 100644 index 000000000000..5d60d2aaef2f --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/models/enum_model.py @@ -0,0 +1,42 @@ +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 EnumModel(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + """ + allowed enum values + """ + AVAILABLE_GREATER_THAN = 'available>' + PENDING_LESS_THAN = 'pending<' + SOLD = 'sold' + ENUM_1 = '1' + ENUM_2 = '2' + def __init__(self): # noqa: E501 + """EnumModel - a model defined in OpenAPI + + """ + self.openapi_types = { + } + + self.attribute_map = { + } + + @classmethod + def from_dict(cls, dikt) -> 'EnumModel': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The EnumModel of this EnumModel. # noqa: E501 + :rtype: EnumModel + """ + return util.deserialize_model(dikt, cls) diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/models/order.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/order.py new file mode 100644 index 000000000000..1fdf0cb3b798 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/models/order.py @@ -0,0 +1,199 @@ +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) -> int: + """Gets the id of this Order. + + + :return: The id of this Order. + :rtype: int + """ + return self._id + + @id.setter + def id(self, id: int): + """Sets the id of this Order. + + + :param id: The id of this Order. + :type id: int + """ + + self._id = id + + @property + def pet_id(self) -> int: + """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: int): + """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) -> int: + """Gets the quantity of this Order. + + + :return: The quantity of this Order. + :rtype: int + """ + return self._quantity + + @quantity.setter + def quantity(self, quantity: int): + """Sets the quantity of this Order. + + + :param quantity: The quantity of this Order. + :type quantity: int + """ + + self._quantity = quantity + + @property + def ship_date(self) -> datetime: + """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: datetime): + """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) -> str: + """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: str): + """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) -> bool: + """Gets the complete of this Order. + + + :return: The complete of this Order. + :rtype: bool + """ + return self._complete + + @complete.setter + def complete(self, complete: bool): + """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/2_0/python-flask/openapi_server/models/pet.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/pet.py new file mode 100644 index 000000000000..b460a10303ee --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/models/pet.py @@ -0,0 +1,207 @@ +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) -> int: + """Gets the id of this Pet. + + + :return: The id of this Pet. + :rtype: int + """ + return self._id + + @id.setter + def id(self, id: int): + """Sets the id of this Pet. + + + :param id: The id of this Pet. + :type id: int + """ + + self._id = id + + @property + def category(self) -> Category: + """Gets the category of this Pet. + + + :return: The category of this Pet. + :rtype: Category + """ + return self._category + + @category.setter + def category(self, category: Category): + """Sets the category of this Pet. + + + :param category: The category of this Pet. + :type category: Category + """ + + self._category = category + + @property + def name(self) -> str: + """Gets the name of this Pet. + + + :return: The name of this Pet. + :rtype: str + """ + return self._name + + @name.setter + def name(self, name: str): + """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) -> List[str]: + """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: List[str]): + """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) -> List[Tag]: + """Gets the tags of this Pet. + + + :return: The tags of this Pet. + :rtype: List[Tag] + """ + return self._tags + + @tags.setter + def tags(self, tags: List[Tag]): + """Sets the tags of this Pet. + + + :param tags: The tags of this Pet. + :type tags: List[Tag] + """ + + self._tags = tags + + @property + def status(self) -> str: + """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: str): + """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/2_0/python-flask/openapi_server/models/tag.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/tag.py new file mode 100644 index 000000000000..2a38c9ee02a5 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/models/tag.py @@ -0,0 +1,87 @@ +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) -> int: + """Gets the id of this Tag. + + + :return: The id of this Tag. + :rtype: int + """ + return self._id + + @id.setter + def id(self, id: int): + """Sets the id of this Tag. + + + :param id: The id of this Tag. + :type id: int + """ + + self._id = id + + @property + def name(self) -> str: + """Gets the name of this Tag. + + + :return: The name of this Tag. + :rtype: str + """ + return self._name + + @name.setter + def name(self, name: str): + """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/2_0/python-flask/openapi_server/models/user.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/user.py new file mode 100644 index 000000000000..868b4c85b941 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/models/user.py @@ -0,0 +1,245 @@ +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) -> int: + """Gets the id of this User. + + + :return: The id of this User. + :rtype: int + """ + return self._id + + @id.setter + def id(self, id: int): + """Sets the id of this User. + + + :param id: The id of this User. + :type id: int + """ + + self._id = id + + @property + def username(self) -> str: + """Gets the username of this User. + + + :return: The username of this User. + :rtype: str + """ + return self._username + + @username.setter + def username(self, username: str): + """Sets the username of this User. + + + :param username: The username of this User. + :type username: str + """ + + self._username = username + + @property + def first_name(self) -> str: + """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: str): + """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) -> str: + """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: str): + """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) -> str: + """Gets the email of this User. + + + :return: The email of this User. + :rtype: str + """ + return self._email + + @email.setter + def email(self, email: str): + """Sets the email of this User. + + + :param email: The email of this User. + :type email: str + """ + + self._email = email + + @property + def password(self) -> str: + """Gets the password of this User. + + + :return: The password of this User. + :rtype: str + """ + return self._password + + @password.setter + def password(self, password: str): + """Sets the password of this User. + + + :param password: The password of this User. + :type password: str + """ + + self._password = password + + @property + def phone(self) -> str: + """Gets the phone of this User. + + + :return: The phone of this User. + :rtype: str + """ + return self._phone + + @phone.setter + def phone(self, phone: str): + """Sets the phone of this User. + + + :param phone: The phone of this User. + :type phone: str + """ + + self._phone = phone + + @property + def user_status(self) -> int: + """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: int): + """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/2_0/python-flask/openapi_server/openapi/openapi.yaml b/samples/server/petstore/2_0/python-flask/openapi_server/openapi/openapi.yaml new file mode 100644 index 000000000000..21e70929a17c --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/openapi/openapi.yaml @@ -0,0 +1,826 @@ +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 +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: + 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 + responses: + "405": + content: {} + description: Invalid input + security: + - petstore_auth: + - write:pets + - read:pets + summary: Add a new pet to the store + tags: + - pet + x-codegen-request-body-name: body + x-openapi-router-controller: openapi_server.controllers.pet_controller + put: + operationId: update_pet + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store + required: true + responses: + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + description: Pet not found + "405": + content: {} + description: Validation exception + security: + - petstore_auth: + - write:pets + - read:pets + summary: Update an existing pet + tags: + - pet + x-codegen-request-body-name: body + x-openapi-router-controller: openapi_server.controllers.pet_controller + /pet/findByStatus: + get: + description: Multiple status values can be provided with comma separated strings + operationId: find_pets_by_status + parameters: + - description: Status values that need to be considered for filter + 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": + content: {} + description: Invalid status value + security: + - petstore_auth: + - write:pets + - 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": + content: {} + description: Invalid tag value + security: + - petstore_auth: + - write:pets + - 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: + - in: header + name: api_key + schema: + type: string + - description: Pet id to delete + in: path + name: petId + required: true + schema: + format: int64 + type: integer + responses: + "400": + content: {} + 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 + in: path + name: petId + required: true + schema: + format: int64 + type: integer + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + description: Pet not found + security: + - api_key: [] + summary: Find pet by ID + 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 + in: path + name: petId + required: true + schema: + format: int64 + type: integer + requestBody: + content: + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/updatePetWithForm_request' + responses: + "405": + content: {} + 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 + in: path + name: petId + required: true + schema: + format: int64 + type: integer + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/uploadFile_request' + 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: + '*/*': + 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": + content: {} + description: Invalid Order + summary: Place an order for a pet + tags: + - store + x-codegen-request-body-name: body + x-openapi-router-controller: openapi_server.controllers.store_controller + /store/order/{orderId}: + delete: + 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 + in: path + name: orderId + required: true + schema: + type: string + responses: + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + 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 generate exceptions + operationId: get_order_by_id + parameters: + - description: ID of pet that needs to be fetched + in: path + name: orderId + required: true + schema: + format: int64 + maximum: 5 + minimum: 1 + type: integer + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Order' + application/json: + schema: + $ref: '#/components/schemas/Order' + description: successful operation + "400": + content: {} + description: Invalid ID supplied + "404": + content: {} + description: Order not found + summary: Find purchase order by ID + tags: + - 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: + '*/*': + schema: + $ref: '#/components/schemas/User' + description: Created user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Create user + tags: + - user + x-codegen-request-body-name: body + x-openapi-router-controller: openapi_server.controllers.user_controller + /user/createWithArray: + post: + operationId: create_users_with_array_input + requestBody: + content: + '*/*': + schema: + items: + $ref: '#/components/schemas/User' + type: array + description: List of user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Creates list of users with given input array + tags: + - user + x-codegen-request-body-name: body + x-openapi-router-controller: openapi_server.controllers.user_controller + /user/createWithList: + post: + operationId: create_users_with_list_input + requestBody: + content: + '*/*': + schema: + items: + $ref: '#/components/schemas/User' + type: array + description: List of user object + required: true + responses: + default: + content: {} + description: successful operation + summary: Creates list of users with given input array + tags: + - user + x-codegen-request-body-name: body + x-openapi-router-controller: openapi_server.controllers.user_controller + /user/login: + get: + operationId: login_user + parameters: + - description: The user name for login + in: query + name: username + required: true + schema: + type: string + - description: The password for login in clear text + in: query + name: password + required: true + schema: + type: string + responses: + "200": + content: + application/xml: + schema: + type: string + application/json: + schema: + type: string + description: successful operation + headers: + X-Rate-Limit: + description: calls per hour allowed by the user + schema: + format: int32 + type: integer + X-Expires-After: + description: date in UTC when token expires + schema: + format: date-time + type: string + "400": + content: {} + 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: + content: {} + description: successful operation + 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 + in: path + name: username + required: true + schema: + type: string + responses: + "400": + content: {} + description: Invalid username supplied + "404": + content: {} + description: User not found + 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. + in: path + name: username + required: true + schema: + type: string + responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/User' + application/json: + schema: + $ref: '#/components/schemas/User' + description: successful operation + "400": + content: {} + description: Invalid username supplied + "404": + content: {} + description: User not found + summary: Get user by user name + tags: + - 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 + in: path + name: username + required: true + schema: + type: string + requestBody: + content: + '*/*': + schema: + $ref: '#/components/schemas/User' + description: Updated user object + required: true + responses: + "400": + content: {} + description: Invalid user supplied + "404": + content: {} + description: User not found + summary: Updated user + tags: + - user + x-codegen-request-body-name: body + x-openapi-router-controller: openapi_server.controllers.user_controller +components: + 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 + title: id + type: integer + petId: + format: int64 + title: petId + type: integer + quantity: + format: int32 + title: quantity + type: integer + shipDate: + format: date-time + title: shipDate + type: string + status: + description: Order Status + enum: + - placed + - approved + - delivered + title: status + type: string + complete: + default: false + title: complete + 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 + title: id + type: integer + name: + title: name + 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 + title: id + type: integer + username: + title: username + type: string + firstName: + title: firstName + type: string + lastName: + title: lastName + type: string + email: + title: email + type: string + password: + title: password + type: string + phone: + title: phone + type: string + userStatus: + description: User Status + format: int32 + title: userStatus + 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 + title: id + type: integer + name: + title: 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 + title: id + type: integer + category: + $ref: '#/components/schemas/Category' + name: + example: doggie + title: name + type: string + photoUrls: + items: + type: string + title: photoUrls + type: array + xml: + name: photoUrl + wrapped: true + tags: + items: + $ref: '#/components/schemas/Tag' + title: tags + type: array + xml: + name: tag + wrapped: true + status: + description: pet status in the store + enum: + - available + - pending + - sold + title: status + 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 + title: code + type: integer + type: + title: type + type: string + message: + title: message + type: string + title: An uploaded response + type: object + EnumModel: + enum: + - available> + - pending< + - sold + - "1" + - "2" + type: string + updatePetWithForm_request: + properties: + name: + description: Updated name of the pet + type: string + status: + description: Updated status of the pet + type: string + type: object + uploadFile_request: + 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 +x-original-swagger-version: "2.0" diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/test/__init__.py b/samples/server/petstore/2_0/python-flask/openapi_server/test/__init__.py new file mode 100644 index 000000000000..364aba9fbf88 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/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/2_0/python-flask/openapi_server/test/test_pet_controller.py b/samples/server/petstore/2_0/python-flask/openapi_server/test/test_pet_controller.py new file mode 100644 index 000000000000..a62cb03709c8 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/test/test_pet_controller.py @@ -0,0 +1,166 @@ +import unittest + +from flask import json + +from openapi_server.models.api_response import ApiResponse # noqa: E501 +from openapi_server.models.pet import Pet # noqa: E501 +from openapi_server.test import BaseTestCase + + +class TestPetController(BaseTestCase): + """PetController integration test stubs""" + + @unittest.skip("Connexion does not support multiple consumes. 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 + """ + body = {"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(body), + 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', ['status_example'])] + 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 consumes. See https://github.com/zalando/connexion/pull/760") + def test_update_pet(self): + """Test case for update_pet + + Update an existing pet + """ + body = {"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(body), + content_type='application/json') + 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='/path/to/file') + 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/2_0/python-flask/openapi_server/test/test_store_controller.py b/samples/server/petstore/2_0/python-flask/openapi_server/test/test_store_controller.py new file mode 100644 index 000000000000..36b656cd827d --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/test/test_store_controller.py @@ -0,0 +1,79 @@ +import unittest + +from flask import json + +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=56), + method='GET', + headers=headers) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + @unittest.skip("*/* not supported by Connexion. Use application/json instead. See https://github.com/zalando/connexion/pull/760") + def test_place_order(self): + """Test case for place_order + + Place an order for a pet + """ + body = openapi_server.Order() + headers = { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + } + response = self.client.open( + '/v2/store/order', + method='POST', + headers=headers, + data=json.dumps(body), + 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/2_0/python-flask/openapi_server/test/test_user_controller.py b/samples/server/petstore/2_0/python-flask/openapi_server/test/test_user_controller.py new file mode 100644 index 000000000000..a991011b3166 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/test/test_user_controller.py @@ -0,0 +1,151 @@ +import unittest + +from flask import json + +from openapi_server.models.user import User # noqa: E501 +from openapi_server.test import BaseTestCase + + +class TestUserController(BaseTestCase): + """UserController integration test stubs""" + + @unittest.skip("*/* not supported by Connexion. Use application/json instead. See https://github.com/zalando/connexion/pull/760") + def test_create_user(self): + """Test case for create_user + + Create user + """ + body = openapi_server.User() + headers = { + 'Content-Type': 'application/json', + } + response = self.client.open( + '/v2/user', + method='POST', + headers=headers, + data=json.dumps(body), + content_type='application/json') + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + @unittest.skip("*/* not supported by Connexion. Use application/json instead. See https://github.com/zalando/connexion/pull/760") + def test_create_users_with_array_input(self): + """Test case for create_users_with_array_input + + Creates list of users with given input array + """ + body = [openapi_server.User()] + headers = { + 'Content-Type': 'application/json', + } + response = self.client.open( + '/v2/user/createWithArray', + method='POST', + headers=headers, + data=json.dumps(body), + content_type='application/json') + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + @unittest.skip("*/* not supported by Connexion. Use application/json instead. See https://github.com/zalando/connexion/pull/760") + def test_create_users_with_list_input(self): + """Test case for create_users_with_list_input + + Creates list of users with given input array + """ + body = [openapi_server.User()] + headers = { + 'Content-Type': 'application/json', + } + response = self.client.open( + '/v2/user/createWithList', + method='POST', + headers=headers, + data=json.dumps(body), + 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 = { + } + 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 = { + } + response = self.client.open( + '/v2/user/logout', + method='GET', + headers=headers) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + @unittest.skip("*/* not supported by Connexion. Use application/json instead. See https://github.com/zalando/connexion/pull/760") + def test_update_user(self): + """Test case for update_user + + Updated user + """ + body = openapi_server.User() + headers = { + 'Content-Type': 'application/json', + } + response = self.client.open( + '/v2/user/{username}'.format(username='username_example'), + method='PUT', + headers=headers, + data=json.dumps(body), + 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/2_0/python-flask/openapi_server/typing_utils.py b/samples/server/petstore/2_0/python-flask/openapi_server/typing_utils.py new file mode 100644 index 000000000000..74e3c913a7db --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/typing_utils.py @@ -0,0 +1,30 @@ +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/2_0/python-flask/openapi_server/util.py b/samples/server/petstore/2_0/python-flask/openapi_server/util.py new file mode 100644 index 000000000000..bd83c5b330bb --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/openapi_server/util.py @@ -0,0 +1,147 @@ +import datetime + +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 (int, 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 = 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 + """ + if string is None: + return None + + 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 + """ + if string is None: + return None + + 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 instance.openapi_types.items(): + 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 data.items() } diff --git a/samples/server/petstore/2_0/python-flask/requirements.txt b/samples/server/petstore/2_0/python-flask/requirements.txt new file mode 100644 index 000000000000..2cb06891ce9f --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/requirements.txt @@ -0,0 +1,13 @@ +connexion[swagger-ui] >= 2.6.0; python_version>="3.6" +# 2.3 is the last version that supports python 3.4-3.5 +connexion[swagger-ui] <= 2.3.0; python_version=="3.5" or python_version=="3.4" +# prevent breaking dependencies from advent of connexion>=3.0 +connexion[swagger-ui] <= 2.14.2; python_version>"3.4" +# connexion requires werkzeug but connexion < 2.4.0 does not install werkzeug +# we must peg werkzeug versions below to fix connexion +# https://github.com/zalando/connexion/pull/1044 +werkzeug == 0.16.1; python_version=="3.5" or python_version=="3.4" +swagger-ui-bundle >= 0.0.2 +python_dateutil >= 2.6.0 +setuptools >= 21.0.0 +Flask == 2.1.1 diff --git a/samples/server/petstore/2_0/python-flask/setup.py b/samples/server/petstore/2_0/python-flask/setup.py new file mode 100644 index 000000000000..802848855890 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/setup.py @@ -0,0 +1,37 @@ +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/2_0/python-flask/test-requirements.txt b/samples/server/petstore/2_0/python-flask/test-requirements.txt new file mode 100644 index 000000000000..58f51d6a0027 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/test-requirements.txt @@ -0,0 +1,4 @@ +pytest~=7.1.0 +pytest-cov>=2.8.1 +pytest-randomly>=1.2.3 +Flask-Testing==0.8.1 diff --git a/samples/server/petstore/2_0/python-flask/tox.ini b/samples/server/petstore/2_0/python-flask/tox.ini new file mode 100644 index 000000000000..7663dfb69e41 --- /dev/null +++ b/samples/server/petstore/2_0/python-flask/tox.ini @@ -0,0 +1,11 @@ +[tox] +envlist = py3 +skipsdist=True + +[testenv] +deps=-r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt + {toxinidir} + +commands= + pytest --cov=openapi_server diff --git a/samples/server/petstore/python-flask/.openapi-generator/FILES b/samples/server/petstore/python-flask/.openapi-generator/FILES index c08d341ed532..601faf458885 100644 --- a/samples/server/petstore/python-flask/.openapi-generator/FILES +++ b/samples/server/petstore/python-flask/.openapi-generator/FILES @@ -7,6 +7,7 @@ git_push.sh openapi_server/__init__.py openapi_server/__main__.py openapi_server/controllers/__init__.py +openapi_server/controllers/fake_controller.py openapi_server/controllers/pet_controller.py openapi_server/controllers/security_controller.py openapi_server/controllers/store_controller.py @@ -16,10 +17,12 @@ openapi_server/models/__init__.py openapi_server/models/api_response.py openapi_server/models/base_model.py openapi_server/models/category.py -openapi_server/models/enum_model.py openapi_server/models/order.py openapi_server/models/pet.py openapi_server/models/tag.py +openapi_server/models/test_enum.py +openapi_server/models/test_enum_with_default.py +openapi_server/models/test_model.py openapi_server/models/user.py openapi_server/openapi/openapi.yaml openapi_server/test/__init__.py diff --git a/samples/server/petstore/python-flask/openapi_server/controllers/fake_controller.py b/samples/server/petstore/python-flask/openapi_server/controllers/fake_controller.py new file mode 100644 index 000000000000..d9847d98d80f --- /dev/null +++ b/samples/server/petstore/python-flask/openapi_server/controllers/fake_controller.py @@ -0,0 +1,21 @@ +import connexion +from typing import Dict +from typing import Tuple +from typing import Union + +from openapi_server import util + + +def fake_query_param_default(has_default=None, no_default=None): # noqa: E501 + """test query parameter default value + + # noqa: E501 + + :param has_default: has default value + :type has_default: str + :param no_default: no default value + :type no_default: str + + :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] + """ + return 'do some magic!' diff --git a/samples/server/petstore/python-flask/openapi_server/controllers/pet_controller.py b/samples/server/petstore/python-flask/openapi_server/controllers/pet_controller.py index 89086c54bd41..6b7d87f1b735 100644 --- a/samples/server/petstore/python-flask/openapi_server/controllers/pet_controller.py +++ b/samples/server/petstore/python-flask/openapi_server/controllers/pet_controller.py @@ -8,18 +8,18 @@ from openapi_server import util -def add_pet(body): # noqa: E501 +def add_pet(pet): # noqa: E501 """Add a new pet to the store # noqa: E501 - :param body: Pet object that needs to be added to the store - :type body: dict | bytes + :param pet: Pet object that needs to be added to the store + :type pet: dict | bytes - :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] + :rtype: Union[Pet, Tuple[Pet, int], Tuple[Pet, int, Dict[str, str]] """ if connexion.request.is_json: - body = Pet.from_dict(connexion.request.get_json()) # noqa: E501 + pet = Pet.from_dict(connexion.request.get_json()) # noqa: E501 return 'do some magic!' @@ -77,18 +77,18 @@ def get_pet_by_id(pet_id): # noqa: E501 return 'do some magic!' -def update_pet(body): # noqa: E501 +def update_pet(pet): # noqa: E501 """Update an existing pet # noqa: E501 - :param body: Pet object that needs to be added to the store - :type body: dict | bytes + :param pet: Pet object that needs to be added to the store + :type pet: dict | bytes - :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] + :rtype: Union[Pet, Tuple[Pet, int], Tuple[Pet, int, Dict[str, str]] """ if connexion.request.is_json: - body = Pet.from_dict(connexion.request.get_json()) # noqa: E501 + pet = Pet.from_dict(connexion.request.get_json()) # noqa: E501 return 'do some magic!' diff --git a/samples/server/petstore/python-flask/openapi_server/controllers/store_controller.py b/samples/server/petstore/python-flask/openapi_server/controllers/store_controller.py index 62887e7adac0..1782980a90a1 100644 --- a/samples/server/petstore/python-flask/openapi_server/controllers/store_controller.py +++ b/samples/server/petstore/python-flask/openapi_server/controllers/store_controller.py @@ -44,16 +44,16 @@ def get_order_by_id(order_id): # noqa: E501 return 'do some magic!' -def place_order(body): # noqa: E501 +def place_order(order): # noqa: E501 """Place an order for a pet # noqa: E501 - :param body: order placed for purchasing the pet - :type body: dict | bytes + :param order: order placed for purchasing the pet + :type order: dict | bytes :rtype: Union[Order, Tuple[Order, int], Tuple[Order, int, Dict[str, str]] """ if connexion.request.is_json: - body = Order.from_dict(connexion.request.get_json()) # noqa: E501 + order = Order.from_dict(connexion.request.get_json()) # noqa: E501 return 'do some magic!' diff --git a/samples/server/petstore/python-flask/openapi_server/controllers/user_controller.py b/samples/server/petstore/python-flask/openapi_server/controllers/user_controller.py index 0acef4751501..7510bacdca6c 100644 --- a/samples/server/petstore/python-flask/openapi_server/controllers/user_controller.py +++ b/samples/server/petstore/python-flask/openapi_server/controllers/user_controller.py @@ -7,48 +7,48 @@ from openapi_server import util -def create_user(body): # noqa: E501 +def create_user(user): # noqa: E501 """Create user This can only be done by the logged in user. # noqa: E501 - :param body: Created user object - :type body: dict | bytes + :param user: Created user object + :type user: dict | bytes :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] """ if connexion.request.is_json: - body = User.from_dict(connexion.request.get_json()) # noqa: E501 + user = User.from_dict(connexion.request.get_json()) # noqa: E501 return 'do some magic!' -def create_users_with_array_input(body): # noqa: E501 +def create_users_with_array_input(user): # noqa: E501 """Creates list of users with given input array # noqa: E501 - :param body: List of user object - :type body: list | bytes + :param user: List of user object + :type user: list | bytes :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] """ if connexion.request.is_json: - body = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501 + user = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501 return 'do some magic!' -def create_users_with_list_input(body): # noqa: E501 +def create_users_with_list_input(user): # noqa: E501 """Creates list of users with given input array # noqa: E501 - :param body: List of user object - :type body: list | bytes + :param user: List of user object + :type user: list | bytes :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] """ if connexion.request.is_json: - body = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501 + user = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501 return 'do some magic!' @@ -104,18 +104,18 @@ def logout_user(): # noqa: E501 return 'do some magic!' -def update_user(username, body): # noqa: E501 +def update_user(username, user): # noqa: E501 """Updated user This can only be done by the logged in user. # noqa: E501 :param username: name that need to be deleted :type username: str - :param body: Updated user object - :type body: dict | bytes + :param user: Updated user object + :type user: dict | bytes :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] """ if connexion.request.is_json: - body = User.from_dict(connexion.request.get_json()) # noqa: E501 + user = User.from_dict(connexion.request.get_json()) # noqa: E501 return 'do some magic!' diff --git a/samples/server/petstore/python-flask/openapi_server/models/__init__.py b/samples/server/petstore/python-flask/openapi_server/models/__init__.py index 21d4d1aeb93d..5f1925e5c792 100644 --- a/samples/server/petstore/python-flask/openapi_server/models/__init__.py +++ b/samples/server/petstore/python-flask/openapi_server/models/__init__.py @@ -2,8 +2,10 @@ # import models into model package from openapi_server.models.api_response import ApiResponse from openapi_server.models.category import Category -from openapi_server.models.enum_model import EnumModel from openapi_server.models.order import Order from openapi_server.models.pet import Pet from openapi_server.models.tag import Tag +from openapi_server.models.test_enum import TestEnum +from openapi_server.models.test_enum_with_default import TestEnumWithDefault +from openapi_server.models.test_model import TestModel from openapi_server.models.user import User diff --git a/samples/server/petstore/python-flask/openapi_server/models/category.py b/samples/server/petstore/python-flask/openapi_server/models/category.py index 4bdec5b25c4f..233e4db0d421 100644 --- a/samples/server/petstore/python-flask/openapi_server/models/category.py +++ b/samples/server/petstore/python-flask/openapi_server/models/category.py @@ -3,8 +3,10 @@ from typing import List, Dict # noqa: F401 from openapi_server.models.base_model import Model +import re from openapi_server import util +import re # noqa: E501 class Category(Model): """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). @@ -83,5 +85,7 @@ def name(self, name: str): :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_server/models/status_enum.py b/samples/server/petstore/python-flask/openapi_server/models/status_enum.py new file mode 100644 index 000000000000..92ba0c556f8c --- /dev/null +++ b/samples/server/petstore/python-flask/openapi_server/models/status_enum.py @@ -0,0 +1,40 @@ +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from openapi_server.models.base_model import Model +from openapi_server import util + + +class StatusEnum(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + """ + allowed enum values + """ + AVAILABLE = 'available' + PENDING = 'pending' + SOLD = 'sold' + def __init__(self): # noqa: E501 + """StatusEnum - a model defined in OpenAPI + + """ + self.openapi_types = { + } + + self.attribute_map = { + } + + @classmethod + def from_dict(cls, dikt) -> 'StatusEnum': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The statusEnum of this StatusEnum. # noqa: E501 + :rtype: StatusEnum + """ + return util.deserialize_model(dikt, cls) diff --git a/samples/server/petstore/python-flask/openapi_server/models/test_enum.py b/samples/server/petstore/python-flask/openapi_server/models/test_enum.py new file mode 100644 index 000000000000..d072a34c622c --- /dev/null +++ b/samples/server/petstore/python-flask/openapi_server/models/test_enum.py @@ -0,0 +1,41 @@ +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from openapi_server.models.base_model import Model +from openapi_server import util + + +class TestEnum(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + """ + allowed enum values + """ + ONE = 'ONE' + TWO = 'TWO' + THREE = 'THREE' + FOUR = 'foUr' + def __init__(self): # noqa: E501 + """TestEnum - a model defined in OpenAPI + + """ + self.openapi_types = { + } + + self.attribute_map = { + } + + @classmethod + def from_dict(cls, dikt) -> 'TestEnum': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The TestEnum of this TestEnum. # noqa: E501 + :rtype: TestEnum + """ + return util.deserialize_model(dikt, cls) diff --git a/samples/server/petstore/python-flask/openapi_server/models/test_enum_with_default.py b/samples/server/petstore/python-flask/openapi_server/models/test_enum_with_default.py new file mode 100644 index 000000000000..cc715175635f --- /dev/null +++ b/samples/server/petstore/python-flask/openapi_server/models/test_enum_with_default.py @@ -0,0 +1,40 @@ +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from openapi_server.models.base_model import Model +from openapi_server import util + + +class TestEnumWithDefault(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + """ + allowed enum values + """ + EIN = 'EIN' + ZWEI = 'ZWEI' + DREI = 'DREI' + def __init__(self): # noqa: E501 + """TestEnumWithDefault - a model defined in OpenAPI + + """ + self.openapi_types = { + } + + self.attribute_map = { + } + + @classmethod + def from_dict(cls, dikt) -> 'TestEnumWithDefault': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The TestEnumWithDefault of this TestEnumWithDefault. # noqa: E501 + :rtype: TestEnumWithDefault + """ + return util.deserialize_model(dikt, cls) diff --git a/samples/server/petstore/python-flask/openapi_server/models/test_model.py b/samples/server/petstore/python-flask/openapi_server/models/test_model.py new file mode 100644 index 000000000000..3550f70389c6 --- /dev/null +++ b/samples/server/petstore/python-flask/openapi_server/models/test_model.py @@ -0,0 +1,177 @@ +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from openapi_server.models.base_model import Model +from openapi_server.models.test_enum import TestEnum +from openapi_server.models.test_enum_with_default import TestEnumWithDefault +from openapi_server import util + +from openapi_server.models.test_enum import TestEnum # noqa: E501 +from openapi_server.models.test_enum_with_default import TestEnumWithDefault # noqa: E501 + +class TestModel(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + def __init__(self, test_enum=None, test_string=None, test_enum_with_default=TestEnumWithDefault.ZWEI, test_string_with_default='ahoy matey', test_inline_defined_enum_with_default='B'): # noqa: E501 + """TestModel - a model defined in OpenAPI + + :param test_enum: The test_enum of this TestModel. # noqa: E501 + :type test_enum: TestEnum + :param test_string: The test_string of this TestModel. # noqa: E501 + :type test_string: str + :param test_enum_with_default: The test_enum_with_default of this TestModel. # noqa: E501 + :type test_enum_with_default: TestEnumWithDefault + :param test_string_with_default: The test_string_with_default of this TestModel. # noqa: E501 + :type test_string_with_default: str + :param test_inline_defined_enum_with_default: The test_inline_defined_enum_with_default of this TestModel. # noqa: E501 + :type test_inline_defined_enum_with_default: str + """ + self.openapi_types = { + 'test_enum': TestEnum, + 'test_string': str, + 'test_enum_with_default': TestEnumWithDefault, + 'test_string_with_default': str, + 'test_inline_defined_enum_with_default': str + } + + self.attribute_map = { + 'test_enum': 'test_enum', + 'test_string': 'test_string', + 'test_enum_with_default': 'test_enum_with_default', + 'test_string_with_default': 'test_string_with_default', + 'test_inline_defined_enum_with_default': 'test_inline_defined_enum_with_default' + } + + self._test_enum = test_enum + self._test_string = test_string + self._test_enum_with_default = test_enum_with_default + self._test_string_with_default = test_string_with_default + self._test_inline_defined_enum_with_default = test_inline_defined_enum_with_default + + @classmethod + def from_dict(cls, dikt) -> 'TestModel': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The TestModel of this TestModel. # noqa: E501 + :rtype: TestModel + """ + return util.deserialize_model(dikt, cls) + + @property + def test_enum(self) -> TestEnum: + """Gets the test_enum of this TestModel. + + + :return: The test_enum of this TestModel. + :rtype: TestEnum + """ + return self._test_enum + + @test_enum.setter + def test_enum(self, test_enum: TestEnum): + """Sets the test_enum of this TestModel. + + + :param test_enum: The test_enum of this TestModel. + :type test_enum: TestEnum + """ + if test_enum is None: + raise ValueError("Invalid value for `test_enum`, must not be `None`") # noqa: E501 + + self._test_enum = test_enum + + @property + def test_string(self) -> str: + """Gets the test_string of this TestModel. + + + :return: The test_string of this TestModel. + :rtype: str + """ + return self._test_string + + @test_string.setter + def test_string(self, test_string: str): + """Sets the test_string of this TestModel. + + + :param test_string: The test_string of this TestModel. + :type test_string: str + """ + + self._test_string = test_string + + @property + def test_enum_with_default(self) -> TestEnumWithDefault: + """Gets the test_enum_with_default of this TestModel. + + + :return: The test_enum_with_default of this TestModel. + :rtype: TestEnumWithDefault + """ + return self._test_enum_with_default + + @test_enum_with_default.setter + def test_enum_with_default(self, test_enum_with_default: TestEnumWithDefault): + """Sets the test_enum_with_default of this TestModel. + + + :param test_enum_with_default: The test_enum_with_default of this TestModel. + :type test_enum_with_default: TestEnumWithDefault + """ + + self._test_enum_with_default = test_enum_with_default + + @property + def test_string_with_default(self) -> str: + """Gets the test_string_with_default of this TestModel. + + + :return: The test_string_with_default of this TestModel. + :rtype: str + """ + return self._test_string_with_default + + @test_string_with_default.setter + def test_string_with_default(self, test_string_with_default: str): + """Sets the test_string_with_default of this TestModel. + + + :param test_string_with_default: The test_string_with_default of this TestModel. + :type test_string_with_default: str + """ + + self._test_string_with_default = test_string_with_default + + @property + def test_inline_defined_enum_with_default(self) -> str: + """Gets the test_inline_defined_enum_with_default of this TestModel. + + + :return: The test_inline_defined_enum_with_default of this TestModel. + :rtype: str + """ + return self._test_inline_defined_enum_with_default + + @test_inline_defined_enum_with_default.setter + def test_inline_defined_enum_with_default(self, test_inline_defined_enum_with_default: str): + """Sets the test_inline_defined_enum_with_default of this TestModel. + + + :param test_inline_defined_enum_with_default: The test_inline_defined_enum_with_default of this TestModel. + :type test_inline_defined_enum_with_default: str + """ + allowed_values = ["A", "B", "C"] # noqa: E501 + if test_inline_defined_enum_with_default not in allowed_values: + raise ValueError( + "Invalid value for `test_inline_defined_enum_with_default` ({0}), must be one of {1}" + .format(test_inline_defined_enum_with_default, allowed_values) + ) + + self._test_inline_defined_enum_with_default = test_inline_defined_enum_with_default diff --git a/samples/server/petstore/python-flask/openapi_server/openapi/openapi.yaml b/samples/server/petstore/python-flask/openapi_server/openapi/openapi.yaml index 21e70929a17c..d99503c94ea5 100644 --- a/samples/server/petstore/python-flask/openapi_server/openapi/openapi.yaml +++ b/samples/server/petstore/python-flask/openapi_server/openapi/openapi.yaml @@ -1,4 +1,4 @@ -openapi: 3.0.1 +openapi: 3.0.0 info: description: "This is a sample server Petstore server. For this sample, you can\ \ use the api key `special-key` to test the authorization filters." @@ -7,6 +7,9 @@ info: url: https://www.apache.org/licenses/LICENSE-2.0.html title: OpenAPI Petstore version: 1.0.0 +externalDocs: + description: Find out more about Swagger + url: http://swagger.io servers: - url: http://petstore.swagger.io/v2 tags: @@ -17,22 +20,54 @@ tags: - description: Operations about user name: user paths: + /fake/query_param_default: + get: + description: "" + operationId: fake_query_param_default + parameters: + - description: has default value + explode: true + in: query + name: hasDefault + required: false + schema: + default: Hello World + type: string + style: form + - description: no default value + explode: true + in: query + name: noDefault + required: false + schema: + type: string + style: form + responses: + "400": + description: Invalid username supplied + "404": + description: User not found + summary: test query parameter default value + tags: + - fake + x-openapi-router-controller: openapi_server.controllers.fake_controller /pet: post: + description: "" operationId: add_pet requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/Pet' - application/xml: - schema: - $ref: '#/components/schemas/Pet' - description: Pet object that needs to be added to the store - required: true + $ref: '#/components/requestBodies/Pet' responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation "405": - content: {} description: Invalid input security: - petstore_auth: @@ -41,29 +76,30 @@ paths: summary: Add a new pet to the store tags: - pet - x-codegen-request-body-name: body x-openapi-router-controller: openapi_server.controllers.pet_controller put: + description: "" + externalDocs: + description: API documentation for the updatePet operation + url: http://petstore.swagger.io/v2/doc/updatePet operationId: update_pet requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/Pet' - application/xml: - schema: - $ref: '#/components/schemas/Pet' - description: Pet object that needs to be added to the store - required: true + $ref: '#/components/requestBodies/Pet' responses: + "200": + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' + description: successful operation "400": - content: {} description: Invalid ID supplied "404": - content: {} description: Pet not found "405": - content: {} description: Validation exception security: - petstore_auth: @@ -72,14 +108,14 @@ paths: summary: Update an existing pet tags: - pet - x-codegen-request-body-name: body x-openapi-router-controller: openapi_server.controllers.pet_controller /pet/findByStatus: get: description: Multiple status values can be provided with comma separated strings operationId: find_pets_by_status parameters: - - description: Status values that need to be considered for filter + - deprecated: true + description: Status values that need to be considered for filter explode: false in: query name: status @@ -109,11 +145,9 @@ paths: type: array description: successful operation "400": - content: {} description: Invalid status value security: - petstore_auth: - - write:pets - read:pets summary: Finds Pets by status tags: @@ -151,11 +185,9 @@ paths: type: array description: successful operation "400": - content: {} description: Invalid tag value security: - petstore_auth: - - write:pets - read:pets summary: Finds Pets by tags tags: @@ -163,22 +195,27 @@ paths: x-openapi-router-controller: openapi_server.controllers.pet_controller /pet/{petId}: delete: + description: "" operationId: delete_pet parameters: - - in: header + - explode: false + in: header name: api_key + required: false schema: type: string + style: simple - description: Pet id to delete + explode: false in: path name: petId required: true schema: format: int64 type: integer + style: simple responses: "400": - content: {} description: Invalid pet value security: - petstore_auth: @@ -193,12 +230,14 @@ paths: operationId: get_pet_by_id parameters: - description: ID of pet to return + explode: false in: path name: petId required: true schema: format: int64 type: integer + style: simple responses: "200": content: @@ -210,10 +249,8 @@ paths: $ref: '#/components/schemas/Pet' description: successful operation "400": - content: {} description: Invalid ID supplied "404": - content: {} description: Pet not found security: - api_key: [] @@ -222,15 +259,18 @@ paths: - pet x-openapi-router-controller: openapi_server.controllers.pet_controller post: + description: "" operationId: update_pet_with_form parameters: - description: ID of pet that needs to be updated + explode: false in: path name: petId required: true schema: format: int64 type: integer + style: simple requestBody: content: application/x-www-form-urlencoded: @@ -238,7 +278,6 @@ paths: $ref: '#/components/schemas/updatePetWithForm_request' responses: "405": - content: {} description: Invalid input security: - petstore_auth: @@ -250,15 +289,18 @@ paths: x-openapi-router-controller: openapi_server.controllers.pet_controller /pet/{petId}/uploadImage: post: + description: "" operationId: upload_file parameters: - description: ID of pet to update + explode: false in: path name: petId required: true schema: format: int64 type: integer + style: simple requestBody: content: multipart/form-data: @@ -301,10 +343,11 @@ paths: x-openapi-router-controller: openapi_server.controllers.store_controller /store/order: post: + description: "" operationId: place_order requestBody: content: - '*/*': + application/json: schema: $ref: '#/components/schemas/Order' description: order placed for purchasing the pet @@ -320,12 +363,10 @@ paths: $ref: '#/components/schemas/Order' description: successful operation "400": - content: {} description: Invalid Order summary: Place an order for a pet tags: - store - x-codegen-request-body-name: body x-openapi-router-controller: openapi_server.controllers.store_controller /store/order/{orderId}: delete: @@ -334,17 +375,17 @@ paths: operationId: delete_order parameters: - description: ID of the order that needs to be deleted + explode: false in: path name: orderId required: true schema: type: string + style: simple responses: "400": - content: {} description: Invalid ID supplied "404": - content: {} description: Order not found summary: Delete purchase order by ID tags: @@ -356,6 +397,7 @@ paths: operationId: get_order_by_id parameters: - description: ID of pet that needs to be fetched + explode: false in: path name: orderId required: true @@ -364,6 +406,7 @@ paths: maximum: 5 minimum: 1 type: integer + style: simple responses: "200": content: @@ -375,10 +418,8 @@ paths: $ref: '#/components/schemas/Order' description: successful operation "400": - content: {} description: Invalid ID supplied "404": - content: {} description: Order not found summary: Find purchase order by ID tags: @@ -390,78 +431,72 @@ paths: operationId: create_user requestBody: content: - '*/*': + application/json: schema: $ref: '#/components/schemas/User' description: Created user object required: true responses: default: - content: {} description: successful operation + security: + - api_key: [] summary: Create user tags: - user - x-codegen-request-body-name: body x-openapi-router-controller: openapi_server.controllers.user_controller /user/createWithArray: post: + description: "" operationId: create_users_with_array_input requestBody: - content: - '*/*': - schema: - items: - $ref: '#/components/schemas/User' - type: array - description: List of user object - required: true + $ref: '#/components/requestBodies/UserArray' responses: default: - content: {} description: successful operation + security: + - api_key: [] summary: Creates list of users with given input array tags: - user - x-codegen-request-body-name: body x-openapi-router-controller: openapi_server.controllers.user_controller /user/createWithList: post: + description: "" operationId: create_users_with_list_input requestBody: - content: - '*/*': - schema: - items: - $ref: '#/components/schemas/User' - type: array - description: List of user object - required: true + $ref: '#/components/requestBodies/UserArray' responses: default: - content: {} description: successful operation + security: + - api_key: [] summary: Creates list of users with given input array tags: - user - x-codegen-request-body-name: body x-openapi-router-controller: openapi_server.controllers.user_controller /user/login: get: + description: "" operationId: login_user parameters: - description: The user name for login + explode: true in: query name: username required: true schema: + pattern: "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$" type: string + style: form - description: The password for login in clear text + explode: true in: query name: password required: true schema: type: string + style: form responses: "200": content: @@ -473,18 +508,29 @@ paths: type: string description: successful operation headers: + Set-Cookie: + description: Cookie authentication key for use with the `api_key` apiKey + authentication. + explode: false + schema: + example: AUTH_KEY=abcde12345; Path=/; HttpOnly + type: string + style: simple X-Rate-Limit: description: calls per hour allowed by the user + explode: false schema: format: int32 type: integer + style: simple X-Expires-After: description: date in UTC when token expires + explode: false schema: format: date-time type: string + style: simple "400": - content: {} description: Invalid username/password supplied summary: Logs user into the system tags: @@ -492,11 +538,13 @@ paths: x-openapi-router-controller: openapi_server.controllers.user_controller /user/logout: get: + description: "" operationId: logout_user responses: default: - content: {} description: successful operation + security: + - api_key: [] summary: Logs out current logged in user session tags: - user @@ -507,31 +555,36 @@ paths: operationId: delete_user parameters: - description: The name that needs to be deleted + explode: false in: path name: username required: true schema: type: string + style: simple responses: "400": - content: {} description: Invalid username supplied "404": - content: {} description: User not found + security: + - api_key: [] summary: Delete user tags: - user x-openapi-router-controller: openapi_server.controllers.user_controller get: + description: "" operationId: get_user_by_name parameters: - description: The name that needs to be fetched. Use user1 for testing. + explode: false in: path name: username required: true schema: type: string + style: simple responses: "200": content: @@ -543,10 +596,8 @@ paths: $ref: '#/components/schemas/User' description: successful operation "400": - content: {} description: Invalid username supplied "404": - content: {} description: User not found summary: Get user by user name tags: @@ -557,31 +608,52 @@ paths: operationId: update_user parameters: - description: name that need to be deleted + explode: false in: path name: username required: true schema: type: string + style: simple requestBody: content: - '*/*': + application/json: schema: $ref: '#/components/schemas/User' description: Updated user object required: true responses: "400": - content: {} description: Invalid user supplied "404": - content: {} description: User not found + security: + - api_key: [] summary: Updated user tags: - user - x-codegen-request-body-name: body x-openapi-router-controller: openapi_server.controllers.user_controller components: + requestBodies: + UserArray: + content: + application/json: + schema: + items: + $ref: '#/components/schemas/User' + type: array + description: List of user object + required: true + Pet: + content: + application/json: + schema: + $ref: '#/components/schemas/Pet' + application/xml: + schema: + $ref: '#/components/schemas/Pet' + description: Pet object that needs to be added to the store + required: true schemas: Order: description: An order for a pets from the pet store @@ -636,6 +708,7 @@ components: title: id type: integer name: + pattern: "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$" title: name type: string title: Pet category @@ -747,6 +820,7 @@ components: name: tag wrapped: true status: + deprecated: true description: pet status in the store enum: - available @@ -780,14 +854,45 @@ components: type: string title: An uploaded response type: object - EnumModel: + TestEnum: + enum: + - ONE + - TWO + - THREE + - foUr + title: TestEnum + type: string + TestEnumWithDefault: + default: ZWEI enum: - - available> - - pending< - - sold - - "1" - - "2" + - EIN + - ZWEI + - DREI + title: TestEnumWithDefault type: string + TestModel: + properties: + test_enum: + $ref: '#/components/schemas/TestEnum' + test_string: + example: Just some string + type: string + test_enum_with_default: + $ref: '#/components/schemas/TestEnumWithDefault' + test_string_with_default: + default: ahoy matey + example: More string + type: string + test_inline_defined_enum_with_default: + default: B + enum: + - A + - B + - C + type: string + required: + - test_enum + type: object updatePetWithForm_request: properties: name: @@ -823,4 +928,3 @@ components: name: api_key type: apiKey x-apikeyInfoFunc: openapi_server.controllers.security_controller.info_from_api_key -x-original-swagger-version: "2.0" diff --git a/samples/server/petstore/python-flask/openapi_server/test/test_fake_controller.py b/samples/server/petstore/python-flask/openapi_server/test/test_fake_controller.py new file mode 100644 index 000000000000..439698473a6a --- /dev/null +++ b/samples/server/petstore/python-flask/openapi_server/test/test_fake_controller.py @@ -0,0 +1,30 @@ +import unittest + +from flask import json + +from openapi_server.test import BaseTestCase + + +class TestFakeController(BaseTestCase): + """FakeController integration test stubs""" + + def test_fake_query_param_default(self): + """Test case for fake_query_param_default + + test query parameter default value + """ + query_string = [('hasDefault', 'Hello World'), + ('noDefault', 'no_default_example')] + headers = { + } + response = self.client.open( + '/v2/fake/query_param_default', + method='GET', + headers=headers, + query_string=query_string) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + + +if __name__ == '__main__': + unittest.main() From 9501e6cc2d2db856cc6349b30cc690766e3c26ae Mon Sep 17 00:00:00 2001 From: welshm Date: Thu, 30 May 2024 09:35:51 -0400 Subject: [PATCH 3/8] Remove unused method --- .../codegen/languages/AbstractPythonCodegen.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java index b842d43ea359..13769cad8b14 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java @@ -1427,12 +1427,6 @@ public String toEnumDefaultValue(CodegenProperty property, String value) { return value; } - @Override - public String toEnumDefaultValue(String value, String datatype) { - // Remove the string encapsulating the value and prefix with the datatype. - return datatype + "." + toEnumVariableName(value, datatype); - } - /** * checks if the data should be classified as "string" in enum * e.g. double in C# needs to be double-quoted (e.g. "2.8") by treating it as a string From 97ab156e1dac76e7102496147cf2c45590543570 Mon Sep 17 00:00:00 2001 From: welshm Date: Thu, 30 May 2024 10:21:09 -0400 Subject: [PATCH 4/8] Update mustaches for FastAPI, Pydantic, and Python for default values --- .../src/main/resources/python-fastapi/model_generic.mustache | 2 +- .../main/resources/python-pydantic-v1/model_generic.mustache | 2 +- .../src/main/resources/python/model_generic.mustache | 2 +- .../petstore/python-aiohttp/petstore_api/models/enum_test.py | 4 ++-- .../client/petstore/python/petstore_api/models/enum_test.py | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python-fastapi/model_generic.mustache b/modules/openapi-generator/src/main/resources/python-fastapi/model_generic.mustache index 1b676e469554..3b01c4fa9ab8 100644 --- a/modules/openapi-generator/src/main/resources/python-fastapi/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python-fastapi/model_generic.mustache @@ -351,7 +351,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} "{{{baseName}}}": {{{dataType}}}.from_dict(obj.get("{{{baseName}}}")) if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}} {{/isEnumOrRef}} {{#isEnumOrRef}} - "{{{baseName}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}} + "{{{baseName}}}": obj.get("{{{baseName}}}"){{#defaultValue}} if obj.get("{{baseName}}") is not None else {{defaultValue}}{{/defaultValue}}{{^-last}},{{/-last}} {{/isEnumOrRef}} {{/isPrimitiveType}} {{#isPrimitiveType}} diff --git a/modules/openapi-generator/src/main/resources/python-pydantic-v1/model_generic.mustache b/modules/openapi-generator/src/main/resources/python-pydantic-v1/model_generic.mustache index 9a24a9b6553e..9a5b0c7fe8fc 100644 --- a/modules/openapi-generator/src/main/resources/python-pydantic-v1/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python-pydantic-v1/model_generic.mustache @@ -343,7 +343,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} "{{{name}}}": {{{dataType}}}.from_dict(obj.get("{{{baseName}}}")) if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}} {{/isEnumOrRef}} {{#isEnumOrRef}} - "{{{name}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}} + "{{{name}}}": obj.get("{{{baseName}}}"){{#defaultValue}} if obj.get("{{baseName}}") is not None else {{defaultValue}}{{/defaultValue}}{{^-last}},{{/-last}} {{/isEnumOrRef}} {{/isPrimitiveType}} {{#isPrimitiveType}} diff --git a/modules/openapi-generator/src/main/resources/python/model_generic.mustache b/modules/openapi-generator/src/main/resources/python/model_generic.mustache index fb9ece0f4639..2fadb7365717 100644 --- a/modules/openapi-generator/src/main/resources/python/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_generic.mustache @@ -363,7 +363,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} "{{{baseName}}}": {{{dataType}}}.from_dict(obj["{{{baseName}}}"]) if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}} {{/isEnumOrRef}} {{#isEnumOrRef}} - "{{{baseName}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}} + "{{{baseName}}}": obj.get("{{{baseName}}}"){{#defaultValue}} if obj.get("{{baseName}}") is not None else {{defaultValue}}{{/defaultValue}}{{^-last}},{{/-last}} {{/isEnumOrRef}} {{/isPrimitiveType}} {{#isPrimitiveType}} diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py index f7e053b23db8..bbbc4102de45 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_test.py @@ -175,8 +175,8 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: "enum_string_vendor_ext": obj.get("enum_string_vendor_ext"), "outerEnum": obj.get("outerEnum"), "outerEnumInteger": obj.get("outerEnumInteger"), - "outerEnumDefaultValue": obj.get("outerEnumDefaultValue"), - "outerEnumIntegerDefaultValue": obj.get("outerEnumIntegerDefaultValue") + "outerEnumDefaultValue": obj.get("outerEnumDefaultValue") if obj.get("outerEnumDefaultValue") is not None else OuterEnumDefaultValue.PLACED, + "outerEnumIntegerDefaultValue": obj.get("outerEnumIntegerDefaultValue") if obj.get("outerEnumIntegerDefaultValue") is not None else OuterEnumIntegerDefaultValue.NUMBER_0 }) return _obj diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py index 918b080940a2..d63819661558 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py @@ -183,8 +183,8 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: "enum_string_vendor_ext": obj.get("enum_string_vendor_ext"), "outerEnum": obj.get("outerEnum"), "outerEnumInteger": obj.get("outerEnumInteger"), - "outerEnumDefaultValue": obj.get("outerEnumDefaultValue"), - "outerEnumIntegerDefaultValue": obj.get("outerEnumIntegerDefaultValue") + "outerEnumDefaultValue": obj.get("outerEnumDefaultValue") if obj.get("outerEnumDefaultValue") is not None else OuterEnumDefaultValue.PLACED, + "outerEnumIntegerDefaultValue": obj.get("outerEnumIntegerDefaultValue") if obj.get("outerEnumIntegerDefaultValue") is not None else OuterEnumIntegerDefaultValue.NUMBER_0 }) # store additional fields in additional_properties for _key in obj.keys(): From 1d8dd73f002c679091f34b2afb244993140215e9 Mon Sep 17 00:00:00 2001 From: welshm Date: Wed, 5 Jun 2024 09:57:31 -0400 Subject: [PATCH 5/8] Address PR feedback and rebase main --- bin/configs/python-flask-enum-handling.yaml | 4 - bin/configs/python-flask.yaml | 4 +- .../resources/2_0/python-flask/petstore.yaml | 703 ------------------ 3 files changed, 2 insertions(+), 709 deletions(-) delete mode 100644 bin/configs/python-flask-enum-handling.yaml delete mode 100644 modules/openapi-generator/src/test/resources/2_0/python-flask/petstore.yaml diff --git a/bin/configs/python-flask-enum-handling.yaml b/bin/configs/python-flask-enum-handling.yaml deleted file mode 100644 index 32c5659ab43f..000000000000 --- a/bin/configs/python-flask-enum-handling.yaml +++ /dev/null @@ -1,4 +0,0 @@ -generatorName: python-flask -outputDir: samples/server/petstore/python-flask -inputSpec: modules/openapi-generator/src/test/resources/3_0/python-flask/petstore.yaml -templateDir: modules/openapi-generator/src/main/resources/python-flask diff --git a/bin/configs/python-flask.yaml b/bin/configs/python-flask.yaml index 5afe28bc1df9..32c5659ab43f 100644 --- a/bin/configs/python-flask.yaml +++ b/bin/configs/python-flask.yaml @@ -1,4 +1,4 @@ generatorName: python-flask -outputDir: samples/server/petstore/2_0/python-flask -inputSpec: modules/openapi-generator/src/test/resources/2_0/python-flask/petstore.yaml +outputDir: samples/server/petstore/python-flask +inputSpec: modules/openapi-generator/src/test/resources/3_0/python-flask/petstore.yaml templateDir: modules/openapi-generator/src/main/resources/python-flask diff --git a/modules/openapi-generator/src/test/resources/2_0/python-flask/petstore.yaml b/modules/openapi-generator/src/test/resources/2_0/python-flask/petstore.yaml deleted file mode 100644 index 952104fbb701..000000000000 --- a/modules/openapi-generator/src/test/resources/2_0/python-flask/petstore.yaml +++ /dev/null @@ -1,703 +0,0 @@ -swagger: '2.0' -info: - description: 'This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.' - version: 1.0.0 - title: OpenAPI Petstore - license: - name: Apache-2.0 - url: 'https://www.apache.org/licenses/LICENSE-2.0.html' -host: petstore.swagger.io -basePath: /v2 -tags: - - name: pet - description: Everything about your Pets - - name: store - description: Access to Petstore orders - - name: user - description: Operations about user -schemes: - - http -paths: - /pet: - post: - tags: - - pet - summary: Add a new pet to the store - description: '' - operationId: addPet - consumes: - - application/json - - application/xml - produces: - - application/xml - - application/json - parameters: - - in: body - name: body - description: Pet object that needs to be added to the store - required: true - schema: - $ref: '#/definitions/Pet' - responses: - '405': - description: Invalid input - security: - - petstore_auth: - - 'write:pets' - - 'read:pets' - put: - tags: - - pet - summary: Update an existing pet - description: '' - operationId: updatePet - consumes: - - application/json - - application/xml - produces: - - application/xml - - application/json - parameters: - - in: body - name: body - description: Pet object that needs to be added to the store - required: true - schema: - $ref: '#/definitions/Pet' - responses: - '400': - description: Invalid ID supplied - '404': - description: Pet not found - '405': - description: Validation exception - security: - - petstore_auth: - - 'write:pets' - - 'read:pets' - /pet/findByStatus: - get: - tags: - - pet - summary: Finds Pets by status - description: Multiple status values can be provided with comma separated strings - operationId: findPetsByStatus - produces: - - application/xml - - application/json - parameters: - - name: status - in: query - description: Status values that need to be considered for filter - required: true - type: array - items: - type: string - enum: - - available - - pending - - sold - default: available - collectionFormat: csv - responses: - '200': - description: successful operation - schema: - type: array - items: - $ref: '#/definitions/Pet' - '400': - description: Invalid status value - security: - - petstore_auth: - - 'write:pets' - - 'read:pets' - /pet/findByTags: - get: - tags: - - pet - summary: Finds Pets by tags - description: 'Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.' - operationId: findPetsByTags - produces: - - application/xml - - application/json - parameters: - - name: tags - in: query - description: Tags to filter by - required: true - type: array - items: - type: string - collectionFormat: csv - responses: - '200': - description: successful operation - schema: - type: array - items: - $ref: '#/definitions/Pet' - '400': - description: Invalid tag value - security: - - petstore_auth: - - 'write:pets' - - 'read:pets' - deprecated: true - '/pet/{petId}': - get: - tags: - - pet - summary: Find pet by ID - description: Returns a single pet - operationId: getPetById - produces: - - application/xml - - application/json - parameters: - - name: petId - in: path - description: ID of pet to return - required: true - type: integer - format: int64 - responses: - '200': - description: successful operation - schema: - $ref: '#/definitions/Pet' - '400': - description: Invalid ID supplied - '404': - description: Pet not found - security: - - api_key: [] - post: - tags: - - pet - summary: Updates a pet in the store with form data - description: '' - operationId: updatePetWithForm - consumes: - - application/x-www-form-urlencoded - produces: - - application/xml - - application/json - parameters: - - name: petId - in: path - description: ID of pet that needs to be updated - required: true - type: integer - format: int64 - - name: name - in: formData - description: Updated name of the pet - required: false - type: string - - name: status - in: formData - description: Updated status of the pet - required: false - type: string - responses: - '405': - description: Invalid input - security: - - petstore_auth: - - 'write:pets' - - 'read:pets' - delete: - tags: - - pet - summary: Deletes a pet - description: '' - operationId: deletePet - produces: - - application/xml - - application/json - parameters: - - name: api_key - in: header - required: false - type: string - - name: petId - in: path - description: Pet id to delete - required: true - type: integer - format: int64 - responses: - '400': - description: Invalid pet value - security: - - petstore_auth: - - 'write:pets' - - 'read:pets' - '/pet/{petId}/uploadImage': - post: - tags: - - pet - summary: uploads an image - description: '' - operationId: uploadFile - consumes: - - multipart/form-data - produces: - - application/json - parameters: - - name: petId - in: path - description: ID of pet to update - required: true - type: integer - format: int64 - - name: additionalMetadata - in: formData - description: Additional data to pass to server - required: false - type: string - - name: file - in: formData - description: file to upload - required: false - type: file - responses: - '200': - description: successful operation - schema: - $ref: '#/definitions/ApiResponse' - security: - - petstore_auth: - - 'write:pets' - - 'read:pets' - /store/inventory: - get: - tags: - - store - summary: Returns pet inventories by status - description: Returns a map of status codes to quantities - operationId: getInventory - produces: - - application/json - parameters: [] - responses: - '200': - description: successful operation - schema: - type: object - additionalProperties: - type: integer - format: int32 - security: - - api_key: [] - /store/order: - post: - tags: - - store - summary: Place an order for a pet - description: '' - operationId: placeOrder - produces: - - application/xml - - application/json - parameters: - - in: body - name: body - description: order placed for purchasing the pet - required: true - schema: - $ref: '#/definitions/Order' - responses: - '200': - description: successful operation - schema: - $ref: '#/definitions/Order' - '400': - description: Invalid Order - '/store/order/{orderId}': - get: - tags: - - store - summary: Find purchase order by ID - description: 'For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions' - operationId: getOrderById - produces: - - application/xml - - application/json - parameters: - - name: orderId - in: path - description: ID of pet that needs to be fetched - required: true - type: integer - maximum: 5 - minimum: 1 - format: int64 - responses: - '200': - description: successful operation - schema: - $ref: '#/definitions/Order' - '400': - description: Invalid ID supplied - '404': - description: Order not found - delete: - tags: - - store - summary: Delete purchase order by ID - description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - operationId: deleteOrder - produces: - - application/xml - - application/json - parameters: - - name: orderId - in: path - description: ID of the order that needs to be deleted - required: true - type: string - responses: - '400': - description: Invalid ID supplied - '404': - description: Order not found - /user: - post: - tags: - - user - summary: Create user - description: This can only be done by the logged in user. - operationId: createUser - produces: - - application/xml - - application/json - parameters: - - in: body - name: body - description: Created user object - required: true - schema: - $ref: '#/definitions/User' - responses: - default: - description: successful operation - /user/createWithArray: - post: - tags: - - user - summary: Creates list of users with given input array - description: '' - operationId: createUsersWithArrayInput - produces: - - application/xml - - application/json - parameters: - - in: body - name: body - description: List of user object - required: true - schema: - type: array - items: - $ref: '#/definitions/User' - responses: - default: - description: successful operation - /user/createWithList: - post: - tags: - - user - summary: Creates list of users with given input array - description: '' - operationId: createUsersWithListInput - produces: - - application/xml - - application/json - parameters: - - in: body - name: body - description: List of user object - required: true - schema: - type: array - items: - $ref: '#/definitions/User' - responses: - default: - description: successful operation - /user/login: - get: - tags: - - user - summary: Logs user into the system - description: '' - operationId: loginUser - produces: - - application/xml - - application/json - parameters: - - name: username - in: query - description: The user name for login - required: true - type: string - - name: password - in: query - description: The password for login in clear text - required: true - type: string - responses: - '200': - description: successful operation - schema: - type: string - headers: - X-Rate-Limit: - type: integer - format: int32 - description: calls per hour allowed by the user - X-Expires-After: - type: string - format: date-time - description: date in UTC when token expires - '400': - description: Invalid username/password supplied - /user/logout: - get: - tags: - - user - summary: Logs out current logged in user session - description: '' - operationId: logoutUser - produces: - - application/xml - - application/json - parameters: [] - responses: - default: - description: successful operation - '/user/{username}': - get: - tags: - - user - summary: Get user by user name - description: '' - operationId: getUserByName - produces: - - application/xml - - application/json - parameters: - - name: username - in: path - description: 'The name that needs to be fetched. Use user1 for testing.' - required: true - type: string - responses: - '200': - description: successful operation - schema: - $ref: '#/definitions/User' - '400': - description: Invalid username supplied - '404': - description: User not found - put: - tags: - - user - summary: Updated user - description: This can only be done by the logged in user. - operationId: updateUser - produces: - - application/xml - - application/json - parameters: - - name: username - in: path - description: name that need to be deleted - required: true - type: string - - in: body - name: body - description: Updated user object - required: true - schema: - $ref: '#/definitions/User' - responses: - '400': - description: Invalid user supplied - '404': - description: User not found - delete: - tags: - - user - summary: Delete user - description: This can only be done by the logged in user. - operationId: deleteUser - produces: - - application/xml - - application/json - parameters: - - name: username - in: path - description: The name that needs to be deleted - required: true - type: string - responses: - '400': - description: Invalid username supplied - '404': - description: User not found -securityDefinitions: - petstore_auth: - type: oauth2 - authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog' - flow: implicit - scopes: - 'write:pets': modify pets in your account - 'read:pets': read your pets - api_key: - type: apiKey - name: api_key - in: header -definitions: - Order: - title: Pet Order - description: An order for a pets from the pet store - type: object - properties: - id: - type: integer - format: int64 - petId: - type: integer - format: int64 - quantity: - type: integer - format: int32 - shipDate: - type: string - format: date-time - status: - type: string - description: Order Status - enum: - - placed - - approved - - delivered - complete: - type: boolean - default: false - xml: - name: Order - Category: - title: Pet category - description: A category for a pet - type: object - properties: - id: - type: integer - format: int64 - name: - type: string - xml: - name: Category - User: - title: a User - description: A User who is purchasing from the pet store - type: object - properties: - id: - type: integer - format: int64 - username: - type: string - firstName: - type: string - lastName: - type: string - email: - type: string - password: - type: string - phone: - type: string - userStatus: - type: integer - format: int32 - description: User Status - xml: - name: User - Tag: - title: Pet Tag - description: A tag for a pet - type: object - properties: - id: - type: integer - format: int64 - name: - type: string - xml: - name: Tag - Pet: - title: a Pet - description: A pet for sale in the pet store - type: object - required: - - name - - photoUrls - properties: - id: - type: integer - format: int64 - category: - $ref: '#/definitions/Category' - name: - type: string - example: doggie - photoUrls: - type: array - xml: - name: photoUrl - wrapped: true - items: - type: string - tags: - type: array - xml: - name: tag - wrapped: true - items: - $ref: '#/definitions/Tag' - status: - type: string - description: pet status in the store - enum: - - available - - pending - - sold - xml: - name: Pet - ApiResponse: - title: An uploaded response - description: Describes the result of uploading an image resource - type: object - properties: - code: - type: integer - format: int32 - type: - type: string - message: - type: string - EnumModel: - enum: - - available> - - pending< - - sold - - 1 - - 2 - type: string From 59ffb3c2fab499693304651999d1659b12ade3a5 Mon Sep 17 00:00:00 2001 From: welshm Date: Thu, 6 Jun 2024 10:52:50 -0400 Subject: [PATCH 6/8] Remove old 2_0 samples --- .../petstore/2_0/python-flask/.dockerignore | 72 -- .../petstore/2_0/python-flask/.gitignore | 66 -- .../python-flask/.openapi-generator-ignore | 23 - .../2_0/python-flask/.openapi-generator/FILES | 31 - .../python-flask/.openapi-generator/VERSION | 1 - .../petstore/2_0/python-flask/.travis.yml | 14 - .../petstore/2_0/python-flask/Dockerfile | 16 - .../petstore/2_0/python-flask/README.md | 49 -- .../petstore/2_0/python-flask/git_push.sh | 57 -- .../python-flask/openapi_server/__init__.py | 0 .../python-flask/openapi_server/__main__.py | 19 - .../openapi_server/controllers/__init__.py | 0 .../controllers/pet_controller.py | 126 --- .../controllers/security_controller.py | 47 - .../controllers/store_controller.py | 59 -- .../controllers/user_controller.py | 121 --- .../python-flask/openapi_server/encoder.py | 19 - .../openapi_server/models/__init__.py | 9 - .../openapi_server/models/api_response.py | 113 --- .../openapi_server/models/base_model.py | 68 -- .../openapi_server/models/category.py | 87 -- .../openapi_server/models/enum_model.py | 42 - .../openapi_server/models/order.py | 199 ----- .../python-flask/openapi_server/models/pet.py | 207 ----- .../python-flask/openapi_server/models/tag.py | 87 -- .../openapi_server/models/user.py | 245 ------ .../openapi_server/openapi/openapi.yaml | 826 ------------------ .../openapi_server/test/__init__.py | 16 - .../test/test_pet_controller.py | 166 ---- .../test/test_store_controller.py | 79 -- .../test/test_user_controller.py | 151 ---- .../openapi_server/typing_utils.py | 30 - .../2_0/python-flask/openapi_server/util.py | 147 ---- .../2_0/python-flask/requirements.txt | 13 - .../server/petstore/2_0/python-flask/setup.py | 37 - .../2_0/python-flask/test-requirements.txt | 4 - .../server/petstore/2_0/python-flask/tox.ini | 11 - 37 files changed, 3257 deletions(-) delete mode 100644 samples/server/petstore/2_0/python-flask/.dockerignore delete mode 100644 samples/server/petstore/2_0/python-flask/.gitignore delete mode 100644 samples/server/petstore/2_0/python-flask/.openapi-generator-ignore delete mode 100644 samples/server/petstore/2_0/python-flask/.openapi-generator/FILES delete mode 100644 samples/server/petstore/2_0/python-flask/.openapi-generator/VERSION delete mode 100644 samples/server/petstore/2_0/python-flask/.travis.yml delete mode 100644 samples/server/petstore/2_0/python-flask/Dockerfile delete mode 100644 samples/server/petstore/2_0/python-flask/README.md delete mode 100644 samples/server/petstore/2_0/python-flask/git_push.sh delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/__init__.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/__main__.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/controllers/__init__.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/controllers/pet_controller.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/controllers/security_controller.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/controllers/store_controller.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/controllers/user_controller.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/encoder.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/__init__.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/api_response.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/base_model.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/category.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/enum_model.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/order.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/pet.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/tag.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/models/user.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/openapi/openapi.yaml delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/test/__init__.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/test/test_pet_controller.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/test/test_store_controller.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/test/test_user_controller.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/typing_utils.py delete mode 100644 samples/server/petstore/2_0/python-flask/openapi_server/util.py delete mode 100644 samples/server/petstore/2_0/python-flask/requirements.txt delete mode 100644 samples/server/petstore/2_0/python-flask/setup.py delete mode 100644 samples/server/petstore/2_0/python-flask/test-requirements.txt delete mode 100644 samples/server/petstore/2_0/python-flask/tox.ini diff --git a/samples/server/petstore/2_0/python-flask/.dockerignore b/samples/server/petstore/2_0/python-flask/.dockerignore deleted file mode 100644 index f9619601908b..000000000000 --- a/samples/server/petstore/2_0/python-flask/.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/2_0/python-flask/.gitignore b/samples/server/petstore/2_0/python-flask/.gitignore deleted file mode 100644 index 43995bd42fa2..000000000000 --- a/samples/server/petstore/2_0/python-flask/.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/2_0/python-flask/.openapi-generator-ignore b/samples/server/petstore/2_0/python-flask/.openapi-generator-ignore deleted file mode 100644 index 7484ee590a38..000000000000 --- a/samples/server/petstore/2_0/python-flask/.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/2_0/python-flask/.openapi-generator/FILES b/samples/server/petstore/2_0/python-flask/.openapi-generator/FILES deleted file mode 100644 index c08d341ed532..000000000000 --- a/samples/server/petstore/2_0/python-flask/.openapi-generator/FILES +++ /dev/null @@ -1,31 +0,0 @@ -.dockerignore -.gitignore -.travis.yml -Dockerfile -README.md -git_push.sh -openapi_server/__init__.py -openapi_server/__main__.py -openapi_server/controllers/__init__.py -openapi_server/controllers/pet_controller.py -openapi_server/controllers/security_controller.py -openapi_server/controllers/store_controller.py -openapi_server/controllers/user_controller.py -openapi_server/encoder.py -openapi_server/models/__init__.py -openapi_server/models/api_response.py -openapi_server/models/base_model.py -openapi_server/models/category.py -openapi_server/models/enum_model.py -openapi_server/models/order.py -openapi_server/models/pet.py -openapi_server/models/tag.py -openapi_server/models/user.py -openapi_server/openapi/openapi.yaml -openapi_server/test/__init__.py -openapi_server/typing_utils.py -openapi_server/util.py -requirements.txt -setup.py -test-requirements.txt -tox.ini diff --git a/samples/server/petstore/2_0/python-flask/.openapi-generator/VERSION b/samples/server/petstore/2_0/python-flask/.openapi-generator/VERSION deleted file mode 100644 index 7e7b8b9bc733..000000000000 --- a/samples/server/petstore/2_0/python-flask/.openapi-generator/VERSION +++ /dev/null @@ -1 +0,0 @@ -7.7.0-SNAPSHOT diff --git a/samples/server/petstore/2_0/python-flask/.travis.yml b/samples/server/petstore/2_0/python-flask/.travis.yml deleted file mode 100644 index ad71ee5ca083..000000000000 --- a/samples/server/petstore/2_0/python-flask/.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/2_0/python-flask/Dockerfile b/samples/server/petstore/2_0/python-flask/Dockerfile deleted file mode 100644 index 4857637c3799..000000000000 --- a/samples/server/petstore/2_0/python-flask/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/2_0/python-flask/README.md b/samples/server/petstore/2_0/python-flask/README.md deleted file mode 100644 index 673c8b3b5a01..000000000000 --- a/samples/server/petstore/2_0/python-flask/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/2_0/python-flask/git_push.sh b/samples/server/petstore/2_0/python-flask/git_push.sh deleted file mode 100644 index f53a75d4fabe..000000000000 --- a/samples/server/petstore/2_0/python-flask/git_push.sh +++ /dev/null @@ -1,57 +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-petstore-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/2_0/python-flask/openapi_server/__init__.py b/samples/server/petstore/2_0/python-flask/openapi_server/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/__main__.py b/samples/server/petstore/2_0/python-flask/openapi_server/__main__.py deleted file mode 100644 index 6045d0156f05..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/__main__.py +++ /dev/null @@ -1,19 +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/2_0/python-flask/openapi_server/controllers/__init__.py b/samples/server/petstore/2_0/python-flask/openapi_server/controllers/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/controllers/pet_controller.py b/samples/server/petstore/2_0/python-flask/openapi_server/controllers/pet_controller.py deleted file mode 100644 index 89086c54bd41..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/controllers/pet_controller.py +++ /dev/null @@ -1,126 +0,0 @@ -import connexion -from typing import Dict -from typing import Tuple -from typing import Union - -from openapi_server.models.api_response import ApiResponse # noqa: E501 -from openapi_server.models.pet import Pet # noqa: E501 -from openapi_server import util - - -def add_pet(body): # noqa: E501 - """Add a new pet to the store - - # noqa: E501 - - :param body: Pet object that needs to be added to the store - :type body: dict | bytes - - :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] - """ - if connexion.request.is_json: - body = 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: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] - """ - 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: Union[List[Pet], Tuple[List[Pet], int], Tuple[List[Pet], int, Dict[str, str]] - """ - 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: Union[List[Pet], Tuple[List[Pet], int], Tuple[List[Pet], int, Dict[str, str]] - """ - 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: Union[Pet, Tuple[Pet, int], Tuple[Pet, int, Dict[str, str]] - """ - return 'do some magic!' - - -def update_pet(body): # noqa: E501 - """Update an existing pet - - # noqa: E501 - - :param body: Pet object that needs to be added to the store - :type body: dict | bytes - - :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] - """ - if connexion.request.is_json: - body = Pet.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: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] - """ - 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: Union[ApiResponse, Tuple[ApiResponse, int], Tuple[ApiResponse, int, Dict[str, str]] - """ - return 'do some magic!' diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/controllers/security_controller.py b/samples/server/petstore/2_0/python-flask/openapi_server/controllers/security_controller.py deleted file mode 100644 index aae1a19e84aa..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/controllers/security_controller.py +++ /dev/null @@ -1,47 +0,0 @@ -from typing import List - - -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)) - - -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'} - diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/controllers/store_controller.py b/samples/server/petstore/2_0/python-flask/openapi_server/controllers/store_controller.py deleted file mode 100644 index 62887e7adac0..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/controllers/store_controller.py +++ /dev/null @@ -1,59 +0,0 @@ -import connexion -from typing import Dict -from typing import Tuple -from typing import Union - -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: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] - """ - 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: Union[Dict[str, int], Tuple[Dict[str, int], int], Tuple[Dict[str, int], int, Dict[str, str]] - """ - 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 generate exceptions # noqa: E501 - - :param order_id: ID of pet that needs to be fetched - :type order_id: int - - :rtype: Union[Order, Tuple[Order, int], Tuple[Order, int, Dict[str, str]] - """ - return 'do some magic!' - - -def place_order(body): # noqa: E501 - """Place an order for a pet - - # noqa: E501 - - :param body: order placed for purchasing the pet - :type body: dict | bytes - - :rtype: Union[Order, Tuple[Order, int], Tuple[Order, int, Dict[str, str]] - """ - if connexion.request.is_json: - body = Order.from_dict(connexion.request.get_json()) # noqa: E501 - return 'do some magic!' diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/controllers/user_controller.py b/samples/server/petstore/2_0/python-flask/openapi_server/controllers/user_controller.py deleted file mode 100644 index 0acef4751501..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/controllers/user_controller.py +++ /dev/null @@ -1,121 +0,0 @@ -import connexion -from typing import Dict -from typing import Tuple -from typing import Union - -from openapi_server.models.user import User # noqa: E501 -from openapi_server import util - - -def create_user(body): # noqa: E501 - """Create user - - This can only be done by the logged in user. # noqa: E501 - - :param body: Created user object - :type body: dict | bytes - - :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] - """ - if connexion.request.is_json: - body = User.from_dict(connexion.request.get_json()) # noqa: E501 - return 'do some magic!' - - -def create_users_with_array_input(body): # noqa: E501 - """Creates list of users with given input array - - # noqa: E501 - - :param body: List of user object - :type body: list | bytes - - :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] - """ - if connexion.request.is_json: - body = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501 - return 'do some magic!' - - -def create_users_with_list_input(body): # noqa: E501 - """Creates list of users with given input array - - # noqa: E501 - - :param body: List of user object - :type body: list | bytes - - :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] - """ - if connexion.request.is_json: - body = [User.from_dict(d) for d in connexion.request.get_json()] # noqa: E501 - 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: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] - """ - 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: Union[User, Tuple[User, int], Tuple[User, int, Dict[str, str]] - """ - 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: Union[str, Tuple[str, int], Tuple[str, int, Dict[str, str]] - """ - return 'do some magic!' - - -def logout_user(): # noqa: E501 - """Logs out current logged in user session - - # noqa: E501 - - - :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] - """ - return 'do some magic!' - - -def update_user(username, body): # noqa: E501 - """Updated user - - This can only be done by the logged in user. # noqa: E501 - - :param username: name that need to be deleted - :type username: str - :param body: Updated user object - :type body: dict | bytes - - :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] - """ - if connexion.request.is_json: - body = User.from_dict(connexion.request.get_json()) # noqa: E501 - return 'do some magic!' diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/encoder.py b/samples/server/petstore/2_0/python-flask/openapi_server/encoder.py deleted file mode 100644 index 60f4fa67e7dc..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/encoder.py +++ /dev/null @@ -1,19 +0,0 @@ -from connexion.apps.flask_app import FlaskJSONEncoder - -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 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/2_0/python-flask/openapi_server/models/__init__.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/__init__.py deleted file mode 100644 index 21d4d1aeb93d..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/models/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -# flake8: noqa -# import models into model package -from openapi_server.models.api_response import ApiResponse -from openapi_server.models.category import Category -from openapi_server.models.enum_model import EnumModel -from openapi_server.models.order import Order -from openapi_server.models.pet import Pet -from openapi_server.models.tag import Tag -from openapi_server.models.user import User diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/models/api_response.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/api_response.py deleted file mode 100644 index 983e11cc4ea2..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/models/api_response.py +++ /dev/null @@ -1,113 +0,0 @@ -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) -> int: - """Gets the code of this ApiResponse. - - - :return: The code of this ApiResponse. - :rtype: int - """ - return self._code - - @code.setter - def code(self, code: int): - """Sets the code of this ApiResponse. - - - :param code: The code of this ApiResponse. - :type code: int - """ - - self._code = code - - @property - def type(self) -> str: - """Gets the type of this ApiResponse. - - - :return: The type of this ApiResponse. - :rtype: str - """ - return self._type - - @type.setter - def type(self, type: str): - """Sets the type of this ApiResponse. - - - :param type: The type of this ApiResponse. - :type type: str - """ - - self._type = type - - @property - def message(self) -> str: - """Gets the message of this ApiResponse. - - - :return: The message of this ApiResponse. - :rtype: str - """ - return self._message - - @message.setter - def message(self, message: str): - """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/2_0/python-flask/openapi_server/models/base_model.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/base_model.py deleted file mode 100644 index c01b423a7432..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/models/base_model.py +++ /dev/null @@ -1,68 +0,0 @@ -import pprint - -import typing - -from openapi_server import util - -T = typing.TypeVar('T') - - -class Model: - # openapiTypes: The key is attribute name and the - # value is attribute type. - openapi_types: typing.Dict[str, type] = {} - - # attributeMap: The key is attribute name and the - # value is json key in definition. - attribute_map: typing.Dict[str, str] = {} - - @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 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/2_0/python-flask/openapi_server/models/category.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/category.py deleted file mode 100644 index 4bdec5b25c4f..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/models/category.py +++ /dev/null @@ -1,87 +0,0 @@ -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 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) -> int: - """Gets the id of this Category. - - - :return: The id of this Category. - :rtype: int - """ - return self._id - - @id.setter - def id(self, id: int): - """Sets the id of this Category. - - - :param id: The id of this Category. - :type id: int - """ - - self._id = id - - @property - def name(self) -> str: - """Gets the name of this Category. - - - :return: The name of this Category. - :rtype: str - """ - return self._name - - @name.setter - def name(self, name: str): - """Sets the name of this Category. - - - :param name: The name of this Category. - :type name: str - """ - - self._name = name diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/models/enum_model.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/enum_model.py deleted file mode 100644 index 5d60d2aaef2f..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/models/enum_model.py +++ /dev/null @@ -1,42 +0,0 @@ -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 EnumModel(Model): - """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - - Do not edit the class manually. - """ - - """ - allowed enum values - """ - AVAILABLE_GREATER_THAN = 'available>' - PENDING_LESS_THAN = 'pending<' - SOLD = 'sold' - ENUM_1 = '1' - ENUM_2 = '2' - def __init__(self): # noqa: E501 - """EnumModel - a model defined in OpenAPI - - """ - self.openapi_types = { - } - - self.attribute_map = { - } - - @classmethod - def from_dict(cls, dikt) -> 'EnumModel': - """Returns the dict as a model - - :param dikt: A dict. - :type: dict - :return: The EnumModel of this EnumModel. # noqa: E501 - :rtype: EnumModel - """ - return util.deserialize_model(dikt, cls) diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/models/order.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/order.py deleted file mode 100644 index 1fdf0cb3b798..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/models/order.py +++ /dev/null @@ -1,199 +0,0 @@ -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) -> int: - """Gets the id of this Order. - - - :return: The id of this Order. - :rtype: int - """ - return self._id - - @id.setter - def id(self, id: int): - """Sets the id of this Order. - - - :param id: The id of this Order. - :type id: int - """ - - self._id = id - - @property - def pet_id(self) -> int: - """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: int): - """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) -> int: - """Gets the quantity of this Order. - - - :return: The quantity of this Order. - :rtype: int - """ - return self._quantity - - @quantity.setter - def quantity(self, quantity: int): - """Sets the quantity of this Order. - - - :param quantity: The quantity of this Order. - :type quantity: int - """ - - self._quantity = quantity - - @property - def ship_date(self) -> datetime: - """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: datetime): - """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) -> str: - """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: str): - """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) -> bool: - """Gets the complete of this Order. - - - :return: The complete of this Order. - :rtype: bool - """ - return self._complete - - @complete.setter - def complete(self, complete: bool): - """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/2_0/python-flask/openapi_server/models/pet.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/pet.py deleted file mode 100644 index b460a10303ee..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/models/pet.py +++ /dev/null @@ -1,207 +0,0 @@ -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) -> int: - """Gets the id of this Pet. - - - :return: The id of this Pet. - :rtype: int - """ - return self._id - - @id.setter - def id(self, id: int): - """Sets the id of this Pet. - - - :param id: The id of this Pet. - :type id: int - """ - - self._id = id - - @property - def category(self) -> Category: - """Gets the category of this Pet. - - - :return: The category of this Pet. - :rtype: Category - """ - return self._category - - @category.setter - def category(self, category: Category): - """Sets the category of this Pet. - - - :param category: The category of this Pet. - :type category: Category - """ - - self._category = category - - @property - def name(self) -> str: - """Gets the name of this Pet. - - - :return: The name of this Pet. - :rtype: str - """ - return self._name - - @name.setter - def name(self, name: str): - """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) -> List[str]: - """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: List[str]): - """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) -> List[Tag]: - """Gets the tags of this Pet. - - - :return: The tags of this Pet. - :rtype: List[Tag] - """ - return self._tags - - @tags.setter - def tags(self, tags: List[Tag]): - """Sets the tags of this Pet. - - - :param tags: The tags of this Pet. - :type tags: List[Tag] - """ - - self._tags = tags - - @property - def status(self) -> str: - """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: str): - """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/2_0/python-flask/openapi_server/models/tag.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/tag.py deleted file mode 100644 index 2a38c9ee02a5..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/models/tag.py +++ /dev/null @@ -1,87 +0,0 @@ -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) -> int: - """Gets the id of this Tag. - - - :return: The id of this Tag. - :rtype: int - """ - return self._id - - @id.setter - def id(self, id: int): - """Sets the id of this Tag. - - - :param id: The id of this Tag. - :type id: int - """ - - self._id = id - - @property - def name(self) -> str: - """Gets the name of this Tag. - - - :return: The name of this Tag. - :rtype: str - """ - return self._name - - @name.setter - def name(self, name: str): - """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/2_0/python-flask/openapi_server/models/user.py b/samples/server/petstore/2_0/python-flask/openapi_server/models/user.py deleted file mode 100644 index 868b4c85b941..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/models/user.py +++ /dev/null @@ -1,245 +0,0 @@ -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) -> int: - """Gets the id of this User. - - - :return: The id of this User. - :rtype: int - """ - return self._id - - @id.setter - def id(self, id: int): - """Sets the id of this User. - - - :param id: The id of this User. - :type id: int - """ - - self._id = id - - @property - def username(self) -> str: - """Gets the username of this User. - - - :return: The username of this User. - :rtype: str - """ - return self._username - - @username.setter - def username(self, username: str): - """Sets the username of this User. - - - :param username: The username of this User. - :type username: str - """ - - self._username = username - - @property - def first_name(self) -> str: - """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: str): - """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) -> str: - """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: str): - """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) -> str: - """Gets the email of this User. - - - :return: The email of this User. - :rtype: str - """ - return self._email - - @email.setter - def email(self, email: str): - """Sets the email of this User. - - - :param email: The email of this User. - :type email: str - """ - - self._email = email - - @property - def password(self) -> str: - """Gets the password of this User. - - - :return: The password of this User. - :rtype: str - """ - return self._password - - @password.setter - def password(self, password: str): - """Sets the password of this User. - - - :param password: The password of this User. - :type password: str - """ - - self._password = password - - @property - def phone(self) -> str: - """Gets the phone of this User. - - - :return: The phone of this User. - :rtype: str - """ - return self._phone - - @phone.setter - def phone(self, phone: str): - """Sets the phone of this User. - - - :param phone: The phone of this User. - :type phone: str - """ - - self._phone = phone - - @property - def user_status(self) -> int: - """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: int): - """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/2_0/python-flask/openapi_server/openapi/openapi.yaml b/samples/server/petstore/2_0/python-flask/openapi_server/openapi/openapi.yaml deleted file mode 100644 index 21e70929a17c..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/openapi/openapi.yaml +++ /dev/null @@ -1,826 +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 -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: - 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 - responses: - "405": - content: {} - description: Invalid input - security: - - petstore_auth: - - write:pets - - read:pets - summary: Add a new pet to the store - tags: - - pet - x-codegen-request-body-name: body - x-openapi-router-controller: openapi_server.controllers.pet_controller - put: - operationId: update_pet - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/Pet' - application/xml: - schema: - $ref: '#/components/schemas/Pet' - description: Pet object that needs to be added to the store - required: true - responses: - "400": - content: {} - description: Invalid ID supplied - "404": - content: {} - description: Pet not found - "405": - content: {} - description: Validation exception - security: - - petstore_auth: - - write:pets - - read:pets - summary: Update an existing pet - tags: - - pet - x-codegen-request-body-name: body - x-openapi-router-controller: openapi_server.controllers.pet_controller - /pet/findByStatus: - get: - description: Multiple status values can be provided with comma separated strings - operationId: find_pets_by_status - parameters: - - description: Status values that need to be considered for filter - 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": - content: {} - description: Invalid status value - security: - - petstore_auth: - - write:pets - - 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": - content: {} - description: Invalid tag value - security: - - petstore_auth: - - write:pets - - 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: - - in: header - name: api_key - schema: - type: string - - description: Pet id to delete - in: path - name: petId - required: true - schema: - format: int64 - type: integer - responses: - "400": - content: {} - 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 - in: path - name: petId - required: true - schema: - format: int64 - type: integer - responses: - "200": - content: - application/xml: - schema: - $ref: '#/components/schemas/Pet' - application/json: - schema: - $ref: '#/components/schemas/Pet' - description: successful operation - "400": - content: {} - description: Invalid ID supplied - "404": - content: {} - description: Pet not found - security: - - api_key: [] - summary: Find pet by ID - 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 - in: path - name: petId - required: true - schema: - format: int64 - type: integer - requestBody: - content: - application/x-www-form-urlencoded: - schema: - $ref: '#/components/schemas/updatePetWithForm_request' - responses: - "405": - content: {} - 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 - in: path - name: petId - required: true - schema: - format: int64 - type: integer - requestBody: - content: - multipart/form-data: - schema: - $ref: '#/components/schemas/uploadFile_request' - 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: - '*/*': - 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": - content: {} - description: Invalid Order - summary: Place an order for a pet - tags: - - store - x-codegen-request-body-name: body - x-openapi-router-controller: openapi_server.controllers.store_controller - /store/order/{orderId}: - delete: - 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 - in: path - name: orderId - required: true - schema: - type: string - responses: - "400": - content: {} - description: Invalid ID supplied - "404": - content: {} - 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 generate exceptions - operationId: get_order_by_id - parameters: - - description: ID of pet that needs to be fetched - in: path - name: orderId - required: true - schema: - format: int64 - maximum: 5 - minimum: 1 - type: integer - responses: - "200": - content: - application/xml: - schema: - $ref: '#/components/schemas/Order' - application/json: - schema: - $ref: '#/components/schemas/Order' - description: successful operation - "400": - content: {} - description: Invalid ID supplied - "404": - content: {} - description: Order not found - summary: Find purchase order by ID - tags: - - 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: - '*/*': - schema: - $ref: '#/components/schemas/User' - description: Created user object - required: true - responses: - default: - content: {} - description: successful operation - summary: Create user - tags: - - user - x-codegen-request-body-name: body - x-openapi-router-controller: openapi_server.controllers.user_controller - /user/createWithArray: - post: - operationId: create_users_with_array_input - requestBody: - content: - '*/*': - schema: - items: - $ref: '#/components/schemas/User' - type: array - description: List of user object - required: true - responses: - default: - content: {} - description: successful operation - summary: Creates list of users with given input array - tags: - - user - x-codegen-request-body-name: body - x-openapi-router-controller: openapi_server.controllers.user_controller - /user/createWithList: - post: - operationId: create_users_with_list_input - requestBody: - content: - '*/*': - schema: - items: - $ref: '#/components/schemas/User' - type: array - description: List of user object - required: true - responses: - default: - content: {} - description: successful operation - summary: Creates list of users with given input array - tags: - - user - x-codegen-request-body-name: body - x-openapi-router-controller: openapi_server.controllers.user_controller - /user/login: - get: - operationId: login_user - parameters: - - description: The user name for login - in: query - name: username - required: true - schema: - type: string - - description: The password for login in clear text - in: query - name: password - required: true - schema: - type: string - responses: - "200": - content: - application/xml: - schema: - type: string - application/json: - schema: - type: string - description: successful operation - headers: - X-Rate-Limit: - description: calls per hour allowed by the user - schema: - format: int32 - type: integer - X-Expires-After: - description: date in UTC when token expires - schema: - format: date-time - type: string - "400": - content: {} - 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: - content: {} - description: successful operation - 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 - in: path - name: username - required: true - schema: - type: string - responses: - "400": - content: {} - description: Invalid username supplied - "404": - content: {} - description: User not found - 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. - in: path - name: username - required: true - schema: - type: string - responses: - "200": - content: - application/xml: - schema: - $ref: '#/components/schemas/User' - application/json: - schema: - $ref: '#/components/schemas/User' - description: successful operation - "400": - content: {} - description: Invalid username supplied - "404": - content: {} - description: User not found - summary: Get user by user name - tags: - - 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 - in: path - name: username - required: true - schema: - type: string - requestBody: - content: - '*/*': - schema: - $ref: '#/components/schemas/User' - description: Updated user object - required: true - responses: - "400": - content: {} - description: Invalid user supplied - "404": - content: {} - description: User not found - summary: Updated user - tags: - - user - x-codegen-request-body-name: body - x-openapi-router-controller: openapi_server.controllers.user_controller -components: - 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 - title: id - type: integer - petId: - format: int64 - title: petId - type: integer - quantity: - format: int32 - title: quantity - type: integer - shipDate: - format: date-time - title: shipDate - type: string - status: - description: Order Status - enum: - - placed - - approved - - delivered - title: status - type: string - complete: - default: false - title: complete - 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 - title: id - type: integer - name: - title: name - 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 - title: id - type: integer - username: - title: username - type: string - firstName: - title: firstName - type: string - lastName: - title: lastName - type: string - email: - title: email - type: string - password: - title: password - type: string - phone: - title: phone - type: string - userStatus: - description: User Status - format: int32 - title: userStatus - 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 - title: id - type: integer - name: - title: 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 - title: id - type: integer - category: - $ref: '#/components/schemas/Category' - name: - example: doggie - title: name - type: string - photoUrls: - items: - type: string - title: photoUrls - type: array - xml: - name: photoUrl - wrapped: true - tags: - items: - $ref: '#/components/schemas/Tag' - title: tags - type: array - xml: - name: tag - wrapped: true - status: - description: pet status in the store - enum: - - available - - pending - - sold - title: status - 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 - title: code - type: integer - type: - title: type - type: string - message: - title: message - type: string - title: An uploaded response - type: object - EnumModel: - enum: - - available> - - pending< - - sold - - "1" - - "2" - type: string - updatePetWithForm_request: - properties: - name: - description: Updated name of the pet - type: string - status: - description: Updated status of the pet - type: string - type: object - uploadFile_request: - 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 -x-original-swagger-version: "2.0" diff --git a/samples/server/petstore/2_0/python-flask/openapi_server/test/__init__.py b/samples/server/petstore/2_0/python-flask/openapi_server/test/__init__.py deleted file mode 100644 index 364aba9fbf88..000000000000 --- a/samples/server/petstore/2_0/python-flask/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/2_0/python-flask/openapi_server/test/test_pet_controller.py b/samples/server/petstore/2_0/python-flask/openapi_server/test/test_pet_controller.py deleted file mode 100644 index a62cb03709c8..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/test/test_pet_controller.py +++ /dev/null @@ -1,166 +0,0 @@ -import unittest - -from flask import json - -from openapi_server.models.api_response import ApiResponse # noqa: E501 -from openapi_server.models.pet import Pet # noqa: E501 -from openapi_server.test import BaseTestCase - - -class TestPetController(BaseTestCase): - """PetController integration test stubs""" - - @unittest.skip("Connexion does not support multiple consumes. 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 - """ - body = {"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(body), - 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', ['status_example'])] - 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 consumes. See https://github.com/zalando/connexion/pull/760") - def test_update_pet(self): - """Test case for update_pet - - Update an existing pet - """ - body = {"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(body), - content_type='application/json') - 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='/path/to/file') - 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/2_0/python-flask/openapi_server/test/test_store_controller.py b/samples/server/petstore/2_0/python-flask/openapi_server/test/test_store_controller.py deleted file mode 100644 index 36b656cd827d..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/test/test_store_controller.py +++ /dev/null @@ -1,79 +0,0 @@ -import unittest - -from flask import json - -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=56), - method='GET', - headers=headers) - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - @unittest.skip("*/* not supported by Connexion. Use application/json instead. See https://github.com/zalando/connexion/pull/760") - def test_place_order(self): - """Test case for place_order - - Place an order for a pet - """ - body = openapi_server.Order() - headers = { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - } - response = self.client.open( - '/v2/store/order', - method='POST', - headers=headers, - data=json.dumps(body), - 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/2_0/python-flask/openapi_server/test/test_user_controller.py b/samples/server/petstore/2_0/python-flask/openapi_server/test/test_user_controller.py deleted file mode 100644 index a991011b3166..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/test/test_user_controller.py +++ /dev/null @@ -1,151 +0,0 @@ -import unittest - -from flask import json - -from openapi_server.models.user import User # noqa: E501 -from openapi_server.test import BaseTestCase - - -class TestUserController(BaseTestCase): - """UserController integration test stubs""" - - @unittest.skip("*/* not supported by Connexion. Use application/json instead. See https://github.com/zalando/connexion/pull/760") - def test_create_user(self): - """Test case for create_user - - Create user - """ - body = openapi_server.User() - headers = { - 'Content-Type': 'application/json', - } - response = self.client.open( - '/v2/user', - method='POST', - headers=headers, - data=json.dumps(body), - content_type='application/json') - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - @unittest.skip("*/* not supported by Connexion. Use application/json instead. See https://github.com/zalando/connexion/pull/760") - def test_create_users_with_array_input(self): - """Test case for create_users_with_array_input - - Creates list of users with given input array - """ - body = [openapi_server.User()] - headers = { - 'Content-Type': 'application/json', - } - response = self.client.open( - '/v2/user/createWithArray', - method='POST', - headers=headers, - data=json.dumps(body), - content_type='application/json') - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - @unittest.skip("*/* not supported by Connexion. Use application/json instead. See https://github.com/zalando/connexion/pull/760") - def test_create_users_with_list_input(self): - """Test case for create_users_with_list_input - - Creates list of users with given input array - """ - body = [openapi_server.User()] - headers = { - 'Content-Type': 'application/json', - } - response = self.client.open( - '/v2/user/createWithList', - method='POST', - headers=headers, - data=json.dumps(body), - 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 = { - } - 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 = { - } - response = self.client.open( - '/v2/user/logout', - method='GET', - headers=headers) - self.assert200(response, - 'Response body is : ' + response.data.decode('utf-8')) - - @unittest.skip("*/* not supported by Connexion. Use application/json instead. See https://github.com/zalando/connexion/pull/760") - def test_update_user(self): - """Test case for update_user - - Updated user - """ - body = openapi_server.User() - headers = { - 'Content-Type': 'application/json', - } - response = self.client.open( - '/v2/user/{username}'.format(username='username_example'), - method='PUT', - headers=headers, - data=json.dumps(body), - 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/2_0/python-flask/openapi_server/typing_utils.py b/samples/server/petstore/2_0/python-flask/openapi_server/typing_utils.py deleted file mode 100644 index 74e3c913a7db..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/typing_utils.py +++ /dev/null @@ -1,30 +0,0 @@ -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/2_0/python-flask/openapi_server/util.py b/samples/server/petstore/2_0/python-flask/openapi_server/util.py deleted file mode 100644 index bd83c5b330bb..000000000000 --- a/samples/server/petstore/2_0/python-flask/openapi_server/util.py +++ /dev/null @@ -1,147 +0,0 @@ -import datetime - -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 (int, 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 = 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 - """ - if string is None: - return None - - 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 - """ - if string is None: - return None - - 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 instance.openapi_types.items(): - 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 data.items() } diff --git a/samples/server/petstore/2_0/python-flask/requirements.txt b/samples/server/petstore/2_0/python-flask/requirements.txt deleted file mode 100644 index 2cb06891ce9f..000000000000 --- a/samples/server/petstore/2_0/python-flask/requirements.txt +++ /dev/null @@ -1,13 +0,0 @@ -connexion[swagger-ui] >= 2.6.0; python_version>="3.6" -# 2.3 is the last version that supports python 3.4-3.5 -connexion[swagger-ui] <= 2.3.0; python_version=="3.5" or python_version=="3.4" -# prevent breaking dependencies from advent of connexion>=3.0 -connexion[swagger-ui] <= 2.14.2; python_version>"3.4" -# connexion requires werkzeug but connexion < 2.4.0 does not install werkzeug -# we must peg werkzeug versions below to fix connexion -# https://github.com/zalando/connexion/pull/1044 -werkzeug == 0.16.1; python_version=="3.5" or python_version=="3.4" -swagger-ui-bundle >= 0.0.2 -python_dateutil >= 2.6.0 -setuptools >= 21.0.0 -Flask == 2.1.1 diff --git a/samples/server/petstore/2_0/python-flask/setup.py b/samples/server/petstore/2_0/python-flask/setup.py deleted file mode 100644 index 802848855890..000000000000 --- a/samples/server/petstore/2_0/python-flask/setup.py +++ /dev/null @@ -1,37 +0,0 @@ -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/2_0/python-flask/test-requirements.txt b/samples/server/petstore/2_0/python-flask/test-requirements.txt deleted file mode 100644 index 58f51d6a0027..000000000000 --- a/samples/server/petstore/2_0/python-flask/test-requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -pytest~=7.1.0 -pytest-cov>=2.8.1 -pytest-randomly>=1.2.3 -Flask-Testing==0.8.1 diff --git a/samples/server/petstore/2_0/python-flask/tox.ini b/samples/server/petstore/2_0/python-flask/tox.ini deleted file mode 100644 index 7663dfb69e41..000000000000 --- a/samples/server/petstore/2_0/python-flask/tox.ini +++ /dev/null @@ -1,11 +0,0 @@ -[tox] -envlist = py3 -skipsdist=True - -[testenv] -deps=-r{toxinidir}/requirements.txt - -r{toxinidir}/test-requirements.txt - {toxinidir} - -commands= - pytest --cov=openapi_server From c03b10dbfd247a53259b2b0aa326e5fec77ce83d Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 8 Jun 2024 15:32:03 +0800 Subject: [PATCH 7/8] update --- ...ith-fake-endpoints-models-for-testing.yaml | 39 +++++- .../python-aiohttp/.openapi-generator/FILES | 6 + .../client/petstore/python-aiohttp/README.md | 3 + .../petstore/python-aiohttp/docs/TestEnum.md | 16 +++ .../docs/TestEnumWithDefault.md | 14 ++ .../petstore/python-aiohttp/docs/TestModel.md | 33 +++++ .../python-aiohttp/petstore_api/__init__.py | 3 + .../petstore_api/models/__init__.py | 3 + .../petstore_api/models/test_enum.py | 39 ++++++ .../models/test_enum_with_default.py | 38 ++++++ .../petstore_api/models/test_model.py | 107 ++++++++++++++++ .../python-aiohttp/test/test_test_enum.py | 33 +++++ .../test/test_test_enum_with_default.py | 33 +++++ .../python-aiohttp/test/test_test_model.py | 56 ++++++++ .../.openapi-generator/FILES | 6 + .../python-pydantic-v1-aiohttp/README.md | 3 + .../docs/TestEnum.md | 16 +++ .../docs/TestEnumWithDefault.md | 14 ++ .../docs/TestModel.md | 32 +++++ .../petstore_api/__init__.py | 3 + .../petstore_api/models/__init__.py | 3 + .../petstore_api/models/test_enum.py | 42 ++++++ .../models/test_enum_with_default.py | 41 ++++++ .../petstore_api/models/test_model.py | 91 +++++++++++++ .../test/test_test_enum.py | 34 +++++ .../test/test_test_enum_with_default.py | 34 +++++ .../test/test_test_model.py | 57 +++++++++ .../.openapi-generator/FILES | 6 + .../petstore/python-pydantic-v1/README.md | 3 + .../python-pydantic-v1/docs/TestEnum.md | 16 +++ .../docs/TestEnumWithDefault.md | 14 ++ .../python-pydantic-v1/docs/TestModel.md | 32 +++++ .../petstore_api/__init__.py | 3 + .../petstore_api/models/__init__.py | 3 + .../petstore_api/models/test_enum.py | 42 ++++++ .../models/test_enum_with_default.py | 41 ++++++ .../petstore_api/models/test_model.py | 103 +++++++++++++++ .../python-pydantic-v1/test/test_test_enum.py | 34 +++++ .../test/test_test_enum_with_default.py | 34 +++++ .../test/test_test_model.py | 57 +++++++++ .../petstore/python/.openapi-generator/FILES | 6 + .../openapi3/client/petstore/python/README.md | 3 + .../client/petstore/python/docs/TestEnum.md | 16 +++ .../python/docs/TestEnumWithDefault.md | 14 ++ .../client/petstore/python/docs/TestModel.md | 33 +++++ .../petstore/python/petstore_api/__init__.py | 3 + .../python/petstore_api/models/__init__.py | 3 + .../python/petstore_api/models/test_enum.py | 39 ++++++ .../models/test_enum_with_default.py | 38 ++++++ .../python/petstore_api/models/test_model.py | 120 ++++++++++++++++++ .../petstore/python/test/test_test_enum.py | 33 +++++ .../test/test_test_enum_with_default.py | 33 +++++ .../petstore/python/test/test_test_model.py | 56 ++++++++ 53 files changed, 1583 insertions(+), 1 deletion(-) create mode 100644 samples/openapi3/client/petstore/python-aiohttp/docs/TestEnum.md create mode 100644 samples/openapi3/client/petstore/python-aiohttp/docs/TestEnumWithDefault.md create mode 100644 samples/openapi3/client/petstore/python-aiohttp/docs/TestModel.md create mode 100644 samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum.py create mode 100644 samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum_with_default.py create mode 100644 samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_model.py create mode 100644 samples/openapi3/client/petstore/python-aiohttp/test/test_test_enum.py create mode 100644 samples/openapi3/client/petstore/python-aiohttp/test/test_test_enum_with_default.py create mode 100644 samples/openapi3/client/petstore/python-aiohttp/test/test_test_model.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/TestEnum.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/TestEnumWithDefault.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/TestModel.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/test_enum.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/test_enum_with_default.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/test_model.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_test_enum.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_test_enum_with_default.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_test_model.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/docs/TestEnum.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/docs/TestEnumWithDefault.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/docs/TestModel.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/test_enum.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/test_enum_with_default.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/test_model.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/test/test_test_enum.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/test/test_test_enum_with_default.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/test/test_test_model.py create mode 100644 samples/openapi3/client/petstore/python/docs/TestEnum.md create mode 100644 samples/openapi3/client/petstore/python/docs/TestEnumWithDefault.md create mode 100644 samples/openapi3/client/petstore/python/docs/TestModel.md create mode 100644 samples/openapi3/client/petstore/python/petstore_api/models/test_enum.py create mode 100644 samples/openapi3/client/petstore/python/petstore_api/models/test_enum_with_default.py create mode 100644 samples/openapi3/client/petstore/python/petstore_api/models/test_model.py create mode 100644 samples/openapi3/client/petstore/python/test/test_test_enum.py create mode 100644 samples/openapi3/client/petstore/python/test/test_test_enum_with_default.py create mode 100644 samples/openapi3/client/petstore/python/test/test_test_model.py diff --git a/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml index 7f5925943583..985d15e5a032 100644 --- a/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml @@ -2792,4 +2792,41 @@ components: - properties: _value: type: string - type: object \ No newline at end of file + type: object + TestEnum: + type: string + enum: + - ONE + - TWO + - THREE + - foUr + TestEnumWithDefault: + type: string + enum: + - EIN + - ZWEI + - DREI + default: ZWEI + TestModel: + type: object + required: + - test_enum + properties: + test_enum: + $ref: "#/components/schemas/TestEnum" + test_string: + type: string + example: "Just some string" + test_enum_with_default: + $ref: "#/components/schemas/TestEnumWithDefault" + test_string_with_default: + type: string + example: "More string" + default: "ahoy matey" + test_inline_defined_enum_with_default: + type: string + enum: + - A + - B + - C + default: B diff --git a/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES index 6b44ba44379a..8f5541c7444c 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES @@ -101,9 +101,12 @@ docs/StoreApi.md docs/Tag.md docs/Task.md docs/TaskActivity.md +docs/TestEnum.md +docs/TestEnumWithDefault.md docs/TestErrorResponsesWithModel400Response.md docs/TestErrorResponsesWithModel404Response.md docs/TestInlineFreeformAdditionalPropertiesRequest.md +docs/TestModel.md docs/TestObjectForMultipartRequestsRequestMarker.md docs/Tiger.md docs/UnnamedDictWithAdditionalModelListProperties.md @@ -218,9 +221,12 @@ petstore_api/models/special_name.py petstore_api/models/tag.py petstore_api/models/task.py petstore_api/models/task_activity.py +petstore_api/models/test_enum.py +petstore_api/models/test_enum_with_default.py petstore_api/models/test_error_responses_with_model400_response.py petstore_api/models/test_error_responses_with_model404_response.py petstore_api/models/test_inline_freeform_additional_properties_request.py +petstore_api/models/test_model.py petstore_api/models/test_object_for_multipart_requests_request_marker.py petstore_api/models/tiger.py petstore_api/models/unnamed_dict_with_additional_model_list_properties.py diff --git a/samples/openapi3/client/petstore/python-aiohttp/README.md b/samples/openapi3/client/petstore/python-aiohttp/README.md index d7fb2bd4d0a7..e50a8dfd6f0e 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/README.md +++ b/samples/openapi3/client/petstore/python-aiohttp/README.md @@ -241,9 +241,12 @@ Class | Method | HTTP request | Description - [Tag](docs/Tag.md) - [Task](docs/Task.md) - [TaskActivity](docs/TaskActivity.md) + - [TestEnum](docs/TestEnum.md) + - [TestEnumWithDefault](docs/TestEnumWithDefault.md) - [TestErrorResponsesWithModel400Response](docs/TestErrorResponsesWithModel400Response.md) - [TestErrorResponsesWithModel404Response](docs/TestErrorResponsesWithModel404Response.md) - [TestInlineFreeformAdditionalPropertiesRequest](docs/TestInlineFreeformAdditionalPropertiesRequest.md) + - [TestModel](docs/TestModel.md) - [TestObjectForMultipartRequestsRequestMarker](docs/TestObjectForMultipartRequestsRequestMarker.md) - [Tiger](docs/Tiger.md) - [UnnamedDictWithAdditionalModelListProperties](docs/UnnamedDictWithAdditionalModelListProperties.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/TestEnum.md b/samples/openapi3/client/petstore/python-aiohttp/docs/TestEnum.md new file mode 100644 index 000000000000..612b62bd4dc4 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/TestEnum.md @@ -0,0 +1,16 @@ +# TestEnum + + +## Enum + +* `ONE` (value: `'ONE'`) + +* `TWO` (value: `'TWO'`) + +* `THREE` (value: `'THREE'`) + +* `FOUR` (value: `'foUr'`) + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/TestEnumWithDefault.md b/samples/openapi3/client/petstore/python-aiohttp/docs/TestEnumWithDefault.md new file mode 100644 index 000000000000..ac8591c95c04 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/TestEnumWithDefault.md @@ -0,0 +1,14 @@ +# TestEnumWithDefault + + +## Enum + +* `EIN` (value: `'EIN'`) + +* `ZWEI` (value: `'ZWEI'`) + +* `DREI` (value: `'DREI'`) + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/TestModel.md b/samples/openapi3/client/petstore/python-aiohttp/docs/TestModel.md new file mode 100644 index 000000000000..2c48f81d32cc --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/TestModel.md @@ -0,0 +1,33 @@ +# TestModel + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**test_enum** | [**TestEnum**](TestEnum.md) | | +**test_string** | **str** | | [optional] +**test_enum_with_default** | [**TestEnumWithDefault**](TestEnumWithDefault.md) | | [optional] +**test_string_with_default** | **str** | | [optional] [default to 'ahoy matey'] +**test_inline_defined_enum_with_default** | **str** | | [optional] [default to 'B'] + +## Example + +```python +from petstore_api.models.test_model import TestModel + +# TODO update the JSON string below +json = "{}" +# create an instance of TestModel from a JSON string +test_model_instance = TestModel.from_json(json) +# print the JSON string representation of the object +print(TestModel.to_json()) + +# convert the object into a dict +test_model_dict = test_model_instance.to_dict() +# create an instance of TestModel from a dict +test_model_from_dict = TestModel.from_dict(test_model_dict) +``` +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py index 3f6c3aabf138..9bdafae2dbb8 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py @@ -130,9 +130,12 @@ from petstore_api.models.tag import Tag from petstore_api.models.task import Task from petstore_api.models.task_activity import TaskActivity +from petstore_api.models.test_enum import TestEnum +from petstore_api.models.test_enum_with_default import TestEnumWithDefault from petstore_api.models.test_error_responses_with_model400_response import TestErrorResponsesWithModel400Response from petstore_api.models.test_error_responses_with_model404_response import TestErrorResponsesWithModel404Response from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest +from petstore_api.models.test_model import TestModel from petstore_api.models.test_object_for_multipart_requests_request_marker import TestObjectForMultipartRequestsRequestMarker from petstore_api.models.tiger import Tiger from petstore_api.models.unnamed_dict_with_additional_model_list_properties import UnnamedDictWithAdditionalModelListProperties diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/__init__.py index 30718c766d7d..4c421c2e0529 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/__init__.py @@ -105,9 +105,12 @@ from petstore_api.models.tag import Tag from petstore_api.models.task import Task from petstore_api.models.task_activity import TaskActivity +from petstore_api.models.test_enum import TestEnum +from petstore_api.models.test_enum_with_default import TestEnumWithDefault from petstore_api.models.test_error_responses_with_model400_response import TestErrorResponsesWithModel400Response from petstore_api.models.test_error_responses_with_model404_response import TestErrorResponsesWithModel404Response from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest +from petstore_api.models.test_model import TestModel from petstore_api.models.test_object_for_multipart_requests_request_marker import TestObjectForMultipartRequestsRequestMarker from petstore_api.models.tiger import Tiger from petstore_api.models.unnamed_dict_with_additional_model_list_properties import UnnamedDictWithAdditionalModelListProperties diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum.py new file mode 100644 index 000000000000..8eae227a84e9 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum.py @@ -0,0 +1,39 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import json +from enum import Enum +from typing_extensions import Self + + +class TestEnum(str, Enum): + """ + TestEnum + """ + + """ + allowed enum values + """ + ONE = 'ONE' + TWO = 'TWO' + THREE = 'THREE' + FOUR = 'foUr' + + @classmethod + def from_json(cls, json_str: str) -> Self: + """Create an instance of TestEnum from a JSON string""" + return cls(json.loads(json_str)) + + diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum_with_default.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum_with_default.py new file mode 100644 index 000000000000..9304d3ab8497 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_enum_with_default.py @@ -0,0 +1,38 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import json +from enum import Enum +from typing_extensions import Self + + +class TestEnumWithDefault(str, Enum): + """ + TestEnumWithDefault + """ + + """ + allowed enum values + """ + EIN = 'EIN' + ZWEI = 'ZWEI' + DREI = 'DREI' + + @classmethod + def from_json(cls, json_str: str) -> Self: + """Create an instance of TestEnumWithDefault from a JSON string""" + return cls(json.loads(json_str)) + + diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_model.py new file mode 100644 index 000000000000..203ac7037a59 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_model.py @@ -0,0 +1,107 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + +from pydantic import BaseModel, ConfigDict, StrictStr, field_validator +from typing import Any, ClassVar, Dict, List, Optional +from petstore_api.models.test_enum import TestEnum +from petstore_api.models.test_enum_with_default import TestEnumWithDefault +from typing import Optional, Set +from typing_extensions import Self + +class TestModel(BaseModel): + """ + TestModel + """ # noqa: E501 + test_enum: TestEnum + test_string: Optional[StrictStr] = None + test_enum_with_default: Optional[TestEnumWithDefault] = None + test_string_with_default: Optional[StrictStr] = 'ahoy matey' + test_inline_defined_enum_with_default: Optional[StrictStr] = 'B' + __properties: ClassVar[List[str]] = ["test_enum", "test_string", "test_enum_with_default", "test_string_with_default", "test_inline_defined_enum_with_default"] + + @field_validator('test_inline_defined_enum_with_default') + def test_inline_defined_enum_with_default_validate_enum(cls, value): + """Validates the enum""" + if value is None: + return value + + if value not in set(['A', 'B', 'C']): + raise ValueError("must be one of enum values ('A', 'B', 'C')") + return value + + model_config = ConfigDict( + populate_by_name=True, + validate_assignment=True, + protected_namespaces=(), + ) + + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.model_dump(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of TestModel from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + """ + excluded_fields: Set[str] = set([ + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + return _dict + + @classmethod + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of TestModel from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "test_enum": obj.get("test_enum"), + "test_string": obj.get("test_string"), + "test_enum_with_default": obj.get("test_enum_with_default"), + "test_string_with_default": obj.get("test_string_with_default") if obj.get("test_string_with_default") is not None else 'ahoy matey', + "test_inline_defined_enum_with_default": obj.get("test_inline_defined_enum_with_default") if obj.get("test_inline_defined_enum_with_default") is not None else 'B' + }) + return _obj + + diff --git a/samples/openapi3/client/petstore/python-aiohttp/test/test_test_enum.py b/samples/openapi3/client/petstore/python-aiohttp/test/test_test_enum.py new file mode 100644 index 000000000000..aec65edf520f --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/test/test_test_enum.py @@ -0,0 +1,33 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest + +from petstore_api.models.test_enum import TestEnum + +class TestTestEnum(unittest.TestCase): + """TestEnum unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testTestEnum(self): + """Test TestEnum""" + # inst = TestEnum() + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-aiohttp/test/test_test_enum_with_default.py b/samples/openapi3/client/petstore/python-aiohttp/test/test_test_enum_with_default.py new file mode 100644 index 000000000000..b51e42819555 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/test/test_test_enum_with_default.py @@ -0,0 +1,33 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest + +from petstore_api.models.test_enum_with_default import TestEnumWithDefault + +class TestTestEnumWithDefault(unittest.TestCase): + """TestEnumWithDefault unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testTestEnumWithDefault(self): + """Test TestEnumWithDefault""" + # inst = TestEnumWithDefault() + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-aiohttp/test/test_test_model.py b/samples/openapi3/client/petstore/python-aiohttp/test/test_test_model.py new file mode 100644 index 000000000000..ce7d299d7dc7 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/test/test_test_model.py @@ -0,0 +1,56 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest + +from petstore_api.models.test_model import TestModel + +class TestTestModel(unittest.TestCase): + """TestModel unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> TestModel: + """Test TestModel + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `TestModel` + """ + model = TestModel() + if include_optional: + return TestModel( + test_enum = 'ONE', + test_string = 'Just some string', + test_enum_with_default = 'ZWEI', + test_string_with_default = 'ahoy matey', + test_inline_defined_enum_with_default = 'B' + ) + else: + return TestModel( + test_enum = 'ONE', + ) + """ + + def testTestModel(self): + """Test TestModel""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/.openapi-generator/FILES index 5bd01d524209..ecb8f4ab0046 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/.openapi-generator/FILES @@ -101,9 +101,12 @@ docs/StoreApi.md docs/Tag.md docs/Task.md docs/TaskActivity.md +docs/TestEnum.md +docs/TestEnumWithDefault.md docs/TestErrorResponsesWithModel400Response.md docs/TestErrorResponsesWithModel404Response.md docs/TestInlineFreeformAdditionalPropertiesRequest.md +docs/TestModel.md docs/TestObjectForMultipartRequestsRequestMarker.md docs/Tiger.md docs/UnnamedDictWithAdditionalModelListProperties.md @@ -218,9 +221,12 @@ petstore_api/models/special_name.py petstore_api/models/tag.py petstore_api/models/task.py petstore_api/models/task_activity.py +petstore_api/models/test_enum.py +petstore_api/models/test_enum_with_default.py petstore_api/models/test_error_responses_with_model400_response.py petstore_api/models/test_error_responses_with_model404_response.py petstore_api/models/test_inline_freeform_additional_properties_request.py +petstore_api/models/test_model.py petstore_api/models/test_object_for_multipart_requests_request_marker.py petstore_api/models/tiger.py petstore_api/models/unnamed_dict_with_additional_model_list_properties.py diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md index 83682c8061f6..f84f70dff5a2 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md @@ -242,9 +242,12 @@ Class | Method | HTTP request | Description - [Tag](docs/Tag.md) - [Task](docs/Task.md) - [TaskActivity](docs/TaskActivity.md) + - [TestEnum](docs/TestEnum.md) + - [TestEnumWithDefault](docs/TestEnumWithDefault.md) - [TestErrorResponsesWithModel400Response](docs/TestErrorResponsesWithModel400Response.md) - [TestErrorResponsesWithModel404Response](docs/TestErrorResponsesWithModel404Response.md) - [TestInlineFreeformAdditionalPropertiesRequest](docs/TestInlineFreeformAdditionalPropertiesRequest.md) + - [TestModel](docs/TestModel.md) - [TestObjectForMultipartRequestsRequestMarker](docs/TestObjectForMultipartRequestsRequestMarker.md) - [Tiger](docs/Tiger.md) - [UnnamedDictWithAdditionalModelListProperties](docs/UnnamedDictWithAdditionalModelListProperties.md) diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/TestEnum.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/TestEnum.md new file mode 100644 index 000000000000..612b62bd4dc4 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/TestEnum.md @@ -0,0 +1,16 @@ +# TestEnum + + +## Enum + +* `ONE` (value: `'ONE'`) + +* `TWO` (value: `'TWO'`) + +* `THREE` (value: `'THREE'`) + +* `FOUR` (value: `'foUr'`) + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/TestEnumWithDefault.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/TestEnumWithDefault.md new file mode 100644 index 000000000000..ac8591c95c04 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/TestEnumWithDefault.md @@ -0,0 +1,14 @@ +# TestEnumWithDefault + + +## Enum + +* `EIN` (value: `'EIN'`) + +* `ZWEI` (value: `'ZWEI'`) + +* `DREI` (value: `'DREI'`) + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/TestModel.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/TestModel.md new file mode 100644 index 000000000000..382658a8105a --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/TestModel.md @@ -0,0 +1,32 @@ +# TestModel + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**test_enum** | [**TestEnum**](TestEnum.md) | | +**test_string** | **str** | | [optional] +**test_enum_with_default** | [**TestEnumWithDefault**](TestEnumWithDefault.md) | | [optional] +**test_string_with_default** | **str** | | [optional] [default to 'ahoy matey'] +**test_inline_defined_enum_with_default** | **str** | | [optional] [default to 'B'] + +## Example + +```python +from petstore_api.models.test_model import TestModel + +# TODO update the JSON string below +json = "{}" +# create an instance of TestModel from a JSON string +test_model_instance = TestModel.from_json(json) +# print the JSON string representation of the object +print TestModel.to_json() + +# convert the object into a dict +test_model_dict = test_model_instance.to_dict() +# create an instance of TestModel from a dict +test_model_from_dict = TestModel.from_dict(test_model_dict) +``` +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/__init__.py index c0b99d8bf822..6c0bf1306221 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/__init__.py @@ -130,9 +130,12 @@ from petstore_api.models.tag import Tag from petstore_api.models.task import Task from petstore_api.models.task_activity import TaskActivity +from petstore_api.models.test_enum import TestEnum +from petstore_api.models.test_enum_with_default import TestEnumWithDefault from petstore_api.models.test_error_responses_with_model400_response import TestErrorResponsesWithModel400Response from petstore_api.models.test_error_responses_with_model404_response import TestErrorResponsesWithModel404Response from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest +from petstore_api.models.test_model import TestModel from petstore_api.models.test_object_for_multipart_requests_request_marker import TestObjectForMultipartRequestsRequestMarker from petstore_api.models.tiger import Tiger from petstore_api.models.unnamed_dict_with_additional_model_list_properties import UnnamedDictWithAdditionalModelListProperties diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/__init__.py index 2124d65dc346..3739b3685bbf 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/__init__.py @@ -105,9 +105,12 @@ from petstore_api.models.tag import Tag from petstore_api.models.task import Task from petstore_api.models.task_activity import TaskActivity +from petstore_api.models.test_enum import TestEnum +from petstore_api.models.test_enum_with_default import TestEnumWithDefault from petstore_api.models.test_error_responses_with_model400_response import TestErrorResponsesWithModel400Response from petstore_api.models.test_error_responses_with_model404_response import TestErrorResponsesWithModel404Response from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest +from petstore_api.models.test_model import TestModel from petstore_api.models.test_object_for_multipart_requests_request_marker import TestObjectForMultipartRequestsRequestMarker from petstore_api.models.tiger import Tiger from petstore_api.models.unnamed_dict_with_additional_model_list_properties import UnnamedDictWithAdditionalModelListProperties diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/test_enum.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/test_enum.py new file mode 100644 index 000000000000..f25ab6a8d6d2 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/test_enum.py @@ -0,0 +1,42 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import json +import pprint +import re # noqa: F401 +from aenum import Enum, no_arg + + + + + +class TestEnum(str, Enum): + """ + TestEnum + """ + + """ + allowed enum values + """ + ONE = 'ONE' + TWO = 'TWO' + THREE = 'THREE' + FOUR = 'foUr' + + @classmethod + def from_json(cls, json_str: str) -> TestEnum: + """Create an instance of TestEnum from a JSON string""" + return TestEnum(json.loads(json_str)) + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/test_enum_with_default.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/test_enum_with_default.py new file mode 100644 index 000000000000..c14a488a041a --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/test_enum_with_default.py @@ -0,0 +1,41 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import json +import pprint +import re # noqa: F401 +from aenum import Enum, no_arg + + + + + +class TestEnumWithDefault(str, Enum): + """ + TestEnumWithDefault + """ + + """ + allowed enum values + """ + EIN = 'EIN' + ZWEI = 'ZWEI' + DREI = 'DREI' + + @classmethod + def from_json(cls, json_str: str) -> TestEnumWithDefault: + """Create an instance of TestEnumWithDefault from a JSON string""" + return TestEnumWithDefault(json.loads(json_str)) + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/test_model.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/test_model.py new file mode 100644 index 000000000000..e158832db37b --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/test_model.py @@ -0,0 +1,91 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + + +from typing import Optional +from pydantic import BaseModel, Field, StrictStr, validator +from petstore_api.models.test_enum import TestEnum +from petstore_api.models.test_enum_with_default import TestEnumWithDefault + +class TestModel(BaseModel): + """ + TestModel + """ + test_enum: TestEnum = Field(...) + test_string: Optional[StrictStr] = None + test_enum_with_default: Optional[TestEnumWithDefault] = None + test_string_with_default: Optional[StrictStr] = 'ahoy matey' + test_inline_defined_enum_with_default: Optional[StrictStr] = 'B' + __properties = ["test_enum", "test_string", "test_enum_with_default", "test_string_with_default", "test_inline_defined_enum_with_default"] + + @validator('test_inline_defined_enum_with_default') + def test_inline_defined_enum_with_default_validate_enum(cls, value): + """Validates the enum""" + if value is None: + return value + + if value not in ('A', 'B', 'C'): + raise ValueError("must be one of enum values ('A', 'B', 'C')") + return value + + class Config: + """Pydantic configuration""" + allow_population_by_field_name = True + validate_assignment = True + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.dict(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> TestModel: + """Create an instance of TestModel from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self): + """Returns the dictionary representation of the model using alias""" + _dict = self.dict(by_alias=True, + exclude={ + }, + exclude_none=True) + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> TestModel: + """Create an instance of TestModel from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return TestModel.parse_obj(obj) + + _obj = TestModel.parse_obj({ + "test_enum": obj.get("test_enum"), + "test_string": obj.get("test_string"), + "test_enum_with_default": obj.get("test_enum_with_default"), + "test_string_with_default": obj.get("test_string_with_default") if obj.get("test_string_with_default") is not None else 'ahoy matey', + "test_inline_defined_enum_with_default": obj.get("test_inline_defined_enum_with_default") if obj.get("test_inline_defined_enum_with_default") is not None else 'B' + }) + return _obj + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_test_enum.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_test_enum.py new file mode 100644 index 000000000000..960400d5bb4c --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_test_enum.py @@ -0,0 +1,34 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from petstore_api.models.test_enum import TestEnum # noqa: E501 + +class TestTestEnum(unittest.TestCase): + """TestEnum unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testTestEnum(self): + """Test TestEnum""" + # inst = TestEnum() + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_test_enum_with_default.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_test_enum_with_default.py new file mode 100644 index 000000000000..f21e39317476 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_test_enum_with_default.py @@ -0,0 +1,34 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from petstore_api.models.test_enum_with_default import TestEnumWithDefault # noqa: E501 + +class TestTestEnumWithDefault(unittest.TestCase): + """TestEnumWithDefault unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testTestEnumWithDefault(self): + """Test TestEnumWithDefault""" + # inst = TestEnumWithDefault() + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_test_model.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_test_model.py new file mode 100644 index 000000000000..8532462a5f19 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_test_model.py @@ -0,0 +1,57 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from petstore_api.models.test_model import TestModel # noqa: E501 + +class TestTestModel(unittest.TestCase): + """TestModel unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> TestModel: + """Test TestModel + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `TestModel` + """ + model = TestModel() # noqa: E501 + if include_optional: + return TestModel( + test_enum = 'ONE', + test_string = 'Just some string', + test_enum_with_default = 'ZWEI', + test_string_with_default = 'ahoy matey', + test_inline_defined_enum_with_default = 'B' + ) + else: + return TestModel( + test_enum = 'ONE', + ) + """ + + def testTestModel(self): + """Test TestModel""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-pydantic-v1/.openapi-generator/FILES index 5bd01d524209..ecb8f4ab0046 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-pydantic-v1/.openapi-generator/FILES @@ -101,9 +101,12 @@ docs/StoreApi.md docs/Tag.md docs/Task.md docs/TaskActivity.md +docs/TestEnum.md +docs/TestEnumWithDefault.md docs/TestErrorResponsesWithModel400Response.md docs/TestErrorResponsesWithModel404Response.md docs/TestInlineFreeformAdditionalPropertiesRequest.md +docs/TestModel.md docs/TestObjectForMultipartRequestsRequestMarker.md docs/Tiger.md docs/UnnamedDictWithAdditionalModelListProperties.md @@ -218,9 +221,12 @@ petstore_api/models/special_name.py petstore_api/models/tag.py petstore_api/models/task.py petstore_api/models/task_activity.py +petstore_api/models/test_enum.py +petstore_api/models/test_enum_with_default.py petstore_api/models/test_error_responses_with_model400_response.py petstore_api/models/test_error_responses_with_model404_response.py petstore_api/models/test_inline_freeform_additional_properties_request.py +petstore_api/models/test_model.py petstore_api/models/test_object_for_multipart_requests_request_marker.py petstore_api/models/tiger.py petstore_api/models/unnamed_dict_with_additional_model_list_properties.py diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/README.md b/samples/openapi3/client/petstore/python-pydantic-v1/README.md index 0dc87a0af0f2..851910eda84f 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/README.md +++ b/samples/openapi3/client/petstore/python-pydantic-v1/README.md @@ -242,9 +242,12 @@ Class | Method | HTTP request | Description - [Tag](docs/Tag.md) - [Task](docs/Task.md) - [TaskActivity](docs/TaskActivity.md) + - [TestEnum](docs/TestEnum.md) + - [TestEnumWithDefault](docs/TestEnumWithDefault.md) - [TestErrorResponsesWithModel400Response](docs/TestErrorResponsesWithModel400Response.md) - [TestErrorResponsesWithModel404Response](docs/TestErrorResponsesWithModel404Response.md) - [TestInlineFreeformAdditionalPropertiesRequest](docs/TestInlineFreeformAdditionalPropertiesRequest.md) + - [TestModel](docs/TestModel.md) - [TestObjectForMultipartRequestsRequestMarker](docs/TestObjectForMultipartRequestsRequestMarker.md) - [Tiger](docs/Tiger.md) - [UnnamedDictWithAdditionalModelListProperties](docs/UnnamedDictWithAdditionalModelListProperties.md) diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/docs/TestEnum.md b/samples/openapi3/client/petstore/python-pydantic-v1/docs/TestEnum.md new file mode 100644 index 000000000000..612b62bd4dc4 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/docs/TestEnum.md @@ -0,0 +1,16 @@ +# TestEnum + + +## Enum + +* `ONE` (value: `'ONE'`) + +* `TWO` (value: `'TWO'`) + +* `THREE` (value: `'THREE'`) + +* `FOUR` (value: `'foUr'`) + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/docs/TestEnumWithDefault.md b/samples/openapi3/client/petstore/python-pydantic-v1/docs/TestEnumWithDefault.md new file mode 100644 index 000000000000..ac8591c95c04 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/docs/TestEnumWithDefault.md @@ -0,0 +1,14 @@ +# TestEnumWithDefault + + +## Enum + +* `EIN` (value: `'EIN'`) + +* `ZWEI` (value: `'ZWEI'`) + +* `DREI` (value: `'DREI'`) + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/docs/TestModel.md b/samples/openapi3/client/petstore/python-pydantic-v1/docs/TestModel.md new file mode 100644 index 000000000000..382658a8105a --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/docs/TestModel.md @@ -0,0 +1,32 @@ +# TestModel + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**test_enum** | [**TestEnum**](TestEnum.md) | | +**test_string** | **str** | | [optional] +**test_enum_with_default** | [**TestEnumWithDefault**](TestEnumWithDefault.md) | | [optional] +**test_string_with_default** | **str** | | [optional] [default to 'ahoy matey'] +**test_inline_defined_enum_with_default** | **str** | | [optional] [default to 'B'] + +## Example + +```python +from petstore_api.models.test_model import TestModel + +# TODO update the JSON string below +json = "{}" +# create an instance of TestModel from a JSON string +test_model_instance = TestModel.from_json(json) +# print the JSON string representation of the object +print TestModel.to_json() + +# convert the object into a dict +test_model_dict = test_model_instance.to_dict() +# create an instance of TestModel from a dict +test_model_from_dict = TestModel.from_dict(test_model_dict) +``` +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/__init__.py index c0b99d8bf822..6c0bf1306221 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/__init__.py @@ -130,9 +130,12 @@ from petstore_api.models.tag import Tag from petstore_api.models.task import Task from petstore_api.models.task_activity import TaskActivity +from petstore_api.models.test_enum import TestEnum +from petstore_api.models.test_enum_with_default import TestEnumWithDefault from petstore_api.models.test_error_responses_with_model400_response import TestErrorResponsesWithModel400Response from petstore_api.models.test_error_responses_with_model404_response import TestErrorResponsesWithModel404Response from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest +from petstore_api.models.test_model import TestModel from petstore_api.models.test_object_for_multipart_requests_request_marker import TestObjectForMultipartRequestsRequestMarker from petstore_api.models.tiger import Tiger from petstore_api.models.unnamed_dict_with_additional_model_list_properties import UnnamedDictWithAdditionalModelListProperties diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/__init__.py index 2124d65dc346..3739b3685bbf 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/__init__.py @@ -105,9 +105,12 @@ from petstore_api.models.tag import Tag from petstore_api.models.task import Task from petstore_api.models.task_activity import TaskActivity +from petstore_api.models.test_enum import TestEnum +from petstore_api.models.test_enum_with_default import TestEnumWithDefault from petstore_api.models.test_error_responses_with_model400_response import TestErrorResponsesWithModel400Response from petstore_api.models.test_error_responses_with_model404_response import TestErrorResponsesWithModel404Response from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest +from petstore_api.models.test_model import TestModel from petstore_api.models.test_object_for_multipart_requests_request_marker import TestObjectForMultipartRequestsRequestMarker from petstore_api.models.tiger import Tiger from petstore_api.models.unnamed_dict_with_additional_model_list_properties import UnnamedDictWithAdditionalModelListProperties diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/test_enum.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/test_enum.py new file mode 100644 index 000000000000..f25ab6a8d6d2 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/test_enum.py @@ -0,0 +1,42 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import json +import pprint +import re # noqa: F401 +from aenum import Enum, no_arg + + + + + +class TestEnum(str, Enum): + """ + TestEnum + """ + + """ + allowed enum values + """ + ONE = 'ONE' + TWO = 'TWO' + THREE = 'THREE' + FOUR = 'foUr' + + @classmethod + def from_json(cls, json_str: str) -> TestEnum: + """Create an instance of TestEnum from a JSON string""" + return TestEnum(json.loads(json_str)) + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/test_enum_with_default.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/test_enum_with_default.py new file mode 100644 index 000000000000..c14a488a041a --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/test_enum_with_default.py @@ -0,0 +1,41 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import json +import pprint +import re # noqa: F401 +from aenum import Enum, no_arg + + + + + +class TestEnumWithDefault(str, Enum): + """ + TestEnumWithDefault + """ + + """ + allowed enum values + """ + EIN = 'EIN' + ZWEI = 'ZWEI' + DREI = 'DREI' + + @classmethod + def from_json(cls, json_str: str) -> TestEnumWithDefault: + """Create an instance of TestEnumWithDefault from a JSON string""" + return TestEnumWithDefault(json.loads(json_str)) + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/test_model.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/test_model.py new file mode 100644 index 000000000000..8055d3995d88 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/test_model.py @@ -0,0 +1,103 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + + +from typing import Any, Dict, Optional +from pydantic import BaseModel, Field, StrictStr, validator +from petstore_api.models.test_enum import TestEnum +from petstore_api.models.test_enum_with_default import TestEnumWithDefault + +class TestModel(BaseModel): + """ + TestModel + """ + test_enum: TestEnum = Field(...) + test_string: Optional[StrictStr] = None + test_enum_with_default: Optional[TestEnumWithDefault] = None + test_string_with_default: Optional[StrictStr] = 'ahoy matey' + test_inline_defined_enum_with_default: Optional[StrictStr] = 'B' + additional_properties: Dict[str, Any] = {} + __properties = ["test_enum", "test_string", "test_enum_with_default", "test_string_with_default", "test_inline_defined_enum_with_default"] + + @validator('test_inline_defined_enum_with_default') + def test_inline_defined_enum_with_default_validate_enum(cls, value): + """Validates the enum""" + if value is None: + return value + + if value not in ('A', 'B', 'C'): + raise ValueError("must be one of enum values ('A', 'B', 'C')") + return value + + class Config: + """Pydantic configuration""" + allow_population_by_field_name = True + validate_assignment = True + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.dict(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> TestModel: + """Create an instance of TestModel from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self): + """Returns the dictionary representation of the model using alias""" + _dict = self.dict(by_alias=True, + exclude={ + "additional_properties" + }, + exclude_none=True) + # puts key-value pairs in additional_properties in the top level + if self.additional_properties is not None: + for _key, _value in self.additional_properties.items(): + _dict[_key] = _value + + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> TestModel: + """Create an instance of TestModel from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return TestModel.parse_obj(obj) + + _obj = TestModel.parse_obj({ + "test_enum": obj.get("test_enum"), + "test_string": obj.get("test_string"), + "test_enum_with_default": obj.get("test_enum_with_default"), + "test_string_with_default": obj.get("test_string_with_default") if obj.get("test_string_with_default") is not None else 'ahoy matey', + "test_inline_defined_enum_with_default": obj.get("test_inline_defined_enum_with_default") if obj.get("test_inline_defined_enum_with_default") is not None else 'B' + }) + # store additional fields in additional_properties + for _key in obj.keys(): + if _key not in cls.__properties: + _obj.additional_properties[_key] = obj.get(_key) + + return _obj + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/test/test_test_enum.py b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_test_enum.py new file mode 100644 index 000000000000..960400d5bb4c --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_test_enum.py @@ -0,0 +1,34 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from petstore_api.models.test_enum import TestEnum # noqa: E501 + +class TestTestEnum(unittest.TestCase): + """TestEnum unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testTestEnum(self): + """Test TestEnum""" + # inst = TestEnum() + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/test/test_test_enum_with_default.py b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_test_enum_with_default.py new file mode 100644 index 000000000000..f21e39317476 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_test_enum_with_default.py @@ -0,0 +1,34 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from petstore_api.models.test_enum_with_default import TestEnumWithDefault # noqa: E501 + +class TestTestEnumWithDefault(unittest.TestCase): + """TestEnumWithDefault unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testTestEnumWithDefault(self): + """Test TestEnumWithDefault""" + # inst = TestEnumWithDefault() + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/test/test_test_model.py b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_test_model.py new file mode 100644 index 000000000000..8532462a5f19 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_test_model.py @@ -0,0 +1,57 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from petstore_api.models.test_model import TestModel # noqa: E501 + +class TestTestModel(unittest.TestCase): + """TestModel unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> TestModel: + """Test TestModel + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `TestModel` + """ + model = TestModel() # noqa: E501 + if include_optional: + return TestModel( + test_enum = 'ONE', + test_string = 'Just some string', + test_enum_with_default = 'ZWEI', + test_string_with_default = 'ahoy matey', + test_inline_defined_enum_with_default = 'B' + ) + else: + return TestModel( + test_enum = 'ONE', + ) + """ + + def testTestModel(self): + """Test TestModel""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python/.openapi-generator/FILES b/samples/openapi3/client/petstore/python/.openapi-generator/FILES index 6b44ba44379a..8f5541c7444c 100755 --- a/samples/openapi3/client/petstore/python/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python/.openapi-generator/FILES @@ -101,9 +101,12 @@ docs/StoreApi.md docs/Tag.md docs/Task.md docs/TaskActivity.md +docs/TestEnum.md +docs/TestEnumWithDefault.md docs/TestErrorResponsesWithModel400Response.md docs/TestErrorResponsesWithModel404Response.md docs/TestInlineFreeformAdditionalPropertiesRequest.md +docs/TestModel.md docs/TestObjectForMultipartRequestsRequestMarker.md docs/Tiger.md docs/UnnamedDictWithAdditionalModelListProperties.md @@ -218,9 +221,12 @@ petstore_api/models/special_name.py petstore_api/models/tag.py petstore_api/models/task.py petstore_api/models/task_activity.py +petstore_api/models/test_enum.py +petstore_api/models/test_enum_with_default.py petstore_api/models/test_error_responses_with_model400_response.py petstore_api/models/test_error_responses_with_model404_response.py petstore_api/models/test_inline_freeform_additional_properties_request.py +petstore_api/models/test_model.py petstore_api/models/test_object_for_multipart_requests_request_marker.py petstore_api/models/tiger.py petstore_api/models/unnamed_dict_with_additional_model_list_properties.py diff --git a/samples/openapi3/client/petstore/python/README.md b/samples/openapi3/client/petstore/python/README.md index 38171d81ae03..e18a660fae7b 100755 --- a/samples/openapi3/client/petstore/python/README.md +++ b/samples/openapi3/client/petstore/python/README.md @@ -241,9 +241,12 @@ Class | Method | HTTP request | Description - [Tag](docs/Tag.md) - [Task](docs/Task.md) - [TaskActivity](docs/TaskActivity.md) + - [TestEnum](docs/TestEnum.md) + - [TestEnumWithDefault](docs/TestEnumWithDefault.md) - [TestErrorResponsesWithModel400Response](docs/TestErrorResponsesWithModel400Response.md) - [TestErrorResponsesWithModel404Response](docs/TestErrorResponsesWithModel404Response.md) - [TestInlineFreeformAdditionalPropertiesRequest](docs/TestInlineFreeformAdditionalPropertiesRequest.md) + - [TestModel](docs/TestModel.md) - [TestObjectForMultipartRequestsRequestMarker](docs/TestObjectForMultipartRequestsRequestMarker.md) - [Tiger](docs/Tiger.md) - [UnnamedDictWithAdditionalModelListProperties](docs/UnnamedDictWithAdditionalModelListProperties.md) diff --git a/samples/openapi3/client/petstore/python/docs/TestEnum.md b/samples/openapi3/client/petstore/python/docs/TestEnum.md new file mode 100644 index 000000000000..612b62bd4dc4 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/TestEnum.md @@ -0,0 +1,16 @@ +# TestEnum + + +## Enum + +* `ONE` (value: `'ONE'`) + +* `TWO` (value: `'TWO'`) + +* `THREE` (value: `'THREE'`) + +* `FOUR` (value: `'foUr'`) + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python/docs/TestEnumWithDefault.md b/samples/openapi3/client/petstore/python/docs/TestEnumWithDefault.md new file mode 100644 index 000000000000..ac8591c95c04 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/TestEnumWithDefault.md @@ -0,0 +1,14 @@ +# TestEnumWithDefault + + +## Enum + +* `EIN` (value: `'EIN'`) + +* `ZWEI` (value: `'ZWEI'`) + +* `DREI` (value: `'DREI'`) + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python/docs/TestModel.md b/samples/openapi3/client/petstore/python/docs/TestModel.md new file mode 100644 index 000000000000..2c48f81d32cc --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/TestModel.md @@ -0,0 +1,33 @@ +# TestModel + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**test_enum** | [**TestEnum**](TestEnum.md) | | +**test_string** | **str** | | [optional] +**test_enum_with_default** | [**TestEnumWithDefault**](TestEnumWithDefault.md) | | [optional] +**test_string_with_default** | **str** | | [optional] [default to 'ahoy matey'] +**test_inline_defined_enum_with_default** | **str** | | [optional] [default to 'B'] + +## Example + +```python +from petstore_api.models.test_model import TestModel + +# TODO update the JSON string below +json = "{}" +# create an instance of TestModel from a JSON string +test_model_instance = TestModel.from_json(json) +# print the JSON string representation of the object +print(TestModel.to_json()) + +# convert the object into a dict +test_model_dict = test_model_instance.to_dict() +# create an instance of TestModel from a dict +test_model_from_dict = TestModel.from_dict(test_model_dict) +``` +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python/petstore_api/__init__.py b/samples/openapi3/client/petstore/python/petstore_api/__init__.py index 3f6c3aabf138..9bdafae2dbb8 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/__init__.py @@ -130,9 +130,12 @@ from petstore_api.models.tag import Tag from petstore_api.models.task import Task from petstore_api.models.task_activity import TaskActivity +from petstore_api.models.test_enum import TestEnum +from petstore_api.models.test_enum_with_default import TestEnumWithDefault from petstore_api.models.test_error_responses_with_model400_response import TestErrorResponsesWithModel400Response from petstore_api.models.test_error_responses_with_model404_response import TestErrorResponsesWithModel404Response from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest +from petstore_api.models.test_model import TestModel from petstore_api.models.test_object_for_multipart_requests_request_marker import TestObjectForMultipartRequestsRequestMarker from petstore_api.models.tiger import Tiger from petstore_api.models.unnamed_dict_with_additional_model_list_properties import UnnamedDictWithAdditionalModelListProperties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py index 30718c766d7d..4c421c2e0529 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py @@ -105,9 +105,12 @@ from petstore_api.models.tag import Tag from petstore_api.models.task import Task from petstore_api.models.task_activity import TaskActivity +from petstore_api.models.test_enum import TestEnum +from petstore_api.models.test_enum_with_default import TestEnumWithDefault from petstore_api.models.test_error_responses_with_model400_response import TestErrorResponsesWithModel400Response from petstore_api.models.test_error_responses_with_model404_response import TestErrorResponsesWithModel404Response from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest +from petstore_api.models.test_model import TestModel from petstore_api.models.test_object_for_multipart_requests_request_marker import TestObjectForMultipartRequestsRequestMarker from petstore_api.models.tiger import Tiger from petstore_api.models.unnamed_dict_with_additional_model_list_properties import UnnamedDictWithAdditionalModelListProperties diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/test_enum.py b/samples/openapi3/client/petstore/python/petstore_api/models/test_enum.py new file mode 100644 index 000000000000..8eae227a84e9 --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/models/test_enum.py @@ -0,0 +1,39 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import json +from enum import Enum +from typing_extensions import Self + + +class TestEnum(str, Enum): + """ + TestEnum + """ + + """ + allowed enum values + """ + ONE = 'ONE' + TWO = 'TWO' + THREE = 'THREE' + FOUR = 'foUr' + + @classmethod + def from_json(cls, json_str: str) -> Self: + """Create an instance of TestEnum from a JSON string""" + return cls(json.loads(json_str)) + + diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/test_enum_with_default.py b/samples/openapi3/client/petstore/python/petstore_api/models/test_enum_with_default.py new file mode 100644 index 000000000000..9304d3ab8497 --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/models/test_enum_with_default.py @@ -0,0 +1,38 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import json +from enum import Enum +from typing_extensions import Self + + +class TestEnumWithDefault(str, Enum): + """ + TestEnumWithDefault + """ + + """ + allowed enum values + """ + EIN = 'EIN' + ZWEI = 'ZWEI' + DREI = 'DREI' + + @classmethod + def from_json(cls, json_str: str) -> Self: + """Create an instance of TestEnumWithDefault from a JSON string""" + return cls(json.loads(json_str)) + + diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/test_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/test_model.py new file mode 100644 index 000000000000..bd78eeb19d7a --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/models/test_model.py @@ -0,0 +1,120 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + +from pydantic import BaseModel, ConfigDict, StrictStr, field_validator +from typing import Any, ClassVar, Dict, List, Optional +from petstore_api.models.test_enum import TestEnum +from petstore_api.models.test_enum_with_default import TestEnumWithDefault +from typing import Optional, Set +from typing_extensions import Self + +class TestModel(BaseModel): + """ + TestModel + """ # noqa: E501 + test_enum: TestEnum + test_string: Optional[StrictStr] = None + test_enum_with_default: Optional[TestEnumWithDefault] = None + test_string_with_default: Optional[StrictStr] = 'ahoy matey' + test_inline_defined_enum_with_default: Optional[StrictStr] = 'B' + additional_properties: Dict[str, Any] = {} + __properties: ClassVar[List[str]] = ["test_enum", "test_string", "test_enum_with_default", "test_string_with_default", "test_inline_defined_enum_with_default"] + + @field_validator('test_inline_defined_enum_with_default') + def test_inline_defined_enum_with_default_validate_enum(cls, value): + """Validates the enum""" + if value is None: + return value + + if value not in set(['A', 'B', 'C']): + raise ValueError("must be one of enum values ('A', 'B', 'C')") + return value + + model_config = ConfigDict( + populate_by_name=True, + validate_assignment=True, + protected_namespaces=(), + ) + + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.model_dump(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of TestModel from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + * Fields in `self.additional_properties` are added to the output dict. + """ + excluded_fields: Set[str] = set([ + "additional_properties", + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + # puts key-value pairs in additional_properties in the top level + if self.additional_properties is not None: + for _key, _value in self.additional_properties.items(): + _dict[_key] = _value + + return _dict + + @classmethod + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of TestModel from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "test_enum": obj.get("test_enum"), + "test_string": obj.get("test_string"), + "test_enum_with_default": obj.get("test_enum_with_default"), + "test_string_with_default": obj.get("test_string_with_default") if obj.get("test_string_with_default") is not None else 'ahoy matey', + "test_inline_defined_enum_with_default": obj.get("test_inline_defined_enum_with_default") if obj.get("test_inline_defined_enum_with_default") is not None else 'B' + }) + # store additional fields in additional_properties + for _key in obj.keys(): + if _key not in cls.__properties: + _obj.additional_properties[_key] = obj.get(_key) + + return _obj + + diff --git a/samples/openapi3/client/petstore/python/test/test_test_enum.py b/samples/openapi3/client/petstore/python/test/test_test_enum.py new file mode 100644 index 000000000000..aec65edf520f --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_test_enum.py @@ -0,0 +1,33 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest + +from petstore_api.models.test_enum import TestEnum + +class TestTestEnum(unittest.TestCase): + """TestEnum unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testTestEnum(self): + """Test TestEnum""" + # inst = TestEnum() + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python/test/test_test_enum_with_default.py b/samples/openapi3/client/petstore/python/test/test_test_enum_with_default.py new file mode 100644 index 000000000000..b51e42819555 --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_test_enum_with_default.py @@ -0,0 +1,33 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest + +from petstore_api.models.test_enum_with_default import TestEnumWithDefault + +class TestTestEnumWithDefault(unittest.TestCase): + """TestEnumWithDefault unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testTestEnumWithDefault(self): + """Test TestEnumWithDefault""" + # inst = TestEnumWithDefault() + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python/test/test_test_model.py b/samples/openapi3/client/petstore/python/test/test_test_model.py new file mode 100644 index 000000000000..ce7d299d7dc7 --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_test_model.py @@ -0,0 +1,56 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest + +from petstore_api.models.test_model import TestModel + +class TestTestModel(unittest.TestCase): + """TestModel unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> TestModel: + """Test TestModel + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `TestModel` + """ + model = TestModel() + if include_optional: + return TestModel( + test_enum = 'ONE', + test_string = 'Just some string', + test_enum_with_default = 'ZWEI', + test_string_with_default = 'ahoy matey', + test_inline_defined_enum_with_default = 'B' + ) + else: + return TestModel( + test_enum = 'ONE', + ) + """ + + def testTestModel(self): + """Test TestModel""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() From d7eadbaf395d177170603e99e8f3c19d8d8418e2 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 8 Jun 2024 15:55:07 +0800 Subject: [PATCH 8/8] update --- .../openapi3/client/petstore/python-aiohttp/docs/TestModel.md | 2 +- .../petstore/python-aiohttp/petstore_api/models/test_model.py | 4 ++-- samples/openapi3/client/petstore/python/docs/TestModel.md | 2 +- .../client/petstore/python/petstore_api/models/test_model.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/TestModel.md b/samples/openapi3/client/petstore/python-aiohttp/docs/TestModel.md index 2c48f81d32cc..91a96b3a58d9 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/docs/TestModel.md +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/TestModel.md @@ -7,7 +7,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **test_enum** | [**TestEnum**](TestEnum.md) | | **test_string** | **str** | | [optional] -**test_enum_with_default** | [**TestEnumWithDefault**](TestEnumWithDefault.md) | | [optional] +**test_enum_with_default** | [**TestEnumWithDefault**](TestEnumWithDefault.md) | | [optional] [default to TestEnumWithDefault.ZWEI] **test_string_with_default** | **str** | | [optional] [default to 'ahoy matey'] **test_inline_defined_enum_with_default** | **str** | | [optional] [default to 'B'] diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_model.py index 203ac7037a59..6bf45255e471 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_model.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/test_model.py @@ -30,7 +30,7 @@ class TestModel(BaseModel): """ # noqa: E501 test_enum: TestEnum test_string: Optional[StrictStr] = None - test_enum_with_default: Optional[TestEnumWithDefault] = None + test_enum_with_default: Optional[TestEnumWithDefault] = TestEnumWithDefault.ZWEI test_string_with_default: Optional[StrictStr] = 'ahoy matey' test_inline_defined_enum_with_default: Optional[StrictStr] = 'B' __properties: ClassVar[List[str]] = ["test_enum", "test_string", "test_enum_with_default", "test_string_with_default", "test_inline_defined_enum_with_default"] @@ -98,7 +98,7 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: _obj = cls.model_validate({ "test_enum": obj.get("test_enum"), "test_string": obj.get("test_string"), - "test_enum_with_default": obj.get("test_enum_with_default"), + "test_enum_with_default": obj.get("test_enum_with_default") if obj.get("test_enum_with_default") is not None else TestEnumWithDefault.ZWEI, "test_string_with_default": obj.get("test_string_with_default") if obj.get("test_string_with_default") is not None else 'ahoy matey', "test_inline_defined_enum_with_default": obj.get("test_inline_defined_enum_with_default") if obj.get("test_inline_defined_enum_with_default") is not None else 'B' }) diff --git a/samples/openapi3/client/petstore/python/docs/TestModel.md b/samples/openapi3/client/petstore/python/docs/TestModel.md index 2c48f81d32cc..91a96b3a58d9 100644 --- a/samples/openapi3/client/petstore/python/docs/TestModel.md +++ b/samples/openapi3/client/petstore/python/docs/TestModel.md @@ -7,7 +7,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **test_enum** | [**TestEnum**](TestEnum.md) | | **test_string** | **str** | | [optional] -**test_enum_with_default** | [**TestEnumWithDefault**](TestEnumWithDefault.md) | | [optional] +**test_enum_with_default** | [**TestEnumWithDefault**](TestEnumWithDefault.md) | | [optional] [default to TestEnumWithDefault.ZWEI] **test_string_with_default** | **str** | | [optional] [default to 'ahoy matey'] **test_inline_defined_enum_with_default** | **str** | | [optional] [default to 'B'] diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/test_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/test_model.py index bd78eeb19d7a..e00b777f80fa 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/test_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/test_model.py @@ -30,7 +30,7 @@ class TestModel(BaseModel): """ # noqa: E501 test_enum: TestEnum test_string: Optional[StrictStr] = None - test_enum_with_default: Optional[TestEnumWithDefault] = None + test_enum_with_default: Optional[TestEnumWithDefault] = TestEnumWithDefault.ZWEI test_string_with_default: Optional[StrictStr] = 'ahoy matey' test_inline_defined_enum_with_default: Optional[StrictStr] = 'B' additional_properties: Dict[str, Any] = {} @@ -106,7 +106,7 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: _obj = cls.model_validate({ "test_enum": obj.get("test_enum"), "test_string": obj.get("test_string"), - "test_enum_with_default": obj.get("test_enum_with_default"), + "test_enum_with_default": obj.get("test_enum_with_default") if obj.get("test_enum_with_default") is not None else TestEnumWithDefault.ZWEI, "test_string_with_default": obj.get("test_string_with_default") if obj.get("test_string_with_default") is not None else 'ahoy matey', "test_inline_defined_enum_with_default": obj.get("test_inline_defined_enum_with_default") if obj.get("test_inline_defined_enum_with_default") is not None else 'B' })