Skip to content

Rename all the service reference things #9559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/ProjectReferences.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Identity.Specification.Tests" ProjectPath="$(RepositoryRoot)src\Identity\Specification.Tests\src\Microsoft.AspNetCore.Identity.Specification.Tests.csproj" />
<ProjectReferenceProvider Include="Microsoft.Web.Xdt.Extensions" ProjectPath="$(RepositoryRoot)src\SiteExtensions\Microsoft.Web.Xdt.Extensions\src\Microsoft.Web.Xdt.Extensions.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.DeveloperCertificates.XPlat" ProjectPath="$(RepositoryRoot)src\Tools\FirstRunCertGenerator\src\Microsoft.AspNetCore.DeveloperCertificates.XPlat.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.ApiDescription.Tasks" ProjectPath="$(RepositoryRoot)src\Mvc\Extensions.ApiDescription.Design\src\Microsoft.Extensions.ApiDescription.Design.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.ApiDescription.Tasks" ProjectPath="$(RepositoryRoot)src\Mvc\Extensions.ApiDescription.Client\src\Microsoft.Extensions.ApiDescription.Client.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.SignalR.Specification.Tests" ProjectPath="$(RepositoryRoot)src\SignalR\server\Specification.Tests\src\Microsoft.AspNetCore.SignalR.Specification.Tests.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Blazor.Build" ProjectPath="$(RepositoryRoot)src\Components\Blazor\Build\src\Microsoft.AspNetCore.Blazor.Build.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore" ProjectPath="$(RepositoryRoot)src\DefaultBuilder\src\Microsoft.AspNetCore.csproj" RefProjectPath="$(RepositoryRoot)src\DefaultBuilder\ref\Microsoft.AspNetCore.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
namespace Microsoft.Extensions.ApiDescription.Tasks
{
/// <summary>
/// Adds or corrects ClassName, Namespace and OutputPath metadata in ServiceFileReference items. Also stores final
/// metadata as SerializedMetadata.
/// Adds or corrects ClassName, FirstForGenerator, Namespace, and OutputPath metadata in OpenApiReference items.
/// Also stores final metadata as SerializedMetadata.
/// </summary>
public class GetFileReferenceMetadata : Task
{
Expand All @@ -35,13 +35,13 @@ public class GetFileReferenceMetadata : Task
public string OutputDirectory { get; set; }

/// <summary>
/// The ServiceFileReference items to update.
/// The OpenApiReference items to update.
/// </summary>
[Required]
public ITaskItem[] Inputs { get; set; }

/// <summary>
/// The updated ServiceFileReference items. Will include ClassName, Namespace and OutputPath metadata.
/// The updated OpenApiReference items. Will include ClassName, Namespace and OutputPath metadata.
/// </summary>
[Output]
public ITaskItem[] Outputs{ get; set; }
Expand All @@ -50,36 +50,45 @@ public class GetFileReferenceMetadata : Task
public override bool Execute()
{
var outputs = new List<ITaskItem>(Inputs.Length);
var codeGenerators = new HashSet<string>();
var destinations = new HashSet<string>();

foreach (var item in Inputs)
{
var codeGenerator = item.GetMetadata("CodeGenerator");
if (string.IsNullOrEmpty(codeGenerator))
{
// This case occurs when user overrides the required metadata with an empty string.
var type = string.IsNullOrEmpty(item.GetMetadata("SourceProject")) ?
"OpenApiReference" :
"OpenApiProjectReference";

Log.LogError(
Resources.FormatInvalidEmptyMetadataValue("CodeGenerator", "OpenApiReference", item.ItemSpec));
continue;
}

var newItem = new TaskItem(item);
outputs.Add(newItem);

var codeGenerator = item.GetMetadata("CodeGenerator");
if (string.IsNullOrEmpty("CodeGenerator"))
if (codeGenerators.Add(codeGenerator))
{
newItem.SetMetadata("FirstForGenerator", "true");
}
else
{
// This case occurs when user forgets to specify the required metadata. We have no default here.
string type;
if (!string.IsNullOrEmpty(item.GetMetadata("SourceProject")))
{
type = "ServiceProjectReference";
}
else
{
type = "ServiceFileReference";
}

Log.LogError(Resources.FormatInvalidEmptyMetadataValue("CodeGenerator", type, item.ItemSpec));
newItem.SetMetadata("FirstForGenerator", "false");
}

var outputPath = item.GetMetadata("OutputPath");
if (string.IsNullOrEmpty(outputPath))
{
// No need to further sanitize this path.
// No need to further sanitize this path because the file must exist.
var filename = item.GetMetadata("Filename");
var isTypeScript = codeGenerator.EndsWith(TypeScriptLanguageName, StringComparison.OrdinalIgnoreCase);
var isTypeScript = codeGenerator.EndsWith(
TypeScriptLanguageName,
StringComparison.OrdinalIgnoreCase);

outputPath = $"{filename}Client{(isTypeScript ? ".ts" : Extension)}";
}

Expand All @@ -94,6 +103,7 @@ public override bool Execute()
// This case may occur when user is experimenting e.g. with multiple code generators or options.
// May also occur when user accidentally duplicates OutputPath metadata.
Log.LogError(Resources.FormatDuplicateFileOutputPaths(outputPath));
continue;
}

MetadataSerializer.SetMetadata(newItem, "OutputPath", outputPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ private static void EscapeValue(string value, StringBuilder builder)
{
if (string.IsNullOrEmpty(value))
{
builder.Append(value);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,9 @@

<ItemGroup>
<Reference Include="Microsoft.Build.Utilities.Core" />
<Reference Include="System.Net.Http" Condition="'$(TargetFramework)' == 'net461'" />
</ItemGroup>

<Target Name="PopulateNuspec">
<MSBuild Projects="../../dotnet-getdocument/src/dotnet-getdocument.csproj"
BuildInParallel="$(BuildInParallel)"
RemoveProperties="RuntimeIdentifier;TargetFrameworks;TargetFramework"
Targets="Publish" />

<PropertyGroup>
<NuspecProperties>
id=$(PackageId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,5 @@
<file src="buildMultiTargeting\*" target="buildMultiTargeting" />
<file src="bin\$configuration$\net461\Microsoft.Extensions.ApiDescription.Tasks.*" target="tasks\net461" />
<file src="bin\$configuration$\netstandard2.0\Microsoft.Extensions.ApiDescription.Tasks.*" target="tasks\netstandard2.0" />
<file src="..\..\dotnet-getdocument\src\bin\$configuration$\netcoreapp2.1\publish\*.*" target="tools" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They aren't necessary with the new client / server split. The tool will come back in Microsoft.Extensions.ApiDescription.Server

<file src="..\..\GetDocumentInsider\src\bin\$configuration$\net461\GetDocument.Insider.*" target="tools\net461" />
<file src="..\..\GetDocumentInsider\src\bin\x86\$configuration$\net461\GetDocument.Insider.*" target="tools\net461-x86" />
<file src="..\..\GetDocumentInsider\src\bin\$configuration$\netcoreapp2.0\GetDocument.Insider.*" target="tools\netcoreapp2.0" />
</files>
</package>

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

Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="DuplicateFileOutputPaths" xml:space="preserve">
<value>Multiple items have OutputPath='{0}'. All ServiceFileReference and ServiceProjectReference items must have unique OutputPath metadata.</value>
<comment>ServiceProjectReference items become ServiceFileReference items and all ServiceFileReference items must have unique OutputPath metadata.</comment>
</data>
<data name="DuplicateProjectDocumentPaths" xml:space="preserve">
<value>Mutliple ServiceProjectReference items have DocumentPath='{0}'. ServiceProjectReference items must have unique DocumentPath metadata.</value>
<value>Multiple items have OutputPath='{0}'. All OpenApiReference items must have unique OutputPath metadata.</value>
</data>
<data name="InvalidEmptyMetadataValue" xml:space="preserve">
<value>Invalid {0} metadata value for {1} item '{2}'. {0} metadata must not be set to the empty string.</value>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project>
<PropertyGroup>
<_ApiDescriptionTasksAssemblyTarget
Condition="'$(MSBuildRuntimeType)' == 'Core'">netstandard2.0</_ApiDescriptionTasksAssemblyTarget>
<_ApiDescriptionTasksAssemblyTarget
Condition="'$(MSBuildRuntimeType)' != 'Core'">net461</_ApiDescriptionTasksAssemblyTarget>
<_ApiDescriptionTasksAssemblyPath>$(MSBuildThisFileDirectory)/../tasks/$(_ApiDescriptionTasksAssemblyTarget)/Microsoft.Extensions.ApiDescription.Tasks.dll</_ApiDescriptionTasksAssemblyPath>
<_ApiDescriptionTasksAssemblyTarget />
</PropertyGroup>
<UsingTask TaskName="GetCurrentItems" AssemblyFile="$(_ApiDescriptionTasksAssemblyPath)" />
<UsingTask TaskName="GetFileReferenceMetadata" AssemblyFile="$(_ApiDescriptionTasksAssemblyPath)" />

<!--
Settings users may update as they see fit.
-->
<PropertyGroup>
<OpenApiDefaultGeneratorOptions Condition="'$(OpenApiDefaultGeneratorOptions)' == ''"></OpenApiDefaultGeneratorOptions>

<!--
If 'true', will generate code for OpenApiReference items during design-time builds. Otherwise, generate code only
for output files that do not yet exist during design-time builds.
-->
<OpenApiGenerateAtDesignTime Condition="'$(OpenApiGenerateAtDesignTime)' == ''">true</OpenApiGenerateAtDesignTime>

<!--
$(OpenApiDefaultOutputDirectory) value is interpreted relative to the project folder, unless already an
absolute path.
-->
<OpenApiDefaultOutputDirectory
Condition="'$(OpenApiDefaultOutputDirectory)' == ''">$(BaseIntermediateOutputPath)</OpenApiDefaultOutputDirectory>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI - BaseIntermediateOutputPath might not be fully set when this file is evaluated. Would recommend moving this to a .targets file instead. BaseIntermediateOutputPath isn't defined until Microsoft.NET.DefaultOutputPaths.targets is evaluated, which happens at the end of project evaluation. Props file evaluation happens near the beginning of project eval.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it's working at the moment. I'll move it if we see issues or if I otherwise must update this PR.

<OpenApiDefaultOutputDirectory>$([MSBuild]::EnsureTrailingSlash('$(OpenApiDefaultOutputDirectory)'))</OpenApiDefaultOutputDirectory>
</PropertyGroup>

<!--
Well-known metadata of the code generator item groups.
-->
<ItemDefinitionGroup>
<!-- OpenApiProjectReference items may also include OpenApiReference metadata. -->
<OpenApiProjectReference />

<OpenApiReference>
<!-- Name of the class to generate. Defaults to match filename in %(OutputPath). -->
<ClassName />
<!--
Code generator to use. Required and must end with "CSharp" or "TypeScript" (the currently-supported target
languages) unless %(OutputPath) is set. Builds will invoke a target named "Generate%(CodeGenerator)" to do
actual code generation.
-->
<CodeGenerator>NSwagCSharp</CodeGenerator>
<!-- Namespace to contain generated class. Default is $(RootNamespace). -->
<Namespace />
<!--
Options to pass to the code generator target then (likely) added to a tool's command line. Value is passed
along to the code generator but otherwise unused in this package.
-->
<Options>$(OpenApiDefaultGeneratorOptions)</Options>
<!--
Path to place generated code. Code generator may interpret path as a filename or directory. Default filename or
folder name is %(Filename)Client.[cs|ts]. Filenames and relative paths (if explicitly set) are combined with
$(OpenApiDefaultOutputDirectory). Final value (depending on $(OpenApiDefaultOutputDirectory)) is likely to be
a path relative to the client project.
-->
<OutputPath />
</OpenApiReference>
</ItemDefinitionGroup>
</Project>
Loading