From 92fdc32afda8a75a9fb96e4dd7ddde917b1fb875 Mon Sep 17 00:00:00 2001 From: cbornet Date: Wed, 19 Sep 2018 15:25:54 +0200 Subject: [PATCH] Fix flask connexion support Use the dev-2.0 git branch of flask connexion to fix the generator. This is not ideal but better than a generator not working at all. Fix #323 --- .../PythonFlaskConnexionServerCodegen.java | 7 ++-- .../flaskConnexion/requirements.mustache | 4 +- .../openapi_server/openapi/openapi.yaml | 40 +++++++++---------- .../flaskConnexion-python2/requirements.txt | 4 +- .../openapi_server/openapi/openapi.yaml | 40 +++++++++---------- .../petstore/flaskConnexion/requirements.txt | 4 +- 6 files changed, 53 insertions(+), 46 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFlaskConnexionServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFlaskConnexionServerCodegen.java index a226d786163b..ab28e6154daa 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFlaskConnexionServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFlaskConnexionServerCodegen.java @@ -312,7 +312,8 @@ public String getSchemaType(Schema p) { @Override public void preprocessOpenAPI(OpenAPI openAPI) { - // need vendor extensions for x-openapi-router-controller + // need vendor extensions for x-swagger-router-controller + // can be changed to x-openapi-router-controller when https://github.com/zalando/connexion/issues/683 is done Map paths = openAPI.getPaths(); if (paths != null) { for (String pathname : paths.keySet()) { @@ -330,9 +331,9 @@ public void preprocessOpenAPI(OpenAPI openAPI) { operationId = getOrGenerateOperationId(operation, pathname, method.toString()); } operation.setOperationId(toOperationId(operationId)); - if (operation.getExtensions() == null || operation.getExtensions().get("x-openapi-router-controller") == null) { + if (operation.getExtensions() == null || operation.getExtensions().get("x-swagger-router-controller") == null) { operation.addExtension( - "x-openapi-router-controller", + "x-swagger-router-controller", controllerPackage + "." + toApiFilename(tag) ); } diff --git a/modules/openapi-generator/src/main/resources/flaskConnexion/requirements.mustache b/modules/openapi-generator/src/main/resources/flaskConnexion/requirements.mustache index 04042d4b1d4a..f0b1190a5681 100644 --- a/modules/openapi-generator/src/main/resources/flaskConnexion/requirements.mustache +++ b/modules/openapi-generator/src/main/resources/flaskConnexion/requirements.mustache @@ -1,4 +1,6 @@ -connexion == 1.1.15 +# Install flask-connexion from git branch dev-2.0. Change when connexion 2.0 is released +git+https://github.com/zalando/connexion.git@35e4e678ef69e703eaf84a48126049808c73b17c#egg=connexion +swagger-ui-bundle python_dateutil == 2.6.0 {{#supportPython2}} typing == 3.5.2.2 diff --git a/samples/server/petstore/flaskConnexion-python2/openapi_server/openapi/openapi.yaml b/samples/server/petstore/flaskConnexion-python2/openapi_server/openapi/openapi.yaml index dca523e5557c..0d8475a2ab94 100644 --- a/samples/server/petstore/flaskConnexion-python2/openapi_server/openapi/openapi.yaml +++ b/samples/server/petstore/flaskConnexion-python2/openapi_server/openapi/openapi.yaml @@ -40,7 +40,7 @@ paths: summary: Add a new pet to the store tags: - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller + x-swagger-router-controller: openapi_server.controllers.pet_controller put: operationId: update_pet requestBody: @@ -70,7 +70,7 @@ paths: summary: Update an existing pet tags: - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller + x-swagger-router-controller: openapi_server.controllers.pet_controller /pet/findByStatus: get: description: Multiple status values can be provided with comma separated strings @@ -115,7 +115,7 @@ paths: summary: Finds Pets by status tags: - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller + x-swagger-router-controller: openapi_server.controllers.pet_controller /pet/findByTags: get: deprecated: true @@ -156,7 +156,7 @@ paths: summary: Finds Pets by tags tags: - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller + x-swagger-router-controller: openapi_server.controllers.pet_controller /pet/{petId}: delete: operationId: delete_pet @@ -183,7 +183,7 @@ paths: summary: Deletes a pet tags: - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller + x-swagger-router-controller: openapi_server.controllers.pet_controller get: description: Returns a single pet operationId: get_pet_by_id @@ -216,7 +216,7 @@ paths: summary: Find pet by ID tags: - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller + x-swagger-router-controller: openapi_server.controllers.pet_controller post: operationId: update_pet_with_form parameters: @@ -249,7 +249,7 @@ paths: summary: Updates a pet in the store with form data tags: - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller + x-swagger-router-controller: openapi_server.controllers.pet_controller /pet/{petId}/uploadImage: post: operationId: upload_file @@ -287,7 +287,7 @@ paths: summary: uploads an image tags: - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller + x-swagger-router-controller: openapi_server.controllers.pet_controller /store/inventory: get: description: Returns a map of status codes to quantities @@ -307,7 +307,7 @@ paths: summary: Returns pet inventories by status tags: - store - x-openapi-router-controller: openapi_server.controllers.store_controller + x-swagger-router-controller: openapi_server.controllers.store_controller /store/order: post: operationId: place_order @@ -334,7 +334,7 @@ paths: summary: Place an order for a pet tags: - store - x-openapi-router-controller: openapi_server.controllers.store_controller + x-swagger-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 @@ -356,7 +356,7 @@ paths: summary: Delete purchase order by ID tags: - store - x-openapi-router-controller: openapi_server.controllers.store_controller + x-swagger-router-controller: openapi_server.controllers.store_controller get: description: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions operationId: get_order_by_id @@ -389,7 +389,7 @@ paths: summary: Find purchase order by ID tags: - store - x-openapi-router-controller: openapi_server.controllers.store_controller + x-swagger-router-controller: openapi_server.controllers.store_controller /user: post: description: This can only be done by the logged in user. @@ -408,7 +408,7 @@ paths: summary: Create user tags: - user - x-openapi-router-controller: openapi_server.controllers.user_controller + x-swagger-router-controller: openapi_server.controllers.user_controller /user/createWithArray: post: operationId: create_users_with_array_input @@ -428,7 +428,7 @@ paths: summary: Creates list of users with given input array tags: - user - x-openapi-router-controller: openapi_server.controllers.user_controller + x-swagger-router-controller: openapi_server.controllers.user_controller /user/createWithList: post: operationId: create_users_with_list_input @@ -448,7 +448,7 @@ paths: summary: Creates list of users with given input array tags: - user - x-openapi-router-controller: openapi_server.controllers.user_controller + x-swagger-router-controller: openapi_server.controllers.user_controller /user/login: get: operationId: login_user @@ -492,7 +492,7 @@ paths: summary: Logs user into the system tags: - user - x-openapi-router-controller: openapi_server.controllers.user_controller + x-swagger-router-controller: openapi_server.controllers.user_controller /user/logout: get: operationId: logout_user @@ -503,7 +503,7 @@ paths: summary: Logs out current logged in user session tags: - user - x-openapi-router-controller: openapi_server.controllers.user_controller + x-swagger-router-controller: openapi_server.controllers.user_controller /user/{username}: delete: description: This can only be done by the logged in user. @@ -525,7 +525,7 @@ paths: summary: Delete user tags: - user - x-openapi-router-controller: openapi_server.controllers.user_controller + x-swagger-router-controller: openapi_server.controllers.user_controller get: operationId: get_user_by_name parameters: @@ -554,7 +554,7 @@ paths: summary: Get user by user name tags: - user - x-openapi-router-controller: openapi_server.controllers.user_controller + x-swagger-router-controller: openapi_server.controllers.user_controller put: description: This can only be done by the logged in user. operationId: update_user @@ -582,7 +582,7 @@ paths: summary: Updated user tags: - user - x-openapi-router-controller: openapi_server.controllers.user_controller + x-swagger-router-controller: openapi_server.controllers.user_controller components: schemas: Order: diff --git a/samples/server/petstore/flaskConnexion-python2/requirements.txt b/samples/server/petstore/flaskConnexion-python2/requirements.txt index 87876f969e9e..48ddf8271440 100644 --- a/samples/server/petstore/flaskConnexion-python2/requirements.txt +++ b/samples/server/petstore/flaskConnexion-python2/requirements.txt @@ -1,4 +1,6 @@ -connexion == 1.1.15 +# Install flask-connexion from git branch dev-2.0. Change when connexion 2.0 is released +git+https://github.com/zalando/connexion.git@35e4e678ef69e703eaf84a48126049808c73b17c#egg=connexion +swagger-ui-bundle python_dateutil == 2.6.0 typing == 3.5.2.2 setuptools >= 21.0.0 diff --git a/samples/server/petstore/flaskConnexion/openapi_server/openapi/openapi.yaml b/samples/server/petstore/flaskConnexion/openapi_server/openapi/openapi.yaml index dca523e5557c..0d8475a2ab94 100644 --- a/samples/server/petstore/flaskConnexion/openapi_server/openapi/openapi.yaml +++ b/samples/server/petstore/flaskConnexion/openapi_server/openapi/openapi.yaml @@ -40,7 +40,7 @@ paths: summary: Add a new pet to the store tags: - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller + x-swagger-router-controller: openapi_server.controllers.pet_controller put: operationId: update_pet requestBody: @@ -70,7 +70,7 @@ paths: summary: Update an existing pet tags: - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller + x-swagger-router-controller: openapi_server.controllers.pet_controller /pet/findByStatus: get: description: Multiple status values can be provided with comma separated strings @@ -115,7 +115,7 @@ paths: summary: Finds Pets by status tags: - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller + x-swagger-router-controller: openapi_server.controllers.pet_controller /pet/findByTags: get: deprecated: true @@ -156,7 +156,7 @@ paths: summary: Finds Pets by tags tags: - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller + x-swagger-router-controller: openapi_server.controllers.pet_controller /pet/{petId}: delete: operationId: delete_pet @@ -183,7 +183,7 @@ paths: summary: Deletes a pet tags: - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller + x-swagger-router-controller: openapi_server.controllers.pet_controller get: description: Returns a single pet operationId: get_pet_by_id @@ -216,7 +216,7 @@ paths: summary: Find pet by ID tags: - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller + x-swagger-router-controller: openapi_server.controllers.pet_controller post: operationId: update_pet_with_form parameters: @@ -249,7 +249,7 @@ paths: summary: Updates a pet in the store with form data tags: - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller + x-swagger-router-controller: openapi_server.controllers.pet_controller /pet/{petId}/uploadImage: post: operationId: upload_file @@ -287,7 +287,7 @@ paths: summary: uploads an image tags: - pet - x-openapi-router-controller: openapi_server.controllers.pet_controller + x-swagger-router-controller: openapi_server.controllers.pet_controller /store/inventory: get: description: Returns a map of status codes to quantities @@ -307,7 +307,7 @@ paths: summary: Returns pet inventories by status tags: - store - x-openapi-router-controller: openapi_server.controllers.store_controller + x-swagger-router-controller: openapi_server.controllers.store_controller /store/order: post: operationId: place_order @@ -334,7 +334,7 @@ paths: summary: Place an order for a pet tags: - store - x-openapi-router-controller: openapi_server.controllers.store_controller + x-swagger-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 @@ -356,7 +356,7 @@ paths: summary: Delete purchase order by ID tags: - store - x-openapi-router-controller: openapi_server.controllers.store_controller + x-swagger-router-controller: openapi_server.controllers.store_controller get: description: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions operationId: get_order_by_id @@ -389,7 +389,7 @@ paths: summary: Find purchase order by ID tags: - store - x-openapi-router-controller: openapi_server.controllers.store_controller + x-swagger-router-controller: openapi_server.controllers.store_controller /user: post: description: This can only be done by the logged in user. @@ -408,7 +408,7 @@ paths: summary: Create user tags: - user - x-openapi-router-controller: openapi_server.controllers.user_controller + x-swagger-router-controller: openapi_server.controllers.user_controller /user/createWithArray: post: operationId: create_users_with_array_input @@ -428,7 +428,7 @@ paths: summary: Creates list of users with given input array tags: - user - x-openapi-router-controller: openapi_server.controllers.user_controller + x-swagger-router-controller: openapi_server.controllers.user_controller /user/createWithList: post: operationId: create_users_with_list_input @@ -448,7 +448,7 @@ paths: summary: Creates list of users with given input array tags: - user - x-openapi-router-controller: openapi_server.controllers.user_controller + x-swagger-router-controller: openapi_server.controllers.user_controller /user/login: get: operationId: login_user @@ -492,7 +492,7 @@ paths: summary: Logs user into the system tags: - user - x-openapi-router-controller: openapi_server.controllers.user_controller + x-swagger-router-controller: openapi_server.controllers.user_controller /user/logout: get: operationId: logout_user @@ -503,7 +503,7 @@ paths: summary: Logs out current logged in user session tags: - user - x-openapi-router-controller: openapi_server.controllers.user_controller + x-swagger-router-controller: openapi_server.controllers.user_controller /user/{username}: delete: description: This can only be done by the logged in user. @@ -525,7 +525,7 @@ paths: summary: Delete user tags: - user - x-openapi-router-controller: openapi_server.controllers.user_controller + x-swagger-router-controller: openapi_server.controllers.user_controller get: operationId: get_user_by_name parameters: @@ -554,7 +554,7 @@ paths: summary: Get user by user name tags: - user - x-openapi-router-controller: openapi_server.controllers.user_controller + x-swagger-router-controller: openapi_server.controllers.user_controller put: description: This can only be done by the logged in user. operationId: update_user @@ -582,7 +582,7 @@ paths: summary: Updated user tags: - user - x-openapi-router-controller: openapi_server.controllers.user_controller + x-swagger-router-controller: openapi_server.controllers.user_controller components: schemas: Order: diff --git a/samples/server/petstore/flaskConnexion/requirements.txt b/samples/server/petstore/flaskConnexion/requirements.txt index 1cf2462510b1..1d33ca8d637e 100644 --- a/samples/server/petstore/flaskConnexion/requirements.txt +++ b/samples/server/petstore/flaskConnexion/requirements.txt @@ -1,3 +1,5 @@ -connexion == 1.1.15 +# Install flask-connexion from git branch dev-2.0. Change when connexion 2.0 is released +git+https://github.com/zalando/connexion.git@35e4e678ef69e703eaf84a48126049808c73b17c#egg=connexion +swagger-ui-bundle python_dateutil == 2.6.0 setuptools >= 21.0.0