From 188e998683d8d753a9b47789431f795e7a6f25a7 Mon Sep 17 00:00:00 2001 From: wing328 Date: Sun, 23 Jul 2017 15:52:02 +0800 Subject: [PATCH] add petstore samples for typescript aurelia --- .gitignore | 1 + bin/apache2-petstore-config.sh | 0 bin/eiffel-petstore.sh | 0 ...java-play-framework-petstore-server-all.sh | 0 ...amework-petstore-server-controller-only.sh | 0 ...work-petstore-server-no-bean-validation.sh | 0 ...k-petstore-server-no-exception-handling.sh | 0 ...-framework-petstore-server-no-interface.sh | 0 ...framework-petstore-server-no-swagger-ui.sh | 0 ...framework-petstore-server-no-wrap-calls.sh | 0 bin/typescript-aurelia-petstore.sh | 31 ++ bin/typescript-jquery-petstore-with-npm.sh | 0 bin/typescript-jquery-petstore.sh | 0 .../typescript-aurelia/default/.gitignore | 3 + .../default/.swagger-codegen-ignore | 23 ++ .../default/.swagger-codegen/VERSION | 1 + .../typescript-aurelia/default/Api.ts | 76 ++++ .../typescript-aurelia/default/AuthStorage.ts | 72 ++++ .../typescript-aurelia/default/PetApi.ts | 369 ++++++++++++++++++ .../typescript-aurelia/default/README.md | 55 +++ .../typescript-aurelia/default/StoreApi.ts | 181 +++++++++ .../typescript-aurelia/default/UserApi.ts | 341 ++++++++++++++++ .../typescript-aurelia/default/git_push.sh | 52 +++ .../typescript-aurelia/default/index.ts | 25 ++ .../typescript-aurelia/default/models.ts | 94 +++++ .../typescript-aurelia/default/package.json | 21 + .../typescript-aurelia/default/tsconfig.json | 14 + .../typescript-aurelia/default/tslint.json | 101 +++++ 28 files changed, 1460 insertions(+) mode change 100644 => 100755 bin/apache2-petstore-config.sh mode change 100644 => 100755 bin/eiffel-petstore.sh mode change 100644 => 100755 bin/java-play-framework-petstore-server-all.sh mode change 100644 => 100755 bin/java-play-framework-petstore-server-controller-only.sh mode change 100644 => 100755 bin/java-play-framework-petstore-server-no-bean-validation.sh mode change 100644 => 100755 bin/java-play-framework-petstore-server-no-exception-handling.sh mode change 100644 => 100755 bin/java-play-framework-petstore-server-no-interface.sh mode change 100644 => 100755 bin/java-play-framework-petstore-server-no-swagger-ui.sh mode change 100644 => 100755 bin/java-play-framework-petstore-server-no-wrap-calls.sh create mode 100755 bin/typescript-aurelia-petstore.sh mode change 100644 => 100755 bin/typescript-jquery-petstore-with-npm.sh mode change 100644 => 100755 bin/typescript-jquery-petstore.sh create mode 100644 samples/client/petstore/typescript-aurelia/default/.gitignore create mode 100644 samples/client/petstore/typescript-aurelia/default/.swagger-codegen-ignore create mode 100644 samples/client/petstore/typescript-aurelia/default/.swagger-codegen/VERSION create mode 100644 samples/client/petstore/typescript-aurelia/default/Api.ts create mode 100644 samples/client/petstore/typescript-aurelia/default/AuthStorage.ts create mode 100644 samples/client/petstore/typescript-aurelia/default/PetApi.ts create mode 100644 samples/client/petstore/typescript-aurelia/default/README.md create mode 100644 samples/client/petstore/typescript-aurelia/default/StoreApi.ts create mode 100644 samples/client/petstore/typescript-aurelia/default/UserApi.ts create mode 100644 samples/client/petstore/typescript-aurelia/default/git_push.sh create mode 100644 samples/client/petstore/typescript-aurelia/default/index.ts create mode 100644 samples/client/petstore/typescript-aurelia/default/models.ts create mode 100644 samples/client/petstore/typescript-aurelia/default/package.json create mode 100644 samples/client/petstore/typescript-aurelia/default/tsconfig.json create mode 100644 samples/client/petstore/typescript-aurelia/default/tslint.json diff --git a/.gitignore b/.gitignore index 8cc98ef5e5b..6e86af71481 100644 --- a/.gitignore +++ b/.gitignore @@ -160,6 +160,7 @@ samples/client/petstore/typescript-fetch/**/dist/ samples/client/petstore/typescript-fetch/**/typings samples/client/petstore/typescript-angular2/npm/npm-debug.log samples/client/petstore/typescript-node/npm/npm-debug.log +samples/client/petstore/typescript-aurelia/**/dist/ # aspnetcore samples/server/petstore/aspnetcore/.vs/ diff --git a/bin/apache2-petstore-config.sh b/bin/apache2-petstore-config.sh old mode 100644 new mode 100755 diff --git a/bin/eiffel-petstore.sh b/bin/eiffel-petstore.sh old mode 100644 new mode 100755 diff --git a/bin/java-play-framework-petstore-server-all.sh b/bin/java-play-framework-petstore-server-all.sh old mode 100644 new mode 100755 diff --git a/bin/java-play-framework-petstore-server-controller-only.sh b/bin/java-play-framework-petstore-server-controller-only.sh old mode 100644 new mode 100755 diff --git a/bin/java-play-framework-petstore-server-no-bean-validation.sh b/bin/java-play-framework-petstore-server-no-bean-validation.sh old mode 100644 new mode 100755 diff --git a/bin/java-play-framework-petstore-server-no-exception-handling.sh b/bin/java-play-framework-petstore-server-no-exception-handling.sh old mode 100644 new mode 100755 diff --git a/bin/java-play-framework-petstore-server-no-interface.sh b/bin/java-play-framework-petstore-server-no-interface.sh old mode 100644 new mode 100755 diff --git a/bin/java-play-framework-petstore-server-no-swagger-ui.sh b/bin/java-play-framework-petstore-server-no-swagger-ui.sh old mode 100644 new mode 100755 diff --git a/bin/java-play-framework-petstore-server-no-wrap-calls.sh b/bin/java-play-framework-petstore-server-no-wrap-calls.sh old mode 100644 new mode 100755 diff --git a/bin/typescript-aurelia-petstore.sh b/bin/typescript-aurelia-petstore.sh new file mode 100755 index 00000000000..ff96244a24c --- /dev/null +++ b/bin/typescript-aurelia-petstore.sh @@ -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 diff --git a/bin/typescript-jquery-petstore-with-npm.sh b/bin/typescript-jquery-petstore-with-npm.sh old mode 100644 new mode 100755 diff --git a/bin/typescript-jquery-petstore.sh b/bin/typescript-jquery-petstore.sh old mode 100644 new mode 100755 diff --git a/samples/client/petstore/typescript-aurelia/default/.gitignore b/samples/client/petstore/typescript-aurelia/default/.gitignore new file mode 100644 index 00000000000..35e2fb2b02e --- /dev/null +++ b/samples/client/petstore/typescript-aurelia/default/.gitignore @@ -0,0 +1,3 @@ +wwwroot/*.js +node_modules +typings diff --git a/samples/client/petstore/typescript-aurelia/default/.swagger-codegen-ignore b/samples/client/petstore/typescript-aurelia/default/.swagger-codegen-ignore new file mode 100644 index 00000000000..c5fa491b4c5 --- /dev/null +++ b/samples/client/petstore/typescript-aurelia/default/.swagger-codegen-ignore @@ -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 diff --git a/samples/client/petstore/typescript-aurelia/default/.swagger-codegen/VERSION b/samples/client/petstore/typescript-aurelia/default/.swagger-codegen/VERSION new file mode 100644 index 00000000000..f9f7450d135 --- /dev/null +++ b/samples/client/petstore/typescript-aurelia/default/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/typescript-aurelia/default/Api.ts b/samples/client/petstore/typescript-aurelia/default/Api.ts new file mode 100644 index 00000000000..f9988b22a81 --- /dev/null +++ b/samples/client/petstore/typescript-aurelia/default/Api.ts @@ -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(context: string, params: T, paramName: keyof T): void { + if (null === params[paramName]) { + throw new Error(`Missing required parameter ${paramName} when calling ${context}`); + } + } +} diff --git a/samples/client/petstore/typescript-aurelia/default/AuthStorage.ts b/samples/client/petstore/typescript-aurelia/default/AuthStorage.ts new file mode 100644 index 00000000000..993c00ec69e --- /dev/null +++ b/samples/client/petstore/typescript-aurelia/default/AuthStorage.ts @@ -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; + + 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; + } +} diff --git a/samples/client/petstore/typescript-aurelia/default/PetApi.ts b/samples/client/petstore/typescript-aurelia/default/PetApi.ts new file mode 100644 index 00000000000..5d4a980b283 --- /dev/null +++ b/samples/client/petstore/typescript-aurelia/default/PetApi.ts @@ -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; +} + +/** + * findPetsByTags - parameters interface + */ +export interface IFindPetsByTagsParams { + tags: Array; +} + +/** + * 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 { + // 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 { + // 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> { + // 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> { + // 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 { + // 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 { + // 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 { + // 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 { + // 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; + } + +} + diff --git a/samples/client/petstore/typescript-aurelia/default/README.md b/samples/client/petstore/typescript-aurelia/default/README.md new file mode 100644 index 00000000000..1796b7e1e89 --- /dev/null +++ b/samples/client/petstore/typescript-aurelia/default/README.md @@ -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')'; +``` diff --git a/samples/client/petstore/typescript-aurelia/default/StoreApi.ts b/samples/client/petstore/typescript-aurelia/default/StoreApi.ts new file mode 100644 index 00000000000..bd618b888dc --- /dev/null +++ b/samples/client/petstore/typescript-aurelia/default/StoreApi.ts @@ -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 { + // 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 { + // 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 { + // 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; + } + +} + diff --git a/samples/client/petstore/typescript-aurelia/default/UserApi.ts b/samples/client/petstore/typescript-aurelia/default/UserApi.ts new file mode 100644 index 00000000000..c569b2a4b79 --- /dev/null +++ b/samples/client/petstore/typescript-aurelia/default/UserApi.ts @@ -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; +} + +/** + * createUsersWithListInput - parameters interface + */ +export interface ICreateUsersWithListInputParams { + body: Array; +} + +/** + * 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 { + // 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 { + // 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 { + // 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 { + // 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 { + // 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 { + // 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 { + // 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 { + // 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; + } + +} + diff --git a/samples/client/petstore/typescript-aurelia/default/git_push.sh b/samples/client/petstore/typescript-aurelia/default/git_push.sh new file mode 100644 index 00000000000..ed374619b13 --- /dev/null +++ b/samples/client/petstore/typescript-aurelia/default/git_push.sh @@ -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' + diff --git a/samples/client/petstore/typescript-aurelia/default/index.ts b/samples/client/petstore/typescript-aurelia/default/index.ts new file mode 100644 index 00000000000..8802b491d48 --- /dev/null +++ b/samples/client/petstore/typescript-aurelia/default/index.ts @@ -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'; diff --git a/samples/client/petstore/typescript-aurelia/default/models.ts b/samples/client/petstore/typescript-aurelia/default/models.ts new file mode 100644 index 00000000000..e6eab3791c9 --- /dev/null +++ b/samples/client/petstore/typescript-aurelia/default/models.ts @@ -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; + tags?: Array; + /** + * 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; +} + diff --git a/samples/client/petstore/typescript-aurelia/default/package.json b/samples/client/petstore/typescript-aurelia/default/package.json new file mode 100644 index 00000000000..0204e3c39c9 --- /dev/null +++ b/samples/client/petstore/typescript-aurelia/default/package.json @@ -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" + } +} diff --git a/samples/client/petstore/typescript-aurelia/default/tsconfig.json b/samples/client/petstore/typescript-aurelia/default/tsconfig.json new file mode 100644 index 00000000000..1a36def5fe7 --- /dev/null +++ b/samples/client/petstore/typescript-aurelia/default/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "declaration": true, + "target": "es5", + "module": "commonjs", + "noImplicitAny": true, + "outDir": "dist", + "rootDir": "." + }, + "exclude": [ + "dist", + "node_modules" + ] +} diff --git a/samples/client/petstore/typescript-aurelia/default/tslint.json b/samples/client/petstore/typescript-aurelia/default/tslint.json new file mode 100644 index 00000000000..6eb02acec8c --- /dev/null +++ b/samples/client/petstore/typescript-aurelia/default/tslint.json @@ -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" + ] + } +}