swagger-api / swagger-api/swagger-codegen-generators
[python-flask] the operationId is not incorrectly sanitized
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
Checklist from your CONTRIBUTING files :
- I have not found a matching issue, neither in swagger-api/swagger-codegen nor swagger-codegen-generators
- I am using the latest master
- kinda, I'm using the Docker version of 2 weeks ago :
swaggerapi/swagger-codegen-cli-v3:3.0.54
- kinda, I'm using the Docker version of 2 weeks ago :
- test locally with the most recent jar
- I'll try to do it soon
Using the python-flask generator, I noticed that some functions generated for the controller, when containing an underscore followed by a digit, have a name different than the operationId.
Minimal reproducible example :
openapi.yml
openapi: 3.0.3
info:
title: Minimal Reproducible Example
description: "."
version: 0.0.0
paths:
/foo:
get:
summary: Get
responses:
"200":
description: Status details
operationId: foo_123
generate_server.bash
set -euo pipefail # check for errors
echo '(re-)create output directory'
rm -Rf ./output && mkdir ./output
echo 'copy the OpenAPI file into it'
cp ./openapi.yml ./output
echo 'generate the server files from the OpenAPI file'
docker run \
--rm \
-u "$(id -u):$(id -g)" \
-v "${PWD}/output:/local" \
swaggerapi/swagger-codegen-cli-v3:3.0.54 \
generate \
-l python-flask \
-i /local/openapi.yml \
-o /local
echo 'check the name of the function defined in the controller'
grep 'foo' < ./output/swagger_server/controllers/default_controller.py
It produces :
check the name of the function defined in the controller
def foo123(): # noqa: E501
Here we can see that the function is named foo123. This is different to the operationId foo123.
I suspect the cause is this line : permalink
public String toOperationId(String operationId) {
// ... snip
return underscore(sanitizeName(operationId));
}
I don't have a Java development environment at hand, so I can't find where these 2 functions are defined (being imported by *) and so can't review them.
For reference, here is the rule for valid Python identifiers (cf Python doc on lexical analysis)) but I find it much inscrutable (with all the Unicode linguo), a dumber (but inexact) version would be (according to this StackOverflow answer) :
identifier ::= (letter|"_") (letter | digit | "_")*
(then applies the rules of keywords and dunder methods, clearly expressed in the Python doc on lexical analysis linked above)
Expected result : the function generated should have the same name than the operationId
Actual result : the function generated have a different name than the operationId
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 PythonFlaskConnexionCodegen.java at the linked toOperationId method, then reproduce the issue using the provided openapi.yml and generate_server.bash files. Compare the generated default_controller.py function name with operationId: foo_123; done means the generated function retains the operationId name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, java, python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100