Merge branch 'leonyu-update_typings_json'

This commit is contained in:
wing328 2016-05-10 18:01:42 +08:00
commit e756ba081a
28 changed files with 3103 additions and 7 deletions

10
.gitignore vendored
View File

@ -116,3 +116,13 @@ samples/client/petstore/python/.venv/
# ts
samples/client/petstore/typescript-node/npm/node_modules
samples/client/petstore/typescript-fetch/with-package-metadata/node_modules
samples/client/petstore/typescript-fetch/with-package-metadata/dist
samples/client/petstore/typescript-fetch/with-package-metadata/typings
samples/client/petstore/typescript-fetch/default/node_modules
samples/client/petstore/typescript-fetch/default/dist
samples/client/petstore/typescript-fetch/default/typings
samples/client/petstore/typescript-fetch/default-es6/node_modules
samples/client/petstore/typescript-fetch/default-es6/dist
samples/client/petstore/typescript-fetch/default-es6/typings

View File

@ -0,0 +1,5 @@
#!/bin/sh
./bin/typescript-fetch-petstore-target-es6.sh
./bin/typescript-fetch-petstore-target-with-package-metadata.sh
./bin/typescript-fetch-petstore.sh

View File

@ -24,11 +24,10 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
@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("api.mustache", "", "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("assign.ts", "", "assign.ts"));
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
supportingFiles.add(new SupportingFile("package.json.mustache", "", "package.json"));
supportingFiles.add(new SupportingFile("typings.json.mustache", "", "typings.json"));
supportingFiles.add(new SupportingFile("tsconfig.json.mustache", "", "tsconfig.json"));

View File

@ -0,0 +1,44 @@
# TypeScript-Fetch
This generator creates TypeScript/JavaScript client that utilizes [Fetch API](https://fetch.spec.whatwg.org/). The codegen Node module can be used in the following environments:
* Node.JS
* Webpack
* Browserify
It is usable in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `typings` in `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html))
### Installation ###
`swagger-codegen` does not generate JavaScript directly. The codegen Node module comes with `package.json` that bundles `typescript` and `typings` so it can self-compile. The self-compile is normally run automatically via the `npm` `postinstall` script of `npm install`.
CAVEAT: Due to [privilege implications](https://docs.npmjs.com/misc/scripts#user), `npm` may skip `postinstall` script if the user is `root`. You would need to manually invoke `npm install` or `npm run postinstall` for the codegen module if that's the case.
#### NPM repository ###
If you remove `"private": true` from `package.json`, you may publish the module to NPM. In which case, you would be able to install the module as any other NPM module.
It maybe useful to use [scoped packages](https://docs.npmjs.com/misc/scope).
#### NPM install local file ###
You should be able to directly install the module using `npm install file:///codegen_path`.
NOTES: If you do `npm install file:///codegen_path --save` NPM might convert your path to relative path, maybe have adverse affect. `npm install` and `npm shrinkwrap` may misbehave if the installation path is not absolute.
#### direct copy/symlink ###
You may also simply copy or symlink the codegen into a directly under your project. The syntax of the usage would differ if you take this route. (See below)
### Usage ###
With ES6 module syntax, the following syntaxes are supported:
```
import * as localName from 'npmName';
import {operationId} from 'npmName';
import * as localName from './symlinkDir';
import {operationId} from './symlinkDir';
```
With CommonJS, the following syntaxes are supported:
```
import localName = require('npmName');
import localName = require('./symlinkDir')';
```

View File

@ -2,8 +2,9 @@
"name": "{{#npmName}}{{{npmName}}}{{/npmName}}{{^npmName}}typescript-fetch-api{{/npmName}}",
"version": "{{#npmVersion}}{{{npmVersion}}}{{/npmVersion}}{{^npmVersion}}0.0.0{{/npmVersion}}",
"private": true,
"main": "dist/api.js",
"browser": "dist/api.js",
"main": "./dist/api.js",
"browser": "./dist/api.js",
"typings": "./dist/api.d.ts",
"dependencies": {
"isomorphic-fetch": "^2.2.1"
},

View File

@ -1,11 +1,13 @@
{
"compilerOptions": {
"declaration": true,
"target": "{{#supportsES6}}es6{{/supportsES6}}{{^supportsES6}}es5{{/supportsES6}}",
"module": "commonjs",
"noImplicitAny": true,
"outDir": "dist"
},
"exclude": [
"dist",
"node_modules",
"typings/browser",
"typings/main",

View File

@ -4,6 +4,6 @@
"ambientDependencies": {
{{^supportsES6}} "es6-promise": "registry:dt/es6-promise#0.0.0+20160423074304",
{{/supportsES6}} "node": "registry:dt/node#4.0.0+20160423143914",
"isomorphic-fetch": "github:leonyu/DefinitelyTyped/isomorphic-fetch/isomorphic-fetch.d.ts#isomorphic-fetch-fix-module"
"isomorphic-fetch": "registry:dt/isomorphic-fetch#0.0.0+20160505171433"
}
}

View File

@ -0,0 +1,44 @@
# TypeScript-Fetch
This generator creates TypeScript/JavaScript client that utilizes [Fetch API](https://fetch.spec.whatwg.org/). The codegen Node module can be used in the following environments:
* Node.JS
* Webpack
* Browserify
It is usable in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `typings` in `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html))
### Installation ###
`swagger-codegen` does not generate JavaScript directly. The codegen Node module comes with `package.json` that bundles `typescript` and `typings` so it can self-compile. The self-compile is normally run automatically via the `npm` `postinstall` script of `npm install`.
CAVEAT: Due to [privilege implications](https://docs.npmjs.com/misc/scripts#user), `npm` may skip `postinstall` script if the user is `root`. You would need to manually invoke `npm install` or `npm run postinstall` for the codegen module if that's the case.
#### NPM repository ###
If you remove `"private": true` from `package.json`, you may publish the module to NPM. In which case, you would be able to install the module as any other NPM module.
It maybe useful to use [scoped packages](https://docs.npmjs.com/misc/scope).
#### NPM install local file ###
You should be able to directly install the module using `npm install file:///codegen_path`.
NOTES: If you do `npm install file:///codegen_path --save` NPM might convert your path to relative path, maybe have adverse affect. `npm install` and `npm shrinkwrap` may misbehave if the installation path is not absolute.
#### direct copy/symlink ###
You may also simply copy or symlink the codegen into a directly under your project. The syntax of the usage would differ if you take this route. (See below)
### Usage ###
With ES6 module syntax, the following syntaxes are supported:
```
import * as localName from 'npmName';
import {operationId} from 'npmName';
import * as localName from './symlinkDir';
import {operationId} from './symlinkDir';
```
With CommonJS, the following syntaxes are supported:
```
import localName = require('npmName');
import localName = require('./symlinkDir')';
```

View File

@ -0,0 +1,855 @@
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 namespace Order {
export type StatusEnum = 'placed' | 'approved' | '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 namespace Pet {
export type StatusEnum = 'available' | 'pending' | '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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).response = response;
throw error;
}
});
}
}
//}

