All Downloads are FREE. Search and download functionalities are using the official Maven repository.

typescript-rxjs.servers.mustache Maven / Gradle / Ivy

There is a newer version: 7.6.0
Show newest version
/**
 *
 * Represents the configuration of a server including its
 * url template and variable configuration based on the url.
 *
 */
export class ServerConfiguration {
    public constructor(private url: string, private variableConfiguration: T, private description: string) {}

    /**
     * Sets the value of the variables of this server.
     *
     * @param variableConfiguration a partial variable configuration for the variables contained in the url
     */
    public setVariables(variableConfiguration: Partial) {
        Object.assign(this.variableConfiguration, variableConfiguration);
    }

    public getConfiguration(): T {
        return this.variableConfiguration;
    }

    public getDescription(): string {
        return this.description;
    }

    /**
     * Constructions the URL this server using the url with variables
     * replaced with their respective values
     */
    public getUrl(): string {
        let replacedUrl = this.url;
        for (const key in this.variableConfiguration) {
            if (this.variableConfiguration.hasOwnProperty(key)) {
                 const re = new RegExp("{" + key + "}","g");
                 replacedUrl = replacedUrl.replace(re, this.variableConfiguration[key]);
            }
        }
        return replacedUrl;
    }
}

{{#servers}}
const server{{-index}} = new ServerConfiguration<{ {{#variables}} "{{name}}": {{#enumValues}}"{{.}}"{{^-last}} | {{/-last}}{{/enumValues}}{{^enumValues}}string{{/enumValues}}{{^-last}},{{/-last}} {{/variables}} }>("{{url}}", { {{#variables}} "{{name}}": "{{defaultValue}}" {{^-last}},{{/-last}}{{/variables}} }, "{{description}}");
{{/servers}}

export const servers = [{{#servers}}server{{-index}}{{^-last}}, {{/-last}}{{/servers}}];




© 2015 - 2024 Weber Informatics LLC | Privacy Policy