Merge pull request #4215 from cbornet/flask_param_name

[Flask] fix parameter naming
This commit is contained in:
wing328 2016-11-23 15:42:42 +08:00 committed by GitHub
commit 44ca30df63
5 changed files with 24 additions and 10 deletions

View File

@ -10,8 +10,7 @@ import io.swagger.models.HttpMethod;
import io.swagger.models.Operation;
import io.swagger.models.Path;
import io.swagger.models.Swagger;
import io.swagger.models.parameters.BodyParameter;
import io.swagger.models.parameters.FormParameter;
import io.swagger.models.parameters.Parameter;
import io.swagger.models.properties.*;
import io.swagger.util.Yaml;
@ -317,6 +316,15 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
controllerPackage + "." + toApiFilename(tag)
);
}
for (Parameter param: operation.getParameters()) {
// sanitize the param name but don't underscore it since it's used for request mapping
String name = param.getName();
String paramName = sanitizeName(name);
if (!paramName.equals(name)) {
LOGGER.warn(name + " cannot be used as parameter name with flask-connexion and was sanitized as " + paramName);
}
param.setName(paramName);
}
}
}
}
@ -405,6 +413,12 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
return name;
}
@Override
public String toParamName(String name) {
// Param name is already sanitized in swagger spec processing
return name;
}
@Override
public String toModelFilename(String name) {
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.

View File

@ -21,14 +21,14 @@ def add_pet(body):
return 'do some magic!'
def delete_pet(petId, apiKey=None):
def delete_pet(petId, api_key=None):
"""
Deletes a pet
:param petId: Pet id to delete
:type petId: int
:param apiKey:
:type apiKey: str
:param api_key:
:type api_key: str
:rtype: None
"""

View File

@ -31,7 +31,7 @@ class TestPetController(BaseTestCase):
Deletes a pet
"""
headers = [('apiKey', 'apiKey_example')]
headers = [('api_key', 'api_key_example')]
response = self.client.open('/v2/pet/{petId}'.format(petId=789),
method='DELETE',
headers=headers)

View File

@ -21,14 +21,14 @@ def add_pet(body):
return 'do some magic!'
def delete_pet(petId, apiKey=None):
def delete_pet(petId, api_key=None):
"""
Deletes a pet
:param petId: Pet id to delete
:type petId: int
:param apiKey:
:type apiKey: str
:param api_key:
:type api_key: str
:rtype: None
"""

View File

@ -31,7 +31,7 @@ class TestPetController(BaseTestCase):
Deletes a pet
"""
headers = [('apiKey', 'apiKey_example')]
headers = [('api_key', 'api_key_example')]
response = self.client.open('/v2/pet/{petId}'.format(petId=789),
method='DELETE',
headers=headers)