forked from loafle/openapi-generator-original
add support for cli (perl)
This commit is contained in:
parent
6ad3a717fe
commit
10e07eaf74
@ -7,16 +7,16 @@ import io.swagger.codegen.SupportingFile;
|
|||||||
import io.swagger.models.properties.ArrayProperty;
|
import io.swagger.models.properties.ArrayProperty;
|
||||||
import io.swagger.models.properties.MapProperty;
|
import io.swagger.models.properties.MapProperty;
|
||||||
import io.swagger.models.properties.Property;
|
import io.swagger.models.properties.Property;
|
||||||
|
import io.swagger.codegen.CliOption;
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
protected String invokerPackage = "SwaggerClient";
|
protected String moduleName = "SwaggerClient";
|
||||||
protected String groupId = "io.swagger";
|
protected String moduleVersion = "1.0.0";
|
||||||
protected String artifactId = "swagger-client";
|
|
||||||
protected String artifactVersion = "1.0.0";
|
|
||||||
|
|
||||||
public PerlClientCodegen() {
|
public PerlClientCodegen() {
|
||||||
super();
|
super();
|
||||||
@ -26,8 +26,6 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
apiTemplateFiles.put("api.mustache", ".pm");
|
apiTemplateFiles.put("api.mustache", ".pm");
|
||||||
templateDir = "perl";
|
templateDir = "perl";
|
||||||
|
|
||||||
typeMapping.clear();
|
|
||||||
languageSpecificPrimitives.clear();
|
|
||||||
|
|
||||||
reservedWords = new HashSet<String>(
|
reservedWords = new HashSet<String>(
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
@ -44,11 +42,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
additionalProperties.put("invokerPackage", invokerPackage);
|
languageSpecificPrimitives.clear();
|
||||||
additionalProperties.put("groupId", groupId);
|
|
||||||
additionalProperties.put("artifactId", artifactId);
|
|
||||||
additionalProperties.put("artifactVersion", artifactVersion);
|
|
||||||
|
|
||||||
languageSpecificPrimitives.add("int");
|
languageSpecificPrimitives.add("int");
|
||||||
languageSpecificPrimitives.add("double");
|
languageSpecificPrimitives.add("double");
|
||||||
languageSpecificPrimitives.add("string");
|
languageSpecificPrimitives.add("string");
|
||||||
@ -58,6 +52,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
languageSpecificPrimitives.add("HASH");
|
languageSpecificPrimitives.add("HASH");
|
||||||
languageSpecificPrimitives.add("object");
|
languageSpecificPrimitives.add("object");
|
||||||
|
|
||||||
|
typeMapping.clear();
|
||||||
typeMapping.put("integer", "int");
|
typeMapping.put("integer", "int");
|
||||||
typeMapping.put("long", "int");
|
typeMapping.put("long", "int");
|
||||||
typeMapping.put("float", "double");
|
typeMapping.put("float", "double");
|
||||||
@ -71,9 +66,31 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
typeMapping.put("map", "HASH");
|
typeMapping.put("map", "HASH");
|
||||||
typeMapping.put("object", "object");
|
typeMapping.put("object", "object");
|
||||||
|
|
||||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", ("lib/WWW/" + invokerPackage).replace('/', File.separatorChar), "ApiClient.pm"));
|
cliOptions.clear();
|
||||||
supportingFiles.add(new SupportingFile("Configuration.mustache", ("lib/WWW/" + invokerPackage).replace('/', File.separatorChar), "Configuration.pm"));
|
cliOptions.add(new CliOption("moduleName", "perl module name, default: SwaggerClient"));
|
||||||
supportingFiles.add(new SupportingFile("BaseObject.mustache", ("lib/WWW/" + invokerPackage).replace('/', File.separatorChar), "Object/BaseObject.pm"));
|
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() {
|
public CodegenType getTag() {
|
||||||
@ -95,11 +112,11 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apiFileFolder() {
|
public String apiFileFolder() {
|
||||||
return (outputFolder + "/lib/WWW/" + invokerPackage + apiPackage()).replace('/', File.separatorChar);
|
return (outputFolder + "/lib/WWW/" + moduleName + apiPackage()).replace('/', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modelFileFolder() {
|
public String modelFileFolder() {
|
||||||
return (outputFolder + "/lib/WWW/" + invokerPackage + modelPackage()).replace('/', File.separatorChar);
|
return (outputFolder + "/lib/WWW/" + moduleName + modelPackage()).replace('/', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package WWW::{{invokerPackage}}::ApiClient;
|
package WWW::{{moduleName}}::ApiClient;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
@ -18,7 +18,7 @@ use Log::Any qw($log);
|
|||||||
use Carp;
|
use Carp;
|
||||||
use Module::Runtime qw(use_module);
|
use Module::Runtime qw(use_module);
|
||||||
|
|
||||||
use WWW::{{invokerPackage}}::Configuration;
|
use WWW::{{moduleName}}::Configuration;
|
||||||
|
|
||||||
sub new
|
sub new
|
||||||
{
|
{
|
||||||
@ -115,8 +115,8 @@ sub call_api {
|
|||||||
else {
|
else {
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{ua}->timeout($self->{http_timeout} || $WWW::{{invokerPackage}}::Configuration::http_timeout);
|
$self->{ua}->timeout($self->{http_timeout} || $WWW::{{moduleName}}::Configuration::http_timeout);
|
||||||
$self->{ua}->agent($self->{http_user_agent} || $WWW::{{invokerPackage}}::Configuration::http_user_agent);
|
$self->{ua}->agent($self->{http_user_agent} || $WWW::{{moduleName}}::Configuration::http_user_agent);
|
||||||
|
|
||||||
my $_response = $self->{ua}->request($_request);
|
my $_response = $self->{ua}->request($_request);
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ sub deserialize
|
|||||||
} elsif (grep /^$class$/, ('string', 'int', 'float', 'bool', 'object')) {
|
} elsif (grep /^$class$/, ('string', 'int', 'float', 'bool', 'object')) {
|
||||||
return $data;
|
return $data;
|
||||||
} else { # model
|
} 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") {
|
if (ref $data eq "HASH") {
|
||||||
return $_instance->from_hash($data);
|
return $_instance->from_hash($data);
|
||||||
} else { # string, need to json decode first
|
} else { # string, need to json decode first
|
||||||
@ -287,10 +287,10 @@ sub select_header_content_type
|
|||||||
sub get_api_key_with_prefix
|
sub get_api_key_with_prefix
|
||||||
{
|
{
|
||||||
my ($self, $api_key) = @_;
|
my ($self, $api_key) = @_;
|
||||||
if ($WWW::{{invokerPackage}}::Configuration::api_key_prefix->{$api_key}) {
|
if ($WWW::{{moduleName}}::Configuration::api_key_prefix->{$api_key}) {
|
||||||
return $WWW::{{invokerPackage}}::Configuration::api_key_prefix->{$api_key}." ".$WWW::{{invokerPackage}}::Configuration::api_key->{$api_key};
|
return $WWW::{{moduleName}}::Configuration::api_key_prefix->{$api_key}." ".$WWW::{{moduleName}}::Configuration::api_key->{$api_key};
|
||||||
} else {
|
} 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)) {
|
if (!defined($auth)) {
|
||||||
}
|
}
|
||||||
{{#authMethods}}elsif ($auth eq '{{name}}') {
|
{{#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}}
|
{{#isOAuth}}# TODO support oauth{{/isOAuth}}
|
||||||
}
|
}
|
||||||
{{/authMethods}}
|
{{/authMethods}}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package WWW::{{invokerPackage}}::Object::BaseObject;
|
package WWW::{{moduleName}}::Object::BaseObject;
|
||||||
|
|
||||||
require 5.6.0;
|
require 5.6.0;
|
||||||
use strict;
|
use strict;
|
||||||
@ -68,7 +68,7 @@ sub _deserialize {
|
|||||||
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
} elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
|
||||||
return $data;
|
return $data;
|
||||||
} else { # hash(model)
|
} else { # hash(model)
|
||||||
my $_instance = eval "WWW::{{invokerPackage}}::Object::$type->new()";
|
my $_instance = eval "WWW::{{moduleName}}::Object::$type->new()";
|
||||||
return $_instance->from_hash($data);
|
return $_instance->from_hash($data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package WWW::{{invokerPackage}}::Configuration;
|
package WWW::{{moduleName}}::Configuration;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
@ -7,6 +7,8 @@ use utf8;
|
|||||||
use Log::Any qw($log);
|
use Log::Any qw($log);
|
||||||
use Carp;
|
use Carp;
|
||||||
|
|
||||||
|
use constant VERSION => '{{moduleVersion}}';
|
||||||
|
|
||||||
# class/static variables
|
# class/static variables
|
||||||
our $api_client;
|
our $api_client;
|
||||||
our $http_timeout = 180;
|
our $http_timeout = 180;
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
# NOTE: This class is auto generated by the swagger code generator program.
|
# NOTE: This class is auto generated by the swagger code generator program.
|
||||||
# Do not edit the class manually.
|
# Do not edit the class manually.
|
||||||
#
|
#
|
||||||
package WWW::{{invokerPackage}}::{{classname}};
|
package WWW::{{moduleName}}::{{classname}};
|
||||||
|
|
||||||
require 5.6.0;
|
require 5.6.0;
|
||||||
use strict;
|
use strict;
|
||||||
@ -27,8 +27,8 @@ use Exporter;
|
|||||||
use Carp qw( croak );
|
use Carp qw( croak );
|
||||||
use Log::Any qw($log);
|
use Log::Any qw($log);
|
||||||
|
|
||||||
use WWW::{{invokerPackage}}::ApiClient;
|
use WWW::{{moduleName}}::ApiClient;
|
||||||
use WWW::{{invokerPackage}}::Configuration;
|
use WWW::{{moduleName}}::Configuration;
|
||||||
|
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
our @EXPORT_OK = qw(
|
our @EXPORT_OK = qw(
|
||||||
@ -38,7 +38,7 @@ our @EXPORT_OK = qw(
|
|||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my $class = shift;
|
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) = (
|
my (%self) = (
|
||||||
'api_client' => $default_api_client,
|
'api_client' => $default_api_client,
|
||||||
@_
|
@_
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{{#models}}
|
{{#models}}
|
||||||
{{#model}}
|
{{#model}}
|
||||||
package WWW::{{invokerPackage}}::Object::{{classname}};
|
package WWW::{{moduleName}}::Object::{{classname}};
|
||||||
|
|
||||||
require 5.6.0;
|
require 5.6.0;
|
||||||
use strict;
|
use strict;
|
||||||
@ -13,7 +13,7 @@ use Log::Any qw($log);
|
|||||||
use Date::Parse;
|
use Date::Parse;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
use base "WWW::{{invokerPackage}}::Object::BaseObject";
|
use base "WWW::{{moduleName}}::Object::BaseObject";
|
||||||
|
|
||||||
#
|
#
|
||||||
#{{description}}
|
#{{description}}
|
||||||
|
@ -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 {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
[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; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the string presentation of the object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>String presentation of the object</returns>
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the JSON string presentation of the object
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>JSON string presentation of the object</returns>
|
||||||
|
public string ToJson() {
|
||||||
|
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
17
samples/client/petstore/objc/client/SWGApiResponse.h
Normal file
17
samples/client/petstore/objc/client/SWGApiResponse.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "SWGObject.h"
|
||||||
|
|
||||||
|
|
||||||
|
@protocol SWGApiResponse
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface SWGApiResponse : SWGObject
|
||||||
|
|
||||||
|
|
||||||
|
@property(nonatomic) NSNumber* code;
|
||||||
|
|
||||||
|
@property(nonatomic) NSString* type;
|
||||||
|
|
||||||
|
@property(nonatomic) NSString* message;
|
||||||
|
|
||||||
|
@end
|
22
samples/client/petstore/objc/client/SWGApiResponse.m
Normal file
22
samples/client/petstore/objc/client/SWGApiResponse.m
Normal file
@ -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
|
@ -7,6 +7,8 @@ use utf8;
|
|||||||
use Log::Any qw($log);
|
use Log::Any qw($log);
|
||||||
use Carp;
|
use Carp;
|
||||||
|
|
||||||
|
use constant VERSION => '1.0.0';
|
||||||
|
|
||||||
# class/static variables
|
# class/static variables
|
||||||
our $api_client;
|
our $api_client;
|
||||||
our $http_timeout = 180;
|
our $http_timeout = 180;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user