Modernize OpenAPI generation#713
Conversation
Agent-Logs-Url: https://github.com/ARKlab/Ark.Tools/sessions/ea77a270-a4cf-4719-8709-555565079f74 Co-authored-by: AndreaCuneo <5227688+AndreaCuneo@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ARKlab/Ark.Tools/sessions/ea77a270-a4cf-4719-8709-555565079f74 Co-authored-by: AndreaCuneo <5227688+AndreaCuneo@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ARKlab/Ark.Tools/sessions/ea77a270-a4cf-4719-8709-555565079f74 Co-authored-by: AndreaCuneo <5227688+AndreaCuneo@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ARKlab/Ark.Tools/sessions/ea77a270-a4cf-4719-8709-555565079f74 Co-authored-by: AndreaCuneo <5227688+AndreaCuneo@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ARKlab/Ark.Tools/sessions/ea77a270-a4cf-4719-8709-555565079f74 Co-authored-by: AndreaCuneo <5227688+AndreaCuneo@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ARKlab/Ark.Tools/sessions/12e682ba-fd19-4a29-8e7e-ebabcc929815 Co-authored-by: AndreaCuneo <5227688+AndreaCuneo@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ARKlab/Ark.Tools/sessions/12e682ba-fd19-4a29-8e7e-ebabcc929815 Co-authored-by: AndreaCuneo <5227688+AndreaCuneo@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
AndreaCuneo
left a comment
There was a problem hiding this comment.
Apply the changes to Ark.Reference project in samples/ to demostrate the migration changes required. Create a step-by-step migration guide.
| { | ||
| base.ConfigureServices(services); | ||
|
|
||
| foreach (var version in Versions) |
There was a problem hiding this comment.
this should be in base class and guarded based on the OpenApi enablement
| <Target Name="RemoveReferencedXmlCommentsFromOpenApi" AfterTargets="GenerateAdditionalXmlFilesForOpenApi"> | ||
| <ItemGroup> | ||
| <!-- The Microsoft OpenAPI XML source generator receives referenced project XML files as AdditionalFiles. | ||
| Ark projects include shared Polyfill XML members, which currently produce duplicate XML comment keys. --> |
There was a problem hiding this comment.
find alternative solution as xml docs are required to be publish. Consider changing the polyfill configuration.
Agent-Logs-Url: https://github.com/ARKlab/Ark.Tools/sessions/efb0656b-1125-4d27-b1dc-ac2ee95348e2 Co-authored-by: AndreaCuneo <5227688+AndreaCuneo@users.noreply.github.com>
| var baseDirectory = AppContext.BaseDirectory; | ||
| var candidates = new[] | ||
| { | ||
| Path.Combine(baseDirectory, $"{entryAssemblyName}_{documentName}.json"), |
| var candidates = new[] | ||
| { | ||
| Path.Combine(baseDirectory, $"{entryAssemblyName}_{documentName}.json"), | ||
| Path.Combine(baseDirectory, $"{entryAssemblyName}.json"), |
| { | ||
| Path.Combine(baseDirectory, $"{entryAssemblyName}_{documentName}.json"), | ||
| Path.Combine(baseDirectory, $"{entryAssemblyName}.json"), | ||
| Path.Combine(baseDirectory, $"{documentName}.json") |
| foreach (var version in versions) | ||
| { | ||
| var documentName = ToDocumentName(version); | ||
| c.SwaggerEndpoint($@"docs/{documentName}", $@"{documentName} Docs"); | ||
| } |
| foreach (var contentType in response.Content.Keys.ToArray()) | ||
| { | ||
| if (!responseType.ApiResponseFormats.Any(x => string.Equals(x.MediaType, contentType, StringComparison.Ordinal))) | ||
| { | ||
| response.Content.Remove(contentType); | ||
| } | ||
| } |
| foreach (var contentType in content.Keys.ToArray()) | ||
| { | ||
| if (contentType.Contains("odata", StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| content.Remove(contentType); | ||
| } | ||
| } |
Agent-Logs-Url: https://github.com/ARKlab/Ark.Tools/sessions/efb0656b-1125-4d27-b1dc-ac2ee95348e2 Co-authored-by: AndreaCuneo <5227688+AndreaCuneo@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
| foreach (var descriptor in descriptors) | ||
| { | ||
| var propertyInfo = _getPropertyInfo(descriptor); | ||
|
|
||
| if (propertyInfo is null || operation.RequestBody?.Content is null || operation.RequestBody.Content.Count == 0) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| var mediaType = operation.RequestBody.Content.First().Value; | ||
|
|
||
| if (mediaType.Schema is not OpenApiSchema schema || schema.Properties is null) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| var groupedProperties = schema.Properties | ||
| .GroupBy(pair => pair.Key.Split('.')[0], StringComparer.Ordinal); | ||
|
|
||
| var schemaProperties = new Dictionary<string, IOpenApiSchema>(StringComparer.Ordinal); | ||
|
|
||
| foreach (var property in groupedProperties) | ||
| { | ||
| if (property.Key == propertyInfo.Name) | ||
| { | ||
| _addEncoding(mediaType, propertyInfo); | ||
|
|
||
| var openApiSchema = await _getSchema(context, propertyInfo, cancellationToken).ConfigureAwait(false); | ||
| schemaProperties.Add(property.Key, openApiSchema); | ||
| } | ||
| else | ||
| { | ||
| schemaProperties.Add(property.Key, property.First().Value); | ||
| } | ||
| } | ||
|
|
||
| schema.Properties = schemaProperties; | ||
| } |
Summary
UseSwashbuckleOpenApias the legacy opt-in.MapOpenApiare DEBUG-only./swagger/docs/{documentName}.SwaggerOperationAttributeandSwaggerResponseAttribute.Validation
dotnet build Ark.Tools.slnx --no-restoredotnet build samples/WebApplicationDemo/WebApplicationDemo.csproj -c Release --no-restoredotnet build samples/Ark.ReferenceProject/Core/Ark.Reference.Core.WebInterface/Ark.Reference.Core.WebInterface.csproj -c Release --no-restoredotnet test --solution Ark.Tools.slnx --no-build