Browse Source

[fix]修复子表swagger默认xml输入格式错误问题

master
贾荣国 3 years ago
parent
commit
d50c8aed57
  1. 6
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/PurchaseOrderCreateDTO.cs
  2. 1
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/PurchaseOrderDetailDTO.cs
  3. 139
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Logs/logs.txt
  4. 49
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Startup.cs

6
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/PurchaseOrderCreateDTO.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using Volo.Abp.Application.Dtos;
using Win_in.Sfs.Scp.WebApi.Domain.Shared;
@ -112,8 +113,9 @@ public class PurchaseOrderCreateDTO : EntityDto,ICanTrace
[Display(Name = "公司(Company)")]
public string Company { set; get; }
[XmlArray(elementName: "poDetails")]
[XmlArrayItem(elementName: "poDetail")]
[XmlArray(elementName: "details")]
[XmlArrayItem(elementName: "PurchaseOrderDetailDTO")]
public virtual List<PurchaseOrderDetailDTO> Details { get; set; }
/// <summary>

1
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/PurchaseOrderDetailDTO.cs

@ -11,7 +11,6 @@ namespace Win_in.Sfs.Scp.WebApi
/// 采购订单明细DTO(Purchase order detail DTO)
/// </summary>
[Serializable, DataContract]
[XmlType("poDetail")]
public class PurchaseOrderDetailDTO : EntityDetailDtoBase
{

139
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Logs/logs.txt

@ -5283,3 +5283,142 @@ DenyAnonymousAuthorizationRequirement: Requires an authenticated user.
2022-01-12 16:52:46.485 +08:00 [INF] Executed action Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) in 16536.2737ms
2022-01-12 16:52:46.485 +08:00 [INF] Executed endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-12 16:52:46.486 +08:00 [INF] Request finished HTTP/2 POST https://localhost:9977/api/scp/part application/xml 530 - 200 1021 application/xml;+charset=utf-8 16599.3958ms
2022-01-12 17:19:49.950 +08:00 [INF] Starting Win_in.Sfs.Scp.WebApi.Xml.Host.
2022-01-12 17:19:51.055 +08:00 [INF] User profile is available. Using 'C:\Users\changketec\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
2022-01-12 17:19:51.979 +08:00 [INF] Now listening on: https://localhost:9977
2022-01-12 17:19:51.979 +08:00 [INF] Application started. Press Ctrl+C to shut down.
2022-01-12 17:19:51.979 +08:00 [INF] Hosting environment: Development
2022-01-12 17:19:51.979 +08:00 [INF] Content root path: D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host
2022-01-12 17:19:54.035 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/index.html - -
2022-01-12 17:19:54.612 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/index.html - - - 200 - text/html;charset=utf-8 579.2845ms
2022-01-12 17:19:54.920 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - -
2022-01-12 17:19:54.923 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - - 200 11964 application/javascript;+charset=utf-8 3.3573ms
2022-01-12 17:19:55.764 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - -
2022-01-12 17:19:56.193 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 429.6386ms
2022-01-12 17:31:45.414 +08:00 [INF] Starting Win_in.Sfs.Scp.WebApi.Xml.Host.
2022-01-12 17:31:46.374 +08:00 [INF] User profile is available. Using 'C:\Users\changketec\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
2022-01-12 17:31:47.037 +08:00 [INF] Now listening on: https://localhost:9977
2022-01-12 17:31:47.037 +08:00 [INF] Application started. Press Ctrl+C to shut down.
2022-01-12 17:31:47.037 +08:00 [INF] Hosting environment: Development
2022-01-12 17:31:47.037 +08:00 [INF] Content root path: D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host
2022-01-12 17:31:48.864 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/index.html - -
2022-01-12 17:31:49.465 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/index.html - - - 200 - text/html;charset=utf-8 603.2456ms
2022-01-12 17:31:49.505 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - -
2022-01-12 17:31:49.508 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - - 200 11964 application/javascript;+charset=utf-8 2.7230ms
2022-01-12 17:31:50.472 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - -
2022-01-12 17:31:50.850 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 378.1960ms
2022-01-12 17:33:10.104 +08:00 [INF] Starting Win_in.Sfs.Scp.WebApi.Xml.Host.
2022-01-12 17:33:11.114 +08:00 [INF] User profile is available. Using 'C:\Users\changketec\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
2022-01-12 17:33:12.190 +08:00 [INF] Now listening on: https://localhost:9977
2022-01-12 17:33:12.191 +08:00 [INF] Application started. Press Ctrl+C to shut down.
2022-01-12 17:33:12.191 +08:00 [INF] Hosting environment: Development
2022-01-12 17:33:12.191 +08:00 [INF] Content root path: D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host
2022-01-12 17:33:13.454 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/index.html - -
2022-01-12 17:33:13.902 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/index.html - - - 200 - text/html;charset=utf-8 451.2027ms
2022-01-12 17:33:13.919 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - -
2022-01-12 17:33:13.922 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - - 200 11964 application/javascript;+charset=utf-8 3.0002ms
2022-01-12 17:33:14.726 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - -
2022-01-12 17:34:45.563 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 90837.3389ms
2022-01-12 17:35:04.863 +08:00 [INF] Starting Win_in.Sfs.Scp.WebApi.Xml.Host.
2022-01-12 17:35:05.837 +08:00 [INF] User profile is available. Using 'C:\Users\changketec\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
2022-01-12 17:35:06.422 +08:00 [INF] Now listening on: https://localhost:9977
2022-01-12 17:35:06.422 +08:00 [INF] Application started. Press Ctrl+C to shut down.
2022-01-12 17:35:06.422 +08:00 [INF] Hosting environment: Development
2022-01-12 17:35:06.422 +08:00 [INF] Content root path: D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host
2022-01-12 17:35:08.044 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/index.html - -
2022-01-12 17:35:08.595 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/index.html - - - 200 - text/html;charset=utf-8 554.7530ms
2022-01-12 17:35:08.615 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - -
2022-01-12 17:35:08.618 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - - 200 11964 application/javascript;+charset=utf-8 2.7575ms
2022-01-12 17:35:09.469 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - -
2022-01-12 17:35:13.499 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 4030.0507ms
2022-01-12 17:36:10.395 +08:00 [INF] Request starting HTTP/2 POST https://localhost:9977/api/scp/po application/xml 975
2022-01-12 17:36:10.431 +08:00 [DBG] AuthenticationScheme: BasicAuthentication was successfully authenticated.
2022-01-12 17:36:10.433 +08:00 [INF] Executing endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-12 17:36:10.456 +08:00 [INF] Route matched with {action = "Create", controller = "PurchaseOrder"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.ActionResult`1[Win_in.Sfs.Scp.WebApi.PurchaseOrderDTO]] CreateAsync(Win_in.Sfs.Scp.WebApi.PurchaseOrderCreateDTO) on controller Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController (Win_in.Sfs.Scp.WebApi.Xml.Host).
2022-01-12 17:36:28.320 +08:00 [INF] Starting Win_in.Sfs.Scp.WebApi.Xml.Host.
2022-01-12 17:36:29.281 +08:00 [INF] User profile is available. Using 'C:\Users\changketec\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
2022-01-12 17:36:29.844 +08:00 [INF] Now listening on: https://localhost:9977
2022-01-12 17:36:29.844 +08:00 [INF] Application started. Press Ctrl+C to shut down.
2022-01-12 17:36:29.844 +08:00 [INF] Hosting environment: Development
2022-01-12 17:36:29.844 +08:00 [INF] Content root path: D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host
2022-01-12 17:36:31.520 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/index.html - -
2022-01-12 17:36:32.031 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/index.html - - - 200 - text/html;charset=utf-8 513.1740ms
2022-01-12 17:36:32.050 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - -
2022-01-12 17:36:32.055 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - - 200 11964 application/javascript;+charset=utf-8 4.9346ms
2022-01-12 17:36:32.903 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - -
2022-01-12 17:36:37.746 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 4842.5504ms
2022-01-12 17:36:48.233 +08:00 [INF] Request starting HTTP/2 POST https://localhost:9977/api/scp/po application/xml 970
2022-01-12 17:36:48.275 +08:00 [DBG] AuthenticationScheme: BasicAuthentication was successfully authenticated.
2022-01-12 17:36:48.277 +08:00 [INF] Executing endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-12 17:36:48.304 +08:00 [INF] Route matched with {action = "Create", controller = "PurchaseOrder"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.ActionResult`1[Win_in.Sfs.Scp.WebApi.PurchaseOrderDTO]] CreateAsync(Win_in.Sfs.Scp.WebApi.PurchaseOrderCreateDTO) on controller Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController (Win_in.Sfs.Scp.WebApi.Xml.Host).
2022-01-12 17:36:56.559 +08:00 [INF] Executing action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) - Validation state: "Valid"
2022-01-12 17:37:16.733 +08:00 [INF] Executed action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host), returned result Microsoft.AspNetCore.Mvc.OkObjectResult in 20166.7287ms.
2022-01-12 17:37:16.749 +08:00 [INF] Executing OkObjectResult, writing value of type 'Win_in.Sfs.Scp.WebApi.PurchaseOrderDTO'.
2022-01-12 17:37:16.777 +08:00 [INF] Executed action Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) in 28470.3143ms
2022-01-12 17:37:16.778 +08:00 [INF] Executed endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-12 17:37:16.781 +08:00 [ERR] An unhandled exception has occurred while executing the request.
System.Runtime.Serialization.InvalidDataContractException: Type 'Win_in.Sfs.Scp.WebApi.PurchaseOrderDetailDTO' with CollectionDataContractAttribute attribute is an invalid collection type since it does not implement IEnumerable interface.
at System.Runtime.Serialization.CollectionDataContract.HandleIfInvalidCollection(Type type, Boolean tryCreate, Boolean hasCollectionDataContract, Boolean createContractWithException, String message, String param, DataContract& dataContract)
at System.Runtime.Serialization.CollectionDataContract.IsCollectionOrTryCreate(Type type, Boolean tryCreate, DataContract& dataContract, Type& itemType, Boolean constructorRequired)
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(Type type)
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidation(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.XmlObjectSerializerContext.GetDataContract(Int32 id, RuntimeTypeHandle typeHandle)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
at WriteArrayOfPurchaseOrderDetailDTOToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , CollectionDataContract )
at System.Runtime.Serialization.CollectionDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerializeReference(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
at WritePurchaseOrderDTOToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract )
at System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
at System.Runtime.Serialization.DataContractSerializer.WriteObject(XmlWriter writer, Object graph)
at Microsoft.AspNetCore.Mvc.Formatters.XmlDataContractSerializerOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
at Microsoft.AspNetCore.Mvc.Formatters.XmlDataContractSerializerOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
at Microsoft.AspNetCore.Mvc.Formatters.XmlDataContractSerializerOutputFormatter.WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeResultAsync>g__Logged|21_0(ResourceInvoker invoker, IActionResult result)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
2022-01-12 17:37:16.836 +08:00 [INF] Request finished HTTP/2 POST https://localhost:9977/api/scp/po application/xml 970 - 500 - text/plain 28602.9115ms
2022-01-12 17:38:13.563 +08:00 [INF] Starting Win_in.Sfs.Scp.WebApi.Xml.Host.
2022-01-12 17:38:14.457 +08:00 [INF] User profile is available. Using 'C:\Users\changketec\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
2022-01-12 17:38:15.160 +08:00 [INF] Now listening on: https://localhost:9977
2022-01-12 17:38:15.160 +08:00 [INF] Application started. Press Ctrl+C to shut down.
2022-01-12 17:38:15.160 +08:00 [INF] Hosting environment: Development
2022-01-12 17:38:15.160 +08:00 [INF] Content root path: D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host
2022-01-12 17:38:16.663 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/index.html - -
2022-01-12 17:38:17.314 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/index.html - - - 200 - text/html;charset=utf-8 654.3528ms
2022-01-12 17:38:17.390 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - -
2022-01-12 17:38:17.415 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - - 200 11964 application/javascript;+charset=utf-8 23.9867ms
2022-01-12 17:38:18.448 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - -
2022-01-12 17:38:18.851 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 402.8870ms
2022-01-12 17:38:29.481 +08:00 [INF] Request starting HTTP/2 POST https://localhost:9977/api/scp/po application/xml 964
2022-01-12 17:38:29.516 +08:00 [DBG] AuthenticationScheme: BasicAuthentication was successfully authenticated.
2022-01-12 17:38:29.518 +08:00 [INF] Executing endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-12 17:38:29.544 +08:00 [INF] Route matched with {action = "Create", controller = "PurchaseOrder"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.ActionResult`1[Win_in.Sfs.Scp.WebApi.PurchaseOrderDTO]] CreateAsync(Win_in.Sfs.Scp.WebApi.PurchaseOrderCreateDTO) on controller Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController (Win_in.Sfs.Scp.WebApi.Xml.Host).
2022-01-12 17:38:31.371 +08:00 [INF] Executing action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) - Validation state: "Valid"
2022-01-12 17:38:33.377 +08:00 [INF] Executed action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host), returned result Microsoft.AspNetCore.Mvc.OkObjectResult in 2003.0938ms.
2022-01-12 17:38:33.386 +08:00 [INF] Executing OkObjectResult, writing value of type 'Win_in.Sfs.Scp.WebApi.PurchaseOrderDTO'.
2022-01-12 17:38:33.402 +08:00 [INF] Executed action Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) in 3855.5986ms
2022-01-12 17:38:33.403 +08:00 [INF] Executed endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-12 17:38:33.404 +08:00 [INF] Request finished HTTP/2 POST https://localhost:9977/api/scp/po application/xml 964 - 200 1410 application/xml;+charset=utf-8 3922.8488ms

49
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Startup.cs

@ -1,3 +1,4 @@
using System;
using ApiBasicAuth.Security;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
@ -8,6 +9,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace Win_in.Sfs.Scp.WebApi.XmlHost
{
@ -38,6 +40,7 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Win_in.Sfs.Scp.WebApi.Xml.Host", Version = "v1" });
c.SchemaFilter<SwaggerFixArraysInXmlFilter>();
});
services.AddAuthentication("BasicAuthentication")
@ -72,4 +75,50 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost
});
}
}
}
internal class SwaggerFixArraysInXmlFilter : ISchemaFilter
{
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
var type = context.Type;
// Fix issues with xml array examples not generating correctly
if (type.IsValueType)
{
return;
}
if (type.Name == "String")
{
return;
}
schema.Xml = new OpenApiXml { Name = type.Name };
if (schema.Properties == null)
{
return;
}
foreach (var property in schema.Properties)
{
//Array property, which wraps its elements
if (property.Value.Type != "array")
{
continue;
}
property.Value.Xml = new OpenApiXml
{
Name = $"{property.Key}",
Wrapped = true
};
property.Value.Items.Xml = new OpenApiXml
{
Name = $"{property.Value.Items.Type}",
Wrapped = true
};
}
}
}
Loading…
Cancel
Save