-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[python-flask] the operationId is not incorrectly sanitized #1263
Comments
The Swagger Codegen @Test
public void testIssue1263_python_respect_operationId() throws IOException {
String path = getTmpFolder().getAbsolutePath() + "/clientdefault";
GenerationRequest request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.SERVER)
.lang("python-flask")
.spec(loadSpecAsNode("3_0_0/issue-1263/swagger.yml", true, false))
.options(
new Options()
.outputDir(path)
);
List<File> files = new GeneratorService().generationRequest(request).generate();
Assert.assertFalse(files.isEmpty());
System.out.println("Generated client in:\n" + path);
String default_controller_file_content = FileUtils.readFileToString(new File(path + "/swagger_server/controllers/default_controller.py"));
System.out.println(default_controller_file_content);
Assert.assertTrue(default_controller_file_content.contains("def foo_123"), "partial string is not contained in the given text");
} with a corresponding Using the debugger, I found that the CodegenOperation codegenOperation = config.fromOperation(config.escapeQuotationMark(resourcePath), httpMethod, operation, schemas, openAPI); Here, the operationId = this.removeNonNameElementToCamelCase(operationId);
public String removeNonNameElementToCamelCase(String name) {
return this.removeNonNameElementToCamelCase(name, "[-_:;#]");
} This makes sense for Java, but not for Python. We need to keep the underscores I'd like to contribute a pull request for this problem. But for that I'd like to know what you think is the best way to solve the problem.
|
Hello,
Checklist from your CONTRIBUTING files :
swaggerapi/swagger-codegen-cli-v3:3.0.54
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 theoperationId
.Minimal reproducible example :
openapi.yml
generate_server.bash
It produces :
Here we can see that the function is named
foo123
. This is different to the operationIdfoo123
.I suspect the cause is this line : permalink
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) :
(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
The text was updated successfully, but these errors were encountered: