Skip to content

[python-flask] [connexion-flask] Parameter names can be mangled in server generation #2927

@Spencatro

Description

@Spencatro
Description

When using swagger-codegen to generate a flask server, connexion and swagger-codegen do not agree on how to represent parameter names, which leads to connexion making requests to endpoints with variable names that do not match the output of swagger-codegen.

Swagger-codegen version

Using swagger-codegen built from source off of master at time of issue being opened (2e402da is latest commit)

Swagger declaration file content or url

simpletest.yaml :


---
swagger: '2.0'
info:
  version: 0.0.0
  title: Simple API
paths:
  /:
    get:
      parameters:
        - name: myOkParameter
          required: false
          type: string
          in: formData
          description: |
            Connexion passes through myOkParameter correctly
        - name: my_broken_parameter
          required: false
          type: string
          in: formData
          description: |
            Connexion creates requests with parameter name my_broken_parameter, but swagger-codegen generates flask code with parameter name myBrokenParameter, resulting in 500 errors out of the box
      responses:
        200:
          description: OK

This command generates controllers/default_controller.py with the following contents:

def root_get(myOkParameter = None, myBrokenParameter = None) -> str:
    return 'do some magic!'

But it should generate these contents instead:

def root_get(myOkParameter = None, my_broken_parameter = None) -> str:
    return 'do some magic!'
Command line used for generation

swagger-codegen generate -i simpletest.yaml -l python-flask -o simple_out_before_fix

Steps to reproduce

1: Generate this server
2: Start the flask server
3: Attempt to make the get request
4: Flask 500 errors

Related issues

Appears to be related to #1938 , but I don't believe the fix implemented there goes far enough to fix the underlying issue (parameter names should not be modified at all, or rather, should be modified in the same way connexion expects them i.e. not at all).

Suggest a Fix

Suggested fix: changes in commit Spencatro@756f0ed . If changes are acceptable, I will open a PR.

It's worth noting that there are likely other edge cases that this fix does not resolve, but this is what I am able and willing to implement at the moment.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions