[Python][Flask] UUID path and querystring arguments generate broken code
Description
Related to #7107
Given an invitation_id field defined as
invitation_id:
type: string
format: uuid
the following code is generated for the controller when invitation_id is used in the path:
def invitation_delete(invitation_id): # noqa: E501
"""invitation_delete
# noqa: E501
:param invitation_id: A UUID value identifying the invitation.
:type invitation_id: dict | bytes
:rtype: None
"""
if connexion.request.is_json:
invitation_id = .from_dict(connexion.request.get_json()) # noqa: E501
return 'do some magic!'
In the docstring :type invitation_id: dict | bytes is not correct.
Also note the unnecessary (and broken) code in the function body:
if connexion.request.is_json:
invitation_id = .from_dict(connexion.request.get_json()) # noqa: E501
Note that this is also the case when it is used as a query string parameter.
Swagger-codegen version
2.3.1
Swagger declaration file content or url
N/A
Command line used for generation
java -jar swagger-codegen-cli-2.3.1.jar generate -i swagger/user_data_store.yml -l python-flask -o .
Steps to reproduce
Generate the code as described above.
Related issues/PRs
Related to #7107
Suggest a fix/enhancement
In the linked code a string with a UUID format is not considered a primitive type and since it is not a File either, it incorrectly defaults to dict | bytes: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/flaskConnexion/controller.mustache#L22-L29
It either needs to be considered a primitive type (str) or potentially be handled as a Python uuid object.
The following code is also incorrectly applied in the template for the same reason: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/flaskConnexion/controller.mustache#L63-L68
Another possible solution: Change https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java#L3587-L3588 to:
if (Boolean.TRUE.equals(property.isUuid) && Boolean.TRUE.equals(property.isString)) {
parameter.isUuid = true;
parameter.isPrimitiveType = true;
} ...
@cobusc the issue has been fixed by #7507 by @aykutakin
Please pull the latest mater or use the SNAPSHOT version to give it a try.