Skip to content

Commit

Permalink
Add endpoint to return pretanslations as USFM (#292)
Browse files Browse the repository at this point in the history
- 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
ddaspit authored Feb 1, 2024
1 parent 323fa98 commit 3d70a91
Show file tree
Hide file tree
Showing 63 changed files with 2,237 additions and 1,192 deletions.
9 changes: 8 additions & 1 deletion Serval.sln
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serval.E2ETests", "tests\Se
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serval.DataFiles.Tests", "tests\Serval.DataFiles.Tests\Serval.DataFiles.Tests.csproj", "{63E4D71B-11BE-4D68-A876-5B1B5F0A4C88}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SIL.DataAccess.Tests", "tests\SIL.DataAccess.Tests\SIL.DataAccess.Tests.csproj", "{71151518-8774-44D0-8E69-D77FA447BEFA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SIL.DataAccess.Tests", "tests\SIL.DataAccess.Tests\SIL.DataAccess.Tests.csproj", "{71151518-8774-44D0-8E69-D77FA447BEFA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serval.Shared.Tests", "tests\Serval.Shared.Tests\Serval.Shared.Tests.csproj", "{0E220C65-AA88-450E-AFB2-844E49060B3F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -120,6 +122,10 @@ Global
{71151518-8774-44D0-8E69-D77FA447BEFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71151518-8774-44D0-8E69-D77FA447BEFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71151518-8774-44D0-8E69-D77FA447BEFA}.Release|Any CPU.Build.0 = Release|Any CPU
{0E220C65-AA88-450E-AFB2-844E49060B3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E220C65-AA88-450E-AFB2-844E49060B3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E220C65-AA88-450E-AFB2-844E49060B3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E220C65-AA88-450E-AFB2-844E49060B3F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -140,6 +146,7 @@ Global
{1F020042-D7B8-4541-9691-26ECFD1FFC73} = {66246A1C-8D45-40FB-A660-C58577122CA7}
{63E4D71B-11BE-4D68-A876-5B1B5F0A4C88} = {66246A1C-8D45-40FB-A660-C58577122CA7}
{71151518-8774-44D0-8E69-D77FA447BEFA} = {66246A1C-8D45-40FB-A660-C58577122CA7}
{0E220C65-AA88-450E-AFB2-844E49060B3F} = {66246A1C-8D45-40FB-A660-C58577122CA7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9F18C25E-E140-43C3-B177-D562E1628370}
Expand Down
72 changes: 72 additions & 0 deletions src/Serval.ApiServer/Templates/Client.Class.ProcessResponse.liquid
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 %}
55 changes: 7 additions & 48 deletions src/Serval.ApiServer/nswag.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"documentGenerator": {
"aspNetCoreToOpenApi": {
"project": "Serval.ApiServer.csproj",
"documentName": "v1",
"msBuildProjectExtensionsPath": null,
"configuration": null,
"runtime": null,
Expand All @@ -12,60 +13,19 @@
"msBuildOutputPath": null,
"verbose": true,
"workingDirectory": null,
"requireParametersWithoutDefault": false,
"apiGroupNames": null,
"defaultPropertyNameHandling": "Default",
"defaultReferenceTypeNullHandling": "Null",
"defaultDictionaryValueReferenceTypeNullHandling": "NotNull",
"defaultResponseReferenceTypeNullHandling": "NotNull",
"generateOriginalParameterNames": true,
"defaultEnumHandling": "Integer",
"flattenInheritanceHierarchy": false,
"generateKnownTypes": true,
"generateEnumMappingDescription": false,
"generateXmlObjects": false,
"generateAbstractProperties": false,
"generateAbstractSchemas": true,
"ignoreObsoleteProperties": false,
"allowReferencesWithProperties": false,
"useXmlDocumentation": true,
"resolveExternalXmlDocumentation": true,
"excludedTypeNames": [],
"serviceHost": null,
"serviceBasePath": null,
"serviceSchemes": [],
"infoTitle": "My Title",
"infoDescription": null,
"infoVersion": "1.0.0",
"documentTemplate": null,
"documentProcessorTypes": [],
"operationProcessorTypes": [],
"typeNameGeneratorType": null,
"schemaNameGeneratorType": null,
"contractResolverType": null,
"serializerSettingsType": null,
"useDocumentProvider": true,
"documentName": "v1",
"aspNetCoreEnvironment": "Development",
"createWebHostBuilderMethod": null,
"startupType": null,
"allowNullableBodyParameters": true,
"useHttpAttributeNameAsOperationId": false,
"output": null,
"outputType": "Swagger2",
"newLineBehavior": "Auto",
"assemblyPaths": [],
"assemblyConfig": null,
"referencePaths": [],
"useNuGetCache": false
"newLineBehavior": "Auto"
}
},
"codeGenerators": {
"openApiToCSharpClient": {
"clientBaseClass": null,
"configurationClass": null,
"generateClientClasses": true,
"suppressClientClassesOutput": false,
"generateClientInterfaces": true,
"suppressClientInterfacesOutput": false,
"clientBaseInterface": null,
"injectHttpClient": true,
"disposeHttpClient": true,
Expand All @@ -83,6 +43,8 @@
"exposeJsonSerializerSettings": false,
"clientClassAccessModifier": "public",
"typeAccessModifier": "public",
"propertySetterAccessModifier": "",
"generateNativeRecords": false,
"generateContractsOutput": false,
"contractsNamespace": null,
"contractsOutputFilePath": null,
Expand Down Expand Up @@ -138,10 +100,7 @@
"generateDtoTypes": true,
"generateOptionalPropertiesAsNullable": false,
"generateNullableReferenceTypes": true,
"templateDirectory": null,
"typeNameGeneratorType": null,
"propertyNameGeneratorType": null,
"enumNameGeneratorType": null,
"templateDirectory": "Templates",
"serviceHost": null,
"serviceSchemes": null,
"output": "../Serval.Client/Client.g.cs",
Expand Down
Loading

0 comments on commit 3d70a91

Please sign in to comment.