swagger-api / swagger-api/swagger-codegen
[python-flask] Error when API path parameters include a dash character.
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Python does not allow to declare variables with a dash "-" character because its considered as a minus operation between two variables.
Thus when the python-flask codegen tools finds a paramter with a dash character in the swagger file, it is automatically translated into a lowbar character "_" into the output swagger.yaml file used for the code generation.
However the input parameter within the API entry URI remains unchanged with the dash character within, resulting into an inconsistency into the python server.
Example:
/data/context/connectivity-service={uuid}/cost-characteristic={cost-name}/:
get:
tags:
- "tapi-connectivity"
description: "returns tapi.topology.CostCharacteristic"
parameters:
- name: "uuid"
in: "path"
description: "Id of connectivity-service"
required: true
type: "string"
- name: "cost-name"
in: "path"
description: "Id of cost-characteristic"
required: true
type: "string"
Error while executing the generated flask server:
python3 -m swagger_server
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/tid/proyecto/TAPIpythonServer/swagger_server/__main__.py", line 16, in <module>
main()
File "/home/tid/proyecto/TAPIpythonServer/swagger_server/__main__.py", line 11, in main
app.add_api('swagger.yaml', arguments={'title': 'tapi-topology,tapi-common,tapi-path-computation,tapi-connectivity,tapi-otsi API'})
File "/home/tid/.local/lib/python3.5/site-packages/connexion/apps/flask_app.py", line 54, in add_api
api = super(FlaskApp, self).add_api(specification, **kwargs)
File "/home/tid/.local/lib/python3.5/site-packages/connexion/apps/abstract.py", line 159, in add_api
options=api_options.as_dict())
File "/home/tid/.local/lib/python3.5/site-packages/connexion/apis/abstract.py", line 92, in __init__
validate_spec(spec)
File "/home/tid/.local/lib/python3.5/site-packages/swagger_spec_validator/validator20.py", line 97, in validate_spec
validate_apis(apis, bound_deref)
File "/home/tid/.local/lib/python3.5/site-packages/swagger_spec_validator/validator20.py", line 302, in validate_apis
validate_unresolvable_path_params(api_name, all_path_params)
File "/home/tid/.local/lib/python3.5/site-packages/swagger_spec_validator/validator20.py", line 523, in validate_unresolvable_path_params
raise SwaggerValidationError(msg)
swagger_spec_validator.common.SwaggerValidationError: Path parameter 'topology-id' used is not documented on '/data/context/connection={uuid}/connection-end-point={topology-id},{node-id},{owned-node-edge-point-id},{connection-end-point-id}/'
Swagger-codegen version
swagger-codegen-cli-2.3.1
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
Start with the generated swagger.yaml and the generated main.py entry point shown in the traceback, then inspect how the Python-Flask generator handles dashed path parameters. Reproduce the failing app.add_api call with the provided path and verify that the generated specification and Flask server use consistent parameter names and start successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, openapi, python
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100