swagger-api/swagger-codegen

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

Open

#2,927 建立於 2016年5月20日

在 GitHub 查看
 (3 留言) (2 反應) (0 負責人)HTML (12,701 star) (5,474 fork)batch import
Issue: BugServer: Pythonhelp wanted

描述

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 (2e402da3efdc63c1fb6ae2238b171c7f488be80b 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 https://github.com/swagger-api/swagger-codegen/issues/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 https://github.com/shawkinsl/swagger-codegen/commit/756f0ed64e60a5a3fe2c70ebee4a34d7a7b68abe . 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.

貢獻者指南