Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export type HttpFile = {{{fileContentDataType}}} & { readonly name: string };
{{/node}}
{{/platforms}}

export type Headers = { [key: string]: string }

{{#platforms}}
{{#deno}}
/**
Expand Down Expand Up @@ -110,7 +112,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URLParse;

Expand All @@ -120,8 +122,9 @@ export class RequestContext {
* @param url url of the requested resource
* @param httpMethod http method
*/
public constructor(url: string, private httpMethod: HttpMethod) {
public constructor(url: string, private httpMethod: HttpMethod, headers: Headers = {}) {
this.url = new URLParse(url, true);
this.headers = headers;
}

/*
Expand Down Expand Up @@ -157,7 +160,7 @@ export class RequestContext {
return this.httpMethod;
}

public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { RequestContext, HttpMethod } from "./http/http{{extensionForDeno}}";
import { RequestContext, HttpMethod, Headers } from "./http/http{{extensionForDeno}}";

export interface BaseServerConfiguration {
getHeaders(): Headers
makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext;
addHeaders(headers: Headers): any;
setHeaderParam(key: string, value: string): void
}

/**
Expand All @@ -11,7 +14,7 @@ export interface BaseServerConfiguration {
*
*/
export class ServerConfiguration<T extends { [key: string]: string }> implements BaseServerConfiguration {
public constructor(private url: string, private variableConfiguration: T) {}
public constructor(private url: string, private variableConfiguration: T, private headers: Headers = {}) {}

/**
* Sets the value of the variables of this server.
Expand All @@ -26,6 +29,18 @@ export class ServerConfiguration<T extends { [key: string]: string }> implements
return this.variableConfiguration
}

public addHeaders(headers: Headers): void {
Object.assign(this.headers, headers);
}

public getHeaders(): Headers {
return this.headers
}

public setHeaderParam(key: string, value: string): void {
this.headers[key] = value;
}

private getUrl() {
let replacedUrl = this.url;
for (const key in this.variableConfiguration) {
Expand All @@ -44,7 +59,7 @@ export class ServerConfiguration<T extends { [key: string]: string }> implements
*
*/
public makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext {
return new RequestContext(this.getUrl() + endpoint, httpMethod);
return new RequestContext(this.getUrl() + endpoint, httpMethod, Object.assign({}, this.headers));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{#useRxJS}}
import type { Observable } from "rxjs";
{{/useRxJS}}
import type { {{^useRxJS}}Promise{{/useRxJS}}HttpLibrary, HttpMethod, RequestContext, ResponseContext } from "../http/http";
import type { {{^useRxJS}}Promise{{/useRxJS}}HttpLibrary, Headers, HttpMethod, RequestContext, ResponseContext } from "../http/http";
import type { {{^useRxJS}}Promise{{/useRxJS}}Middleware } from "../middleware";
import type { BaseServerConfiguration } from "../servers";

Expand All @@ -15,5 +15,8 @@ export abstract class AbstractMiddleware implements {{^useRxJS}}Promise{{/useRxJ
}

export abstract class AbstractServerConfiguration implements BaseServerConfiguration {
public abstract getHeaders(): Headers
public abstract makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext;
public abstract addHeaders(headers: Headers): any;
public abstract setHeaderParam(key: string, value: string): void
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export enum HttpMethod {
*/
export type HttpFile = Blob & { readonly name: string };

export type Headers = { [key: string]: string }


export class HttpException extends Error {
public constructor(msg: string) {
Expand All @@ -41,7 +43,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URLParse;

Expand All @@ -51,8 +53,9 @@ export class RequestContext {
* @param url url of the requested resource
* @param httpMethod http method
*/
public constructor(url: string, private httpMethod: HttpMethod) {
public constructor(url: string, private httpMethod: HttpMethod, headers: Headers = {}) {
this.url = new URLParse(url, true);
this.headers = headers;
}

/*
Expand Down Expand Up @@ -88,7 +91,7 @@ export class RequestContext {
return this.httpMethod;
}

public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { RequestContext, HttpMethod } from "./http/http";
import { RequestContext, HttpMethod, Headers } from "./http/http";

export interface BaseServerConfiguration {
getHeaders(): Headers
makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext;
addHeaders(headers: Headers): any;
setHeaderParam(key: string, value: string): void
}

/**
Expand All @@ -11,7 +14,7 @@ export interface BaseServerConfiguration {
*
*/
export class ServerConfiguration<T extends { [key: string]: string }> implements BaseServerConfiguration {
public constructor(private url: string, private variableConfiguration: T) {}
public constructor(private url: string, private variableConfiguration: T, private headers: Headers = {}) {}

/**
* Sets the value of the variables of this server.
Expand All @@ -26,6 +29,18 @@ export class ServerConfiguration<T extends { [key: string]: string }> implements
return this.variableConfiguration
}

public addHeaders(headers: Headers): void {
Object.assign(this.headers, headers);
}

public getHeaders(): Headers {
return this.headers
}

public setHeaderParam(key: string, value: string): void {
this.headers[key] = value;
}

private getUrl() {
let replacedUrl = this.url;
for (const key in this.variableConfiguration) {
Expand All @@ -44,7 +59,7 @@ export class ServerConfiguration<T extends { [key: string]: string }> implements
*
*/
public makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext {
return new RequestContext(this.getUrl() + endpoint, httpMethod);
return new RequestContext(this.getUrl() + endpoint, httpMethod, Object.assign({}, this.headers));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export type HttpFile = {
name: string
};

export type Headers = { [key: string]: string }


export class HttpException extends Error {
public constructor(msg: string) {
Expand All @@ -47,7 +49,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URLParse;

Expand All @@ -57,8 +59,9 @@ export class RequestContext {
* @param url url of the requested resource
* @param httpMethod http method
*/
public constructor(url: string, private httpMethod: HttpMethod) {
public constructor(url: string, private httpMethod: HttpMethod, headers: Headers = {}) {
this.url = new URLParse(url, true);
this.headers = headers;
}

/*
Expand Down Expand Up @@ -94,7 +97,7 @@ export class RequestContext {
return this.httpMethod;
}

public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { RequestContext, HttpMethod } from "./http/http";
import { RequestContext, HttpMethod, Headers } from "./http/http";

export interface BaseServerConfiguration {
getHeaders(): Headers
makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext;
addHeaders(headers: Headers): any;
setHeaderParam(key: string, value: string): void
}

/**
Expand All @@ -11,7 +14,7 @@ export interface BaseServerConfiguration {
*
*/
export class ServerConfiguration<T extends { [key: string]: string }> implements BaseServerConfiguration {
public constructor(private url: string, private variableConfiguration: T) {}
public constructor(private url: string, private variableConfiguration: T, private headers: Headers = {}) {}

/**
* Sets the value of the variables of this server.
Expand All @@ -26,6 +29,18 @@ export class ServerConfiguration<T extends { [key: string]: string }> implements
return this.variableConfiguration
}

public addHeaders(headers: Headers): void {
Object.assign(this.headers, headers);
}

public getHeaders(): Headers {
return this.headers
}

public setHeaderParam(key: string, value: string): void {
this.headers[key] = value;
}

private getUrl() {
let replacedUrl = this.url;
for (const key in this.variableConfiguration) {
Expand All @@ -44,7 +59,7 @@ export class ServerConfiguration<T extends { [key: string]: string }> implements
*
*/
public makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext {
return new RequestContext(this.getUrl() + endpoint, httpMethod);
return new RequestContext(this.getUrl() + endpoint, httpMethod, Object.assign({}, this.headers));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export enum HttpMethod {
*/
export type HttpFile = Blob & { readonly name: string };

export type Headers = { [key: string]: string }

/**
* URLParse Wrapper for Deno
*/
Expand Down Expand Up @@ -70,7 +72,7 @@ export type RequestBody = undefined | string | FormData | URLSearchParams;
* Represents an HTTP request context
*/
export class RequestContext {
private headers: { [key: string]: string } = {};
private headers: Headers = {};
private body: RequestBody = undefined;
private url: URLParse;

Expand All @@ -80,8 +82,9 @@ export class RequestContext {
* @param url url of the requested resource
* @param httpMethod http method
*/
public constructor(url: string, private httpMethod: HttpMethod) {
public constructor(url: string, private httpMethod: HttpMethod, headers: Headers = {}) {
this.url = new URLParse(url, true);
this.headers = headers;
}

/*
Expand Down Expand Up @@ -117,7 +120,7 @@ export class RequestContext {
return this.httpMethod;
}

public getHeaders(): { [key: string]: string } {
public getHeaders(): Headers {
return this.headers;
}

Expand Down
21 changes: 18 additions & 3 deletions samples/openapi3/client/petstore/typescript/builds/deno/servers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { RequestContext, HttpMethod } from "./http/http.ts";
import { RequestContext, HttpMethod, Headers } from "./http/http.ts";

export interface BaseServerConfiguration {
getHeaders(): Headers
makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext;
addHeaders(headers: Headers): any;
setHeaderParam(key: string, value: string): void
}

/**
Expand All @@ -11,7 +14,7 @@ export interface BaseServerConfiguration {
*
*/
export class ServerConfiguration<T extends { [key: string]: string }> implements BaseServerConfiguration {
public constructor(private url: string, private variableConfiguration: T) {}
public constructor(private url: string, private variableConfiguration: T, private headers: Headers = {}) {}

/**
* Sets the value of the variables of this server.
Expand All @@ -26,6 +29,18 @@ export class ServerConfiguration<T extends { [key: string]: string }> implements
return this.variableConfiguration
}

public addHeaders(headers: Headers): void {
Object.assign(this.headers, headers);
}

public getHeaders(): Headers {
return this.headers
}

public setHeaderParam(key: string, value: string): void {
this.headers[key] = value;
}

private getUrl() {
let replacedUrl = this.url;
for (const key in this.variableConfiguration) {
Expand All @@ -44,7 +59,7 @@ export class ServerConfiguration<T extends { [key: string]: string }> implements
*
*/
public makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext {
return new RequestContext(this.getUrl() + endpoint, httpMethod);
return new RequestContext(this.getUrl() + endpoint, httpMethod, Object.assign({}, this.headers));
}
}

Expand Down
Loading