Merge branch 'leonyu-typescript-fetch'

This commit is contained in:
wing328 2016-05-05 17:13:10 +08:00
commit b92e240ac2
19 changed files with 1518 additions and 0 deletions

View File

@ -0,0 +1,31 @@
#!/bin/sh
SCRIPT="$0"
while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done
if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
if [ ! -f "$executable" ]
then
mvn clean package
fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-fetch -o samples/client/petstore/typescript-fetch/"
java $JAVA_OPTS -jar $executable $ags

View File

@ -0,0 +1,10 @@
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
If Not Exist %executable% (
mvn clean package
)
set JAVA_OPTS=%JAVA_OPTS% -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties
set ags=generate -t modules\swagger-codegen\src\main\resources\typescript-fetch -i modules\swagger-codegen\src\test\resources\2_0\petstore.json -l typescript-fetch -o samples\client\petstore\typescript-fetch
java %JAVA_OPTS% -jar %executable% %ags%

View File

@ -0,0 +1,38 @@
package io.swagger.codegen.languages;
import io.swagger.codegen.SupportingFile;
import java.io.File;
public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodegen {
@Override
public String getName() {
return "typescript-fetch";
}
@Override
public String getHelp() {
return "Generates a TypeScript client library using Fetch API (beta).";
}
@Override
public void processOpts() {
super.processOpts();
final String defaultFolder = apiPackage().replace('.', File.separatorChar);
supportingFiles.add(new SupportingFile("api.mustache", null, "api.ts"));
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
supportingFiles.add(new SupportingFile("assign.ts", defaultFolder, "assign.ts"));
supportingFiles.add(new SupportingFile("package.json", "", "package.json"));
supportingFiles.add(new SupportingFile("typings.json", "", "typings.json"));
supportingFiles.add(new SupportingFile("tsconfig.json", "", "tsconfig.json"));
}
public TypeScriptFetchClientCodegen() {
super();
outputFolder = "generated-code/typescript-fetch";
embeddedTemplateDir = templateDir = "TypeScript-Fetch";
}
}

View File

@ -39,6 +39,7 @@ io.swagger.codegen.languages.TizenClientCodegen
io.swagger.codegen.languages.TypeScriptAngular2ClientCodegen
io.swagger.codegen.languages.TypeScriptAngularClientCodegen
io.swagger.codegen.languages.TypeScriptNodeClientCodegen
io.swagger.codegen.languages.TypeScriptFetchClientCodegen
io.swagger.codegen.languages.AkkaScalaClientCodegen
io.swagger.codegen.languages.CsharpDotNet2ClientCodegen
io.swagger.codegen.languages.ClojureClientCodegen

View File

