Skip to content
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

Fixed #10129 for swagger-codegen where python was getting the type "O… #930

Merged
merged 1 commit into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,10 @@ public String toParamName(String name) {

@Override
public String toModelName(String name) {
if (name == null) {
// sanitizeName will return "Object" for null, but this is called "object" in python
return "object";
}
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
// remove dollar sign
name = name.replaceAll("$", "");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.swagger.codegen.v3.generators.python;

import io.swagger.codegen.v3.generators.AbstractCodegenTest;
import org.testng.Assert;
import org.testng.annotations.Test;

public class PythonClientCodegenTest extends AbstractCodegenTest {
@Test
public void testToModelName() {
PythonClientCodegen pythonClientCodegen = new PythonClientCodegen();

// no type - this is 'object' in Python
Assert.assertEquals(pythonClientCodegen.toModelName(null), "object");
// assume this is a model type - "null" is not special in Python
Assert.assertEquals(pythonClientCodegen.toModelName("null"), "Null");
// reserved word
Assert.assertEquals(pythonClientCodegen.toModelName("return"), "ModelReturn");
Assert.assertEquals(pythonClientCodegen.toModelName("None"), "ModelNone");
// $
Assert.assertEquals(pythonClientCodegen.toModelName("my$result"), "Myresult");
// Starts with number
Assert.assertEquals(pythonClientCodegen.toModelName("999Bad"), "Model999Bad");
// Camel Case
Assert.assertEquals(pythonClientCodegen.toModelName("camel_case"), "CamelCase");
}

@Test
public void testToModelNamePrefixSuffix() {
PythonClientCodegen pythonClientCodegen = new PythonClientCodegen();
pythonClientCodegen.setModelNamePrefix("xprefixx");

// Camel Case
Assert.assertEquals(pythonClientCodegen.toModelName("camel_case"), "XprefixxCamelCase");

pythonClientCodegen.setModelNamePrefix(null);
pythonClientCodegen.setModelNameSuffix("xsuffixx");

// Camel Case
Assert.assertEquals(pythonClientCodegen.toModelName("camel_case"), "CamelCaseXsuffixx");
}
}