update ts angular2 petstore oas2 (#249)

This commit is contained in:
William Cheng 2018-04-27 22:12:30 +08:00 committed by GitHub
parent 509fdd892b
commit 78c865e268
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 84 additions and 93 deletions

View File

@ -1 +1 @@
2.4.0-SNAPSHOT
3.0.0-SNAPSHOT

View File

@ -2,7 +2,7 @@
### Building
To build an compile the typescript sources to javascript use:
To install the required dependencies and to build the typescript sources run:
```
npm install
npm run build
@ -14,7 +14,7 @@ First build the package than run ```npm publish```
### consuming
navigate to the folder of your consuming project and run one of next commando's.
Navigate to the folder of your consuming project and run one of next commands.
_published:_
@ -22,7 +22,7 @@ _published:_
npm install @swagger/angular2-typescript-petstore@0.0.1 --save
```
_unPublished (not recommended):_
_without publishing (not recommended):_
```
npm install PATH_TO_GENERATED_PACKAGE --save
@ -37,9 +37,16 @@ npm link
In your project:
```
npm link @swagger/angular2-typescript-petstore@0.0.1
npm link @swagger/angular2-typescript-petstore
```
__Note for Windows users:__ The Angular CLI has troubles to use linked npm packages.
Please refer to this issue https://github.com/angular/angular-cli/issues/8284 for a solution / workaround.
Published packages are not effected by this issue.
#### General usage
In your Angular project:

View File

@ -61,10 +61,10 @@ export class PetService {
/**
*
* @summary Add a new pet to the store
* @param body Pet object that needs to be added to the store
* @param pet Pet object that needs to be added to the store
*/
public addPet(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> {
return this.addPetWithHttpInfo(body, extraHttpRequestParams)
public addPet(pet: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> {
return this.addPetWithHttpInfo(pet, extraHttpRequestParams)
.map((response: Response) => {
if (response.status === 204) {
return undefined;
@ -142,10 +142,10 @@ export class PetService {
/**
*
* @summary Update an existing pet
* @param body Pet object that needs to be added to the store
* @param pet Pet object that needs to be added to the store
*/
public updatePet(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> {
return this.updatePetWithHttpInfo(body, extraHttpRequestParams)
public updatePet(pet: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> {
return this.updatePetWithHttpInfo(pet, extraHttpRequestParams)
.map((response: Response) => {
if (response.status === 204) {
return undefined;
@ -195,12 +195,12 @@ export class PetService {
/**
* Add a new pet to the store
*
* @param body Pet object that needs to be added to the store
* @param pet Pet object that needs to be added to the store
*/
public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
if (body === null || body === undefined) {
throw new Error('Required parameter body was null or undefined when calling addPet.');
public addPetWithHttpInfo(pet: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
if (pet === null || pet === undefined) {
throw new Error('Required parameter pet was null or undefined when calling addPet.');
}
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
@ -215,8 +215,6 @@ export class PetService {
// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAcceptSelected != undefined) {
@ -236,7 +234,7 @@ export class PetService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Post,
headers: headers,
body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612
body: pet == null ? '' : JSON.stringify(pet), // https://github.com/angular/angular/issues/10612
withCredentials:this.configuration.withCredentials
});
// https://github.com/swagger-api/swagger-codegen/issues/4037
@ -274,8 +272,6 @@ export class PetService {
// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAcceptSelected != undefined) {
@ -455,12 +451,12 @@ export class PetService {
/**
* Update an existing pet
*
* @param body Pet object that needs to be added to the store
* @param pet Pet object that needs to be added to the store
*/
public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
if (body === null || body === undefined) {
throw new Error('Required parameter body was null or undefined when calling updatePet.');
public updatePetWithHttpInfo(pet: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
if (pet === null || pet === undefined) {
throw new Error('Required parameter pet was null or undefined when calling updatePet.');
}
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
@ -475,8 +471,6 @@ export class PetService {
// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAcceptSelected != undefined) {
@ -496,7 +490,7 @@ export class PetService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Put,
headers: headers,
body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612
body: pet == null ? '' : JSON.stringify(pet), // https://github.com/angular/angular/issues/10612
withCredentials:this.configuration.withCredentials
});
// https://github.com/swagger-api/swagger-codegen/issues/4037
@ -532,8 +526,6 @@ export class PetService {
// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAcceptSelected != undefined) {

View File

@ -107,10 +107,10 @@ export class StoreService {
/**
*
* @summary Place an order for a pet
* @param body order placed for purchasing the pet
* @param order order placed for purchasing the pet
*/
public placeOrder(body: Order, extraHttpRequestParams?: RequestOptionsArgs): Observable<Order> {
return this.placeOrderWithHttpInfo(body, extraHttpRequestParams)
public placeOrder(order: Order, extraHttpRequestParams?: RequestOptionsArgs): Observable<Order> {
return this.placeOrderWithHttpInfo(order, extraHttpRequestParams)
.map((response: Response) => {
if (response.status === 204) {
return undefined;
@ -136,8 +136,6 @@ export class StoreService {
// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAcceptSelected != undefined) {
@ -244,12 +242,12 @@ export class StoreService {
/**
* Place an order for a pet
*
* @param body order placed for purchasing the pet
* @param order order placed for purchasing the pet
*/
public placeOrderWithHttpInfo(body: Order, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
if (body === null || body === undefined) {
throw new Error('Required parameter body was null or undefined when calling placeOrder.');
public placeOrderWithHttpInfo(order: Order, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
if (order === null || order === undefined) {
throw new Error('Required parameter order was null or undefined when calling placeOrder.');
}
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
@ -275,7 +273,7 @@ export class StoreService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Post,
headers: headers,
body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612
body: order == null ? '' : JSON.stringify(order), // https://github.com/angular/angular/issues/10612
withCredentials:this.configuration.withCredentials
});
// https://github.com/swagger-api/swagger-codegen/issues/4037

View File

@ -60,10 +60,10 @@ export class UserService {
/**
* This can only be done by the logged in user.
* @summary Create user
* @param body Created user object
* @param user Created user object
*/
public createUser(body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> {
return this.createUserWithHttpInfo(body, extraHttpRequestParams)
public createUser(user: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> {
return this.createUserWithHttpInfo(user, extraHttpRequestParams)
.map((response: Response) => {
if (response.status === 204) {
return undefined;
@ -76,10 +76,10 @@ export class UserService {
/**
*
* @summary Creates list of users with given input array
* @param body List of user object
* @param user List of user object
*/
public createUsersWithArrayInput(body: Array<User>, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> {
return this.createUsersWithArrayInputWithHttpInfo(body, extraHttpRequestParams)
public createUsersWithArrayInput(user: Array<User>, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> {
return this.createUsersWithArrayInputWithHttpInfo(user, extraHttpRequestParams)
.map((response: Response) => {
if (response.status === 204) {
return undefined;
@ -92,10 +92,10 @@ export class UserService {
/**
*
* @summary Creates list of users with given input array
* @param body List of user object
* @param user List of user object
*/
public createUsersWithListInput(body: Array<User>, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> {
return this.createUsersWithListInputWithHttpInfo(body, extraHttpRequestParams)
public createUsersWithListInput(user: Array<User>, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> {
return this.createUsersWithListInputWithHttpInfo(user, extraHttpRequestParams)
.map((response: Response) => {
if (response.status === 204) {
return undefined;
@ -173,10 +173,10 @@ export class UserService {
* This can only be done by the logged in user.
* @summary Updated user
* @param username name that need to be deleted
* @param body Updated user object
* @param user Updated user object
*/
public updateUser(username: string, body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> {
return this.updateUserWithHttpInfo(username, body, extraHttpRequestParams)
public updateUser(username: string, user: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> {
return this.updateUserWithHttpInfo(username, user, extraHttpRequestParams)
.map((response: Response) => {
if (response.status === 204) {
return undefined;
@ -190,20 +190,18 @@ export class UserService {
/**
* Create user
* This can only be done by the logged in user.
* @param body Created user object
* @param user Created user object
*/
public createUserWithHttpInfo(body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
if (body === null || body === undefined) {
throw new Error('Required parameter body was null or undefined when calling createUser.');
public createUserWithHttpInfo(user: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
if (user === null || user === undefined) {
throw new Error('Required parameter user was null or undefined when calling createUser.');
}
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAcceptSelected != undefined) {
@ -221,7 +219,7 @@ export class UserService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Post,
headers: headers,
body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612
body: user == null ? '' : JSON.stringify(user), // https://github.com/angular/angular/issues/10612
withCredentials:this.configuration.withCredentials
});
// https://github.com/swagger-api/swagger-codegen/issues/4037
@ -235,20 +233,18 @@ export class UserService {
/**
* Creates list of users with given input array
*
* @param body List of user object
* @param user List of user object
*/
public createUsersWithArrayInputWithHttpInfo(body: Array<User>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
if (body === null || body === undefined) {
throw new Error('Required parameter body was null or undefined when calling createUsersWithArrayInput.');
public createUsersWithArrayInputWithHttpInfo(user: Array<User>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
if (user === null || user === undefined) {
throw new Error('Required parameter user was null or undefined when calling createUsersWithArrayInput.');
}
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAcceptSelected != undefined) {
@ -266,7 +262,7 @@ export class UserService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Post,
headers: headers,
body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612
body: user == null ? '' : JSON.stringify(user), // https://github.com/angular/angular/issues/10612
withCredentials:this.configuration.withCredentials
});
// https://github.com/swagger-api/swagger-codegen/issues/4037
@ -280,20 +276,18 @@ export class UserService {
/**
* Creates list of users with given input array
*
* @param body List of user object
* @param user List of user object
*/
public createUsersWithListInputWithHttpInfo(body: Array<User>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
if (body === null || body === undefined) {
throw new Error('Required parameter body was null or undefined when calling createUsersWithListInput.');
public createUsersWithListInputWithHttpInfo(user: Array<User>, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
if (user === null || user === undefined) {
throw new Error('Required parameter user was null or undefined when calling createUsersWithListInput.');
}
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAcceptSelected != undefined) {
@ -311,7 +305,7 @@ export class UserService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Post,
headers: headers,
body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612
body: user == null ? '' : JSON.stringify(user), // https://github.com/angular/angular/issues/10612
withCredentials:this.configuration.withCredentials
});
// https://github.com/swagger-api/swagger-codegen/issues/4037
@ -337,8 +331,6 @@ export class UserService {
// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAcceptSelected != undefined) {
@ -418,10 +410,10 @@ export class UserService {
}
let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper());
if (username !== undefined) {
if (username !== undefined && username !== null) {
queryParameters.set('username', <any>username);
}
if (password !== undefined) {
if (password !== undefined && password !== null) {
queryParameters.set('password', <any>password);
}
@ -466,8 +458,6 @@ export class UserService {
// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAcceptSelected != undefined) {
@ -495,23 +485,21 @@ export class UserService {
* Updated user
* This can only be done by the logged in user.
* @param username name that need to be deleted
* @param body Updated user object
* @param user Updated user object
*/
public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
public updateUserWithHttpInfo(username: string, user: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
if (username === null || username === undefined) {
throw new Error('Required parameter username was null or undefined when calling updateUser.');
}
if (body === null || body === undefined) {
throw new Error('Required parameter body was null or undefined when calling updateUser.');
if (user === null || user === undefined) {
throw new Error('Required parameter user was null or undefined when calling updateUser.');
}
let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845
// to determine the Accept header
let httpHeaderAccepts: string[] = [
'application/xml',
'application/json'
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAcceptSelected != undefined) {
@ -529,7 +517,7 @@ export class UserService {
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Put,
headers: headers,
body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612
body: user == null ? '' : JSON.stringify(user), // https://github.com/angular/angular/issues/10612
withCredentials:this.configuration.withCredentials
});
// https://github.com/swagger-api/swagger-codegen/issues/4037

View File

@ -28,8 +28,8 @@ export class Configuration {
* Select the correct content-type to use for a request.
* Uses {@link Configuration#isJsonMime} to determine the correct content-type.
* If no content type is found return the first found type if the contentTypes is not empty
* @param {string[]} contentTypes - the array of content types that are available for selection
* @returns {string} the selected content-type or <code>undefined</code> if no selection could be made.
* @param contentTypes - the array of content types that are available for selection
* @returns the selected content-type or <code>undefined</code> if no selection could be made.
*/
public selectHeaderContentType (contentTypes: string[]): string | undefined {
if (contentTypes.length == 0) {
@ -47,8 +47,8 @@ export class Configuration {
* Select the correct accept content-type to use for a request.
* Uses {@link Configuration#isJsonMime} to determine the correct accept content-type.
* If no content type is found return the first found type if the contentTypes is not empty
* @param {string[]} accepts - the array of content types that are available for selection.
* @returns {string} the selected content-type or <code>undefined</code> if no selection could be made.
* @param accepts - the array of content types that are available for selection.
* @returns the selected content-type or <code>undefined</code> if no selection could be made.
*/
public selectHeaderAccept(accepts: string[]): string | undefined {
if (accepts.length == 0) {
@ -69,8 +69,8 @@ export class Configuration {
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* @param {string} mime - MIME (Multipurpose Internet Mail Extensions)
* @return {boolean} True if the given MIME is JSON, false otherwise.
* @param mime - MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is JSON, false otherwise.
*/
public isJsonMime(mime: string): boolean {
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');

View File

@ -8,9 +8,10 @@
],
"license": "Unlicense",
"main": "dist/index.js",
"module": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"build": "tsc --outDir dist/",
"build": "ngc",
"postinstall": "npm run build"
},
"peerDependencies": {
@ -24,6 +25,7 @@
"zone.js": "^0.7.6"
},
"devDependencies": {
"@angular/compiler-cli": "^2.0.0",
"@angular/core": "^2.0.0",
"@angular/http": "^2.0.0",
"@angular/common": "^2.0.0",

View File

@ -21,5 +21,9 @@
"filesGlob": [
"./model/*.ts",
"./api/*.ts"
]
],
"angularCompilerOptions": {
"genDir": "dist",
"skipTemplateCodegen": true
}
}