swagger-api / swagger-api/swagger-codegen
[python-flask] [connexion-flask] Parameter names can be mangled in server generation
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with simpletest.yaml using the shown swagger-codegen command, then inspect generated controllers/default_controller.py and the Flask request path. Done means the generated parameter remains my_broken_parameter and the described GET request no longer produces a 500 error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100