Skip to content

Commit 24e0d10

Browse files
Fixes for OpenAPI document generation with M.E.ApiDescription.Server (#57096)
* Get full path of OpenApiDocumentsDirectory Convert `$(OpenApiDocumentsDirectory)` to a full path before passing it to the `dotnet-getdocument` tool. Relates to #57044. * Avoid warning about invalid OpenAPI version Do not emit warning about an invalid OpenAPI version in the `dotnet-getdocument` tool if no explicit value was passed to the tool via the `` argument. Relates to #57044. * Fix TargetTest tests Fix tests failing locally in Visual Studio due to test assets not being copied to the output directory. * Fix tests Fix assertions looking for relative paths instead of absolute paths.
1 parent 6dc454f commit 24e0d10

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

src/Tools/Extensions.ApiDescription.Client/test/Microsoft.Extensions.ApiDescription.Client.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
Link="ProcessHelpers\DotNetMuxer.cs" />
1717
<Compile Include="$(ToolSharedSourceRoot)TestHelpers\Temporary*.cs" LinkBase="TestHelpers" />
1818

19-
<Content Include="..\src\build\**\*" LinkBase="build" />
20-
<Content Include="..\src\buildMultiTargeting\**\*" LinkBase="buildMultiTargeting" />
21-
<Content Include="TestProjects\**\*" />
19+
<Content Include="..\src\build\**\*" LinkBase="build" CopyToOutputDirectory="PreserveNewest" />
20+
<Content Include="..\src\buildMultiTargeting\**\*" LinkBase="buildMultiTargeting" CopyToOutputDirectory="PreserveNewest" />
21+
<Content Include="TestProjects\**\*" CopyToOutputDirectory="PreserveNewest" />
2222

2323
<Reference Include="Microsoft.Extensions.ApiDescription.Client" />
2424
</ItemGroup>

src/Tools/Extensions.ApiDescription.Client/test/TargetTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public async Task AddsExpectedItems()
7777

7878
Assert.Equal(0, process.ExitCode);
7979
Assert.Empty(process.Error);
80-
Assert.Contains($"Compile: {Path.Combine("obj", "azureMonitorClient.cs")}", process.Output);
80+
Assert.Contains($"Compile: {Path.Combine(_temporaryDirectory.Root, "obj", "azureMonitorClient.cs")}", process.Output);
8181
Assert.Contains($"FileWrites: {Path.Combine("obj", "azureMonitorClient.cs")}", process.Output);
8282
Assert.DoesNotContain("TypeScriptCompile:", process.Output);
8383
}
@@ -120,9 +120,9 @@ public async Task AddsExpectedItems_WithMultipleFiles()
120120

121121
Assert.Equal(0, process.ExitCode);
122122
Assert.Empty(process.Error);
123-
Assert.Contains($"Compile: {Path.Combine("obj", "azureMonitorClient.cs")}", process.Output);
124-
Assert.Contains($"Compile: {Path.Combine("obj", "NSwagClient.cs")}", process.Output);
125-
Assert.Contains($"Compile: {Path.Combine("obj", "swashbuckleClient.cs")}", process.Output);
123+
Assert.Contains($"Compile: {Path.Combine(_temporaryDirectory.Root, "obj", "azureMonitorClient.cs")}", process.Output);
124+
Assert.Contains($"Compile: {Path.Combine(_temporaryDirectory.Root, "obj", "NSwagClient.cs")}", process.Output);
125+
Assert.Contains($"Compile: {Path.Combine(_temporaryDirectory.Root, "obj", "swashbuckleClient.cs")}", process.Output);
126126
Assert.Contains($"FileWrites: {Path.Combine("obj", "azureMonitorClient.cs")}", process.Output);
127127
Assert.Contains($"FileWrites: {Path.Combine("obj", "NSwagClient.cs")}", process.Output);
128128
Assert.Contains($"FileWrites: {Path.Combine("obj", "swashbuckleClient.cs")}", process.Output);

src/Tools/Extensions.ApiDescription.Server/src/build/Microsoft.Extensions.ApiDescription.Server.targets

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@
5151
Text="OpenAPI document generation is not supported when targeting netcoreapp2.0 or earlier. Disable the feature or move to a later target framework." />
5252

5353
<PropertyGroup>
54+
<_DotNetGetDocumentOutputPath>$(OpenApiDocumentsDirectory.TrimEnd('\'))</_DotNetGetDocumentOutputPath>
55+
<_DotNetGetDocumentOutputPath>$([System.IO.Path]::GetFullPath('$(_DotNetGetDocumentOutputPath)'))</_DotNetGetDocumentOutputPath>
5456
<_DotNetGetDocumentCommand>dotnet "$(MSBuildThisFileDirectory)../tools/dotnet-getdocument.dll" --assembly "$(TargetPath)"</_DotNetGetDocumentCommand>
5557
<_DotNetGetDocumentCommand>$(_DotNetGetDocumentCommand) --file-list "$(_OpenApiDocumentsCache)" --framework "$(TargetFrameworkMoniker)"</_DotNetGetDocumentCommand>
56-
<_DotNetGetDocumentCommand>$(_DotNetGetDocumentCommand) --output "$(OpenApiDocumentsDirectory.TrimEnd('\'))" --project "$(MSBuildProjectName)"</_DotNetGetDocumentCommand>
58+
<_DotNetGetDocumentCommand>$(_DotNetGetDocumentCommand) --output "$(_DotNetGetDocumentOutputPath)" --project "$(MSBuildProjectName)"</_DotNetGetDocumentCommand>
5759
<_DotNetGetDocumentCommand Condition=" '$(ProjectAssetsFile)' != '' ">$(_DotNetGetDocumentCommand) --assets-file "$(ProjectAssetsFile)"</_DotNetGetDocumentCommand>
5860
<_DotNetGetDocumentCommand Condition=" '$(PlatformTarget)' != '' ">$(_DotNetGetDocumentCommand) --platform "$(PlatformTarget)"</_DotNetGetDocumentCommand>
5961
<_DotNetGetDocumentCommand Condition=" '$(PlatformTarget)' == '' AND '$(Platform)' != '' ">$(_DotNetGetDocumentCommand) --platform "$(Platform)"</_DotNetGetDocumentCommand>

src/Tools/GetDocumentInsider/src/Commands/GetDocumentCommandWorker.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,10 @@ private string GetDocument(
326326
}
327327
else
328328
{
329-
_reporter.WriteWarning(Resources.FormatInvalidOpenApiVersion(_context.OpenApiVersion));
329+
if (!string.IsNullOrWhiteSpace(_context.OpenApiVersion))
330+
{
331+
_reporter.WriteWarning(Resources.FormatInvalidOpenApiVersion(_context.OpenApiVersion));
332+
}
330333
arguments = [documentName, writer, OpenApiSpecVersion.OpenApi3_0];
331334
}
332335
}

0 commit comments

Comments
 (0)