[TypeScript][Angular] Better support for "Accept", "Content-Type" (#6454)

* add consumes and produces as corresponding headers if present

* add check for empty array
fix copy/paste error

* fix styling

* add isJsonMime
filter produces- and consumes-Arrays for json-mime items
This commit is contained in:
stoetti
2017-09-23 09:48:05 +02:00
committed by wing328
parent b1e7a4f724
commit 07df0759d3
10 changed files with 284 additions and 0 deletions

View File

@@ -78,6 +78,11 @@ export class {{classname}} {
return false;
}
public isJsonMime(mime: string): boolean {
const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$');
return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
}
{{#operation}}
/**
* {{&notes}}
@@ -175,6 +180,11 @@ export class {{classname}} {
'{{{mediaType}}}'{{#hasMore}},{{/hasMore}}
{{/consumes}}
];
if (consumes != null && consumes.length > 0) {
headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"));
}
let canConsumeForm = this.canConsumeForm(consumes);
let useForm = false;
{{#formParams}}
@@ -194,6 +204,10 @@ export class {{classname}} {
{{/produces}}
];
if (produces != null && produces.length > 0) {
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'));
}
{{#authMethods}}
// authentication ({{name}}) required
{{#isApiKey}}