Skip to content

Commit 16678b8

Browse files
committed
update ts angular v2, v4 petstore samples
1 parent 07df075 commit 16678b8

File tree

12 files changed

+282
-132
lines changed

12 files changed

+282
-132
lines changed

samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ export class PetService {
7474
return false;
7575
}
7676

77+
public isJsonMime(mime: string): boolean {
78+
const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$');
79+
return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
80+
}
81+
7782
/**
7883
*
7984
* @summary Add a new pet to the store
@@ -230,8 +235,8 @@ export class PetService {
230235
'application/json'
231236
];
232237

233-
if ((produces != null) && (produces.length > 0)) {
234-
headers.set('Accept', produces.join(';'));
238+
if (produces != null && produces.length > 0) {
239+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
235240
}
236241

237242
// authentication (petstore_auth) required
@@ -289,8 +294,8 @@ export class PetService {
289294
'application/json'
290295
];
291296

292-
if ((produces != null) && (produces.length > 0)) {
293-
headers.set('Accept', produces.join(';'));
297+
if (produces != null && produces.length > 0) {
298+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
294299
}
295300

296301
// authentication (petstore_auth) required
@@ -343,8 +348,8 @@ export class PetService {
343348
'application/json'
344349
];
345350

346-
if ((produces != null) && (produces.length > 0)) {
347-
headers.set('Accept', produces.join(';'));
351+
if (produces != null && produces.length > 0) {
352+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
348353
}
349354

350355
// authentication (petstore_auth) required
@@ -397,8 +402,8 @@ export class PetService {
397402
'application/json'
398403
];
399404

400-
if ((produces != null) && (produces.length > 0)) {
401-
headers.set('Accept', produces.join(';'));
405+
if (produces != null && produces.length > 0) {
406+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
402407
}
403408

404409
// authentication (petstore_auth) required
@@ -448,8 +453,8 @@ export class PetService {
448453
'application/json'
449454
];
450455

451-
if ((produces != null) && (produces.length > 0)) {
452-
headers.set('Accept', produces.join(';'));
456+
if (produces != null && produces.length > 0) {
457+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
453458
}
454459

455460
// authentication (api_key) required
@@ -494,8 +499,8 @@ export class PetService {
494499
'application/json'
495500
];
496501

497-
if ((produces != null) && (produces.length > 0)) {
498-
headers.set('Accept', produces.join(';'));
502+
if (produces != null && produces.length > 0) {
503+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
499504
}
500505

501506
// authentication (petstore_auth) required
@@ -548,8 +553,8 @@ export class PetService {
548553
'application/x-www-form-urlencoded'
549554
];
550555

551-
if ((consumes != null) && (consumes.length > 0)) {
552-
headers.set('Content-Type', consumes.join(';'));
556+
if (consumes != null && consumes.length > 0) {
557+
headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"));
553558
}
554559

555560
let canConsumeForm = this.canConsumeForm(consumes);
@@ -564,8 +569,8 @@ export class PetService {
564569
'application/json'
565570
];
566571

567-
if ((produces != null) && (produces.length > 0)) {
568-
headers.set('Accept', produces.join(';'));
572+
if (produces != null && produces.length > 0) {
573+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
569574
}
570575

571576
// authentication (petstore_auth) required
@@ -624,8 +629,8 @@ export class PetService {
624629
'multipart/form-data'
625630
];
626631

627-
if ((consumes != null) && (consumes.length > 0)) {
628-
headers.set('Content-Type', consumes.join(';'));
632+
if (consumes != null && consumes.length > 0) {
633+
headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"));
629634
}
630635

631636
let canConsumeForm = this.canConsumeForm(consumes);
@@ -640,8 +645,8 @@ export class PetService {
640645
'application/json'
641646
];
642647

643-
if ((produces != null) && (produces.length > 0)) {
644-
headers.set('Accept', produces.join(';'));
648+
if (produces != null && produces.length > 0) {
649+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
645650
}
646651

647652
// authentication (petstore_auth) required

samples/client/petstore/typescript-angular-v2/default/api/store.service.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ export class StoreService {
7373
return false;
7474
}
7575

76+
public isJsonMime(mime: string): boolean {
77+
const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$');
78+
return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
79+
}
80+
7681
/**
7782
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
7883
* @summary Delete purchase order by ID
@@ -160,8 +165,8 @@ export class StoreService {
160165
'application/json'
161166
];
162167

163-
if ((produces != null) && (produces.length > 0)) {
164-
headers.set('Accept', produces.join(';'));
168+
if (produces != null && produces.length > 0) {
169+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
165170
}
166171

167172

@@ -195,8 +200,8 @@ export class StoreService {
195200
'application/json'
196201
];
197202

198-
if ((produces != null) && (produces.length > 0)) {
199-
headers.set('Accept', produces.join(';'));
203+
if (produces != null && produces.length > 0) {
204+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
200205
}
201206

202207
// authentication (api_key) required
@@ -242,8 +247,8 @@ export class StoreService {
242247
'application/json'
243248
];
244249

245-
if ((produces != null) && (produces.length > 0)) {
246-
headers.set('Accept', produces.join(';'));
250+
if (produces != null && produces.length > 0) {
251+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
247252
}
248253

249254

@@ -283,8 +288,8 @@ export class StoreService {
283288
'application/json'
284289
];
285290

286-
if ((produces != null) && (produces.length > 0)) {
287-
headers.set('Accept', produces.join(';'));
291+
if (produces != null && produces.length > 0) {
292+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
288293
}
289294

290295

samples/client/petstore/typescript-angular-v2/default/api/user.service.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ export class UserService {
7373
return false;
7474
}
7575

76+
public isJsonMime(mime: string): boolean {
77+
const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$');
78+
return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
79+
}
80+
7681
/**
7782
* This can only be done by the logged in user.
7883
* @summary Create user
@@ -225,8 +230,8 @@ export class UserService {
225230
'application/json'
226231
];
227232

228-
if ((produces != null) && (produces.length > 0)) {
229-
headers.set('Accept', produces.join(';'));
233+
if (produces != null && produces.length > 0) {
234+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
230235
}
231236

232237

@@ -269,8 +274,8 @@ export class UserService {
269274
'application/json'
270275
];
271276

272-
if ((produces != null) && (produces.length > 0)) {
273-
headers.set('Accept', produces.join(';'));
277+
if (produces != null && produces.length > 0) {
278+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
274279
}
275280

276281

@@ -313,8 +318,8 @@ export class UserService {
313318
'application/json'
314319
];
315320

316-
if ((produces != null) && (produces.length > 0)) {
317-
headers.set('Accept', produces.join(';'));
321+
if (produces != null && produces.length > 0) {
322+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
318323
}
319324

320325

@@ -358,8 +363,8 @@ export class UserService {
358363
'application/json'
359364
];
360365

361-
if ((produces != null) && (produces.length > 0)) {
362-
headers.set('Accept', produces.join(';'));
366+
if (produces != null && produces.length > 0) {
367+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
363368
}
364369

365370

@@ -400,8 +405,8 @@ export class UserService {
400405
'application/json'
401406
];
402407

403-
if ((produces != null) && (produces.length > 0)) {
404-
headers.set('Accept', produces.join(';'));
408+
if (produces != null && produces.length > 0) {
409+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
405410
}
406411

407412

@@ -454,8 +459,8 @@ export class UserService {
454459
'application/json'
455460
];
456461

457-
if ((produces != null) && (produces.length > 0)) {
458-
headers.set('Accept', produces.join(';'));
462+
if (produces != null && produces.length > 0) {
463+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
459464
}
460465

461466

@@ -490,8 +495,8 @@ export class UserService {
490495
'application/json'
491496
];
492497

493-
if ((produces != null) && (produces.length > 0)) {
494-
headers.set('Accept', produces.join(';'));
498+
if (produces != null && produces.length > 0) {
499+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
495500
}
496501

497502

@@ -537,8 +542,8 @@ export class UserService {
537542
'application/json'
538543
];
539544

540-
if ((produces != null) && (produces.length > 0)) {
541-
headers.set('Accept', produces.join(';'));
545+
if (produces != null && produces.length > 0) {
546+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
542547
}
543548

544549

samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ export class PetService {
7474
return false;
7575
}
7676

77+
public isJsonMime(mime: string): boolean {
78+
const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$');
79+
return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
80+
}
81+
7782
/**
7883
*
7984
* @summary Add a new pet to the store
@@ -230,8 +235,8 @@ export class PetService {
230235
'application/json'
231236
];
232237

233-
if ((produces != null) && (produces.length > 0)) {
234-
headers.set('Accept', produces.join(';'));
238+
if (produces != null && produces.length > 0) {
239+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
235240
}
236241

237242
// authentication (petstore_auth) required
@@ -289,8 +294,8 @@ export class PetService {
289294
'application/json'
290295
];
291296

292-
if ((produces != null) && (produces.length > 0)) {
293-
headers.set('Accept', produces.join(';'));
297+
if (produces != null && produces.length > 0) {
298+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
294299
}
295300

296301
// authentication (petstore_auth) required
@@ -343,8 +348,8 @@ export class PetService {
343348
'application/json'
344349
];
345350

346-
if ((produces != null) && (produces.length > 0)) {
347-
headers.set('Accept', produces.join(';'));
351+
if (produces != null && produces.length > 0) {
352+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
348353
}
349354

350355
// authentication (petstore_auth) required
@@ -397,8 +402,8 @@ export class PetService {
397402
'application/json'
398403
];
399404

400-
if ((produces != null) && (produces.length > 0)) {
401-
headers.set('Accept', produces.join(';'));
405+
if (produces != null && produces.length > 0) {
406+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
402407
}
403408

404409
// authentication (petstore_auth) required
@@ -448,8 +453,8 @@ export class PetService {
448453
'application/json'
449454
];
450455

451-
if ((produces != null) && (produces.length > 0)) {
452-
headers.set('Accept', produces.join(';'));
456+
if (produces != null && produces.length > 0) {
457+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
453458
}
454459

455460
// authentication (api_key) required
@@ -494,8 +499,8 @@ export class PetService {
494499
'application/json'
495500
];
496501

497-
if ((produces != null) && (produces.length > 0)) {
498-
headers.set('Accept', produces.join(';'));
502+
if (produces != null && produces.length > 0) {
503+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
499504
}
500505

501506
// authentication (petstore_auth) required
@@ -548,8 +553,8 @@ export class PetService {
548553
'application/x-www-form-urlencoded'
549554
];
550555

551-
if ((consumes != null) && (consumes.length > 0)) {
552-
headers.set('Content-Type', consumes.join(';'));
556+
if (consumes != null && consumes.length > 0) {
557+
headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"));
553558
}
554559

555560
let canConsumeForm = this.canConsumeForm(consumes);
@@ -564,8 +569,8 @@ export class PetService {
564569
'application/json'
565570
];
566571

567-
if ((produces != null) && (produces.length > 0)) {
568-
headers.set('Accept', produces.join(';'));
572+
if (produces != null && produces.length > 0) {
573+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
569574
}
570575

571576
// authentication (petstore_auth) required
@@ -624,8 +629,8 @@ export class PetService {
624629
'multipart/form-data'
625630
];
626631

627-
if ((consumes != null) && (consumes.length > 0)) {
628-
headers.set('Content-Type', consumes.join(';'));
632+
if (consumes != null && consumes.length > 0) {
633+
headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"));
629634
}
630635

631636
let canConsumeForm = this.canConsumeForm(consumes);
@@ -640,8 +645,8 @@ export class PetService {
640645
'application/json'
641646
];
642647

643-
if ((produces != null) && (produces.length > 0)) {
644-
headers.set('Accept', produces.join(';'));
648+
if (produces != null && produces.length > 0) {
649+
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
645650
}
646651

647652
// authentication (petstore_auth) required

0 commit comments

Comments
 (0)