View File

@ -0,0 +1,18 @@
export function assign (target: any, ...args: any[]) {
'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,18 @@
{
"name": "typescript-fetch-api",
"version": "0.0.0",
"private": true,
"main": "./dist/api.js",
"browser": "./dist/api.js",
"typings": "./dist/api.d.ts",
"dependencies": {
"isomorphic-fetch": "^2.2.1"
},
"scripts" : {
"install" : "typings install && tsc"
},
"devDependencies": {
"typescript": "^1.8.10",
"typings": "^0.8.1"
}
}

View File

@ -0,0 +1,16 @@
{
"compilerOptions": {
"declaration": true,
"target": "es6",
"module": "commonjs",
"noImplicitAny": true,
"outDir": "dist"
},
"exclude": [
"dist",
"node_modules",
"typings/browser",
"typings/main",
"typings/main.d.ts"
]
}

View File

@ -0,0 +1,8 @@
{
"version": false,
"dependencies": {},
"ambientDependencies": {
"node": "registry:dt/node#4.0.0+20160423143914",
"isomorphic-fetch": "registry:dt/isomorphic-fetch#0.0.0+20160505171433"
}
}

View File

@ -0,0 +1,44 @@
# TypeScript-Fetch
This generator creates TypeScript/JavaScript client that utilizes [Fetch API](https://fetch.spec.whatwg.org/). The codegen Node module can be used in the following environments:
* Node.JS
* Webpack
* Browserify
It is usable in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `typings` in `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html))
### Installation ###
`swagger-codegen` does not generate JavaScript directly. The codegen Node module comes with `package.json` that bundles `typescript` and `typings` so it can self-compile. The self-compile is normally run automatically via the `npm` `postinstall` script of `npm install`.
CAVEAT: Due to [privilege implications](https://docs.npmjs.com/misc/scripts#user), `npm` may skip `postinstall` script if the user is `root`. You would need to manually invoke `npm install` or `npm run postinstall` for the codegen module if that's the case.
#### NPM repository ###
If you remove `"private": true` from `package.json`, you may publish the module to NPM. In which case, you would be able to install the module as any other NPM module.
It maybe useful to use [scoped packages](https://docs.npmjs.com/misc/scope).
#### NPM install local file ###
You should be able to directly install the module using `npm install file:///codegen_path`.
NOTES: If you do `npm install file:///codegen_path --save` NPM might convert your path to relative path, maybe have adverse affect. `npm install` and `npm shrinkwrap` may misbehave if the installation path is not absolute.
#### direct copy/symlink ###
You may also simply copy or symlink the codegen into a directly under your project. The syntax of the usage would differ if you take this route. (See below)
### Usage ###
With ES6 module syntax, the following syntaxes are supported:
```
import * as localName from 'npmName';
import {operationId} from 'npmName';
import * as localName from './symlinkDir';
import {operationId} from './symlinkDir';
```
With CommonJS, the following syntaxes are supported:
```
import localName = require('npmName');
import localName = require('./symlinkDir')';
```

View File

@ -0,0 +1,855 @@
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 namespace Order {
export type StatusEnum = 'placed' | 'approved' | '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 namespace Pet {
export type StatusEnum = 'available' | 'pending' | '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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).response = response;
throw error;
}
});
}
}
//}

