start adding packaging info to nodejs client.

This commit is contained in:
Kristof Vrolijkx
2016-04-25 08:08:19 +02:00
parent 4ad7ea6556
commit 28f444e808
21 changed files with 159 additions and 568 deletions

View File

@@ -26,6 +26,6 @@ fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-angular2 -c bin/typescript-angular2-petstore-with-npm.json -o samples/client/petstore/typescript-angular2/npm"
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-angular2 -c bin/typescript-petstore-npm.json -o samples/client/petstore/typescript-angular2/npm"
java $JAVA_OPTS -jar $executable $ags

View File

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

View File

@@ -30,7 +30,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
outputFolder = "generated-code/typescript-angular";
modelTemplateFiles.put("model.mustache", ".ts");
apiTemplateFiles.put("api.mustache", ".ts");
embeddedTemplateDir = templateDir = "TypeScript-Angular";
embeddedTemplateDir = templateDir = "typescript-angular";
apiPackage = "API.Client";
modelPackage = "API.Client";
}

View File

@@ -1,8 +1,26 @@
package io.swagger.codegen.languages;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import io.swagger.codegen.SupportingFile;
public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen {
private static final Logger LOGGER = LoggerFactory.getLogger(TypeScriptNodeClientCodegen.class);
private static final SimpleDateFormat SNAPSHOT_SUFFIX_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");
public static final String NPM_NAME = "npmName";
public static final String NPM_VERSION = "npmVersion";
public static final String NPM_REPOSITORY = "npmRepository";
public static final String SNAPSHOT = "snapshot";
protected String npmName = null;
protected String npmVersion = "1.0.0";
protected String npmRepository = null;
@Override
public String getName() {
@@ -14,18 +32,71 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen
return "Generates a TypeScript nodejs client library.";
}
@Override
@Override
public void processOpts() {
super.processOpts();
supportingFiles.add(new SupportingFile("api.mustache", null, "api.ts"));
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
//supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
LOGGER.warn("check additionals: " + additionalProperties.get(NPM_NAME));
if(additionalProperties.containsKey(NPM_NAME)) {
addNpmPackageGeneration();
}
}
private void addNpmPackageGeneration() {
if(additionalProperties.containsKey(NPM_NAME)) {
this.setNpmName(additionalProperties.get(NPM_NAME).toString());
}
if (additionalProperties.containsKey(NPM_VERSION)) {
this.setNpmVersion(additionalProperties.get(NPM_VERSION).toString());
}
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
}
additionalProperties.put(NPM_VERSION, npmVersion);
if (additionalProperties.containsKey(NPM_REPOSITORY)) {
this.setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString());
}
//Files for building our lib
supportingFiles.add(new SupportingFile("package.mustache", getPackageRootDirectory(), "package.json"));
supportingFiles.add(new SupportingFile("typings.mustache", getPackageRootDirectory(), "typings.json"));
supportingFiles.add(new SupportingFile("tsconfig.mustache", getPackageRootDirectory(), "tsconfig.json"));
}
private String getPackageRootDirectory() {
String indexPackage = modelPackage.substring(0, Math.max(0, modelPackage.lastIndexOf('.')));
return indexPackage.replace('.', File.separatorChar);
}
public TypeScriptNodeClientCodegen() {
super();
outputFolder = "generated-code/typescript-node";
embeddedTemplateDir = templateDir = "TypeScript-node";
embeddedTemplateDir = templateDir = "typescript-node";
}
public void setNpmName(String npmName) {
this.npmName = npmName;
}
public void setNpmVersion(String npmVersion) {
this.npmVersion = npmVersion;
}
public String getNpmVersion() {
return npmVersion;
}
public String getNpmRepository() {
return npmRepository;
}
public void setNpmRepository(String npmRepository) {
this.npmRepository = npmRepository;
}
}

View File

@@ -2,6 +2,7 @@
"name": "{{npmName}}",
"version": "{{npmVersion}}",
"description": "swagger client for {{npmName}}",
"author": "Kristof Vrolijkx",
"keywords": [
"swagger-client"
],
@@ -31,5 +32,4 @@
"registry":"{{npmRepository}}"
}
{{/npmRepository}}
}

View File

