Skip to content

Commit

Permalink
Merge pull request #930 from atlassian-forks/python-object
Browse files Browse the repository at this point in the history
Fixed #10129 for swagger-codegen where python was getting the type "O…
  • Loading branch information
HugoMario committed Jul 6, 2021
2 parents a36fd69 + d0d1b55 commit f3710d3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
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");
}
}

0 comments on commit f3710d3

Please sign in to comment.