View File

@ -0,0 +1,18 @@
export function assign (target: any, ...args: any[]) {
'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,18 @@
{
"name": "typescript-fetch-api",
"version": "0.0.0",
"private": true,
"main": "./dist/api.js",
"browser": "./dist/api.js",
"typings": "./dist/api.d.ts",
"dependencies": {
"isomorphic-fetch": "^2.2.1"
},
"scripts" : {
"install" : "typings install && tsc"
},
"devDependencies": {
"typescript": "^1.8.10",
"typings": "^0.8.1"
}
}

View File

@ -0,0 +1,16 @@
{
"compilerOptions": {
"declaration": true,
"target": "es5",
"module": "commonjs",
"noImplicitAny": true,
"outDir": "dist"
},
"exclude": [
"dist",
"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": "registry:dt/isomorphic-fetch#0.0.0+20160505171433"
}
}

View File

@ -0,0 +1,44 @@
# TypeScript-Fetch
This generator creates TypeScript/JavaScript client that utilizes [Fetch API](https://fetch.spec.whatwg.org/). The codegen Node module can be used in the following environments:
* Node.JS
* Webpack
* Browserify
It is usable in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `typings` in `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html))
### Installation ###
`swagger-codegen` does not generate JavaScript directly. The codegen Node module comes with `package.json` that bundles `typescript` and `typings` so it can self-compile. The self-compile is normally run automatically via the `npm` `postinstall` script of `npm install`.
CAVEAT: Due to [privilege implications](https://docs.npmjs.com/misc/scripts#user), `npm` may skip `postinstall` script if the user is `root`. You would need to manually invoke `npm install` or `npm run postinstall` for the codegen module if that's the case.
#### NPM repository ###
If you remove `"private": true` from `package.json`, you may publish the module to NPM. In which case, you would be able to install the module as any other NPM module.
It maybe useful to use [scoped packages](https://docs.npmjs.com/misc/scope).
#### NPM install local file ###
You should be able to directly install the module using `npm install file:///codegen_path`.
NOTES: If you do `npm install file:///codegen_path --save` NPM might convert your path to relative path, maybe have adverse affect. `npm install` and `npm shrinkwrap` may misbehave if the installation path is not absolute.
#### direct copy/symlink ###
You may also simply copy or symlink the codegen into a directly under your project. The syntax of the usage would differ if you take this route. (See below)
### Usage ###
With ES6 module syntax, the following syntaxes are supported:
```
import * as localName from 'npmName';
import {operationId} from 'npmName';
import * as localName from './symlinkDir';
import {operationId} from './symlinkDir';
```
With CommonJS, the following syntaxes are supported:
```
import localName = require('npmName');
import localName = require('./symlinkDir')';
```

View File

@ -0,0 +1,855 @@
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 namespace Order {
export type StatusEnum = 'placed' | 'approved' | '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 namespace Pet {
export type StatusEnum = 'available' | 'pending' | '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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).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 {
let error = new Error(response.statusText);
(error as any).response = response;
throw error;
}
});
}
}
//}

View File

@ -0,0 +1,18 @@
export function assign (target: any, ...args: any[]) {
'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,18 @@
{
"name": "@swagger/typescript-fetch-petstore",
"version": "0.0.1",
"private": true,
"main": "./dist/api.js",
"browser": "./dist/api.js",
"typings": "./dist/api.d.ts",
"dependencies": {
"isomorphic-fetch": "^2.2.1"
},
"scripts" : {
"install" : "typings install && tsc"
},
"devDependencies": {
"typescript": "^1.8.10",
"typings": "^0.8.1"
}
}

View File

@ -0,0 +1,16 @@
{
"compilerOptions": {
"declaration": true,
"target": "es5",
"module": "commonjs",
"noImplicitAny": true,
"outDir": "dist"
},
"exclude": [
"dist",
"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": "registry:dt/isomorphic-fetch#0.0.0+20160505171433"
}
}