@@ -2,4 +2,4 @@
"ambientDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160317120654"
}
}
}

View File

@@ -0,0 +1,22 @@
{
"name": "{{npmName}}",
"version": "{{npmVersion}}",
"description": "NodeJS client for {{npmName}}",
"main": "api.js",
"scripts": {
"build": "typings install && tsc"
},
"author": "Mads M. Tandrup",
"license": "Apache 2.0",
"dependencies": {
"bluebird": "^3.3.5",
"request": "^2.72.0"
},
"devDependencies": {
"typescript": "^1.8.10",
"typings": "^0.8.1",
}{{#npmRepository}},
"publishConfig":{
"registry":"{{npmRepository}}"
}{{/npmRepository}}
}

View File

@@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"target": "ES5"
},
"files": [
"api.ts",
"client.ts",
"typings/main.d.ts"
]
}

View File

@@ -0,0 +1,5 @@
{
"ambientDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160317120654"
}
}

View File

@@ -1,4 +1,4 @@
## @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201604241113
## @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201604242228
### Building
@@ -19,7 +19,7 @@ navigate to the folder of your consuming project and run one of next commando's.
_published:_
```
npm install @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201604241113 --save
npm install @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201604242228 --save
```
_unPublished (not recommended):_

View File

@@ -1,7 +1,8 @@
{
"name": "@swagger/angular2-typescript-petstore",
"version": "0.0.1-SNAPSHOT.201604241113",
"version": "0.0.1-SNAPSHOT.201604242228",
"description": "swagger client for @swagger/angular2-typescript-petstore",
"author": "Kristof Vrolijkx",
"keywords": [
"swagger-client"
],
@@ -30,5 +31,4 @@
"publishConfig":{
"registry":"https://skimdb.npmjs.com/registry"
}
}

View File

@@ -2,4 +2,4 @@
"ambientDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160317120654"
}
}
}

View File

