diff --git a/modules/openapi-generator/src/main/resources/typescript/http/http.mustache b/modules/openapi-generator/src/main/resources/typescript/http/http.mustache index 67ff4139aee1..6dc521f7ccc6 100644 --- a/modules/openapi-generator/src/main/resources/typescript/http/http.mustache +++ b/modules/openapi-generator/src/main/resources/typescript/http/http.mustache @@ -183,6 +183,13 @@ export class RequestContext { } public setHeaderParam(key: string, value: string): void { + // Delete any existing headers with case-insensitive matching keys + const lowerKey = key.toLowerCase(); + for (const existingKey in this.headers) { + if (existingKey.toLowerCase() === lowerKey) { + delete this.headers[existingKey]; + } + } this.headers[key] = value; } diff --git a/samples/client/echo_api/typescript/build/http/http.ts b/samples/client/echo_api/typescript/build/http/http.ts index 7eaf00563272..a5f59b18c70f 100644 --- a/samples/client/echo_api/typescript/build/http/http.ts +++ b/samples/client/echo_api/typescript/build/http/http.ts @@ -133,6 +133,13 @@ export class RequestContext { } public setHeaderParam(key: string, value: string): void { + // Delete any existing headers with case-insensitive matching keys + const lowerKey = key.toLowerCase(); + for (const existingKey in this.headers) { + if (existingKey.toLowerCase() === lowerKey) { + delete this.headers[existingKey]; + } + } this.headers[key] = value; } diff --git a/samples/client/others/typescript/builds/array-of-lists/http/http.ts b/samples/client/others/typescript/builds/array-of-lists/http/http.ts index d48cbd6b7705..6ac932c7c23a 100644 --- a/samples/client/others/typescript/builds/array-of-lists/http/http.ts +++ b/samples/client/others/typescript/builds/array-of-lists/http/http.ts @@ -124,6 +124,13 @@ export class RequestContext { } public setHeaderParam(key: string, value: string): void { + // Delete any existing headers with case-insensitive matching keys + const lowerKey = key.toLowerCase(); + for (const existingKey in this.headers) { + if (existingKey.toLowerCase() === lowerKey) { + delete this.headers[existingKey]; + } + } this.headers[key] = value; } diff --git a/samples/client/others/typescript/builds/enum-single-value/http/http.ts b/samples/client/others/typescript/builds/enum-single-value/http/http.ts index d48cbd6b7705..6ac932c7c23a 100644 --- a/samples/client/others/typescript/builds/enum-single-value/http/http.ts +++ b/samples/client/others/typescript/builds/enum-single-value/http/http.ts @@ -124,6 +124,13 @@ export class RequestContext { } public setHeaderParam(key: string, value: string): void { + // Delete any existing headers with case-insensitive matching keys + const lowerKey = key.toLowerCase(); + for (const existingKey in this.headers) { + if (existingKey.toLowerCase() === lowerKey) { + delete this.headers[existingKey]; + } + } this.headers[key] = value; } diff --git a/samples/client/others/typescript/builds/null-types-simple/http/http.ts b/samples/client/others/typescript/builds/null-types-simple/http/http.ts index d48cbd6b7705..6ac932c7c23a 100644 --- a/samples/client/others/typescript/builds/null-types-simple/http/http.ts +++ b/samples/client/others/typescript/builds/null-types-simple/http/http.ts @@ -124,6 +124,13 @@ export class RequestContext { } public setHeaderParam(key: string, value: string): void { + // Delete any existing headers with case-insensitive matching keys + const lowerKey = key.toLowerCase(); + for (const existingKey in this.headers) { + if (existingKey.toLowerCase() === lowerKey) { + delete this.headers[existingKey]; + } + } this.headers[key] = value; } diff --git a/samples/client/others/typescript/builds/with-unique-items/http/http.ts b/samples/client/others/typescript/builds/with-unique-items/http/http.ts index d48cbd6b7705..6ac932c7c23a 100644 --- a/samples/client/others/typescript/builds/with-unique-items/http/http.ts +++ b/samples/client/others/typescript/builds/with-unique-items/http/http.ts @@ -124,6 +124,13 @@ export class RequestContext { } public setHeaderParam(key: string, value: string): void { + // Delete any existing headers with case-insensitive matching keys + const lowerKey = key.toLowerCase(); + for (const existingKey in this.headers) { + if (existingKey.toLowerCase() === lowerKey) { + delete this.headers[existingKey]; + } + } this.headers[key] = value; } diff --git a/samples/client/others/typescript/encode-decode/build/http/http.ts b/samples/client/others/typescript/encode-decode/build/http/http.ts index 7eaf00563272..a5f59b18c70f 100644 --- a/samples/client/others/typescript/encode-decode/build/http/http.ts +++ b/samples/client/others/typescript/encode-decode/build/http/http.ts @@ -133,6 +133,13 @@ export class RequestContext { } public setHeaderParam(key: string, value: string): void { + // Delete any existing headers with case-insensitive matching keys + const lowerKey = key.toLowerCase(); + for (const existingKey in this.headers) { + if (existingKey.toLowerCase() === lowerKey) { + delete this.headers[existingKey]; + } + } this.headers[key] = value; } diff --git a/samples/openapi3/client/petstore/typescript/builds/browser/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/browser/http/http.ts index d48cbd6b7705..6ac932c7c23a 100644 --- a/samples/openapi3/client/petstore/typescript/builds/browser/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/browser/http/http.ts @@ -124,6 +124,13 @@ export class RequestContext { } public setHeaderParam(key: string, value: string): void { + // Delete any existing headers with case-insensitive matching keys + const lowerKey = key.toLowerCase(); + for (const existingKey in this.headers) { + if (existingKey.toLowerCase() === lowerKey) { + delete this.headers[existingKey]; + } + } this.headers[key] = value; } diff --git a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/http/http.ts index d48cbd6b7705..6ac932c7c23a 100644 --- a/samples/openapi3/client/petstore/typescript/builds/composed-schemas/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/composed-schemas/http/http.ts @@ -124,6 +124,13 @@ export class RequestContext { } public setHeaderParam(key: string, value: string): void { + // Delete any existing headers with case-insensitive matching keys + const lowerKey = key.toLowerCase(); + for (const existingKey in this.headers) { + if (existingKey.toLowerCase() === lowerKey) { + delete this.headers[existingKey]; + } + } this.headers[key] = value; } diff --git a/samples/openapi3/client/petstore/typescript/builds/default/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/default/http/http.ts index 7eaf00563272..a5f59b18c70f 100644 --- a/samples/openapi3/client/petstore/typescript/builds/default/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/default/http/http.ts @@ -133,6 +133,13 @@ export class RequestContext { } public setHeaderParam(key: string, value: string): void { + // Delete any existing headers with case-insensitive matching keys + const lowerKey = key.toLowerCase(); + for (const existingKey in this.headers) { + if (existingKey.toLowerCase() === lowerKey) { + delete this.headers[existingKey]; + } + } this.headers[key] = value; } diff --git a/samples/openapi3/client/petstore/typescript/builds/deno/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/deno/http/http.ts index 0b57a8a07b1b..c71b19bf2895 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno/http/http.ts @@ -123,6 +123,13 @@ export class RequestContext { } public setHeaderParam(key: string, value: string): void { + // Delete any existing headers with case-insensitive matching keys + const lowerKey = key.toLowerCase(); + for (const existingKey in this.headers) { + if (existingKey.toLowerCase() === lowerKey) { + delete this.headers[existingKey]; + } + } this.headers[key] = value; } diff --git a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/http/http.ts index 0b57a8a07b1b..c71b19bf2895 100644 --- a/samples/openapi3/client/petstore/typescript/builds/deno_object_params/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/deno_object_params/http/http.ts @@ -123,6 +123,13 @@ export class RequestContext { } public setHeaderParam(key: string, value: string): void { + // Delete any existing headers with case-insensitive matching keys + const lowerKey = key.toLowerCase(); + for (const existingKey in this.headers) { + if (existingKey.toLowerCase() === lowerKey) { + delete this.headers[existingKey]; + } + } this.headers[key] = value; } diff --git a/samples/openapi3/client/petstore/typescript/builds/explode-query/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/explode-query/http/http.ts index 7eaf00563272..a5f59b18c70f 100644 --- a/samples/openapi3/client/petstore/typescript/builds/explode-query/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/explode-query/http/http.ts @@ -133,6 +133,13 @@ export class RequestContext { } public setHeaderParam(key: string, value: string): void { + // Delete any existing headers with case-insensitive matching keys + const lowerKey = key.toLowerCase(); + for (const existingKey in this.headers) { + if (existingKey.toLowerCase() === lowerKey) { + delete this.headers[existingKey]; + } + } this.headers[key] = value; } diff --git a/samples/openapi3/client/petstore/typescript/builds/inversify/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/inversify/http/http.ts index e96c984cb800..b2c101e5f228 100644 --- a/samples/openapi3/client/petstore/typescript/builds/inversify/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/inversify/http/http.ts @@ -133,6 +133,13 @@ export class RequestContext { } public setHeaderParam(key: string, value: string): void { + // Delete any existing headers with case-insensitive matching keys + const lowerKey = key.toLowerCase(); + for (const existingKey in this.headers) { + if (existingKey.toLowerCase() === lowerKey) { + delete this.headers[existingKey]; + } + } this.headers[key] = value; } diff --git a/samples/openapi3/client/petstore/typescript/builds/jquery/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/jquery/http/http.ts index 0fb26e3bb3f8..db24c4927063 100644 --- a/samples/openapi3/client/petstore/typescript/builds/jquery/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/jquery/http/http.ts @@ -124,6 +124,13 @@ export class RequestContext { } public setHeaderParam(key: string, value: string): void { + // Delete any existing headers with case-insensitive matching keys + const lowerKey = key.toLowerCase(); + for (const existingKey in this.headers) { + if (existingKey.toLowerCase() === lowerKey) { + delete this.headers[existingKey]; + } + } this.headers[key] = value; } diff --git a/samples/openapi3/client/petstore/typescript/builds/nullable-enum/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/nullable-enum/http/http.ts index d48cbd6b7705..6ac932c7c23a 100644 --- a/samples/openapi3/client/petstore/typescript/builds/nullable-enum/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/nullable-enum/http/http.ts @@ -124,6 +124,13 @@ export class RequestContext { } public setHeaderParam(key: string, value: string): void { + // Delete any existing headers with case-insensitive matching keys + const lowerKey = key.toLowerCase(); + for (const existingKey in this.headers) { + if (existingKey.toLowerCase() === lowerKey) { + delete this.headers[existingKey]; + } + } this.headers[key] = value; } diff --git a/samples/openapi3/client/petstore/typescript/builds/object_params/http/http.ts b/samples/openapi3/client/petstore/typescript/builds/object_params/http/http.ts index 7eaf00563272..a5f59b18c70f 100644 --- a/samples/openapi3/client/petstore/typescript/builds/object_params/http/http.ts +++ b/samples/openapi3/client/petstore/typescript/builds/object_params/http/http.ts @@ -133,6 +133,13 @@ export class RequestContext { } public setHeaderParam(key: string, value: string): void { + // Delete any existing headers with case-insensitive matching keys + const lowerKey = key.toLowerCase(); + for (const existingKey in this.headers) { + if (existingKey.toLowerCase() === lowerKey) { + delete this.headers[existingKey]; + } + } this.headers[key] = value; } diff --git a/samples/openapi3/client/petstore/typescript/tests/default/test/http/isomorphic-fetch.test.ts b/samples/openapi3/client/petstore/typescript/tests/default/test/http/isomorphic-fetch.test.ts index 748c7ad46e33..a99e4c652672 100644 --- a/samples/openapi3/client/petstore/typescript/tests/default/test/http/isomorphic-fetch.test.ts +++ b/samples/openapi3/client/petstore/typescript/tests/default/test/http/isomorphic-fetch.test.ts @@ -67,5 +67,29 @@ for (let libName in libs) { done(); }).catch(done) }) + }) -} \ No newline at end of file + describe("Header Case Sensitivity", () => { + it("different case header key is replaced", () => { + let requestContext = new petstore.RequestContext("http://httpbin.org/cookies", petstore.HttpMethod.GET); + expect(requestContext.getHeaders().testkey1).to.be.undefined; + + requestContext.setHeaderParam("testkey1","testvalue1"); + expect(requestContext.getHeaders().testkey1).to.eq("testvalue1"); + + requestContext.setHeaderParam("tEsTkeY1","testvalue2"); + expect(requestContext.getHeaders().testkey1).to.be.undefined; + expect(requestContext.getHeaders().tEsTkeY1).to.eq("testvalue2"); + }) + it("indentical header key writes replace content", () => { + let requestContext = new petstore.RequestContext("http://httpbin.org/cookies", petstore.HttpMethod.GET); + expect(requestContext.getHeaders().testkey1).to.be.undefined; + + requestContext.setHeaderParam("testkey1","testvalue1"); + expect(requestContext.getHeaders().testkey1).to.eq("testvalue1"); + + requestContext.setHeaderParam("testkey1","testvalue2"); + expect(requestContext.getHeaders().testkey1).to.eq("testvalue2"); + }) + }) +}