/
Andru196
/
NSwagClone
Обзор
Документация
Войти
/
Andru196
/
NSwagClone
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
1
Аналитика
Безопасность
master
src/NSwag.CodeGeneration.TypeScript/Templates/JQueryCallbacksClient.liquid
98 строк
5 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 }}, {% endfor %}onSuccess?: ({% if operation.HasResultType %}result: {{ operation.ResultType }}{% endif %}) => void, onFail?: (exception: {{ operation.ExceptionType }}, reason: string) => void): JQueryXHR; {% endfor -%}} {% endif -%} {% if ExportTypes %}export {% endif %}class {{ Class }} {% if HasBaseClass %}extends {{ BaseClass }} {% endif %}{% if GenerateClientInterfaces %}implements I{{ Class }} {% endif %}{ baseUrl: string; beforeSend: any = undefined; 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 %}baseUrl?: string) { {% if HasBaseClass -%} super({% if HasConfigurationClass %}configuration{% endif %}); {% endif -%} {% 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 }}, {% endfor %}onSuccess?: ({% if operation.HasResultType %}result: {{ operation.ResultType }}{% endif %}) => void, onFail?: (exception: {{ operation.ExceptionType }}, reason: string) => void): JQueryXHR { {% template Client.RequestUrl %} {% if operation.HasBody -%} {% template Client.RequestBody %} {% endif -%} let jqXhr = jQuery.ajax({% if UseTransformOptionsMethod %}this.transformOptions({% endif %}{ url: url_, beforeSend: this.beforeSend, type: "{{ operation.HttpMethodLower }}", {% if operation.HasBody -%} data: content_, {% endif -%} {% if operation.HasFormParameters -%} mimeType: "multipart/form-data", contentType: false, {% else -%} dataType: "text", {% endif -%} 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 %}){% endif %}); jqXhr.done((_data, _textStatus, xhr) => { this.process{{ operation.ActualOperationNameUpper }}WithCallbacks(url_, xhr, onSuccess, onFail); }).fail((xhr) => { this.process{{ operation.ActualOperationNameUpper }}WithCallbacks(url_, xhr, onSuccess, onFail); }); return jqXhr; } private process{{ operation.ActualOperationNameUpper }}WithCallbacks(_url: string, xhr: any, onSuccess?: any, onFail?: any): void { try { {% if UseTransformResultMethod -%} let result = this.transformResult(_url, xhr, (xhr) => this.process{{ operation.ActualOperationNameUpper }}(xhr)); {% else -%} let result = this.process{{ operation.ActualOperationNameUpper }}(xhr); {% endif -%} if (onSuccess !== undefined) onSuccess(result); } catch (e) { if (onFail !== undefined) onFail(e, "http_service_exception"); } } protected process{{ operation.ActualOperationNameUpper }}(xhr: any): {{ operation.ResultType }}{% if operation.HasResultType and SupportsStrictNullChecks %} | null{% endif %} { const status = xhr.status; {% template Client.ProcessResponse %} } {% endfor -%} } {% endif -%}