forked from loafle/openapi-generator-original
Merge branch 'master' into new-sync-master-to-2.3.0
This commit is contained in:
@@ -32,6 +32,7 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class ExampleGenerator {
|
||||
@@ -47,9 +48,12 @@ public class ExampleGenerator {
|
||||
private static final String NONE = "none";
|
||||
|
||||
protected Map<String, Model> examples;
|
||||
private Random random;
|
||||
|
||||
public ExampleGenerator(Map<String, Model> examples) {
|
||||
this.examples = examples;
|
||||
// use a fixed seed to make the "random" numbers reproducible.
|
||||
this.random = new Random("ExampleGenerator".hashCode());
|
||||
}
|
||||
|
||||
public List<Map<String, String>> generate(Map<String, Object> examples, List<String> mediaTypes, Property property) {
|
||||
@@ -187,13 +191,13 @@ public class ExampleGenerator {
|
||||
private double randomNumber(Double min, Double max) {
|
||||
if (min != null && max != null) {
|
||||
double range = max - min;
|
||||
return Math.random() * range + min;
|
||||
return random.nextDouble() * range + min;
|
||||
} else if (min != null) {
|
||||
return Math.random() + min;
|
||||
return random.nextDouble() + min;
|
||||
} else if (max != null) {
|
||||
return Math.random() * max;
|
||||
return random.nextDouble() * max;
|
||||
} else {
|
||||
return Math.random() * 10;
|
||||
return random.nextDouble() * 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class AsyncScalaClientCodegen extends AbstractScalaCodegen implements Cod
|
||||
importMapping.remove("Map");
|
||||
|
||||
importMapping.put("DateTime", "org.joda.time.DateTime");
|
||||
importMapping.put("ListBuffer", "scala.collections.mutable.ListBuffer");
|
||||
importMapping.put("ListBuffer", "scala.collection.mutable.ListBuffer");
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("enum", "NSString");
|
||||
|
||||
@@ -76,7 +76,7 @@ public class ScalaClientCodegen extends AbstractScalaCodegen implements CodegenC
|
||||
importMapping.remove("Map");
|
||||
|
||||
importMapping.put("DateTime", "org.joda.time.DateTime");
|
||||
importMapping.put("ListBuffer", "scala.collections.mutable.ListBuffer");
|
||||
importMapping.put("ListBuffer", "scala.collection.mutable.ListBuffer");
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("enum", "NSString");
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.properties.BooleanProperty;
|
||||
|
||||
public class TypeScriptJqueryClientCodegen extends AbstractTypeScriptClientCodegen {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TypeScriptNodeClientCodegen.class);
|
||||
private static final SimpleDateFormat SNAPSHOT_SUFFIX_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");
|
||||
|
||||
public static final String NPM_NAME = "npmName";
|
||||
public static final String NPM_VERSION = "npmVersion";
|
||||
public static final String NPM_REPOSITORY = "npmRepository";
|
||||
public static final String SNAPSHOT = "snapshot";
|
||||
|
||||
protected String npmName = null;
|
||||
protected String npmVersion = "1.0.0";
|
||||
protected String npmRepository = null;
|
||||
|
||||
public TypeScriptJqueryClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/typescript-jquery";
|
||||
embeddedTemplateDir = templateDir = "typescript-jquery";
|
||||
|
||||
this.cliOptions.add(new CliOption(NPM_NAME, "The name under which you want to publish generated npm package"));
|
||||
this.cliOptions.add(new CliOption(NPM_VERSION, "The version of your npm package"));
|
||||
this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
|
||||
this.cliOptions.add(new CliOption(SNAPSHOT, "When setting this property to true the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm", BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString()));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
supportingFiles.add(new SupportingFile("api.mustache", null, "api.ts"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
|
||||
LOGGER.warn("check additionals: " + additionalProperties.get(NPM_NAME));
|
||||
if(additionalProperties.containsKey(NPM_NAME)) {
|
||||
addNpmPackageGeneration();
|
||||
}
|
||||
}
|
||||
|
||||
private void addNpmPackageGeneration() {
|
||||
if(additionalProperties.containsKey(NPM_NAME)) {
|
||||
this.setNpmName(additionalProperties.get(NPM_NAME).toString());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(NPM_VERSION)) {
|
||||
this.setNpmVersion(additionalProperties.get(NPM_VERSION).toString());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
||||
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||
}
|
||||
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||
|
||||
if (additionalProperties.containsKey(NPM_REPOSITORY)) {
|
||||
this.setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString());
|
||||
}
|
||||
|
||||
//Files for building our lib
|
||||
supportingFiles.add(new SupportingFile("package.mustache", getPackageRootDirectory(), "package.json"));
|
||||
supportingFiles.add(new SupportingFile("typings.mustache", getPackageRootDirectory(), "typings.json"));
|
||||
supportingFiles.add(new SupportingFile("tsconfig.mustache", getPackageRootDirectory(), "tsconfig.json"));
|
||||
}
|
||||
|
||||
private String getPackageRootDirectory() {
|
||||
String indexPackage = modelPackage.substring(0, Math.max(0, modelPackage.lastIndexOf('.')));
|
||||
return indexPackage.replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "typescript-jquery";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a TypeScript jquery client library.";
|
||||
}
|
||||
|
||||
|
||||
public void setNpmName(String npmName) {
|
||||
this.npmName = npmName;
|
||||
}
|
||||
|
||||
public void setNpmVersion(String npmVersion) {
|
||||
this.npmVersion = npmVersion;
|
||||
}
|
||||
|
||||
public String getNpmVersion() {
|
||||
return npmVersion;
|
||||
}
|
||||
|
||||
public String getNpmRepository() {
|
||||
return npmRepository;
|
||||
}
|
||||
|
||||
public void setNpmRepository(String npmRepository) {
|
||||
this.npmRepository = npmRepository;
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,7 @@ io.swagger.codegen.languages.Swift3Codegen
|
||||
io.swagger.codegen.languages.TizenClientCodegen
|
||||
io.swagger.codegen.languages.TypeScriptAngular2ClientCodegen
|
||||
io.swagger.codegen.languages.TypeScriptAngularClientCodegen
|
||||
io.swagger.codegen.languages.TypeScriptJqueryClientCodegen
|
||||
io.swagger.codegen.languages.TypeScriptNodeClientCodegen
|
||||
io.swagger.codegen.languages.TypeScriptFetchClientCodegen
|
||||
io.swagger.codegen.languages.AkkaScalaClientCodegen
|
||||
|
||||
@@ -8,6 +8,7 @@ package {{package}}
|
||||
|
||||
import {{invokerPackage}}.ApiModel
|
||||
import org.joda.time.DateTime
|
||||
import java.util.UUID
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
|
||||
@@ -0,0 +1,269 @@
|
||||
import * as $ from 'jquery';
|
||||
|
||||
let defaultBasePath = '{{basePath}}';
|
||||
|
||||
// ===============================================
|
||||
// This file is autogenerated - Please do not edit
|
||||
// ===============================================
|
||||
|
||||
/* tslint:disable:no-unused-variable */
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
{{#description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/description}}
|
||||
export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
|
||||
{{#vars}}
|
||||
{{#description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/description}}
|
||||
'{{name}}': {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}};
|
||||
{{/vars}}
|
||||
}
|
||||
|
||||
{{#hasEnums}}
|
||||
export namespace {{classname}} {
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
export enum {{enumName}} {
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{name}} = <any> {{{value}}}{{^-last}},{{/-last}}
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{/vars}}
|
||||
}
|
||||
{{/hasEnums}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
export interface Authentication {
|
||||
/**
|
||||
* Apply authentication settings to header and query params.
|
||||
*/
|
||||
applyToRequest(requestOptions: JQueryAjaxSettings): void;
|
||||
}
|
||||
|
||||
export class HttpBasicAuth implements Authentication {
|
||||
public username: string;
|
||||
public password: string;
|
||||
applyToRequest(requestOptions: any): void {
|
||||
requestOptions.username = this.username;
|
||||
requestOptions.password = this.password;
|
||||
}
|
||||
}
|
||||
|
||||
export class ApiKeyAuth implements Authentication {
|
||||
public apiKey: string;
|
||||
|
||||
constructor(private location: string, private paramName: string) {
|
||||
}
|
||||
|
||||
applyToRequest(requestOptions: JQueryAjaxSettings): void {
|
||||
requestOptions.headers[this.paramName] = this.apiKey;
|
||||
}
|
||||
}
|
||||
|
||||
export class OAuth implements Authentication {
|
||||
public accessToken: string;
|
||||
|
||||
applyToRequest(requestOptions: JQueryAjaxSettings): void {
|
||||
requestOptions.headers["Authorization"] = "Bearer " + this.accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
export class VoidAuth implements Authentication {
|
||||
public username: string;
|
||||
public password: string;
|
||||
applyToRequest(requestOptions: JQueryAjaxSettings): void {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
{{#operations}}
|
||||
{{#description}}
|
||||
/**
|
||||
* {{&description}}
|
||||
*/
|
||||
{{/description}}
|
||||
export enum {{classname}}ApiKeys {
|
||||
{{#authMethods}}
|
||||
{{#isApiKey}}
|
||||
{{name}},
|
||||
{{/isApiKey}}
|
||||
{{/authMethods}}
|
||||
}
|
||||
|
||||
export class {{classname}} {
|
||||
protected basePath = defaultBasePath;
|
||||
protected defaultHeaders : any = {};
|
||||
|
||||
protected authentications = {
|
||||
'default': <Authentication>new VoidAuth(),
|
||||
{{#authMethods}}
|
||||
{{#isBasic}}
|
||||
'{{name}}': new HttpBasicAuth(),
|
||||
{{/isBasic}}
|
||||
{{#isApiKey}}
|
||||
'{{name}}': new ApiKeyAuth({{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{^isKeyInHeader}}'query'{{/isKeyInHeader}}, '{{keyParamName}}'),
|
||||
{{/isApiKey}}
|
||||
{{#isOAuth}}
|
||||
'{{name}}': new OAuth(),
|
||||
{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
}
|
||||
|
||||
constructor(basePath?: string);
|
||||
{{#authMethods}}
|
||||
{{#isBasic}}
|
||||
constructor(username: string, password: string, basePath?: string);
|
||||
{{/isBasic}}
|
||||
{{/authMethods}}
|
||||
constructor(basePathOrUsername: string, password?: string, basePath?: string) {
|
||||
if (password) {
|
||||
{{#authMethods}}
|
||||
{{#isBasic}}
|
||||
this.username = basePathOrUsername;
|
||||
this.password = password
|
||||
{{/isBasic}}
|
||||
{{/authMethods}}
|
||||
if (basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
} else {
|
||||
if (basePathOrUsername) {
|
||||
this.basePath = basePathOrUsername
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public setApiKey(key: {{classname}}ApiKeys, value: string) {
|
||||
this.authentications[{{classname}}ApiKeys[key]].apiKey = value;
|
||||
}
|
||||
{{#authMethods}}
|
||||
{{#isBasic}}
|
||||
|
||||
set username(username: string) {
|
||||
this.authentications.{{name}}.username = username;
|
||||
}
|
||||
|
||||
set password(password: string) {
|
||||
this.authentications.{{name}}.password = password;
|
||||
}
|
||||
{{/isBasic}}
|
||||
{{#isOAuth}}
|
||||
|
||||
set accessToken(token: string) {
|
||||
this.authentications.{{name}}.accessToken = token;
|
||||
}
|
||||
{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
private extendObj<T1, T2 extends T1>(objA: T2, objB: T2): T1|T2 {
|
||||
for(let key in objB){
|
||||
if(objB.hasOwnProperty(key)){
|
||||
objA[key] = objB[key];
|
||||
}
|
||||
}
|
||||
return objA;
|
||||
}
|
||||
|
||||
{{#operation}}
|
||||
/**
|
||||
* {{summary}}
|
||||
* {{notes}}
|
||||
{{#allParams}}* @param {{paramName}} {{description}}
|
||||
{{/allParams}}*/
|
||||
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : JQueryPromise<{ response: JQueryXHR; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> {
|
||||
let localVarPath = this.basePath + '{{path}}'{{#pathParams}}
|
||||
.replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};
|
||||
let queryParameters: any = {};
|
||||
let headerParams: any = this.extendObj({}, this.defaultHeaders);
|
||||
|
||||
{{#allParams}}{{#required}}
|
||||
// verify required parameter '{{paramName}}' is not null or undefined
|
||||
if ({{paramName}} === null || {{paramName}} === undefined) {
|
||||
throw new Error('Required parameter {{paramName}} was null or undefined when calling {{nickname}}.');
|
||||
}
|
||||
{{/required}}{{/allParams}}
|
||||
{{#queryParams}}
|
||||
if ({{paramName}} !== undefined) {
|
||||
queryParameters['{{baseName}}'] = {{paramName}};
|
||||
}
|
||||
|
||||
{{/queryParams}}
|
||||
|
||||
localVarPath = localVarPath + "?" + $.param(queryParameters);
|
||||
|
||||
{{#headerParams}}
|
||||
headerParams['{{baseName}}'] = {{paramName}};
|
||||
|
||||
{{/headerParams}}
|
||||
|
||||
{{^bodyParam}}
|
||||
let reqHasFile = false;
|
||||
let reqDict = {};
|
||||
let reqFormData = new FormData();
|
||||
{{#formParams}}
|
||||
{{#isFile}}
|
||||
reqHasFile = true;
|
||||
{{/isFile}}
|
||||
if ({{paramName}} !== undefined) {
|
||||
reqFormData.append('{{baseName}}', {{paramName}});
|
||||
reqDict['{{baseName}}'] = {{paramName}};
|
||||
}
|
||||
|
||||
{{/formParams}}
|
||||
{{/bodyParam}}
|
||||
{{#bodyParam}}
|
||||
let reqDict = {{paramName}};
|
||||
let reqFormData = new FormData();
|
||||
reqFormData.append('{{paramName}}', {{paramName}});
|
||||
{{#isFile}}
|
||||
let reqHasFile = true;
|
||||
{{/isFile}}
|
||||
{{^isFile}}
|
||||
let reqHasFile = false;
|
||||
{{/isFile}}
|
||||
{{/bodyParam}}
|
||||
|
||||
let requestOptions: JQueryAjaxSettings = {
|
||||
url: localVarPath,
|
||||
type: '{{httpMethod}}',
|
||||
headers: headerParams,
|
||||
processData: false
|
||||
};
|
||||
|
||||
if (Object.keys(reqDict).length) {
|
||||
requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict);
|
||||
requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8';
|
||||
}
|
||||
|
||||
{{#authMethods}}
|
||||
this.authentications.{{name}}.applyToRequest(requestOptions);
|
||||
|
||||
{{/authMethods}}
|
||||
this.authentications.default.applyToRequest(requestOptions);
|
||||
|
||||
let dfd = $.Deferred();
|
||||
$.ajax(requestOptions).then(
|
||||
(data: {{{returnType}}}, textStatus: string, jqXHR: JQueryXHR) =>
|
||||
dfd.resolve({ response: jqXHR, body: data }),
|
||||
(xhr: JQueryXHR, textStatus: string, errorThrown: string) =>
|
||||
dfd.reject({ response: xhr, body: errorThrown })
|
||||
);
|
||||
return dfd.promise();
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
{{/apis}}
|
||||
{{/apiInfo}}
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/bin/sh
|
||||
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
|
||||
#
|
||||
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
|
||||
|
||||
git_user_id=$1
|
||||
git_repo_id=$2
|
||||
release_note=$3
|
||||
|
||||
if [ "$git_user_id" = "" ]; then
|
||||
git_user_id="{{{gitUserId}}}"
|
||||
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
|
||||
fi
|
||||
|
||||
if [ "$git_repo_id" = "" ]; then
|
||||
git_repo_id="{{{gitRepoId}}}"
|
||||
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
|
||||
fi
|
||||
|
||||
if [ "$release_note" = "" ]; then
|
||||
release_note="{{{releaseNote}}}"
|
||||
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
|
||||
fi
|
||||
|
||||
# Initialize the local directory as a Git repository
|
||||
git init
|
||||
|
||||
# Adds the files in the local repository and stages them for commit.
|
||||
git add .
|
||||
|
||||
# Commits the tracked changes and prepares them to be pushed to a remote repository.
|
||||
git commit -m "$release_note"
|
||||
|
||||
# Sets the new remote
|
||||
git_remote=`git remote`
|
||||
if [ "$git_remote" = "" ]; then # git remote not defined
|
||||
|
||||
if [ "$GIT_TOKEN" = "" ]; then
|
||||
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment."
|
||||
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
|
||||
else
|
||||
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
git pull origin master
|
||||
|
||||
# Pushes (Forces) the changes in the local repository up to the remote repository
|
||||
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
|
||||
git push origin master 2>&1 | grep -v 'To https'
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "{{npmName}}",
|
||||
"version": "{{npmVersion}}",
|
||||
"description": "JQuery client for {{npmName}}",
|
||||
"main": "api.js",
|
||||
"scripts": {
|
||||
"build": "tsc"
|
||||
},
|
||||
"author": "Swagger Codegen Contributors",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bluebird": "^3.3.5",
|
||||
"request": "^2.72.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^1.8.10",
|
||||
"typings": "^0.8.1"
|
||||
}{{#npmRepository}},
|
||||
"publishConfig":{
|
||||
"registry":"{{npmRepository}}"
|
||||
}{{/npmRepository}}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"noImplicitAny": false,
|
||||
"suppressImplicitAnyIndexErrors": true,
|
||||
"target": "{{#supportsES6}}ES6{{/supportsES6}}{{^supportsES6}}ES5{{/supportsES6}}",
|
||||
"moduleResolution": "node",
|
||||
"removeComments": true,
|
||||
"sourceMap": true,
|
||||
"noLib": false,
|
||||
"declaration": true
|
||||
},
|
||||
"files": [
|
||||
"api.ts",
|
||||
"typings/main.d.ts"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"ambientDependencies": {
|
||||
"bluebird": "registry:dt/bluebird#2.0.0+20160319051630",
|
||||
"core-js": "registry:dt/core-js#0.0.0+20160317120654",
|
||||
"node": "registry:dt/node#4.0.0+20160423143914"
|
||||
},
|
||||
"dependencies": {
|
||||
"request": "registry:npm/request#2.69.0+20160304121250"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user