diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PerlClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PerlClientCodegen.java index 1b0da2698e2..39218e9d8dc 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PerlClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PerlClientCodegen.java @@ -7,16 +7,16 @@ import io.swagger.codegen.SupportingFile; import io.swagger.models.properties.ArrayProperty; import io.swagger.models.properties.MapProperty; import io.swagger.models.properties.Property; +import io.swagger.codegen.CliOption; + import java.io.File; import java.util.Arrays; import java.util.HashSet; public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { - protected String invokerPackage = "SwaggerClient"; - protected String groupId = "io.swagger"; - protected String artifactId = "swagger-client"; - protected String artifactVersion = "1.0.0"; + protected String moduleName = "SwaggerClient"; + protected String moduleVersion = "1.0.0"; public PerlClientCodegen() { super(); @@ -26,8 +26,6 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { apiTemplateFiles.put("api.mustache", ".pm"); templateDir = "perl"; - typeMapping.clear(); - languageSpecificPrimitives.clear(); reservedWords = new HashSet( Arrays.asList( @@ -44,11 +42,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { ) ); - additionalProperties.put("invokerPackage", invokerPackage); - additionalProperties.put("groupId", groupId); - additionalProperties.put("artifactId", artifactId); - additionalProperties.put("artifactVersion", artifactVersion); - + languageSpecificPrimitives.clear(); languageSpecificPrimitives.add("int"); languageSpecificPrimitives.add("double"); languageSpecificPrimitives.add("string"); @@ -58,6 +52,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { languageSpecificPrimitives.add("HASH"); languageSpecificPrimitives.add("object"); + typeMapping.clear(); typeMapping.put("integer", "int"); typeMapping.put("long", "int"); typeMapping.put("float", "double"); @@ -71,9 +66,31 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { typeMapping.put("map", "HASH"); typeMapping.put("object", "object"); - supportingFiles.add(new SupportingFile("ApiClient.mustache", ("lib/WWW/" + invokerPackage).replace('/', File.separatorChar), "ApiClient.pm")); - supportingFiles.add(new SupportingFile("Configuration.mustache", ("lib/WWW/" + invokerPackage).replace('/', File.separatorChar), "Configuration.pm")); - supportingFiles.add(new SupportingFile("BaseObject.mustache", ("lib/WWW/" + invokerPackage).replace('/', File.separatorChar), "Object/BaseObject.pm")); + cliOptions.clear(); + cliOptions.add(new CliOption("moduleName", "perl module name, default: SwaggerClient")); + cliOptions.add(new CliOption("moduleVersion", "perl module version, default: 1.0.0")); + } + + + @Override + public void processOpts() { + super.processOpts(); + + if (additionalProperties.containsKey("moduleVersion")) { + moduleVersion = (String) additionalProperties.get("moduleVersion"); + } else { + additionalProperties.put("moduleVersion", moduleVersion); + } + + if (additionalProperties.containsKey("moduleName")) { + moduleName = (String) additionalProperties.get("moduleName"); + } else { + additionalProperties.put("moduleName", moduleName); + } + + supportingFiles.add(new SupportingFile("ApiClient.mustache", ("lib/WWW/" + moduleName).replace('/', File.separatorChar), "ApiClient.pm")); + supportingFiles.add(new SupportingFile("Configuration.mustache", ("lib/WWW/" + moduleName).replace('/', File.separatorChar), "Configuration.pm")); + supportingFiles.add(new SupportingFile("BaseObject.mustache", ("lib/WWW/" + moduleName).replace('/', File.separatorChar), "Object/BaseObject.pm")); } public CodegenType getTag() { @@ -95,11 +112,11 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String apiFileFolder() { - return (outputFolder + "/lib/WWW/" + invokerPackage + apiPackage()).replace('/', File.separatorChar); + return (outputFolder + "/lib/WWW/" + moduleName + apiPackage()).replace('/', File.separatorChar); } public String modelFileFolder() { - return (outputFolder + "/lib/WWW/" + invokerPackage + modelPackage()).replace('/', File.separatorChar); + return (outputFolder + "/lib/WWW/" + moduleName + modelPackage()).replace('/', File.separatorChar); } @Override diff --git a/modules/swagger-codegen/src/main/resources/perl/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/perl/ApiClient.mustache index f57642ff293..7124424baa6 100644 --- a/modules/swagger-codegen/src/main/resources/perl/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/ApiClient.mustache @@ -1,4 +1,4 @@ -package WWW::{{invokerPackage}}::ApiClient; +package WWW::{{moduleName}}::ApiClient; use strict; use warnings; @@ -18,7 +18,7 @@ use Log::Any qw($log); use Carp; use Module::Runtime qw(use_module); -use WWW::{{invokerPackage}}::Configuration; +use WWW::{{moduleName}}::Configuration; sub new { @@ -115,8 +115,8 @@ sub call_api { else { } - $self->{ua}->timeout($self->{http_timeout} || $WWW::{{invokerPackage}}::Configuration::http_timeout); - $self->{ua}->agent($self->{http_user_agent} || $WWW::{{invokerPackage}}::Configuration::http_user_agent); + $self->{ua}->timeout($self->{http_timeout} || $WWW::{{moduleName}}::Configuration::http_timeout); + $self->{ua}->agent($self->{http_user_agent} || $WWW::{{moduleName}}::Configuration::http_user_agent); my $_response = $self->{ua}->request($_request); @@ -237,7 +237,7 @@ sub deserialize } elsif (grep /^$class$/, ('string', 'int', 'float', 'bool', 'object')) { return $data; } else { # model - my $_instance = use_module("WWW::SwaggerClient::Object::$class")->new; + my $_instance = use_module("WWW::{{moduleName}}::Object::$class")->new; if (ref $data eq "HASH") { return $_instance->from_hash($data); } else { # string, need to json decode first @@ -287,10 +287,10 @@ sub select_header_content_type sub get_api_key_with_prefix { my ($self, $api_key) = @_; - if ($WWW::{{invokerPackage}}::Configuration::api_key_prefix->{$api_key}) { - return $WWW::{{invokerPackage}}::Configuration::api_key_prefix->{$api_key}." ".$WWW::{{invokerPackage}}::Configuration::api_key->{$api_key}; + if ($WWW::{{moduleName}}::Configuration::api_key_prefix->{$api_key}) { + return $WWW::{{moduleName}}::Configuration::api_key_prefix->{$api_key}." ".$WWW::{{moduleName}}::Configuration::api_key->{$api_key}; } else { - return $WWW::{{invokerPackage}}::Configuration::api_key->{$api_key}; + return $WWW::{{moduleName}}::Configuration::api_key->{$api_key}; } } @@ -310,7 +310,7 @@ sub update_params_for_auth { if (!defined($auth)) { } {{#authMethods}}elsif ($auth eq '{{name}}') { - {{#isApiKey}}{{#isKeyInHeader}}$header_params->{'{{keyParamName}}'} = $self->get_api_key_with_prefix('{{keyParamName}}');{{/isKeyInHeader}}{{#isKeyInQuery}}$query_params->{'{{keyParamName}}'} = $self->get_api_key_with_prefix('{{keyParamName}}');{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}$header_params->{'Authorization'} = 'Basic '.encode_base64($WWW::{{invokerPackage}}::Configuration::username.":".$WWW::{{invokerPackage}}::Configuration::password);{{/isBasic}} + {{#isApiKey}}{{#isKeyInHeader}}$header_params->{'{{keyParamName}}'} = $self->get_api_key_with_prefix('{{keyParamName}}');{{/isKeyInHeader}}{{#isKeyInQuery}}$query_params->{'{{keyParamName}}'} = $self->get_api_key_with_prefix('{{keyParamName}}');{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}$header_params->{'Authorization'} = 'Basic '.encode_base64($WWW::{{moduleName}}::Configuration::username.":".$WWW::{{moduleName}}::Configuration::password);{{/isBasic}} {{#isOAuth}}# TODO support oauth{{/isOAuth}} } {{/authMethods}} diff --git a/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache b/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache index b4a7885a798..4be9f8408d6 100644 --- a/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/BaseObject.mustache @@ -1,4 +1,4 @@ -package WWW::{{invokerPackage}}::Object::BaseObject; +package WWW::{{moduleName}}::Object::BaseObject; require 5.6.0; use strict; @@ -68,7 +68,7 @@ sub _deserialize { } elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) { return $data; } else { # hash(model) - my $_instance = eval "WWW::{{invokerPackage}}::Object::$type->new()"; + my $_instance = eval "WWW::{{moduleName}}::Object::$type->new()"; return $_instance->from_hash($data); } } diff --git a/modules/swagger-codegen/src/main/resources/perl/Configuration.mustache b/modules/swagger-codegen/src/main/resources/perl/Configuration.mustache index 38eb2ad8dae..0a097dda7bd 100644 --- a/modules/swagger-codegen/src/main/resources/perl/Configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/Configuration.mustache @@ -1,4 +1,4 @@ -package WWW::{{invokerPackage}}::Configuration; +package WWW::{{moduleName}}::Configuration; use strict; use warnings; @@ -7,6 +7,8 @@ use utf8; use Log::Any qw($log); use Carp; +use constant VERSION => '{{moduleVersion}}'; + # class/static variables our $api_client; our $http_timeout = 180; diff --git a/modules/swagger-codegen/src/main/resources/perl/api.mustache b/modules/swagger-codegen/src/main/resources/perl/api.mustache index c67139ee33d..6fb3227a6e5 100644 --- a/modules/swagger-codegen/src/main/resources/perl/api.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/api.mustache @@ -17,7 +17,7 @@ # NOTE: This class is auto generated by the swagger code generator program. # Do not edit the class manually. # -package WWW::{{invokerPackage}}::{{classname}}; +package WWW::{{moduleName}}::{{classname}}; require 5.6.0; use strict; @@ -27,8 +27,8 @@ use Exporter; use Carp qw( croak ); use Log::Any qw($log); -use WWW::{{invokerPackage}}::ApiClient; -use WWW::{{invokerPackage}}::Configuration; +use WWW::{{moduleName}}::ApiClient; +use WWW::{{moduleName}}::Configuration; {{#operations}} our @EXPORT_OK = qw( @@ -38,7 +38,7 @@ our @EXPORT_OK = qw( sub new { my $class = shift; - my $default_api_client = $WWW::{{invokerPackage}}::Configuration::api_client ? $WWW::{{invokerPackage}}::Configuration::api_client : WWW::{{invokerPackage}}::ApiClient->new; + my $default_api_client = $WWW::{{moduleName}}::Configuration::api_client ? $WWW::{{moduleName}}::Configuration::api_client : WWW::{{moduleName}}::ApiClient->new; my (%self) = ( 'api_client' => $default_api_client, @_ diff --git a/modules/swagger-codegen/src/main/resources/perl/object.mustache b/modules/swagger-codegen/src/main/resources/perl/object.mustache index c527957a9b1..c3a15b012bb 100644 --- a/modules/swagger-codegen/src/main/resources/perl/object.mustache +++ b/modules/swagger-codegen/src/main/resources/perl/object.mustache @@ -1,6 +1,6 @@ {{#models}} {{#model}} -package WWW::{{invokerPackage}}::Object::{{classname}}; +package WWW::{{moduleName}}::Object::{{classname}}; require 5.6.0; use strict; @@ -13,7 +13,7 @@ use Log::Any qw($log); use Date::Parse; use DateTime; -use base "WWW::{{invokerPackage}}::Object::BaseObject"; +use base "WWW::{{moduleName}}::Object::BaseObject"; # #{{description}} diff --git a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/ApiResponse.cs b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/ApiResponse.cs new file mode 100644 index 00000000000..7b23e25cb55 --- /dev/null +++ b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/ApiResponse.cs @@ -0,0 +1,61 @@ +using System; +using System.Text; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.Serialization; +using Newtonsoft.Json; + +namespace IO.Swagger.Model { + + /// + /// + /// + [DataContract] + public class ApiResponse { + + + [DataMember(Name="code", EmitDefaultValue=false)] + public int? Code { get; set; } + + + + [DataMember(Name="type", EmitDefaultValue=false)] + public string Type { get; set; } + + + + [DataMember(Name="message", EmitDefaultValue=false)] + public string Message { get; set; } + + + + /// + /// Get the string presentation of the object + /// + /// String presentation of the object + public override string ToString() { + var sb = new StringBuilder(); + sb.Append("class ApiResponse {\n"); + + sb.Append(" Code: ").Append(Code).Append("\n"); + + sb.Append(" Type: ").Append(Type).Append("\n"); + + sb.Append(" Message: ").Append(Message).Append("\n"); + + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Get the JSON string presentation of the object + /// + /// JSON string presentation of the object + public string ToJson() { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + +} + + +} diff --git a/samples/client/petstore/java/src/main/java/io/swagger/client/model/ApiResponse.java b/samples/client/petstore/java/src/main/java/io/swagger/client/model/ApiResponse.java new file mode 100644 index 00000000000..802fa4743f7 --- /dev/null +++ b/samples/client/petstore/java/src/main/java/io/swagger/client/model/ApiResponse.java @@ -0,0 +1,64 @@ +package io.swagger.client.model; + + +import io.swagger.annotations.*; +import com.fasterxml.jackson.annotation.JsonProperty; + + +@ApiModel(description = "") +public class ApiResponse { + + private Integer code = null; + private String type = null; + private String message = null; + + + /** + **/ + @ApiModelProperty(value = "") + @JsonProperty("code") + public Integer getCode() { + return code; + } + public void setCode(Integer code) { + this.code = code; + } + + + /** + **/ + @ApiModelProperty(value = "") + @JsonProperty("type") + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + + /** + **/ + @ApiModelProperty(value = "") + @JsonProperty("message") + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ApiResponse {\n"); + + sb.append(" code: ").append(code).append("\n"); + sb.append(" type: ").append(type).append("\n"); + sb.append(" message: ").append(message).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} diff --git a/samples/client/petstore/objc/client/SWGApiResponse.h b/samples/client/petstore/objc/client/SWGApiResponse.h new file mode 100644 index 00000000000..38525ad185d --- /dev/null +++ b/samples/client/petstore/objc/client/SWGApiResponse.h @@ -0,0 +1,17 @@ +#import +#import "SWGObject.h" + + +@protocol SWGApiResponse +@end + +@interface SWGApiResponse : SWGObject + + +@property(nonatomic) NSNumber* code; + +@property(nonatomic) NSString* type; + +@property(nonatomic) NSString* message; + +@end diff --git a/samples/client/petstore/objc/client/SWGApiResponse.m b/samples/client/petstore/objc/client/SWGApiResponse.m new file mode 100644 index 00000000000..08d8f7dae18 --- /dev/null +++ b/samples/client/petstore/objc/client/SWGApiResponse.m @@ -0,0 +1,22 @@ +#import "SWGApiResponse.h" + +@implementation SWGApiResponse + ++ (JSONKeyMapper *)keyMapper +{ + return [[JSONKeyMapper alloc] initWithDictionary:@{ @"code": @"code", @"type": @"type", @"message": @"message" }]; +} + ++ (BOOL)propertyIsOptional:(NSString *)propertyName +{ + NSArray *optionalProperties = @[@"code", @"type", @"message"]; + + if ([optionalProperties containsObject:propertyName]) { + return YES; + } + else { + return NO; + } +} + +@end diff --git a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Configuration.pm b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Configuration.pm index bbce9d74759..aaa387236d9 100644 --- a/samples/client/petstore/perl/lib/WWW/SwaggerClient/Configuration.pm +++ b/samples/client/petstore/perl/lib/WWW/SwaggerClient/Configuration.pm @@ -7,6 +7,8 @@ use utf8; use Log::Any qw($log); use Carp; +use constant VERSION => '1.0.0'; + # class/static variables our $api_client; our $http_timeout = 180;