@@ -1,3 +0,0 @@
/node_modules
/typings
/*.js

View File

@@ -1,22 +0,0 @@
# SwaggerClient
Sample of TypeScript Node.js petstore client
## Testing the generated code
```
npm install
npm test
```
This will compile the code and run a small test application that will do some simple test calls to the Swagger Petstore API.
To clean the workspace run:
```
npm run clean
```
## Author
mads@maetzke-tandrup.dk, Swagger-Codegen community

View File

@@ -8,78 +8,11 @@ import http = require('http');
/* tslint:disable:no-unused-variable */
export class Animal {
"className": string;
}
export class Cat extends Animal {
"declawed": boolean;
}
export class Category {
"id": number;
"name": string;
}
export class Dog extends Animal {
"breed": string;
}
export class FormatTest {
"integer": number;
"int32": number;
"int64": number;
"number": number;
"float": number;
"double": number;
"string": string;
"byte": string;
"binary": string;
"date": Date;
"dateTime": string;
}
export class InlineResponse200 {
"tags": Array<Tag>;
"id": number;
"category": any;
/**
* pet status in the store
*/
"status": InlineResponse200.StatusEnum;
"name": string;
"photoUrls": Array<string>;
}
export namespace InlineResponse200 {
export enum StatusEnum {
available = <any> 'available',
pending = <any> 'pending',
sold = <any> 'sold'
}
}
/**
* Model for testing model name starting with number
*/
export class Model200Response {
"name": number;
}
/**
* Model for testing reserved words
*/
export class ModelReturn {
"return": number;
}
/**
* Model for testing model name same as property name
*/
export class Name {
"name": number;
"snakeCase": number;
}
export class Order {
"id": number;
"petId": number;
@@ -118,10 +51,6 @@ export namespace Pet {
sold = <any> 'sold'
}
}
export class SpecialModelName {
"$Special[propertyName]": number;
}
export class Tag {
"id": number;
"name": string;
@@ -191,11 +120,7 @@ class VoidAuth implements Authentication {
}
export enum PetApiApiKeys {
test_api_key_header,
api_key,
test_api_client_secret,
test_api_client_id,
test_api_key_query,
}
export class PetApi {
@@ -204,21 +129,13 @@ export class PetApi {
protected authentications = {
'default': <Authentication>new VoidAuth(),
'test_api_key_header': new ApiKeyAuth('header', 'test_api_key_header'),
'api_key': new ApiKeyAuth('header', 'api_key'),
'test_http_basic': new HttpBasicAuth(),
'test_api_client_secret': new ApiKeyAuth('header', 'x-test_api_client_secret'),
'test_api_client_id': new ApiKeyAuth('header', 'x-test_api_client_id'),
'test_api_key_query': new ApiKeyAuth('query', 'test_api_key_query'),
'petstore_auth': new OAuth(),
'api_key': new ApiKeyAuth('header', 'api_key'),
}
constructor(basePath?: string);
constructor(username: string, password: string, basePath?: string);
constructor(basePathOrUsername: string, password?: string, basePath?: string) {
if (password) {
this.username = basePathOrUsername;
this.password = password
if (basePath) {
this.basePath = basePath;
}
@@ -233,14 +150,6 @@ export class PetApi {
this.authentications[PetApiApiKeys[key]].apiKey = value;
}
set username(username: string) {
this.authentications.test_http_basic.username = username;
}
set password(password: string) {
this.authentications.test_http_basic.password = password;
}
set accessToken(token: string) {
this.authentications.petstore_auth.accessToken = token;
}
@@ -264,57 +173,6 @@ export class PetApi {
let formParams: any = {};
let useFormData = false;
let localVarDeferred = promise.defer<{ response: http.ClientResponse; body?: any; }>();
let requestOptions: request.Options = {
method: 'POST',
qs: queryParameters,
headers: headerParams,
uri: localVarPath,
json: true,
body: body,
}
this.authentications.petstore_auth.applyToRequest(requestOptions);
this.authentications.default.applyToRequest(requestOptions);
if (Object.keys(formParams).length) {
if (useFormData) {
(<any>requestOptions).formData = formParams;
} else {
requestOptions.form = formParams;
}
}
request(requestOptions, (error, response, body) => {
if (error) {
localVarDeferred.reject(error);
} else {
if (response.statusCode >= 200 && response.statusCode <= 299) {
localVarDeferred.resolve({ response: response, body: body });
} else {
localVarDeferred.reject({ response: response, body: body });
}
}
});
return localVarDeferred.promise;
}
/**
* Fake endpoint to test byte array in body parameter for adding a new pet to the store
*
* @param body Pet object in the form of byte array
*/
public addPetUsingByteArray (body?: string) : Promise<{ response: http.ClientResponse; body?: any; }> {
const localVarPath = this.basePath + '/pet?testing_byte_array&#x3D;true';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let formParams: any = {};
let useFormData = false;
let localVarDeferred = promise.defer<{ response: http.ClientResponse; body?: any; }>();
@@ -415,8 +273,8 @@ export class PetApi {
}
/**
* Finds Pets by status
* Multiple status values can be provided with comma separated strings
* @param status Status values that need to be considered for query
* Multiple status values can be provided with comma seperated strings
* @param status Status values that need to be considered for filter
*/
public findPetsByStatus (status?: Array<string>) : Promise<{ response: http.ClientResponse; body: Array<Pet>; }> {
const localVarPath = this.basePath + '/pet/findByStatus';
@@ -551,126 +409,10 @@ export class PetApi {
json: true,
}
this.authentications.api_key.applyToRequest(requestOptions);
this.authentications.petstore_auth.applyToRequest(requestOptions);
this.authentications.default.applyToRequest(requestOptions);
if (Object.keys(formParams).length) {
if (useFormData) {
(<any>requestOptions).formData = formParams;
} else {
requestOptions.form = formParams;
}
}
request(requestOptions, (error, response, body) => {
if (error) {
localVarDeferred.reject(error);
} else {
if (response.statusCode >= 200 && response.statusCode <= 299) {
localVarDeferred.resolve({ response: response, body: body });
} else {
localVarDeferred.reject({ response: response, body: body });
}
}
});
return localVarDeferred.promise;
}
/**
* Fake endpoint to test inline arbitrary object return by &#39;Find pet by ID&#39;
* 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 getPetByIdInObject (petId: number) : Promise<{ response: http.ClientResponse; body: InlineResponse200; }> {
const localVarPath = this.basePath + '/pet/{petId}?response&#x3D;inline_arbitrary_object'
.replace('{' + 'petId' + '}', String(petId));
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let formParams: any = {};
// verify required parameter 'petId' is not null or undefined
if (petId === null || petId === undefined) {
throw new Error('Required parameter petId was null or undefined when calling getPetByIdInObject.');
}
let useFormData = false;
let localVarDeferred = promise.defer<{ response: http.ClientResponse; body: InlineResponse200; }>();
let requestOptions: request.Options = {
method: 'GET',
qs: queryParameters,
headers: headerParams,
uri: localVarPath,
json: true,
}
this.authentications.api_key.applyToRequest(requestOptions);
this.authentications.petstore_auth.applyToRequest(requestOptions);
this.authentications.default.applyToRequest(requestOptions);
if (Object.keys(formParams).length) {
if (useFormData) {
(<any>requestOptions).formData = formParams;
} else {
requestOptions.form = formParams;
}
}
request(requestOptions, (error, response, body) => {
if (error) {
localVarDeferred.reject(error);
} else {
if (response.statusCode >= 200 && response.statusCode <= 299) {
localVarDeferred.resolve({ response: response, body: body });
} else {
localVarDeferred.reject({ response: response, body: body });
}
}
});
return localVarDeferred.promise;
}
/**
* Fake endpoint to test byte array return by &#39;Find pet by ID&#39;
* 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 petPetIdtestingByteArraytrueGet (petId: number) : Promise<{ response: http.ClientResponse; body: string; }> {
const localVarPath = this.basePath + '/pet/{petId}?testing_byte_array&#x3D;true'
.replace('{' + 'petId' + '}', String(petId));
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let formParams: any = {};
// verify required parameter 'petId' is not null or undefined
if (petId === null || petId === undefined) {
throw new Error('Required parameter petId was null or undefined when calling petPetIdtestingByteArraytrueGet.');
}
let useFormData = false;
let localVarDeferred = promise.defer<{ response: http.ClientResponse; body: string; }>();
let requestOptions: request.Options = {
method: 'GET',
qs: queryParameters,
headers: headerParams,
uri: localVarPath,
json: true,
}
this.authentications.api_key.applyToRequest(requestOptions);
this.authentications.petstore_auth.applyToRequest(requestOptions);
this.authentications.default.applyToRequest(requestOptions);
if (Object.keys(formParams).length) {
@@ -881,11 +623,7 @@ export class PetApi {
}
}
export enum StoreApiApiKeys {
test_api_key_header,
api_key,
test_api_client_secret,
test_api_client_id,
test_api_key_query,
}
export class StoreApi {
@@ -894,21 +632,13 @@ export class StoreApi {
protected authentications = {
'default': <Authentication>new VoidAuth(),
'test_api_key_header': new ApiKeyAuth('header', 'test_api_key_header'),
'api_key': new ApiKeyAuth('header', 'api_key'),
'test_http_basic': new HttpBasicAuth(),
'test_api_client_secret': new ApiKeyAuth('header', 'x-test_api_client_secret'),
'test_api_client_id': new ApiKeyAuth('header', 'x-test_api_client_id'),
'test_api_key_query': new ApiKeyAuth('query', 'test_api_key_query'),
'petstore_auth': new OAuth(),
'api_key': new ApiKeyAuth('header', 'api_key'),
}
constructor(basePath?: string);
constructor(username: string, password: string, basePath?: string);
constructor(basePathOrUsername: string, password?: string, basePath?: string) {
if (password) {
this.username = basePathOrUsername;
this.password = password
if (basePath) {
this.basePath = basePath;
}
@@ -923,14 +653,6 @@ export class StoreApi {
this.authentications[StoreApiApiKeys[key]].apiKey = value;
}
set username(username: string) {
this.authentications.test_http_basic.username = username;
}
set password(password: string) {
this.authentications.test_http_basic.password = password;
}
set accessToken(token: string) {
this.authentications.petstore_auth.accessToken = token;
}
@@ -996,62 +718,6 @@ export class StoreApi {
return localVarDeferred.promise;
}
/**
* Finds orders by status
* A single status value can be provided as a string
* @param status Status value that needs to be considered for query
*/
public findOrdersByStatus (status?: string) : Promise<{ response: http.ClientResponse; body: Array<Order>; }> {
const localVarPath = this.basePath + '/store/findByStatus';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let formParams: any = {};
if (status !== undefined) {
queryParameters['status'] = status;
}
let useFormData = false;
let localVarDeferred = promise.defer<{ response: http.ClientResponse; body: Array<Order>; }>();
let requestOptions: request.Options = {
method: 'GET',
qs: queryParameters,
headers: headerParams,
uri: localVarPath,
json: true,
}
this.authentications.test_api_client_id.applyToRequest(requestOptions);
this.authentications.test_api_client_secret.applyToRequest(requestOptions);
this.authentications.default.applyToRequest(requestOptions);
if (Object.keys(formParams).length) {
if (useFormData) {
(<any>requestOptions).formData = formParams;
} else {
requestOptions.form = formParams;
}
}
request(requestOptions, (error, response, body) => {
if (error) {
localVarDeferred.reject(error);
} else {
if (response.statusCode >= 200 && response.statusCode <= 299) {
localVarDeferred.resolve({ response: response, body: body });
} else {
localVarDeferred.reject({ response: response, body: body });
}
}
});
return localVarDeferred.promise;
}
/**
* Returns pet inventories by status
* Returns a map of status codes to quantities
@@ -1101,55 +767,6 @@ export class StoreApi {
return localVarDeferred.promise;
}
/**
* Fake endpoint to test arbitrary object return by &#39;Get inventory&#39;
* Returns an arbitrary object which is actually a map of status codes to quantities
*/
public getInventoryInObject () : Promise<{ response: http.ClientResponse; body: any; }> {
const localVarPath = this.basePath + '/store/inventory?response&#x3D;arbitrary_object';
let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders);
let formParams: any = {};
let useFormData = false;
let localVarDeferred = promise.defer<{ response: http.ClientResponse; body: any; }>();
let requestOptions: request.Options = {
method: 'GET',
qs: queryParameters,
headers: headerParams,
uri: localVarPath,
json: true,
}
this.authentications.api_key.applyToRequest(requestOptions);
this.authentications.default.applyToRequest(requestOptions);
if (Object.keys(formParams).length) {
if (useFormData) {
(<any>requestOptions).formData = formParams;
} else {
requestOptions.form = formParams;
}
}
request(requestOptions, (error, response, body) => {
if (error) {
localVarDeferred.reject(error);
} else {
if (response.statusCode >= 200 && response.statusCode <= 299) {
localVarDeferred.resolve({ response: response, body: body });
} else {
localVarDeferred.reject({ response: response, body: body });
}
}
});
return localVarDeferred.promise;
}
/**
* Find purchase order by ID
* For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generated exceptions
@@ -1180,10 +797,6 @@ export class StoreApi {
json: true,
}
this.authentications.test_api_key_header.applyToRequest(requestOptions);
this.authentications.test_api_key_query.applyToRequest(requestOptions);
this.authentications.default.applyToRequest(requestOptions);
if (Object.keys(formParams).length) {
@@ -1233,10 +846,6 @@ export class StoreApi {
body: body,
}
this.authentications.test_api_client_id.applyToRequest(requestOptions);
this.authentications.test_api_client_secret.applyToRequest(requestOptions);
this.authentications.default.applyToRequest(requestOptions);
if (Object.keys(formParams).length) {
@@ -1263,11 +872,7 @@ export class StoreApi {
}
}
export enum UserApiApiKeys {
test_api_key_header,
api_key,
test_api_client_secret,
test_api_client_id,
test_api_key_query,
}
export class UserApi {
@@ -1276,21 +881,13 @@ export class UserApi {
protected authentications = {
'default': <Authentication>new VoidAuth(),
'test_api_key_header': new ApiKeyAuth('header', 'test_api_key_header'),
'api_key': new ApiKeyAuth('header', 'api_key'),
'test_http_basic': new HttpBasicAuth(),
'test_api_client_secret': new ApiKeyAuth('header', 'x-test_api_client_secret'),
'test_api_client_id': new ApiKeyAuth('header', 'x-test_api_client_id'),
'test_api_key_query': new ApiKeyAuth('query', 'test_api_key_query'),
'petstore_auth': new OAuth(),
'api_key': new ApiKeyAuth('header', 'api_key'),
}
constructor(basePath?: string);
constructor(username: string, password: string, basePath?: string);
constructor(basePathOrUsername: string, password?: string, basePath?: string) {
if (password) {
this.username = basePathOrUsername;
this.password = password
if (basePath) {
this.basePath = basePath;
}
@@ -1305,14 +902,6 @@ export class UserApi {
this.authentications[UserApiApiKeys[key]].apiKey = value;
}
set username(username: string) {
this.authentications.test_http_basic.username = username;
}
set password(password: string) {
this.authentications.test_http_basic.password = password;
}
set accessToken(token: string) {
this.authentications.petstore_auth.accessToken = token;
}
@@ -1501,8 +1090,6 @@ export class UserApi {
json: true,
}
this.authentications.test_http_basic.applyToRequest(requestOptions);
this.authentications.default.applyToRequest(requestOptions);
if (Object.keys(formParams).length) {

View File

@@ -1,59 +0,0 @@
import api = require('./api');
import fs = require('fs');
var petApi = new api.PetApi();
petApi.setApiKey(api.PetApiApiKeys.api_key, 'special-key');
petApi.setApiKey(api.PetApiApiKeys.test_api_key_header, 'query-key');
var tag1 = new api.Tag();
tag1.id = 18291;
tag1.name = 'TS tag 1';
var pet = new api.Pet();
pet.name = 'TypeScriptDoggie';
pet.id = 18291;
pet.photoUrls = ["http://url1", "http://url2"];
pet.tags = [tag1];
var petId: any;
var exitCode = 0;
// Test various API calls to the petstore
petApi.addPet(pet)
.then((res) => {
var newPet = <api.Pet>res.body;
petId = newPet.id;
console.log(`Created pet with ID ${petId}`);
newPet.status = api.Pet.StatusEnum.available;
return petApi.updatePet(newPet);
})
.then((res) => {
console.log('Updated pet using POST body');
return petApi.updatePetWithForm(petId, undefined, "pending");
})
.then((res) => {
console.log('Updated pet using POST form');
return petApi.uploadFile(petId, undefined, fs.createReadStream('sample.png'));
})
.then((res) => {
console.log('Uploaded image');
return petApi.getPetById(petId);
})
.then((res) => {
console.log('Got pet by ID: ' + JSON.stringify(res.body));
if (res.body.status != api.Pet.StatusEnum.pending) {
throw new Error("Unexpected pet status");
}
})
.catch((err: any) => {
console.error(err);
exitCode = 1;
})
.finally(() => {
return petApi.deletePet(petId);
})
.then((res) => {
console.log('Deleted pet');
process.exit(exitCode);
});

View File

@@ -1,21 +0,0 @@
{
"name": "petstore-typescript-node-sample",
"version": "1.0.0",
"description": "Sample of generated TypeScript petstore client",
"main": "api.js",
"scripts": {
"postinstall": "tsd reinstall --overwrite",
"test": "tsc && node client.js",
"clean": "rm -Rf node_modules/ typings/ *.js"
},
"author": "Mads M. Tandrup",
"license": "Apache 2.0",
"dependencies": {
"bluebird": "^2.9.34",
"request": "^2.60.0"
},
"devDependencies": {
"tsd": "^0.6.3",
"typescript": "^1.5.3"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 B

View File

@@ -1,13 +0,0 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"target": "ES5"
},
"files": [
"api.ts",
"client.ts",
"typings/tsd.d.ts"
]
}

View File

@@ -1,21 +0,0 @@
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"bluebird/bluebird.d.ts": {
"commit": "f6c8ca47193fb67947944a3170912672ac3e908e"
},
"request/request.d.ts": {
"commit": "f6c8ca47193fb67947944a3170912672ac3e908e"
},
"form-data/form-data.d.ts": {
"commit": "f6c8ca47193fb67947944a3170912672ac3e908e"
},
"node/node.d.ts": {
"commit": "f6c8ca47193fb67947944a3170912672ac3e908e"
}
}
}