@ -0,0 +1,133 @@
import * as querystring from 'querystring';
import * as fetch from 'isomorphic-fetch';
import {assign} from './assign';
{{#models}}
{{#model}}
{{#description}}
/**
* {{{description}}}
*/
{{/description}}
export interface {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
{{#vars}}
{{#description}}
/**
* {{{description}}}
*/
{{/description}}
"{{name}}"{{^required}}?{{/required}}: {{#isEnum}}{{classname}}.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}};
{{/vars}}
}
{{#hasEnums}}
{{#vars}}
{{#isEnum}}
export enum {{datatypeWithEnum}} { {{#allowableValues}}{{#values}}
{{.}} = <any> '{{.}}'{{^-last}},{{/-last}}{{/values}}{{/allowableValues}}
}
{{/isEnum}}
{{/vars}}
{{/hasEnums}}
{{/model}}
{{/models}}
{{#apiInfo}}
{{#apis}}
{{#operations}}
//export namespace {{package}} {
'use strict';
{{#description}}
/**
* {{&description}}
*/
{{/description}}
export class {{classname}} {
protected basePath = '{{basePath}}';
public defaultHeaders : any = {};
constructor(basePath?: string) {
if (basePath) {
this.basePath = basePath;
}
}
{{#operation}}
/**
* {{summary}}
* {{notes}}
{{#allParams}}* @param {{paramName}} {{description}}
{{/allParams}}*/
public {{nickname}} (params: { {{#allParams}} {{paramName}}{{^required}}?{{/required}}: {{{dataType}}};{{/allParams}} }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> {
const localVarPath = this.basePath + '{{path}}'{{#pathParams}}
.replace('{' + '{{baseName}}' + '}', String(params.{{paramName}})){{/pathParams}};
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
{{#hasFormParams}}
let formParams: any = {};
headerParams['Content-Type'] = 'application/x-www-form-urlencoded';
{{/hasFormParams}}
{{#hasBodyParam}}
headerParams['Content-Type'] = 'application/json';
{{/hasBodyParam}}
{{#allParams}}
{{#required}}
// verify required parameter '{{paramName}}' is set
if (params.{{paramName}} == null) {
throw new Error('Missing required parameter {{paramName}} when calling {{nickname}}');
}
{{/required}}
{{/allParams}}
{{#queryParams}}
if (params.{{paramName}} !== undefined) {
queryParameters['{{baseName}}'] = params.{{paramName}};
}
{{/queryParams}}
{{#headerParams}}
headerParams['{{baseName}}'] = params.{{paramName}};
{{/headerParams}}
{{#formParams}}
formParams['{{baseName}}'] = params.{{paramName}};
{{/formParams}}
let fetchParams = {
method: '{{httpMethod}}',
headers: headerParams,
{{#bodyParam}}body: JSON.stringify(params.{{paramName}}),
{{/bodyParam}}
{{#hasFormParams}}body: querystring.stringify(formParams),
{{/hasFormParams}}
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
{{/operation}}
}
//}
{{/operations}}
{{/apis}}
{{/apiInfo}}

View File

@ -0,0 +1,18 @@
export function assign (target, ...args) {
'use strict';
if (target === undefined || target === null) {
throw new TypeError('Cannot convert undefined or null to object');
}
var output = Object(target);
for (let source of args) {
if (source !== undefined && source !== null) {
for (var nextKey in source) {
if (source.hasOwnProperty(nextKey)) {
output[nextKey] = source[nextKey];
}
}
}
}
return output;
};

View File

@ -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'

View File

@ -0,0 +1,10 @@
{
"private": true,
"dependencies": {
"isomorphic-fetch": "^2.2.1"
},
"devDependencies": {
"typescript": "^1.8.10",
"typings": "^0.8.1"
}
}

View File

@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es5"
},
"exclude": [
"node_modules",
"typings/browser",
"typings/main",
"typings/main.d.ts"
]
}

View File

@ -0,0 +1,9 @@
{
"version": false,
"dependencies": {},
"ambientDependencies": {
"es6-promise": "registry:dt/es6-promise#0.0.0+20160423074304",
"node": "registry:dt/node#4.0.0+20160423143914",
"isomorphic-fetch": "github:leonyu/DefinitelyTyped/isomorphic-fetch/isomorphic-fetch.d.ts#isomorphic-fetch-fix-module"
}
}

View File

@ -0,0 +1,33 @@
package io.swagger.codegen.options;
import com.google.common.collect.ImmutableMap;
import io.swagger.codegen.CodegenConstants;
import java.util.Map;
public class TypeScriptFetchClientOptionsProvider implements OptionsProvider {
public static final String SORT_PARAMS_VALUE = "false";
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
public static final Boolean SUPPORTS_ES6_VALUE = false;
public static final String MODEL_PROPERTY_NAMING_VALUE = "camelCase";
@Override
public String getLanguage() {
return "typescript-fetch";
}
@Override
public Map<String, String> createOptions() {
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
return builder.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
.put(CodegenConstants.MODEL_PROPERTY_NAMING, MODEL_PROPERTY_NAMING_VALUE)
.put(CodegenConstants.SUPPORTS_ES6, String.valueOf(SUPPORTS_ES6_VALUE))
.build();
}
@Override
public boolean isServer() {
return false;
}
}

View File

@ -0,0 +1,36 @@
package io.swagger.codegen.typescriptfetch;
import io.swagger.codegen.AbstractOptionsTest;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.languages.TypeScriptFetchClientCodegen;
import io.swagger.codegen.options.TypeScriptFetchClientOptionsProvider;
import mockit.Expectations;
import mockit.Tested;
public class TypeScriptFetchClientOptionsTest extends AbstractOptionsTest {
@Tested
private TypeScriptFetchClientCodegen clientCodegen;
public TypeScriptFetchClientOptionsTest() {
super(new TypeScriptFetchClientOptionsProvider());
}
@Override
protected CodegenConfig getCodegenConfig() {
return clientCodegen;
}
@SuppressWarnings("unused")
@Override
protected void setExpectations() {
new Expectations(clientCodegen) {{
clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(TypeScriptFetchClientOptionsProvider.SORT_PARAMS_VALUE));
times = 1;
clientCodegen.setModelPropertyNaming(TypeScriptFetchClientOptionsProvider.MODEL_PROPERTY_NAMING_VALUE);
times = 1;
clientCodegen.setSupportsES6(TypeScriptFetchClientOptionsProvider.SUPPORTS_ES6_VALUE);
times = 1;
}};
}
}

View File

@ -0,0 +1,177 @@
package io.swagger.codegen.typescriptfetch;
import com.google.common.collect.Sets;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.CodegenProperty;
import io.swagger.codegen.DefaultCodegen;
import io.swagger.codegen.languages.TypeScriptFetchClientCodegen;
import io.swagger.models.ArrayModel;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.*;
import org.testng.Assert;
import org.testng.annotations.Test;
@SuppressWarnings("static-method")
public class TypeScriptFetchModelTest {
@Test(description = "convert a simple TypeScript Angular model")
public void simpleModelTest() {
final Model model = new ModelImpl()
.description("a sample model")
.property("id", new LongProperty())
.property("name", new StringProperty())
.property("createdAt", new DateTimeProperty())
.required("id")
.required("name");
final DefaultCodegen codegen = new TypeScriptFetchClientCodegen();
final CodegenModel cm = codegen.fromModel("sample", model);
Assert.assertEquals(cm.name, "sample");
Assert.assertEquals(cm.classname, "Sample");
Assert.assertEquals(cm.description, "a sample model");
Assert.assertEquals(cm.vars.size(), 3);
final CodegenProperty property1 = cm.vars.get(0);
Assert.assertEquals(property1.baseName, "id");
Assert.assertEquals(property1.datatype, "number");
Assert.assertEquals(property1.name, "id");
Assert.assertEquals(property1.defaultValue, "null");
Assert.assertEquals(property1.baseType, "number");
Assert.assertTrue(property1.hasMore);
Assert.assertTrue(property1.required);
Assert.assertTrue(property1.isNotContainer);
final CodegenProperty property2 = cm.vars.get(1);
Assert.assertEquals(property2.baseName, "name");
Assert.assertEquals(property2.datatype, "string");
Assert.assertEquals(property2.name, "name");
Assert.assertEquals(property2.defaultValue, "null");
Assert.assertEquals(property2.baseType, "string");
Assert.assertTrue(property2.hasMore);
Assert.assertTrue(property2.required);
Assert.assertTrue(property2.isNotContainer);
final CodegenProperty property3 = cm.vars.get(2);
Assert.assertEquals(property3.baseName, "createdAt");
Assert.assertEquals(property3.complexType, null);
Assert.assertEquals(property3.datatype, "Date");
Assert.assertEquals(property3.name, "createdAt");
Assert.assertEquals(property3.defaultValue, "null");
Assert.assertNull(property3.hasMore);
Assert.assertNull(property3.required);
Assert.assertTrue(property3.isNotContainer);
}
@Test(description = "convert a model with list property")
public void listPropertyTest() {
final Model model = new ModelImpl()
.description("a sample model")
.property("id", new LongProperty())
.property("urls", new ArrayProperty().items(new StringProperty()))
.required("id");
final DefaultCodegen codegen = new TypeScriptFetchClientCodegen();
final CodegenModel cm = codegen.fromModel("sample", model);
Assert.assertEquals(cm.name, "sample");
Assert.assertEquals(cm.classname, "Sample");
Assert.assertEquals(cm.description, "a sample model");
Assert.assertEquals(cm.vars.size(), 2);
final CodegenProperty property1 = cm.vars.get(0);
Assert.assertEquals(property1.baseName, "id");
Assert.assertEquals(property1.datatype, "number");
Assert.assertEquals(property1.name, "id");
Assert.assertEquals(property1.defaultValue, "null");
Assert.assertEquals(property1.baseType, "number");
Assert.assertTrue(property1.hasMore);
Assert.assertTrue(property1.required);
Assert.assertTrue(property1.isNotContainer);
final CodegenProperty property2 = cm.vars.get(1);
Assert.assertEquals(property2.baseName, "urls");
Assert.assertEquals(property2.datatype, "Array<string>");
Assert.assertEquals(property2.name, "urls");
Assert.assertEquals(property2.baseType, "Array");
Assert.assertNull(property2.hasMore);
Assert.assertNull(property2.required);
Assert.assertTrue(property2.isContainer);
}
@Test(description = "convert a model with complex property")
public void complexPropertyTest() {
final Model model = new ModelImpl()
.description("a sample model")
.property("children", new RefProperty("#/definitions/Children"));
final DefaultCodegen codegen = new TypeScriptFetchClientCodegen();
final CodegenModel cm = codegen.fromModel("sample", model);
Assert.assertEquals(cm.name, "sample");
Assert.assertEquals(cm.classname, "Sample");
Assert.assertEquals(cm.description, "a sample model");
Assert.assertEquals(cm.vars.size(), 1);
final CodegenProperty property1 = cm.vars.get(0);
Assert.assertEquals(property1.baseName, "children");
Assert.assertEquals(property1.datatype, "Children");
Assert.assertEquals(property1.name, "children");
Assert.assertEquals(property1.defaultValue, "null");
Assert.assertEquals(property1.baseType, "Children");
Assert.assertNull(property1.required);
Assert.assertTrue(property1.isNotContainer);
}
@Test(description = "convert a model with complex list property")
public void complexListPropertyTest() {
final Model model = new ModelImpl()
.description("a sample model")
.property("children", new ArrayProperty()
.items(new RefProperty("#/definitions/Children")));
final DefaultCodegen codegen = new TypeScriptFetchClientCodegen();
final CodegenModel cm = codegen.fromModel("sample", model);
Assert.assertEquals(cm.name, "sample");
Assert.assertEquals(cm.classname, "Sample");
Assert.assertEquals(cm.description, "a sample model");
Assert.assertEquals(cm.vars.size(), 1);
final CodegenProperty property1 = cm.vars.get(0);
Assert.assertEquals(property1.baseName, "children");
Assert.assertEquals(property1.complexType, "Children");
Assert.assertEquals(property1.datatype, "Array<Children>");
Assert.assertEquals(property1.name, "children");
Assert.assertEquals(property1.baseType, "Array");
Assert.assertNull(property1.required);
Assert.assertTrue(property1.isContainer);
}
@Test(description = "convert an array model")
public void arrayModelTest() {
final Model model = new ArrayModel()
.description("an array model")
.items(new RefProperty("#/definitions/Children"));
final DefaultCodegen codegen = new TypeScriptFetchClientCodegen();
final CodegenModel cm = codegen.fromModel("sample", model);
Assert.assertEquals(cm.name, "sample");
Assert.assertEquals(cm.classname, "Sample");
Assert.assertEquals(cm.description, "an array model");
Assert.assertEquals(cm.vars.size(), 0);
}
@Test(description = "convert a map model")
public void mapModelTest() {
final Model model = new ModelImpl()
.description("a map model")
.additionalProperties(new RefProperty("#/definitions/Children"));
final DefaultCodegen codegen = new TypeScriptFetchClientCodegen();
final CodegenModel cm = codegen.fromModel("sample", model);
Assert.assertEquals(cm.name, "sample");
Assert.assertEquals(cm.classname, "Sample");
Assert.assertEquals(cm.description, "a map model");
Assert.assertEquals(cm.vars.size(), 0);
Assert.assertEquals(cm.imports.size(), 1);
Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("Children")).size(), 1);
}
}

View File

@ -0,0 +1,859 @@
import * as querystring from 'querystring';
import * as fetch from 'isomorphic-fetch';
import {assign} from './assign';
export interface Category {
"id"?: number;
"name"?: string;
}
export interface Order {
"id"?: number;
"petId"?: number;
"quantity"?: number;
"shipDate"?: Date;
/**
* Order Status
*/
"status"?: Order.StatusEnum;
"complete"?: boolean;
}
export enum StatusEnum {
placed = <any> 'placed',
approved = <any> 'approved',
delivered = <any> 'delivered'
}
export interface Pet {
"id"?: number;
"category"?: Category;
"name": string;
"photoUrls": Array<string>;
"tags"?: Array<Tag>;
/**
* pet status in the store
*/
"status"?: Pet.StatusEnum;
}
export enum StatusEnum {
available = <any> 'available',
pending = <any> 'pending',
sold = <any> 'sold'
}
export interface Tag {
"id"?: number;
"name"?: string;
}
export interface User {
"id"?: number;
"username"?: string;
"firstName"?: string;
"lastName"?: string;
"email"?: string;
"password"?: string;
"phone"?: string;
/**
* User Status
*/
"userStatus"?: number;
}
//export namespace {
'use strict';
export class PetApi {
protected basePath = 'http://petstore.swagger.io/v2';
public defaultHeaders : any = {};
constructor(basePath?: string) {
if (basePath) {
this.basePath = basePath;
}
}
/**
* Add a new pet to the store
*
* @param body Pet object that needs to be added to the store
*/
public addPet (params: { body?: Pet; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<{}> {
const localVarPath = this.basePath + '/pet';
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
headerParams['Content-Type'] = 'application/json';
let fetchParams = {
method: 'POST',
headers: headerParams,
body: JSON.stringify(params.body),
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
/**
* Deletes a pet
*
* @param petId Pet id to delete
* @param apiKey
*/
public deletePet (params: { petId: number; apiKey?: string; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<{}> {
const localVarPath = this.basePath + '/pet/{petId}'
.replace('{' + 'petId' + '}', String(params.petId));
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
// verify required parameter 'petId' is set
if (params.petId == null) {
throw new Error('Missing required parameter petId when calling deletePet');
}
headerParams['api_key'] = params.apiKey;
let fetchParams = {
method: 'DELETE',
headers: headerParams,
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
/**
* Finds Pets by status
* Multiple status values can be provided with comma seperated strings
* @param status Status values that need to be considered for filter
*/
public findPetsByStatus (params: { status?: Array<string>; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<Array<Pet>> {
const localVarPath = this.basePath + '/pet/findByStatus';
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
if (params.status !== undefined) {
queryParameters['status'] = params.status;
}
let fetchParams = {
method: 'GET',
headers: headerParams,
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
/**
* Finds Pets by tags
* Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
* @param tags Tags to filter by
*/
public findPetsByTags (params: { tags?: Array<string>; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<Array<Pet>> {
const localVarPath = this.basePath + '/pet/findByTags';
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
if (params.tags !== undefined) {
queryParameters['tags'] = params.tags;
}
let fetchParams = {
method: 'GET',
headers: headerParams,
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
/**
* Find pet by ID
* Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
* @param petId ID of pet that needs to be fetched
*/
public getPetById (params: { petId: number; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<Pet> {
const localVarPath = this.basePath + '/pet/{petId}'
.replace('{' + 'petId' + '}', String(params.petId));
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
// verify required parameter 'petId' is set
if (params.petId == null) {
throw new Error('Missing required parameter petId when calling getPetById');
}
let fetchParams = {
method: 'GET',
headers: headerParams,
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
/**
* Update an existing pet
*
* @param body Pet object that needs to be added to the store
*/
public updatePet (params: { body?: Pet; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<{}> {
const localVarPath = this.basePath + '/pet';
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
headerParams['Content-Type'] = 'application/json';
let fetchParams = {
method: 'PUT',
headers: headerParams,
body: JSON.stringify(params.body),
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
/**
* Updates a pet in the store with form data
*
* @param petId ID of pet that needs to be updated
* @param name Updated name of the pet
* @param status Updated status of the pet
*/
public updatePetWithForm (params: { petId: string; name?: string; status?: string; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<{}> {
const localVarPath = this.basePath + '/pet/{petId}'
.replace('{' + 'petId' + '}', String(params.petId));
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
let formParams: any = {};
headerParams['Content-Type'] = 'application/x-www-form-urlencoded';
// verify required parameter 'petId' is set
if (params.petId == null) {
throw new Error('Missing required parameter petId when calling updatePetWithForm');
}
formParams['name'] = params.name;
formParams['status'] = params.status;
let fetchParams = {
method: 'POST',
headers: headerParams,
body: querystring.stringify(formParams),
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
/**
* uploads an image
*
* @param petId ID of pet to update
* @param additionalMetadata Additional data to pass to server
* @param file file to upload
*/
public uploadFile (params: { petId: number; additionalMetadata?: string; file?: any; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<{}> {
const localVarPath = this.basePath + '/pet/{petId}/uploadImage'
.replace('{' + 'petId' + '}', String(params.petId));
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
let formParams: any = {};
headerParams['Content-Type'] = 'application/x-www-form-urlencoded';
// verify required parameter 'petId' is set
if (params.petId == null) {
throw new Error('Missing required parameter petId when calling uploadFile');
}
formParams['additionalMetadata'] = params.additionalMetadata;
formParams['file'] = params.file;
let fetchParams = {
method: 'POST',
headers: headerParams,
body: querystring.stringify(formParams),
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
}
//}
//export namespace {
'use strict';
export class StoreApi {
protected basePath = 'http://petstore.swagger.io/v2';
public defaultHeaders : any = {};
constructor(basePath?: string) {
if (basePath) {
this.basePath = basePath;
}
}
/**
* Delete purchase order by ID
* For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
* @param orderId ID of the order that needs to be deleted
*/
public deleteOrder (params: { orderId: string; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<{}> {
const localVarPath = this.basePath + '/store/order/{orderId}'
.replace('{' + 'orderId' + '}', String(params.orderId));
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
// verify required parameter 'orderId' is set
if (params.orderId == null) {
throw new Error('Missing required parameter orderId when calling deleteOrder');
}
let fetchParams = {
method: 'DELETE',
headers: headerParams,
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
/**
* Returns pet inventories by status
* Returns a map of status codes to quantities
*/
public getInventory (params: { }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<{ [key: string]: number; }> {
const localVarPath = this.basePath + '/store/inventory';
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
let fetchParams = {
method: 'GET',
headers: headerParams,
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
/**
* Find purchase order by ID
* For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generated exceptions
* @param orderId ID of pet that needs to be fetched
*/
public getOrderById (params: { orderId: string; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<Order> {
const localVarPath = this.basePath + '/store/order/{orderId}'
.replace('{' + 'orderId' + '}', String(params.orderId));
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
// verify required parameter 'orderId' is set
if (params.orderId == null) {
throw new Error('Missing required parameter orderId when calling getOrderById');
}
let fetchParams = {
method: 'GET',
headers: headerParams,
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
/**
* Place an order for a pet
*
* @param body order placed for purchasing the pet
*/
public placeOrder (params: { body?: Order; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<Order> {
const localVarPath = this.basePath + '/store/order';
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
headerParams['Content-Type'] = 'application/json';
let fetchParams = {
method: 'POST',
headers: headerParams,
body: JSON.stringify(params.body),
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
}
//}
//export namespace {
'use strict';
export class UserApi {
protected basePath = 'http://petstore.swagger.io/v2';
public defaultHeaders : any = {};
constructor(basePath?: string) {
if (basePath) {
this.basePath = basePath;
}
}
/**
* Create user
* This can only be done by the logged in user.
* @param body Created user object
*/
public createUser (params: { body?: User; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<{}> {
const localVarPath = this.basePath + '/user';
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
headerParams['Content-Type'] = 'application/json';
let fetchParams = {
method: 'POST',
headers: headerParams,
body: JSON.stringify(params.body),
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
/**
* Creates list of users with given input array
*
* @param body List of user object
*/
public createUsersWithArrayInput (params: { body?: Array<User>; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<{}> {
const localVarPath = this.basePath + '/user/createWithArray';
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
headerParams['Content-Type'] = 'application/json';
let fetchParams = {
method: 'POST',
headers: headerParams,
body: JSON.stringify(params.body),
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
/**
* Creates list of users with given input array
*
* @param body List of user object
*/
public createUsersWithListInput (params: { body?: Array<User>; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<{}> {
const localVarPath = this.basePath + '/user/createWithList';
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
headerParams['Content-Type'] = 'application/json';
let fetchParams = {
method: 'POST',
headers: headerParams,
body: JSON.stringify(params.body),
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
/**
* Delete user
* This can only be done by the logged in user.
* @param username The name that needs to be deleted
*/
public deleteUser (params: { username: string; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<{}> {
const localVarPath = this.basePath + '/user/{username}'
.replace('{' + 'username' + '}', String(params.username));
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
// verify required parameter 'username' is set
if (params.username == null) {
throw new Error('Missing required parameter username when calling deleteUser');
}
let fetchParams = {
method: 'DELETE',
headers: headerParams,
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
/**
* Get user by user name
*
* @param username The name that needs to be fetched. Use user1 for testing.
*/
public getUserByName (params: { username: string; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<User> {
const localVarPath = this.basePath + '/user/{username}'
.replace('{' + 'username' + '}', String(params.username));
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
// verify required parameter 'username' is set
if (params.username == null) {
throw new Error('Missing required parameter username when calling getUserByName');
}
let fetchParams = {
method: 'GET',
headers: headerParams,
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
/**
* Logs user into the system
*
* @param username The user name for login
* @param password The password for login in clear text
*/
public loginUser (params: { username?: string; password?: string; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<string> {
const localVarPath = this.basePath + '/user/login';
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
if (params.username !== undefined) {
queryParameters['username'] = params.username;
}
if (params.password !== undefined) {
queryParameters['password'] = params.password;
}
let fetchParams = {
method: 'GET',
headers: headerParams,
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
/**
* Logs out current logged in user session
*
*/
public logoutUser (params: { }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<{}> {
const localVarPath = this.basePath + '/user/logout';
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
let fetchParams = {
method: 'GET',
headers: headerParams,
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
/**
* Updated user
* This can only be done by the logged in user.
* @param username name that need to be deleted
* @param body Updated user object
*/
public updateUser (params: { username: string; body?: User; }, extraQueryParams?: any, extraFetchParams?: any ) : Promise<{}> {
const localVarPath = this.basePath + '/user/{username}'
.replace('{' + 'username' + '}', String(params.username));
let queryParameters: any = assign({}, extraQueryParams);
let headerParams: any = assign({}, this.defaultHeaders);
headerParams['Content-Type'] = 'application/json';
// verify required parameter 'username' is set
if (params.username == null) {
throw new Error('Missing required parameter username when calling updateUser');
}
let fetchParams = {
method: 'PUT',
headers: headerParams,
body: JSON.stringify(params.body),
};
if (extraFetchParams) {
fetchParams = assign(fetchParams, extraFetchParams);
}
let localVarPathWithQueryParameters = localVarPath + (localVarPath.indexOf('?') !== -1 ? '&' : '?') + querystring.stringify(queryParameters);
return fetch(localVarPathWithQueryParameters, fetchParams).then((response) => {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
var error = new Error(response.statusText);
error['response'] = response;
throw error;
}
});
}
}
//}

View File

@ -0,0 +1,18 @@
export function assign (target, ...args) {
'use strict';
if (target === undefined || target === null) {
throw new TypeError('Cannot convert undefined or null to object');
}
var output = Object(target);
for (let source of args) {
if (source !== undefined && source !== null) {
for (var nextKey in source) {
if (source.hasOwnProperty(nextKey)) {
output[nextKey] = source[nextKey];
}
}
}
}
return output;
};

View File

@ -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="GIT_USER_ID"
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
fi
if [ "$git_repo_id" = "" ]; then
git_repo_id="GIT_REPO_ID"
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
fi
if [ "$release_note" = "" ]; then
release_note="Minor update"
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'

View File

@ -0,0 +1,10 @@
{
"private": true,
"dependencies": {
"isomorphic-fetch": "^2.2.1"
},
"devDependencies": {
"typescript": "^1.8.10",
"typings": "^0.8.1"
}
}

View File

@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es5"
},
"exclude": [
"node_modules",
"typings/browser",
"typings/main",
"typings/main.d.ts"
]
}

View File

@ -0,0 +1,9 @@
{
"version": false,
"dependencies": {},
"ambientDependencies": {
"es6-promise": "registry:dt/es6-promise#0.0.0+20160423074304",
"node": "registry:dt/node#4.0.0+20160423143914",
"isomorphic-fetch": "github:leonyu/DefinitelyTyped/isomorphic-fetch/isomorphic-fetch.d.ts#isomorphic-fetch-fix-module"
}
}