-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add endpoint to return pretanslations as USFM (#292)
- add Scripture data file service - cleanup translation controllers - cleanup tests - update test dependencies - customize NSwag client template to support "text/plain" response
- Loading branch information
Showing
63 changed files
with
2,237 additions
and
1,192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/Serval.ApiServer/Templates/Client.Class.ProcessResponse.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{% if response.HasType -%} | ||
{% if response.IsFile -%} | ||
{% if response.IsSuccess -%} | ||
var responseStream_ = response_.Content == null ? System.IO.Stream.Null : await response_.Content.ReadAsStreamAsync().ConfigureAwait(false); | ||
var fileResponse_ = new FileResponse(status_, headers_, responseStream_, {% if InjectHttpClient or DisposeHttpClient == false %}null{% else %}client_{% endif %}, response_); | ||
disposeClient_ = false; disposeResponse_ = false; // response and client are disposed by FileResponse | ||
return fileResponse_; | ||
{% else -%} | ||
var objectResponse_ = await ReadObjectResponseAsync<{{ response.Type }}>(response_, headers_, cancellationToken).ConfigureAwait(false); | ||
throw new {{ ExceptionClass }}<{{ response.Type }}>("{{ response.ExceptionDescription }}", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); | ||
{% endif -%} | ||
{% elsif response.IsPlainText or operation.Produces == "text/plain" -%} | ||
var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); | ||
var result_ = ({{ response.Type }})System.Convert.ChangeType(responseData_, typeof({{ response.Type }})); | ||
{% if response.IsSuccess -%} | ||
{% if operation.WrapResponse -%} | ||
return new {{ ResponseClass }}<{{ operation.UnwrappedResultType }}>(status_, headers_, result_); | ||
{% else -%} | ||
return result_; | ||
{% endif -%} | ||
{% else -%} | ||
throw new {{ ExceptionClass }}<{{ response.Type }}>("{{ response.ExceptionDescription }}", status_, responseData_, headers_, result_, null); | ||
{% endif -%} | ||
{% else -%} | ||
var objectResponse_ = await ReadObjectResponseAsync<{{ response.Type }}>(response_, headers_, cancellationToken).ConfigureAwait(false); | ||
{% if response.IsNullable == false -%} | ||
if (objectResponse_.Object == null) | ||
{ | ||
throw new {{ ExceptionClass }}("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); | ||
} | ||
{% endif -%} | ||
{% if response.IsSuccess -%} | ||
{% if operation.WrapResponse -%} | ||
return new {{ ResponseClass }}<{{ operation.UnwrappedResultType }}>(status_, headers_, objectResponse_.Object); | ||
{% else -%} | ||
return objectResponse_.Object; | ||
{% endif -%} | ||
{% endif -%} | ||
{% if response.IsSuccess == false -%} | ||
{% if response.InheritsExceptionSchema -%} | ||
var responseObject_ = objectResponse_.Object != null ? objectResponse_.Object : new {{ response.Type }}(); | ||
responseObject_.Data.Add("HttpStatus", status_.ToString()); | ||
responseObject_.Data.Add("HttpHeaders", headers_); | ||
responseObject_.Data.Add("HttpResponse", objectResponse_.Text); | ||
{% if WrapDtoExceptions -%} | ||
throw new {{ ExceptionClass }}("{{ response.ExceptionDescription }}", status_, objectResponse_.Text, headers_, responseObject_); | ||
{% else -%} | ||
throw responseObject_; | ||
{% endif -%} | ||
{% else -%} | ||
throw new {{ ExceptionClass }}<{{ response.Type }}>("{{ response.ExceptionDescription }}", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); | ||
{% endif -%} | ||
{% endif -%} | ||
{% endif -%} | ||
{% elsif response.IsSuccess -%} | ||
{% if operation.HasResultType -%} | ||
{% if operation.WrapResponse -%} | ||
return new {{ ResponseClass }}<{{ operation.UnwrappedResultType }}>(status_, headers_, {{ operation.UnwrappedResultDefaultValue }}); | ||
{% else -%} | ||
return {{ operation.UnwrappedResultDefaultValue }}; | ||
{% endif -%} | ||
{% else -%} | ||
{% if operation.WrapResponse -%} | ||
return new {{ ResponseClass }}(status_, headers_); | ||
{% else -%} | ||
return; | ||
{% endif -%} | ||
{% endif -%} | ||
{% else -%}{% comment %} implied: `if !response.HasType` so just read it as text {% endcomment %} | ||
string responseText_ = ( response_.Content == null ) ? string.Empty : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); | ||
throw new {{ ExceptionClass }}("{{ response.ExceptionDescription }}", status_, responseText_, headers_, null); | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.