Skip to content

Commit

Permalink
DMU-3198 Include models nuget package documentation in Swagger output.
Browse files Browse the repository at this point in the history
  • Loading branch information
hgj52 committed Feb 24, 2020
1 parent 6119220 commit 4aaa449
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 21 deletions.
14 changes: 7 additions & 7 deletions Controllers/ArchiveController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Text.Json;
using System.Xml.Serialization;
using Microsoft.AspNetCore.Authorization;
Expand Down Expand Up @@ -83,18 +84,17 @@ public IActionResult Post([FromBody] ArchiveMessage archiveMessage)
});

Directory.CreateDirectory(_settings.Value.ArchiveFolder);

System.IO.File.WriteAllBytes(Path.Combine(_settings.Value.ArchiveFolder, $"archiveDoc-{archiveMessage.JobId}.pdf"), archiveMessage.MainDocument.DocumentData);
var archiveId = Guid.NewGuid();
System.IO.File.WriteAllBytes(Path.Combine(_settings.Value.ArchiveFolder, $"archiveDoc-{archiveId}.pdf"), archiveMessage.MainDocument.DocumentData);

// Don't save document data in JSON or XML
archiveMessage.MainDocument.DocumentData = null;
if (archiveMessage.Addendums != null) foreach (var addendum in archiveMessage.Addendums) addendum.DocumentData = null;

System.IO.File.WriteAllText(Path.Combine(_settings.Value.ArchiveFolder, $"archiveDoc-{archiveMessage.JobId}.json"), JsonSerializer.Serialize(archiveMessage));
using (var fs = new FileStream(Path.Combine(_settings.Value.ArchiveFolder, $"archiveDoc-{archiveMessage.JobId}.xml"), FileMode.Create))
System.IO.File.WriteAllText(Path.Combine(_settings.Value.ArchiveFolder, $"archiveDoc-{archiveId}.json"), JsonSerializer.Serialize(archiveMessage));
using (var fs = new FileStream(Path.Combine(_settings.Value.ArchiveFolder, $"archiveDoc-{archiveId}.xml"), FileMode.Create))
new XmlSerializer(typeof(ArchiveMessage)).Serialize(fs, archiveMessage);

return Ok();
return Ok($"Archive ID: {archiveId}");
}
}
}
39 changes: 39 additions & 0 deletions Documentation/OneTooXRestArchiveTest.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions OneTooXRestArchiveTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>OneTooXRestArchiveTest.xml</DocumentationFile>
<DocumentationFile>Documentation/OneTooXRestArchiveTest.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -18,7 +18,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="4.1.1" />
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
<PackageReference Include="OneTooX.RestPush.Model" Version="1.2.5" />
<PackageReference Include="OneTooX.RestPush.Model" Version="1.2.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
</ItemGroup>

Expand Down
16 changes: 4 additions & 12 deletions Startup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
Expand All @@ -8,7 +8,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.Net.Http.Headers;
using Microsoft.OpenApi.Models;
using OneTooXRestArchiveTest.Security;
using OneTooXRestArchiveTest.User;
Expand Down Expand Up @@ -42,7 +41,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1.0", new OpenApiInfo { Title = "OneTooX Archive API", Version = "v1.0" });
c.IncludeXmlComments(XmlCommentsFilePath);
foreach (var xml in XmlCommentsFilePaths) c.IncludeXmlComments(xml);
});
}

Expand All @@ -69,14 +68,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
});
}

private static string XmlCommentsFilePath
{
get
{
var basePath = PlatformServices.Default.Application.ApplicationBasePath;
var fileName = typeof(Startup).GetTypeInfo().Assembly.GetName().Name + ".xml";
return Path.Combine(basePath, fileName);
}
}
private static IEnumerable<string> XmlCommentsFilePaths
=> Directory.EnumerateFiles(PlatformServices.Default.Application.ApplicationBasePath, "OneTooX*.xml", SearchOption.AllDirectories);
}
}

0 comments on commit 4aaa449

Please sign in to comment.