Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* 'master' of https://github.com/swagger-api/swagger-codegen:
  Issue swagger-api#3687 silence resty logging [Go] (swagger-api#3705)
  update ruby regular expression to use \A
  [Ruby] Fix ambiguous regex (swagger-api#3716)
  [PHP] Corrected PHPDoc type declarations (swagger-api#3710)
  Python collection formatting fixes/support (swagger-api#3697)
  php: Fix syntax error when pattern contains a single quote
  ruby: Fix syntax error when pattern contains a single quote
  [Scalatra] replace {} with : in scalatra path (swagger-api#3694)
  java: Javadoc fixes
  Spelling fixes
  Added 'modelPropertyNaming' option for Scala (swagger-api#3685)
  Added functionality to handle optional parameters for Scala (swagger-api#3683)
  Python fixes (swagger-api#3689)
  • Loading branch information
acramatte committed Sep 5, 2016
2 parents 2c21344 + f751e50 commit c3bbd6f
Show file tree
Hide file tree
Showing 467 changed files with 2,976 additions and 1,039 deletions.
Expand Up @@ -801,12 +801,12 @@ public DefaultCodegen() {
cliOptions.add(CliOption.newBoolean(CodegenConstants.ENSURE_UNIQUE_PARAMS, CodegenConstants
.ENSURE_UNIQUE_PARAMS_DESC).defaultValue(Boolean.TRUE.toString()));

// initalize special character mapping
// initialize special character mapping
initalizeSpecialCharacterMapping();
}

/**
* Initalize special character mapping
* Initialize special character mapping
*/
protected void initalizeSpecialCharacterMapping() {
// Initialize special characters
Expand Down
Expand Up @@ -29,6 +29,7 @@
import org.apache.commons.lang3.StringUtils;

public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig {
protected String modelPropertyNaming= "camelCase";
protected String invokerPackage = "io.swagger.client";
protected String groupId = "io.swagger";
protected String artifactId = "swagger-scala-client";
Expand Down Expand Up @@ -136,6 +137,44 @@ public ScalaClientCodegen() {

cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
cliOptions.add(new CliOption(CodegenConstants.MODEL_PROPERTY_NAMING, CodegenConstants.MODEL_PROPERTY_NAMING_DESC).defaultValue("camelCase"));
}

@Override
public void processOpts() {
super.processOpts();

if (additionalProperties.containsKey(CodegenConstants.MODEL_PROPERTY_NAMING)) {
setModelPropertyNaming((String) additionalProperties.get(CodegenConstants.MODEL_PROPERTY_NAMING));
}
}

public void setModelPropertyNaming(String naming) {
if ("original".equals(naming) || "camelCase".equals(naming) ||
"PascalCase".equals(naming) || "snake_case".equals(naming)) {
this.modelPropertyNaming = naming;
} else {
throw new IllegalArgumentException("Invalid model property naming '" +
naming + "'. Must be 'original', 'camelCase', " +
"'PascalCase' or 'snake_case'");
}
}

public String getModelPropertyNaming() {
return this.modelPropertyNaming;
}

public String getNameUsingModelPropertyNaming(String name) {
switch (CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.valueOf(getModelPropertyNaming())) {
case original: return name;
case camelCase: return camelize(name, true);
case PascalCase: return camelize(name);
case snake_case: return underscore(name);
default: throw new IllegalArgumentException("Invalid model property naming '" +
name + "'. Must be 'original', 'camelCase', " +
"'PascalCase' or 'snake_case'");
}

}

@Override
Expand Down Expand Up @@ -287,9 +326,7 @@ public String toVarName(String name) {
return name;
}

// camelize (lower first character) the variable name
// pet_id => petId
name = camelize(name, true);
name = getNameUsingModelPropertyNaming(name);

// for reserved word or word starting with number, append _
if (isReservedWord(name) || name.matches("^\\d.*")) {
Expand Down
Expand Up @@ -4,6 +4,7 @@
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.CodegenOperation;
import io.swagger.codegen.CodegenParameter;
import io.swagger.codegen.CodegenType;
import io.swagger.codegen.DefaultCodegen;
import io.swagger.codegen.SupportingFile;
Expand Down Expand Up @@ -161,8 +162,29 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
for (CodegenOperation op : operationList) {
// force http method to lower case
op.httpMethod = op.httpMethod.toLowerCase();

String[] items = op.path.split("/", -1);
String scalaPath = "";
int pathParamIndex = 0;

for (int i = 0; i < items.length; ++i) {
if (items[i].matches("^\\{(.*)\\}$")) { // wrap in {}
scalaPath = scalaPath + ":" + items[i].replace("{", "").replace("}", "");
pathParamIndex++;
} else {
scalaPath = scalaPath + items[i];
}

if (i != items.length -1) {
scalaPath = scalaPath + "/";
}
}

op.vendorExtensions.put("x-scalatra-path", scalaPath);
}

return objs;
}

Expand Down
Expand Up @@ -8,7 +8,7 @@ import java.util.Map;
/**
* API response returned by API call.
*
* @param T The type of data that is deserialized from response body
* @param <T> The type of data that is deserialized from response body
*/
public class ApiResponse<T> {
final private int statusCode;
Expand Down
Expand Up @@ -151,10 +151,9 @@ class DateAdapter implements JsonSerializer<Date>, JsonDeserializer<Date> {
*
* @param json Json element
* @param date Type
* @param typeOfSrc Type
* @param context Json Serialization Context
* @return Date
* @throw JsonParseException if fail to parse
* @throws JsonParseException if fail to parse
*/
@Override
public Date deserialize(JsonElement json, Type date, JsonDeserializationContext context) throws JsonParseException {
Expand Down
@@ -1,4 +1,4 @@
/**
/*
* {{{appName}}}
* {{{appDescription}}}
*
Expand Down
Expand Up @@ -8,6 +8,7 @@ import (
"reflect"
"strings"
"net/url"
"io/ioutil"
"github.com/go-resty/resty"
)

Expand Down Expand Up @@ -107,7 +108,7 @@ func (c *APIClient) prepareClient() *resty.Client {
if c.config.Timeout != nil {
rClient.SetTimeout(*c.config.Timeout)
}

rClient.SetLogger(ioutil.Discard)
return rClient
}

Expand Down
Expand Up @@ -37,7 +37,7 @@ class ObjectSerializer
*
* @param mixed $data the data to serialize
*
* @return string serialized form of $data
* @return string|object serialized form of $data
*/
public static function sanitizeForSerialization($data)
{
Expand Down Expand Up @@ -100,7 +100,7 @@ class ObjectSerializer
* If it's a string, pass through unchanged. It will be url-encoded
* later.
*
* @param object $object an object to be serialized to a string
* @param string[]|string|\DateTime $object an object to be serialized to a string
*
* @return string the serialized object
*/
Expand Down Expand Up @@ -132,7 +132,7 @@ class ObjectSerializer
* the http body (form parameter). If it's a string, pass through unchanged
* If it's a datetime object, format it in ISO8601
*
* @param string $value the value of the form parameter
* @param string|\SplFileObject $value the value of the form parameter
*
* @return string the form string
*/
Expand All @@ -150,7 +150,7 @@ class ObjectSerializer
* the parameter. If it's a string, pass through unchanged
* If it's a datetime object, format it in ISO8601
*
* @param string $value the value of the parameter
* @param string|\DateTime $value the value of the parameter
*
* @return string the header string
*/
Expand All @@ -166,9 +166,10 @@ class ObjectSerializer
/**
* Serialize an array to a string.
*
* @param array $collection collection to serialize to a string
* @param string $collectionFormat the format use for serialization (csv,
* @param array $collection collection to serialize to a string
* @param string $collectionFormat the format use for serialization (csv,
* ssv, tsv, pipes, multi)
* @param bool $allowCollectionFormatMulti allow collection format to be a multidimensional array
*
* @return string
*/
Expand Down Expand Up @@ -199,12 +200,12 @@ class ObjectSerializer
/**
* Deserialize a JSON string into an object
*
* @param mixed $data object or primitive to be deserialized
* @param string $class class name is passed as a string
* @param string $httpHeaders HTTP headers
* @param string $discriminator discriminator if polymorphism is used
* @param mixed $data object or primitive to be deserialized
* @param string $class class name is passed as a string
* @param string[] $httpHeaders HTTP headers
* @param string $discriminator discriminator if polymorphism is used
*
* @return object an instance of $class
* @return object|array|null an single or an array of $class instances
*/
public static function deserialize($data, $class, $httpHeaders = null, $discriminator = null)
{
Expand Down
4 changes: 2 additions & 2 deletions modules/swagger-codegen/src/main/resources/php/api.mustache
Expand Up @@ -115,7 +115,7 @@ use \{{invokerPackage}}\ObjectSerializer;
{{#allParams}}
* @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}}
* @return Array of {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}null{{/returnType}}, HTTP status code, HTTP response headers (array of strings)
* @return array of {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}null{{/returnType}}, HTTP status code, HTTP response headers (array of strings)
* @throws \{{invokerPackage}}\ApiException on non-2xx response
*/
public function {{operationId}}WithHttpInfo({{#allParams}}${{paramName}}{{^required}} = null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
Expand Down Expand Up @@ -150,7 +150,7 @@ use \{{invokerPackage}}\ObjectSerializer;
{{/minimum}}
{{#pattern}}
if ({{^required}}!is_null(${{paramName}}) && {{/required}}!preg_match("{{{pattern}}}", ${{paramName}})) {
throw new \InvalidArgumentException('invalid value for "{{paramName}}" when calling {{classname}}.{{operationId}}, must conform to the pattern {{{pattern}}}.');
throw new \InvalidArgumentException("invalid value for \"{{paramName}}\" when calling {{classname}}.{{operationId}}, must conform to the pattern {{{pattern}}}.");
}
{{/pattern}}

Expand Down
Expand Up @@ -70,9 +70,9 @@ class Configuration
protected $password = '';
/**
* The default instance of ApiClient
* The default header(s)
*
* @var \{{invokerPackage}}\ApiClient
* @var array
*/
protected $defaultHeaders = array();
Expand Down Expand Up @@ -262,7 +262,7 @@ class Configuration
* @param string $headerName header name (e.g. Token)
* @param string $headerValue header value (e.g. 1z8wp3)
*
* @return ApiClient
* @return Configuration
*/
public function addDefaultHeader($headerName, $headerValue)
{
Expand Down Expand Up @@ -324,7 +324,7 @@ class Configuration
*
* @param string $userAgent the user agent of the api client
*
* @return ApiClient
* @return Configuration
*/
public function setUserAgent($userAgent)
{
Expand All @@ -351,7 +351,7 @@ class Configuration
*
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
*
* @return ApiClient
* @return Configuration
*/
public function setCurlTimeout($seconds)
{
Expand Down
Expand Up @@ -87,7 +87,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple

/**
* Constructor
* @param mixed[] $data Associated array of property value initalizing the model
* @param mixed[] $data Associated array of property values initializing the model
*/
public function __construct(array $data = null)
{
Expand Down Expand Up @@ -271,7 +271,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
{{/minimum}}
{{#pattern}}
if (!preg_match("{{{pattern}}}", ${{name}})) {
throw new \InvalidArgumentException('invalid value for ${{name}} when calling {{classname}}.{{operationId}}, must be conform to the pattern {{{pattern}}}.');
throw new \InvalidArgumentException("invalid value for ${{name}} when calling {{classname}}.{{operationId}}, must conform to the pattern {{{pattern}}}.");
}
{{/pattern}}
{{/hasValidation}}
Expand Down
18 changes: 13 additions & 5 deletions modules/swagger-codegen/src/main/resources/python/api.mustache
Expand Up @@ -140,30 +140,37 @@ class {{classname}}(object):
{{/pattern}}
{{/hasValidation}}
{{/allParams}}

collection_formats = {}

resource_path = '{{path}}'.replace('{format}', 'json')
path_params = {}
{{#pathParams}}
if '{{paramName}}' in params:
path_params['{{baseName}}'] = params['{{paramName}}']
path_params['{{baseName}}'] = params['{{paramName}}']{{#isListContainer}}
collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isListContainer}}
{{/pathParams}}

query_params = {}
{{#queryParams}}
if '{{paramName}}' in params:
query_params['{{baseName}}'] = params['{{paramName}}']
query_params['{{baseName}}'] = params['{{paramName}}']{{#isListContainer}}
collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isListContainer}}
{{/queryParams}}

header_params = {}
{{#headerParams}}
if '{{paramName}}' in params:
header_params['{{baseName}}'] = params['{{paramName}}']
header_params['{{baseName}}'] = params['{{paramName}}']{{#isListContainer}}
collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isListContainer}}
{{/headerParams}}

form_params = []
local_var_files = {}
{{#formParams}}
if '{{paramName}}' in params:
{{#notFile}}form_params.append(('{{baseName}}', params['{{paramName}}'])){{/notFile}}{{#isFile}}local_var_files['{{baseName}}'] = params['{{paramName}}']{{/isFile}}
{{#notFile}}form_params.append(('{{baseName}}', params['{{paramName}}'])){{/notFile}}{{#isFile}}local_var_files['{{baseName}}'] = params['{{paramName}}']{{/isFile}}{{#isListContainer}}
collection_formats['{{baseName}}'] = '{{collectionFormat}}'{{/isListContainer}}
{{/formParams}}

body_params = None
Expand Down Expand Up @@ -195,6 +202,7 @@ class {{classname}}(object):
response_type={{#returnType}}'{{returnType}}'{{/returnType}}{{^returnType}}None{{/returnType}},
auth_settings=auth_settings,
callback=params.get('callback'),
_return_http_data_only=params.get('_return_http_data_only'))
_return_http_data_only=params.get('_return_http_data_only'),
collection_formats=collection_formats)
{{/operation}}
{{/operations}}

0 comments on commit c3bbd6f

Please sign in to comment.