forked from loafle/openapi-generator-original
add petstore samples for typescript aurelia
This commit is contained in:
parent
21619c5320
commit
188e998683
1
.gitignore
vendored
1
.gitignore
vendored
@ -160,6 +160,7 @@ samples/client/petstore/typescript-fetch/**/dist/
|
|||||||
samples/client/petstore/typescript-fetch/**/typings
|
samples/client/petstore/typescript-fetch/**/typings
|
||||||
samples/client/petstore/typescript-angular2/npm/npm-debug.log
|
samples/client/petstore/typescript-angular2/npm/npm-debug.log
|
||||||
samples/client/petstore/typescript-node/npm/npm-debug.log
|
samples/client/petstore/typescript-node/npm/npm-debug.log
|
||||||
|
samples/client/petstore/typescript-aurelia/**/dist/
|
||||||
|
|
||||||
# aspnetcore
|
# aspnetcore
|
||||||
samples/server/petstore/aspnetcore/.vs/
|
samples/server/petstore/aspnetcore/.vs/
|
||||||
|
0
bin/apache2-petstore-config.sh
Normal file → Executable file
0
bin/apache2-petstore-config.sh
Normal file → Executable file
0
bin/eiffel-petstore.sh
Normal file → Executable file
0
bin/eiffel-petstore.sh
Normal file → Executable file
0
bin/java-play-framework-petstore-server-all.sh
Normal file → Executable file
0
bin/java-play-framework-petstore-server-all.sh
Normal file → Executable file
0
bin/java-play-framework-petstore-server-controller-only.sh
Normal file → Executable file
0
bin/java-play-framework-petstore-server-controller-only.sh
Normal file → Executable file
0
bin/java-play-framework-petstore-server-no-bean-validation.sh
Normal file → Executable file
0
bin/java-play-framework-petstore-server-no-bean-validation.sh
Normal file → Executable file
0
bin/java-play-framework-petstore-server-no-exception-handling.sh
Normal file → Executable file
0
bin/java-play-framework-petstore-server-no-exception-handling.sh
Normal file → Executable file
0
bin/java-play-framework-petstore-server-no-interface.sh
Normal file → Executable file
0
bin/java-play-framework-petstore-server-no-interface.sh
Normal file → Executable file
0
bin/java-play-framework-petstore-server-no-swagger-ui.sh
Normal file → Executable file
0
bin/java-play-framework-petstore-server-no-swagger-ui.sh
Normal file → Executable file
0
bin/java-play-framework-petstore-server-no-wrap-calls.sh
Normal file → Executable file
0
bin/java-play-framework-petstore-server-no-wrap-calls.sh
Normal file → Executable file
31
bin/typescript-aurelia-petstore.sh
Executable file
31
bin/typescript-aurelia-petstore.sh
Executable 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.yaml -l typescript-aurelia -o samples/client/petstore/typescript-aurelia/default"
|
||||||
|
|
||||||
|
java $JAVA_OPTS -jar $executable $ags
|
0
bin/typescript-jquery-petstore-with-npm.sh
Normal file → Executable file
0
bin/typescript-jquery-petstore-with-npm.sh
Normal file → Executable file
0
bin/typescript-jquery-petstore.sh
Normal file → Executable file
0
bin/typescript-jquery-petstore.sh
Normal file → Executable file
3
samples/client/petstore/typescript-aurelia/default/.gitignore
vendored
Normal file
3
samples/client/petstore/typescript-aurelia/default/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
wwwroot/*.js
|
||||||
|
node_modules
|
||||||
|
typings
|
@ -0,0 +1,23 @@
|
|||||||
|
# Swagger Codegen Ignore
|
||||||
|
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
|
||||||
|
|
||||||
|
# Use this file to prevent files from being overwritten by the generator.
|
||||||
|
# The patterns follow closely to .gitignore or .dockerignore.
|
||||||
|
|
||||||
|
# As an example, the C# client generator defines ApiClient.cs.
|
||||||
|
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
|
||||||
|
#ApiClient.cs
|
||||||
|
|
||||||
|
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||||
|
#foo/*/qux
|
||||||
|
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||||
|
#foo/**/qux
|
||||||
|
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can also negate patterns with an exclamation (!).
|
||||||
|
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||||
|
#docs/*.md
|
||||||
|
# Then explicitly reverse the ignore rule for a single file:
|
||||||
|
#!docs/README.md
|
@ -0,0 +1 @@
|
|||||||
|
2.3.0-SNAPSHOT
|
76
samples/client/petstore/typescript-aurelia/default/Api.ts
Normal file
76
samples/client/petstore/typescript-aurelia/default/Api.ts
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/**
|
||||||
|
* Swagger Petstore
|
||||||
|
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* OpenAPI spec version: 1.0.0
|
||||||
|
* Contact: apiteam@swagger.io
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by the swagger code generator program.
|
||||||
|
* https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { HttpClient } from 'aurelia-http-client';
|
||||||
|
import { AuthStorage } from './AuthStorage';
|
||||||
|
|
||||||
|
const BASE_PATH = 'http://petstore.swagger.io/v2'.replace(/\/+$/, '');
|
||||||
|
|
||||||
|
export class Api {
|
||||||
|
basePath: string;
|
||||||
|
httpClient: HttpClient;
|
||||||
|
authStorage: AuthStorage;
|
||||||
|
|
||||||
|
constructor(httpClient: HttpClient, authStorage: AuthStorage, basePath: string = BASE_PATH) {
|
||||||
|
this.basePath = basePath;
|
||||||
|
this.httpClient = httpClient;
|
||||||
|
this.authStorage = authStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encodes a query string.
|
||||||
|
*
|
||||||
|
* @param params The params to encode.
|
||||||
|
* @return An encoded query string.
|
||||||
|
*/
|
||||||
|
protected queryString(params: { [key: string]: any }): string {
|
||||||
|
const queries = [];
|
||||||
|
for (let key in params) {
|
||||||
|
const value = this.toString(params[key]);
|
||||||
|
if (value != null) {
|
||||||
|
queries.push(`${key}=${encodeURIComponent(value)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return queries.join('&');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a value to string.
|
||||||
|
*
|
||||||
|
* @param value The value to convert.
|
||||||
|
*/
|
||||||
|
protected toString(value: any): string | null {
|
||||||
|
if (value === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
switch (typeof value) {
|
||||||
|
case 'undefined': return null;
|
||||||
|
case 'boolean': return value ? 'true' : 'false';
|
||||||
|
case 'string': return value;
|
||||||
|
default: return '' + value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures that a given parameter is set.
|
||||||
|
*
|
||||||
|
* @param context A name for the callee's context.
|
||||||
|
* @param params The parameters being set.
|
||||||
|
* @param paramName The required parameter to check.
|
||||||
|
*/
|
||||||
|
protected ensureParamIsSet<T>(context: string, params: T, paramName: keyof T): void {
|
||||||
|
if (null === params[paramName]) {
|
||||||
|
throw new Error(`Missing required parameter ${paramName} when calling ${context}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
/**
|
||||||
|
* Swagger Petstore
|
||||||
|
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* OpenAPI spec version: 1.0.0
|
||||||
|
* Contact: apiteam@swagger.io
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by the swagger code generator program.
|
||||||
|
* https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to storage authentication data
|
||||||
|
*/
|
||||||
|
export class AuthStorage {
|
||||||
|
private storage: Map<string, string>;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.storage = new Map();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the api_key auth method value.
|
||||||
|
*
|
||||||
|
* @param value The new value to set for api_key.
|
||||||
|
*/
|
||||||
|
setapi_key(value: string): this {
|
||||||
|
this.storage.set('api_key', value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the api_key auth method value.
|
||||||
|
*/
|
||||||
|
removeapi_key(): this {
|
||||||
|
this.storage.delete('api_key');
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the api_key auth method value.
|
||||||
|
*/
|
||||||
|
getapi_key(): null | string {
|
||||||
|
return this.storage.get('api_key') || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the petstore_auth auth method value.
|
||||||
|
*
|
||||||
|
* @param value The new value to set for petstore_auth.
|
||||||
|
*/
|
||||||
|
setpetstore_auth(value: string): this {
|
||||||
|
this.storage.set('petstore_auth', value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the petstore_auth auth method value.
|
||||||
|
*/
|
||||||
|
removepetstore_auth(): this {
|
||||||
|
this.storage.delete('petstore_auth');
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the petstore_auth auth method value.
|
||||||
|
*/
|
||||||
|
getpetstore_auth(): null | string {
|
||||||
|
return this.storage.get('petstore_auth') || null;
|
||||||
|
}
|
||||||
|
}
|
369
samples/client/petstore/typescript-aurelia/default/PetApi.ts
Normal file
369
samples/client/petstore/typescript-aurelia/default/PetApi.ts
Normal file
@ -0,0 +1,369 @@
|
|||||||
|
/**
|
||||||
|
* Swagger Petstore
|
||||||
|
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* OpenAPI spec version: 1.0.0
|
||||||
|
* Contact: apiteam@swagger.io
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by the swagger code generator program.
|
||||||
|
* https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { autoinject } from 'aurelia-framework';
|
||||||
|
import { HttpClient } from 'aurelia-http-client';
|
||||||
|
import { Api } from './Api';
|
||||||
|
import { AuthStorage } from './AuthStorage';
|
||||||
|
import {
|
||||||
|
Array<string>,
|
||||||
|
any,
|
||||||
|
Pet,
|
||||||
|
ApiResponse,
|
||||||
|
} from './models';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* addPet - parameters interface
|
||||||
|
*/
|
||||||
|
export interface IAddPetParams {
|
||||||
|
body: Pet;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deletePet - parameters interface
|
||||||
|
*/
|
||||||
|
export interface IDeletePetParams {
|
||||||
|
petId: number;
|
||||||
|
apiKey?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* findPetsByStatus - parameters interface
|
||||||
|
*/
|
||||||
|
export interface IFindPetsByStatusParams {
|
||||||
|
status: Array<string>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* findPetsByTags - parameters interface
|
||||||
|
*/
|
||||||
|
export interface IFindPetsByTagsParams {
|
||||||
|
tags: Array<string>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getPetById - parameters interface
|
||||||
|
*/
|
||||||
|
export interface IGetPetByIdParams {
|
||||||
|
petId: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updatePet - parameters interface
|
||||||
|
*/
|
||||||
|
export interface IUpdatePetParams {
|
||||||
|
body: Pet;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updatePetWithForm - parameters interface
|
||||||
|
*/
|
||||||
|
export interface IUpdatePetWithFormParams {
|
||||||
|
petId: number;
|
||||||
|
name?: string;
|
||||||
|
status?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* uploadFile - parameters interface
|
||||||
|
*/
|
||||||
|
export interface IUploadFileParams {
|
||||||
|
petId: number;
|
||||||
|
additionalMetadata?: string;
|
||||||
|
file?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PetApi - API class
|
||||||
|
*/
|
||||||
|
@autoinject()
|
||||||
|
export class PetApi extends Api {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new PetApi class.
|
||||||
|
*
|
||||||
|
* @param httpClient The Aurelia HTTP client to be injected.
|
||||||
|
*/
|
||||||
|
constructor(httpClient: HttpClient, authStorage: AuthStorage) {
|
||||||
|
super(httpClient, authStorage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new pet to the store
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param params.body Pet object that needs to be added to the store
|
||||||
|
*/
|
||||||
|
async addPet(params: IAddPetParams): Promise<any> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('addPet', params, 'body');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/pet`;
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asPost()
|
||||||
|
// Encode body parameter
|
||||||
|
.withHeader('content-type', 'application/json')
|
||||||
|
.withContent(JSON.stringify(params['body'] || {}))
|
||||||
|
|
||||||
|
// Authentication 'petstore_auth' required
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a pet
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param params.petId Pet id to delete
|
||||||
|
* @param params.apiKey
|
||||||
|
*/
|
||||||
|
async deletePet(params: IDeletePetParams): Promise<any> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('deletePet', params, 'petId');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/pet/{petId}`
|
||||||
|
.replace(`{${'petId'}}`, `${params['petId']}`);
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asDelete()
|
||||||
|
.withHeader('api_key', params['apiKey'])
|
||||||
|
// Authentication 'petstore_auth' required
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds Pets by status
|
||||||
|
*
|
||||||
|
* Multiple status values can be provided with comma separated strings
|
||||||
|
* @param params.status Status values that need to be considered for filter
|
||||||
|
*/
|
||||||
|
async findPetsByStatus(params: IFindPetsByStatusParams): Promise<Array<Pet>> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('findPetsByStatus', params, 'status');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/pet/findByStatus`;
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asGet()
|
||||||
|
// Set query parameters
|
||||||
|
.withParams({
|
||||||
|
'status': params['status'],
|
||||||
|
})
|
||||||
|
|
||||||
|
// Authentication 'petstore_auth' required
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds Pets by tags
|
||||||
|
*
|
||||||
|
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||||
|
* @param params.tags Tags to filter by
|
||||||
|
*/
|
||||||
|
async findPetsByTags(params: IFindPetsByTagsParams): Promise<Array<Pet>> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('findPetsByTags', params, 'tags');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/pet/findByTags`;
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asGet()
|
||||||
|
// Set query parameters
|
||||||
|
.withParams({
|
||||||
|
'tags': params['tags'],
|
||||||
|
})
|
||||||
|
|
||||||
|
// Authentication 'petstore_auth' required
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find pet by ID
|
||||||
|
*
|
||||||
|
* Returns a single pet
|
||||||
|
* @param params.petId ID of pet to return
|
||||||
|
*/
|
||||||
|
async getPetById(params: IGetPetByIdParams): Promise<Pet> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('getPetById', params, 'petId');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/pet/{petId}`
|
||||||
|
.replace(`{${'petId'}}`, `${params['petId']}`);
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asGet()
|
||||||
|
|
||||||
|
// Authentication 'api_key' required
|
||||||
|
.withHeader('api_key', this.authStorage.getapi_key())
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an existing pet
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param params.body Pet object that needs to be added to the store
|
||||||
|
*/
|
||||||
|
async updatePet(params: IUpdatePetParams): Promise<any> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('updatePet', params, 'body');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/pet`;
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asPut()
|
||||||
|
// Encode body parameter
|
||||||
|
.withHeader('content-type', 'application/json')
|
||||||
|
.withContent(JSON.stringify(params['body'] || {}))
|
||||||
|
|
||||||
|
// Authentication 'petstore_auth' required
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates a pet in the store with form data
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param params.petId ID of pet that needs to be updated
|
||||||
|
* @param params.name Updated name of the pet
|
||||||
|
* @param params.status Updated status of the pet
|
||||||
|
*/
|
||||||
|
async updatePetWithForm(params: IUpdatePetWithFormParams): Promise<any> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('updatePetWithForm', params, 'petId');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/pet/{petId}`
|
||||||
|
.replace(`{${'petId'}}`, `${params['petId']}`);
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asPost()
|
||||||
|
// Encode form parameters
|
||||||
|
.withHeader('content-type', 'application/x-www-form-urlencoded')
|
||||||
|
.withContent(this.queryString({
|
||||||
|
'name': params['name'],
|
||||||
|
'status': params['status'],
|
||||||
|
}))
|
||||||
|
|
||||||
|
// Authentication 'petstore_auth' required
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* uploads an image
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param params.petId ID of pet to update
|
||||||
|
* @param params.additionalMetadata Additional data to pass to server
|
||||||
|
* @param params.file file to upload
|
||||||
|
*/
|
||||||
|
async uploadFile(params: IUploadFileParams): Promise<ApiResponse> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('uploadFile', params, 'petId');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/pet/{petId}/uploadImage`
|
||||||
|
.replace(`{${'petId'}}`, `${params['petId']}`);
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asPost()
|
||||||
|
// Encode form parameters
|
||||||
|
.withHeader('content-type', 'application/x-www-form-urlencoded')
|
||||||
|
.withContent(this.queryString({
|
||||||
|
'additionalMetadata': params['additionalMetadata'],
|
||||||
|
'file': params['file'],
|
||||||
|
}))
|
||||||
|
|
||||||
|
// Authentication 'petstore_auth' required
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
55
samples/client/petstore/typescript-aurelia/default/README.md
Normal file
55
samples/client/petstore/typescript-aurelia/default/README.md
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
# TypeScript-Aurelia
|
||||||
|
|
||||||
|
This generator creates TypeScript/JavaScript client that is injectable by [Aurelia](http://aurelia.io/).
|
||||||
|
The generated Node module can be used in the following environments:
|
||||||
|
|
||||||
|
Environment
|
||||||
|
* Node.js
|
||||||
|
* Webpack
|
||||||
|
* Browserify
|
||||||
|
|
||||||
|
Language level
|
||||||
|
* ES5 - you must have a Promises/A+ library installed
|
||||||
|
* ES6
|
||||||
|
|
||||||
|
Module system
|
||||||
|
* CommonJS
|
||||||
|
* ES6 module system
|
||||||
|
|
||||||
|
It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html))
|
||||||
|
|
||||||
|
### Installation ###
|
||||||
|
|
||||||
|
`swagger-codegen` does not generate JavaScript directly. The generated Node module comes with `package.json` that bundles `typescript` and `typings` so it can self-compile during `prepublish` stage. The should be run automatically during `npm install` or `npm publish`.
|
||||||
|
|
||||||
|
CAVEAT: Due to [privilege implications](https://docs.npmjs.com/misc/scripts#user), `npm` would skip all scripts if the user is `root`. You would need to manually run it with `npm run prepublish` or run `npm install --unsafe-perm`.
|
||||||
|
|
||||||
|
#### NPM ####
|
||||||
|
You may publish the module to NPM. In this 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).
|
||||||
|
|
||||||
|
You can also use `npm link` to link the module. However, this would not modify `package.json` of the installing project, as such you would need to relink every time you deploy that project.
|
||||||
|
|
||||||
|
You can also directly install the module using `npm install file_path`. If you do `npm install file_path --save`, NPM will save relative path to `package.json`. In this case, `npm install` and `npm shrinkwrap` may misbehave. You would need to manually edit `package.json` and replace it with absolute path.
|
||||||
|
|
||||||
|
Regardless of which method you deployed your NPM module, the ES6 module syntaxes are as follows:
|
||||||
|
```
|
||||||
|
import * as localName from 'npmName';
|
||||||
|
import {operationId} from 'npmName';
|
||||||
|
```
|
||||||
|
The CommonJS syntax is as follows:
|
||||||
|
```
|
||||||
|
import localName = require('npmName');
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Direct copy/symlink ####
|
||||||
|
You may also simply copy or symlink the generated module into a directory under your project. The syntax of this is as follows:
|
||||||
|
|
||||||
|
With ES6 module syntax, the following syntaxes are supported:
|
||||||
|
```
|
||||||
|
import * as localName from './symlinkDir';
|
||||||
|
import {operationId} from './symlinkDir';
|
||||||
|
```
|
||||||
|
The CommonJS syntax is as follows:
|
||||||
|
```
|
||||||
|
import localName = require('./symlinkDir')';
|
||||||
|
```
|
181
samples/client/petstore/typescript-aurelia/default/StoreApi.ts
Normal file
181
samples/client/petstore/typescript-aurelia/default/StoreApi.ts
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
/**
|
||||||
|
* Swagger Petstore
|
||||||
|
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* OpenAPI spec version: 1.0.0
|
||||||
|
* Contact: apiteam@swagger.io
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by the swagger code generator program.
|
||||||
|
* https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { autoinject } from 'aurelia-framework';
|
||||||
|
import { HttpClient } from 'aurelia-http-client';
|
||||||
|
import { Api } from './Api';
|
||||||
|
import { AuthStorage } from './AuthStorage';
|
||||||
|
import {
|
||||||
|
Order,
|
||||||
|
} from './models';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deleteOrder - parameters interface
|
||||||
|
*/
|
||||||
|
export interface IDeleteOrderParams {
|
||||||
|
orderId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getInventory - parameters interface
|
||||||
|
*/
|
||||||
|
export interface IGetInventoryParams {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getOrderById - parameters interface
|
||||||
|
*/
|
||||||
|
export interface IGetOrderByIdParams {
|
||||||
|
orderId: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* placeOrder - parameters interface
|
||||||
|
*/
|
||||||
|
export interface IPlaceOrderParams {
|
||||||
|
body: Order;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StoreApi - API class
|
||||||
|
*/
|
||||||
|
@autoinject()
|
||||||
|
export class StoreApi extends Api {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new StoreApi class.
|
||||||
|
*
|
||||||
|
* @param httpClient The Aurelia HTTP client to be injected.
|
||||||
|
*/
|
||||||
|
constructor(httpClient: HttpClient, authStorage: AuthStorage) {
|
||||||
|
super(httpClient, authStorage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete purchase order by ID
|
||||||
|
*
|
||||||
|
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||||
|
* @param params.orderId ID of the order that needs to be deleted
|
||||||
|
*/
|
||||||
|
async deleteOrder(params: IDeleteOrderParams): Promise<any> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('deleteOrder', params, 'orderId');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/store/order/{orderId}`
|
||||||
|
.replace(`{${'orderId'}}`, `${params['orderId']}`);
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asDelete()
|
||||||
|
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns pet inventories by status
|
||||||
|
*
|
||||||
|
* Returns a map of status codes to quantities
|
||||||
|
*/
|
||||||
|
async getInventory(): Promise<{ [key: string]: number; }> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/store/inventory`;
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asGet()
|
||||||
|
|
||||||
|
// Authentication 'api_key' required
|
||||||
|
.withHeader('api_key', this.authStorage.getapi_key())
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find purchase order by ID
|
||||||
|
*
|
||||||
|
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||||
|
* @param params.orderId ID of pet that needs to be fetched
|
||||||
|
*/
|
||||||
|
async getOrderById(params: IGetOrderByIdParams): Promise<Order> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('getOrderById', params, 'orderId');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/store/order/{orderId}`
|
||||||
|
.replace(`{${'orderId'}}`, `${params['orderId']}`);
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asGet()
|
||||||
|
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Place an order for a pet
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param params.body order placed for purchasing the pet
|
||||||
|
*/
|
||||||
|
async placeOrder(params: IPlaceOrderParams): Promise<Order> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('placeOrder', params, 'body');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/store/order`;
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asPost()
|
||||||
|
// Encode body parameter
|
||||||
|
.withHeader('content-type', 'application/json')
|
||||||
|
.withContent(JSON.stringify(params['body'] || {}))
|
||||||
|
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
341
samples/client/petstore/typescript-aurelia/default/UserApi.ts
Normal file
341
samples/client/petstore/typescript-aurelia/default/UserApi.ts
Normal file
@ -0,0 +1,341 @@
|
|||||||
|
/**
|
||||||
|
* Swagger Petstore
|
||||||
|
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* OpenAPI spec version: 1.0.0
|
||||||
|
* Contact: apiteam@swagger.io
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by the swagger code generator program.
|
||||||
|
* https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { autoinject } from 'aurelia-framework';
|
||||||
|
import { HttpClient } from 'aurelia-http-client';
|
||||||
|
import { Api } from './Api';
|
||||||
|
import { AuthStorage } from './AuthStorage';
|
||||||
|
import {
|
||||||
|
User,
|
||||||
|
Array<User>,
|
||||||
|
} from './models';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* createUser - parameters interface
|
||||||
|
*/
|
||||||
|
export interface ICreateUserParams {
|
||||||
|
body: User;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* createUsersWithArrayInput - parameters interface
|
||||||
|
*/
|
||||||
|
export interface ICreateUsersWithArrayInputParams {
|
||||||
|
body: Array<User>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* createUsersWithListInput - parameters interface
|
||||||
|
*/
|
||||||
|
export interface ICreateUsersWithListInputParams {
|
||||||
|
body: Array<User>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deleteUser - parameters interface
|
||||||
|
*/
|
||||||
|
export interface IDeleteUserParams {
|
||||||
|
username: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getUserByName - parameters interface
|
||||||
|
*/
|
||||||
|
export interface IGetUserByNameParams {
|
||||||
|
username: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loginUser - parameters interface
|
||||||
|
*/
|
||||||
|
export interface ILoginUserParams {
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* logoutUser - parameters interface
|
||||||
|
*/
|
||||||
|
export interface ILogoutUserParams {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updateUser - parameters interface
|
||||||
|
*/
|
||||||
|
export interface IUpdateUserParams {
|
||||||
|
username: string;
|
||||||
|
body: User;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UserApi - API class
|
||||||
|
*/
|
||||||
|
@autoinject()
|
||||||
|
export class UserApi extends Api {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new UserApi class.
|
||||||
|
*
|
||||||
|
* @param httpClient The Aurelia HTTP client to be injected.
|
||||||
|
*/
|
||||||
|
constructor(httpClient: HttpClient, authStorage: AuthStorage) {
|
||||||
|
super(httpClient, authStorage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create user
|
||||||
|
*
|
||||||
|
* This can only be done by the logged in user.
|
||||||
|
* @param params.body Created user object
|
||||||
|
*/
|
||||||
|
async createUser(params: ICreateUserParams): Promise<any> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('createUser', params, 'body');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/user`;
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asPost()
|
||||||
|
// Encode body parameter
|
||||||
|
.withHeader('content-type', 'application/json')
|
||||||
|
.withContent(JSON.stringify(params['body'] || {}))
|
||||||
|
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates list of users with given input array
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param params.body List of user object
|
||||||
|
*/
|
||||||
|
async createUsersWithArrayInput(params: ICreateUsersWithArrayInputParams): Promise<any> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('createUsersWithArrayInput', params, 'body');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/user/createWithArray`;
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asPost()
|
||||||
|
// Encode body parameter
|
||||||
|
.withHeader('content-type', 'application/json')
|
||||||
|
.withContent(JSON.stringify(params['body'] || {}))
|
||||||
|
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates list of users with given input array
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param params.body List of user object
|
||||||
|
*/
|
||||||
|
async createUsersWithListInput(params: ICreateUsersWithListInputParams): Promise<any> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('createUsersWithListInput', params, 'body');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/user/createWithList`;
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asPost()
|
||||||
|
// Encode body parameter
|
||||||
|
.withHeader('content-type', 'application/json')
|
||||||
|
.withContent(JSON.stringify(params['body'] || {}))
|
||||||
|
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete user
|
||||||
|
*
|
||||||
|
* This can only be done by the logged in user.
|
||||||
|
* @param params.username The name that needs to be deleted
|
||||||
|
*/
|
||||||
|
async deleteUser(params: IDeleteUserParams): Promise<any> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('deleteUser', params, 'username');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/user/{username}`
|
||||||
|
.replace(`{${'username'}}`, `${params['username']}`);
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asDelete()
|
||||||
|
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get user by user name
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param params.username The name that needs to be fetched. Use user1 for testing.
|
||||||
|
*/
|
||||||
|
async getUserByName(params: IGetUserByNameParams): Promise<User> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('getUserByName', params, 'username');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/user/{username}`
|
||||||
|
.replace(`{${'username'}}`, `${params['username']}`);
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asGet()
|
||||||
|
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs user into the system
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param params.username The user name for login
|
||||||
|
* @param params.password The password for login in clear text
|
||||||
|
*/
|
||||||
|
async loginUser(params: ILoginUserParams): Promise<string> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('loginUser', params, 'username');
|
||||||
|
this.ensureParamIsSet('loginUser', params, 'password');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/user/login`;
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asGet()
|
||||||
|
// Set query parameters
|
||||||
|
.withParams({
|
||||||
|
'username': params['username'],
|
||||||
|
'password': params['password'],
|
||||||
|
})
|
||||||
|
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs out current logged in user session
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
async logoutUser(): Promise<any> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/user/logout`;
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asGet()
|
||||||
|
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updated user
|
||||||
|
*
|
||||||
|
* This can only be done by the logged in user.
|
||||||
|
* @param params.username name that need to be deleted
|
||||||
|
* @param params.body Updated user object
|
||||||
|
*/
|
||||||
|
async updateUser(params: IUpdateUserParams): Promise<any> {
|
||||||
|
// Verify required parameters are set
|
||||||
|
this.ensureParamIsSet('updateUser', params, 'username');
|
||||||
|
this.ensureParamIsSet('updateUser', params, 'body');
|
||||||
|
|
||||||
|
// Create URL to call
|
||||||
|
const url = `${this.basePath}/user/{username}`
|
||||||
|
.replace(`{${'username'}}`, `${params['username']}`);
|
||||||
|
|
||||||
|
const response = await this.httpClient.createRequest(url)
|
||||||
|
// Set HTTP method
|
||||||
|
.asPut()
|
||||||
|
// Encode body parameter
|
||||||
|
.withHeader('content-type', 'application/json')
|
||||||
|
.withContent(JSON.stringify(params['body'] || {}))
|
||||||
|
|
||||||
|
// Send the request
|
||||||
|
.send();
|
||||||
|
|
||||||
|
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||||
|
throw new Error(response.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the content
|
||||||
|
return response.content;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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'
|
||||||
|
|
25
samples/client/petstore/typescript-aurelia/default/index.ts
Normal file
25
samples/client/petstore/typescript-aurelia/default/index.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* Swagger Petstore
|
||||||
|
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* OpenAPI spec version: 1.0.0
|
||||||
|
* Contact: apiteam@swagger.io
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by the swagger code generator program.
|
||||||
|
* https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export { Api } from './Api';
|
||||||
|
export { AuthStorage } from './AuthStorage';
|
||||||
|
export { PetApi } from './PetApi';
|
||||||
|
export { StoreApi } from './StoreApi';
|
||||||
|
export { UserApi } from './UserApi';
|
||||||
|
export {
|
||||||
|
ApiResponse,
|
||||||
|
Category,
|
||||||
|
Order,
|
||||||
|
Pet,
|
||||||
|
Tag,
|
||||||
|
User,
|
||||||
|
} from './models';
|
94
samples/client/petstore/typescript-aurelia/default/models.ts
Normal file
94
samples/client/petstore/typescript-aurelia/default/models.ts
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
/**
|
||||||
|
* Swagger Petstore
|
||||||
|
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* OpenAPI spec version: 1.0.0
|
||||||
|
* Contact: apiteam@swagger.io
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by the swagger code generator program.
|
||||||
|
* https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the result of uploading an image resource
|
||||||
|
*/
|
||||||
|
export interface ApiResponse {
|
||||||
|
code?: number;
|
||||||
|
type?: string;
|
||||||
|
message?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A category for a pet
|
||||||
|
*/
|
||||||
|
export interface Category {
|
||||||
|
id?: number;
|
||||||
|
name?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An order for a pets from the pet store
|
||||||
|
*/
|
||||||
|
export interface Order {
|
||||||
|
id?: number;
|
||||||
|
petId?: number;
|
||||||
|
quantity?: number;
|
||||||
|
shipDate?: Date;
|
||||||
|
/**
|
||||||
|
* Order Status
|
||||||
|
*/
|
||||||
|
status?: OrderStatusEnum;
|
||||||
|
complete?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum for the status property.
|
||||||
|
*/
|
||||||
|
export type OrderStatusEnum = 'placed' | 'approved' | 'delivered';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A pet for sale in the pet store
|
||||||
|
*/
|
||||||
|
export interface Pet {
|
||||||
|
id?: number;
|
||||||
|
category?: Category;
|
||||||
|
name: string;
|
||||||
|
photoUrls: Array<string>;
|
||||||
|
tags?: Array<Tag>;
|
||||||
|
/**
|
||||||
|
* pet status in the store
|
||||||
|
*/
|
||||||
|
status?: PetStatusEnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum for the status property.
|
||||||
|
*/
|
||||||
|
export type PetStatusEnum = 'available' | 'pending' | 'sold';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A tag for a pet
|
||||||
|
*/
|
||||||
|
export interface Tag {
|
||||||
|
id?: number;
|
||||||
|
name?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A User who is purchasing from the pet store
|
||||||
|
*/
|
||||||
|
export interface User {
|
||||||
|
id?: number;
|
||||||
|
username?: string;
|
||||||
|
firstName?: string;
|
||||||
|
lastName?: string;
|
||||||
|
email?: string;
|
||||||
|
password?: string;
|
||||||
|
phone?: string;
|
||||||
|
/**
|
||||||
|
* User Status
|
||||||
|
*/
|
||||||
|
userStatus?: number;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "typescript-fetch-api",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"license": "Unlicense",
|
||||||
|
"main": "./dist/api.js",
|
||||||
|
"browser": "./dist/api.js",
|
||||||
|
"typings": "./dist/api.d.ts",
|
||||||
|
"dependencies": {
|
||||||
|
"core-js": "^2.4.0",
|
||||||
|
"isomorphic-fetch": "^2.2.1"
|
||||||
|
},
|
||||||
|
"scripts" : {
|
||||||
|
"prepublish" : "typings install && tsc",
|
||||||
|
"test": "tslint api.ts"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"tslint": "^3.15.1",
|
||||||
|
"typescript": "^1.8.10",
|
||||||
|
"typings": "^1.0.4"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"declaration": true,
|
||||||
|
"target": "es5",
|
||||||
|
"module": "commonjs",
|
||||||
|
"noImplicitAny": true,
|
||||||
|
"outDir": "dist",
|
||||||
|
"rootDir": "."
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"dist",
|
||||||
|
"node_modules"
|
||||||
|
]
|
||||||
|
}
|
101
samples/client/petstore/typescript-aurelia/default/tslint.json
Normal file
101
samples/client/petstore/typescript-aurelia/default/tslint.json
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
{
|
||||||
|
"jsRules": {
|
||||||
|
"class-name": true,
|
||||||
|
"comment-format": [
|
||||||
|
true,
|
||||||
|
"check-space"
|
||||||
|
],
|
||||||
|
"indent": [
|
||||||
|
true,
|
||||||
|
"spaces"
|
||||||
|
],
|
||||||
|
"no-duplicate-variable": true,
|
||||||
|
"no-eval": true,
|
||||||
|
"no-trailing-whitespace": true,
|
||||||
|
"no-unsafe-finally": true,
|
||||||
|
"one-line": [
|
||||||
|
true,
|
||||||
|
"check-open-brace",
|
||||||
|
"check-whitespace"
|
||||||
|
],
|
||||||
|
"quotemark": [
|
||||||
|
true,
|
||||||
|
"double"
|
||||||
|
],
|
||||||
|
"semicolon": [
|
||||||
|
true,
|
||||||
|
"always"
|
||||||
|
],
|
||||||
|
"triple-equals": [
|
||||||
|
true,
|
||||||
|
"allow-null-check"
|
||||||
|
],
|
||||||
|
"variable-name": [
|
||||||
|
true,
|
||||||
|
"ban-keywords"
|
||||||
|
],
|
||||||
|
"whitespace": [
|
||||||
|
true,
|
||||||
|
"check-branch",
|
||||||
|
"check-decl",
|
||||||
|
"check-operator",
|
||||||
|
"check-separator",
|
||||||
|
"check-type"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"class-name": true,
|
||||||
|
"comment-format": [
|
||||||
|
true,
|
||||||
|
"check-space"
|
||||||
|
],
|
||||||
|
"indent": [
|
||||||
|
true,
|
||||||
|
"spaces"
|
||||||
|
],
|
||||||
|
"no-eval": true,
|
||||||
|
"no-internal-module": true,
|
||||||
|
"no-trailing-whitespace": true,
|
||||||
|
"no-unsafe-finally": true,
|
||||||
|
"no-var-keyword": true,
|
||||||
|
"one-line": [
|
||||||
|
true,
|
||||||
|
"check-open-brace",
|
||||||
|
"check-whitespace"
|
||||||
|
],
|
||||||
|
"quotemark": [
|
||||||
|
true,
|
||||||
|
"double"
|
||||||
|
],
|
||||||
|
"semicolon": [
|
||||||
|
true,
|
||||||
|
"always"
|
||||||
|
],
|
||||||
|
"triple-equals": [
|
||||||
|
true,
|
||||||
|
"allow-null-check"
|
||||||
|
],
|
||||||
|
"typedef-whitespace": [
|
||||||
|
true,
|
||||||
|
{
|
||||||
|
"call-signature": "nospace",
|
||||||
|
"index-signature": "nospace",
|
||||||
|
"parameter": "nospace",
|
||||||
|
"property-declaration": "nospace",
|
||||||
|
"variable-declaration": "nospace"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"variable-name": [
|
||||||
|
true,
|
||||||
|
"ban-keywords"
|
||||||
|
],
|
||||||
|
"whitespace": [
|
||||||
|
true,
|
||||||
|
"check-branch",
|
||||||
|
"check-decl",
|
||||||
|
"check-operator",
|
||||||
|
"check-separator",
|
||||||
|
"check-type"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user