[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}}

View File

@@ -230,6 +230,10 @@ export class PetService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -285,6 +289,10 @@ export class PetService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -335,6 +343,10 @@ export class PetService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -385,6 +397,10 @@ export class PetService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -432,6 +448,10 @@ export class PetService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (api_key) required
if (this.configuration.apiKeys["api_key"]) {
headers.set('api_key', this.configuration.apiKeys["api_key"]);
@@ -474,6 +494,10 @@ export class PetService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -523,6 +547,11 @@ export class PetService {
let consumes: string[] = [
'application/x-www-form-urlencoded'
];
if ((consumes != null) && (consumes.length > 0)) {
headers.set('Content-Type', consumes.join(';'));
}
let canConsumeForm = this.canConsumeForm(consumes);
let useForm = false;
let formParams = new (useForm ? FormData : URLSearchParams as any)() as {
@@ -535,6 +564,10 @@ export class PetService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -590,6 +623,11 @@ export class PetService {
let consumes: string[] = [
'multipart/form-data'
];
if ((consumes != null) && (consumes.length > 0)) {
headers.set('Content-Type', consumes.join(';'));
}
let canConsumeForm = this.canConsumeForm(consumes);
let useForm = false;
useForm = canConsumeForm;
@@ -602,6 +640,10 @@ export class PetService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {

View File

@@ -160,6 +160,10 @@ export class StoreService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Delete,
@@ -191,6 +195,10 @@ export class StoreService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (api_key) required
if (this.configuration.apiKeys["api_key"]) {
headers.set('api_key', this.configuration.apiKeys["api_key"]);
@@ -234,6 +242,10 @@ export class StoreService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
@@ -271,6 +283,10 @@ export class StoreService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
headers.set('Content-Type', 'application/json');

View File

@@ -225,6 +225,10 @@ export class UserService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
headers.set('Content-Type', 'application/json');
@@ -265,6 +269,10 @@ export class UserService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
headers.set('Content-Type', 'application/json');
@@ -305,6 +313,10 @@ export class UserService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
headers.set('Content-Type', 'application/json');
@@ -346,6 +358,10 @@ export class UserService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Delete,
@@ -384,6 +400,10 @@ export class UserService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
@@ -434,6 +454,10 @@ export class UserService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
@@ -466,6 +490,10 @@ export class UserService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
@@ -509,6 +537,10 @@ export class UserService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
headers.set('Content-Type', 'application/json');

View File

@@ -230,6 +230,10 @@ export class PetService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -285,6 +289,10 @@ export class PetService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -335,6 +343,10 @@ export class PetService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -385,6 +397,10 @@ export class PetService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -432,6 +448,10 @@ export class PetService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (api_key) required
if (this.configuration.apiKeys["api_key"]) {
headers.set('api_key', this.configuration.apiKeys["api_key"]);
@@ -474,6 +494,10 @@ export class PetService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -523,6 +547,11 @@ export class PetService {
let consumes: string[] = [
'application/x-www-form-urlencoded'
];
if ((consumes != null) && (consumes.length > 0)) {
headers.set('Content-Type', consumes.join(';'));
}
let canConsumeForm = this.canConsumeForm(consumes);
let useForm = false;
let formParams = new (useForm ? FormData : URLSearchParams as any)() as {
@@ -535,6 +564,10 @@ export class PetService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -590,6 +623,11 @@ export class PetService {
let consumes: string[] = [
'multipart/form-data'
];
if ((consumes != null) && (consumes.length > 0)) {
headers.set('Content-Type', consumes.join(';'));
}
let canConsumeForm = this.canConsumeForm(consumes);
let useForm = false;
useForm = canConsumeForm;
@@ -602,6 +640,10 @@ export class PetService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {

View File

@@ -160,6 +160,10 @@ export class StoreService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Delete,
@@ -191,6 +195,10 @@ export class StoreService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (api_key) required
if (this.configuration.apiKeys["api_key"]) {
headers.set('api_key', this.configuration.apiKeys["api_key"]);
@@ -234,6 +242,10 @@ export class StoreService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
@@ -271,6 +283,10 @@ export class StoreService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
headers.set('Content-Type', 'application/json');

View File

@@ -225,6 +225,10 @@ export class UserService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
headers.set('Content-Type', 'application/json');
@@ -265,6 +269,10 @@ export class UserService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
headers.set('Content-Type', 'application/json');
@@ -305,6 +313,10 @@ export class UserService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
headers.set('Content-Type', 'application/json');
@@ -346,6 +358,10 @@ export class UserService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Delete,
@@ -384,6 +400,10 @@ export class UserService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
@@ -434,6 +454,10 @@ export class UserService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
@@ -466,6 +490,10 @@ export class UserService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
@@ -509,6 +537,10 @@ export class UserService {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
headers.set('Content-Type', 'application/json');

View File

@@ -231,6 +231,10 @@ export class PetService implements PetServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -286,6 +290,10 @@ export class PetService implements PetServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -336,6 +344,10 @@ export class PetService implements PetServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -386,6 +398,10 @@ export class PetService implements PetServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -433,6 +449,10 @@ export class PetService implements PetServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (api_key) required
if (this.configuration.apiKeys["api_key"]) {
headers.set('api_key', this.configuration.apiKeys["api_key"]);
@@ -475,6 +495,10 @@ export class PetService implements PetServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -524,6 +548,11 @@ export class PetService implements PetServiceInterface {
let consumes: string[] = [
'application/x-www-form-urlencoded'
];
if ((consumes != null) && (consumes.length > 0)) {
headers.set('Content-Type', consumes.join(';'));
}
let canConsumeForm = this.canConsumeForm(consumes);
let useForm = false;
let formParams = new (useForm ? FormData : URLSearchParams as any)() as {
@@ -536,6 +565,10 @@ export class PetService implements PetServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@@ -591,6 +624,11 @@ export class PetService implements PetServiceInterface {
let consumes: string[] = [
'multipart/form-data'
];
if ((consumes != null) && (consumes.length > 0)) {
headers.set('Content-Type', consumes.join(';'));
}
let canConsumeForm = this.canConsumeForm(consumes);
let useForm = false;
useForm = canConsumeForm;
@@ -603,6 +641,10 @@ export class PetService implements PetServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {

View File

@@ -161,6 +161,10 @@ export class StoreService implements StoreServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Delete,
@@ -192,6 +196,10 @@ export class StoreService implements StoreServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
// authentication (api_key) required
if (this.configuration.apiKeys["api_key"]) {
headers.set('api_key', this.configuration.apiKeys["api_key"]);
@@ -235,6 +243,10 @@ export class StoreService implements StoreServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
@@ -272,6 +284,10 @@ export class StoreService implements StoreServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
headers.set('Content-Type', 'application/json');

View File

@@ -226,6 +226,10 @@ export class UserService implements UserServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
headers.set('Content-Type', 'application/json');
@@ -266,6 +270,10 @@ export class UserService implements UserServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
headers.set('Content-Type', 'application/json');
@@ -306,6 +314,10 @@ export class UserService implements UserServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
headers.set('Content-Type', 'application/json');
@@ -347,6 +359,10 @@ export class UserService implements UserServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Delete,
@@ -385,6 +401,10 @@ export class UserService implements UserServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
@@ -435,6 +455,10 @@ export class UserService implements UserServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
@@ -467,6 +491,10 @@ export class UserService implements UserServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
@@ -510,6 +538,10 @@ export class UserService implements UserServiceInterface {
'application/json'
];
if ((produces != null) && (produces.length > 0)) {
headers.set('Accept', produces.join(';'));
}
headers.set('Content-Type', 'application/json');