/
Andru196
/
NSwagClone
Обзор
Документация
Войти
/
Andru196
/
NSwagClone
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
1
Аналитика
Безопасность
master
src/NSwag.CodeGeneration.TypeScript/Templates/AngularJSClient.liquid
97 строк
4 KB
Erik
- renamed ConsumesFormUrlEncoded to ConsumesOnlyFormUrlEncoded in liquid templates (#5029)
29 мар 2025, 18:52
Не верифицирован
29 мар 2025, 18:52
71ae244
Код
Авторство
О чём код?
{% if HasOperations -%} {% if GenerateClientInterfaces -%} {% if ExportTypes %}export {% endif %}interface I{{ Class }} { {% for operation in Operations -%} {% template Client.Method.Documentation %} {{ operation.MethodAccessModifier }}{{ operation.ActualOperationName }}({% for parameter in operation.Parameters %}{{ parameter.VariableName }}{% if GenerateOptionalParameters and parameter.IsOptional %}?{% endif %}: {{ parameter.Type }}{{ parameter.TypePostfix }}{% if parameter.IsLast == false %}, {% endif %}{% endfor %}): ng.IPromise<{{ operation.ResultType }}>; {% endfor -%}} {%- endif -%} {% if ExportTypes %}export {% endif %}class {{ Class }} {% if HasBaseClass %}extends {{ BaseClass }} {% endif %}{% if GenerateClientInterfaces %}implements I{{ Class }} {% endif %}{ private baseUrl: string{% if SupportsStrictNullChecks %} | undefined{% endif %} = undefined; private http: ng.IHttpService; private q: ng.IQService; protected jsonParseReviver: {% if SupportsStrictNullChecks %}((key: string, value: any) => any) | undefined{% else %}(key: string, value: any) => any{% endif %} = undefined; {%- if HasExtendedConstructor == false -%} constructor({% if HasConfigurationClass %}configuration: {{ ConfigurationClass }}, {% endif %}$http: ng.IHttpService, $q: ng.IQService, baseUrl?: string) { {%- if HasBaseClass -%} super({% if HasConfigurationClass %}configuration{% endif %}); {%- endif -%} this.http = $http; this.q = $q; {%- if UseGetBaseUrlMethod -%} this.baseUrl = baseUrl ?? this.getBaseUrl("{{ BaseUrl }}"); {%- else -%} this.baseUrl = baseUrl ?? "{{ BaseUrl }}"; {%- endif -%} } {%- endif -%} {% if HasExtensionCode -%} {{ ExtensionCode }} {%- endif -%} {% for operation in Operations %} {% template Client.Method.Documentation %} {{ operation.MethodAccessModifier }}{{ operation.ActualOperationName }}({% for parameter in operation.Parameters %}{{ parameter.VariableName }}{% if GenerateOptionalParameters and parameter.IsOptional %}?{% endif %}: {{ parameter.Type }}{{ parameter.TypePostfix }}{% if parameter.IsLast == false %}, {% endif %}{% endfor %}): ng.IPromise<{{ operation.ResultType }}> { {% template Client.RequestUrl %} {% if operation.HasBody -%} {% template Client.RequestBody %} {% endif -%} var options_: ng.IRequestConfig = { url: url_, method: "{{ operation.HttpMethodUpper | upcase }}", {% if operation.IsFile -%} responseType: "arraybuffer", {% endif -%} {% if operation.HasBody -%} data: content_, {% endif -%} transformResponse: [], headers: { {%- for parameter in operation.HeaderParameters -%} "{{ parameter.Name }}": {{ parameter.VariableName }} !== undefined && {{ parameter.VariableName }} !== null ? "" + {{ parameter.VariableName }} : "", {% endfor -%} {% if operation.HasContent or operation.ConsumesOnlyFormUrlEncoded -%} "Content-Type": "{{ operation.Consumes }}", {% endif -%} {% if operation.HasResultType and operation.HasAcceptHeaderParameterParameter == false -%} "Accept": "{{ operation.Produces }}" {% endif -%} } }; {% if UseTransformOptionsMethod -%} return this.transformOptions(options_).then(transformedOptions_ => { return this.http(transformedOptions_); }).then((_response) => { {% else -%} return this.http(options_).then((_response) => { {% endif -%} {% if UseTransformResultMethod -%} return this.transformResult(url_, _response, (_response) => this.process{{ operation.ActualOperationNameUpper }}(_response)); {% else -%} return this.process{{ operation.ActualOperationNameUpper }}(_response); {% endif -%} }, (_response) => { if (_response.status) {% if UseTransformResultMethod -%} return this.transformResult(url_, _response, (_response) => this.process{{ operation.ActualOperationNameUpper }}(_response)); {% else -%} return this.process{{ operation.ActualOperationNameUpper }}(_response); {% endif -%} throw _response; }); } protected process{{ operation.ActualOperationNameUpper }}(response: any): ng.IPromise<{{ operation.ResultType }}> { const status = response.status; {% template Client.ProcessResponse %} } {% endfor -%} } {%- endif -%}