From 4aaa449ef9fe12c409dbb7df4e9a88acebfe776a Mon Sep 17 00:00:00 2001 From: Henning Gammelgaard Jensen Date: Mon, 24 Feb 2020 15:36:30 +0100 Subject: [PATCH] DMU-3198 Include models nuget package documentation in Swagger output. --- Controllers/ArchiveController.cs | 14 ++++----- Documentation/OneTooXRestArchiveTest.xml | 39 ++++++++++++++++++++++++ OneTooXRestArchiveTest.csproj | 4 +-- Startup.cs | 16 +++------- 4 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 Documentation/OneTooXRestArchiveTest.xml diff --git a/Controllers/ArchiveController.cs b/Controllers/ArchiveController.cs index dc91b17..b4e9fc2 100644 --- a/Controllers/ArchiveController.cs +++ b/Controllers/ArchiveController.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using System.Text.Json; using System.Xml.Serialization; using Microsoft.AspNetCore.Authorization; @@ -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}"); } } } diff --git a/Documentation/OneTooXRestArchiveTest.xml b/Documentation/OneTooXRestArchiveTest.xml new file mode 100644 index 0000000..54e4db0 --- /dev/null +++ b/Documentation/OneTooXRestArchiveTest.xml @@ -0,0 +1,39 @@ + + + + OneTooXRestArchiveTest + + + + + Post the archive message. + + + The Content-Type header must be set and correspond to the content of the body. +
+ Use the Accept header to control the format of the response. Possible values are application/json (default) and application/xml. +

+ If the invocation succeeds HTTP status code 200 is returned. +
+ If the invocation fails a problem details object is returned. The problem details object follows the guidelines in RFC-7807. + The following problem types are explicitly supported by the archive client: +
+
  • +
    https://onetoox.dk/unknown-receiver
    +
    The receiver is not known in the receiving system
    +
  • +
  • +
    https://onetoox.dk/invalid-archive-category
    +
    The archive category is not valid
    +
  • +
  • +
    https://onetoox.dk/validation-error
    +
    Validation error. The specific error is described by the title and detail attributes
    +
  • +
    +
    + + +
    +
    +
    diff --git a/OneTooXRestArchiveTest.csproj b/OneTooXRestArchiveTest.csproj index 3d57f5f..4a95008 100644 --- a/OneTooXRestArchiveTest.csproj +++ b/OneTooXRestArchiveTest.csproj @@ -5,7 +5,7 @@ - OneTooXRestArchiveTest.xml + Documentation/OneTooXRestArchiveTest.xml @@ -18,7 +18,7 @@ - + diff --git a/Startup.cs b/Startup.cs index e608cdf..f793186 100644 --- a/Startup.cs +++ b/Startup.cs @@ -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; @@ -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; @@ -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); }); } @@ -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 XmlCommentsFilePaths + => Directory.EnumerateFiles(PlatformServices.Default.Application.ApplicationBasePath, "OneTooX*.xml", SearchOption.AllDirectories); } }