Skip to content

Commit

Permalink
**Do not merge yet** Use new Microsoft.Extensions.ApiDescription.Serv…
Browse files Browse the repository at this point in the history
…er package

- !!! the Microsoft.Extensions.ApiDescription.* package version is not public as far as I know !!!
- provides document download on build and aligns with Microsoft.Extensions.ApiDescription.Client p2p references
  - this feature is on by default
  - can be disabled using `<OpenApiRetrieveDocuments>false</OpenApiRetrieveDocuments>`
  - timing can be changed using `<OpenApiRetrieveDocumentsAfterBuild>false</OpenApiRetrieveDocumentsAfterBuild>`
    - then, depend on the `RetrieveOpenApiDocuments` target from somewhere else
- add `GetDocumentNames()` to `IDocumentProvider` and `AspNetCoreOpenApiDocumentGenerator`
- rename `IDocumentProvider` namespace Microsoft.Extensions.ApiDescription -> Microsoft.Extensions.ApiDescriptions
  - avoid conflict with `Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescription` type
- depend on Microsoft.Extensions.ApiDescription.Server package from NSwag.AspNetCore package
  - restore and update the previously-unused (then deleted) NSwag.AspNetCore.nuspec file

nits:
- remove and sort `using`s
- take VS suggestions in `NSwagServiceCollectionExtensions`
- add missing `NSwagServiceCollectionExtensions` copyright header
- correct spelling in `AspNetCoreOpenApiDocumentGenerator`
  • Loading branch information
dougbu committed Jun 10, 2019
1 parent 023edb5 commit 1cf2396
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<copyright>Copyright © Rico Suter, 2019</copyright>
<developmentDependency>true</developmentDependency>
<dependencies>
<dependency id="Microsoft.Extensions.ApiDescription.Client" version="0.3.0-preview5-19227-01" />
<dependency id="NSwag.MSBuild" version="12.0.0" />
<dependency id="Microsoft.Extensions.ApiDescription.Client" version="0.3.0-preview6.19307.2" />
<dependency id="NSwag.MSBuild" version="13.0.0" />
</dependencies>
<references />
</metadata>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
using Microsoft.AspNetCore.Mvc;
//-----------------------------------------------------------------------
// <copyright file="NSwagServiceCollectionExtensions.cs" company="NSwag">
// Copyright (c) Rico Suter. All rights reserved.
// </copyright>
// <license>https://github.com/NSwag/NSwag/blob/master/LICENSE.md</license>
// <author>Rico Suter, mail@rsuter.com</author>
//-----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.ApiDescriptions;
using Microsoft.Extensions.Options;
using NJsonSchema;
using NSwag.AspNetCore;
using NSwag.Generation;
using NSwag.Generation.AspNetCore;
using NSwag.Generation.Processors;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.Extensions.DependencyInjection
{
Expand Down Expand Up @@ -55,8 +64,10 @@ public static IServiceCollection AddSwaggerDocument(this IServiceCollection serv
{
serviceCollection.AddSingleton(services =>
{
var settings = new AspNetCoreOpenApiDocumentGeneratorSettings();
settings.SchemaType = SchemaType.Swagger2;
var settings = new AspNetCoreOpenApiDocumentGeneratorSettings
{
SchemaType = SchemaType.Swagger2,
};
configure?.Invoke(settings, services);
Expand All @@ -83,8 +94,8 @@ public static IServiceCollection AddSwaggerDocument(this IServiceCollection serv
// Used by UseDocumentProvider CLI setting
serviceCollection.AddSingleton<IOpenApiDocumentGenerator>(s => s.GetRequiredService<OpenApiDocumentProvider>());

// Used by the Microsoft.Extensions.ApiDescription tool
serviceCollection.AddSingleton<ApiDescription.IDocumentProvider>(s => s.GetRequiredService<OpenApiDocumentProvider>());
// Used by the <c>dotnet-getdocument</c> tool from the Microsoft.Extensions.ApiDescription.Server package.
serviceCollection.AddSingleton<IDocumentProvider>(s => s.GetRequiredService<OpenApiDocumentProvider>());
}

return serviceCollection;
Expand Down
7 changes: 5 additions & 2 deletions src/NSwag.AspNetCore/IDocumentProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
// <author>Rico Suter, mail@rsuter.com</author>
//-----------------------------------------------------------------------

using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

namespace Microsoft.Extensions.ApiDescription
namespace Microsoft.Extensions.ApiDescriptions
{
// This service will be looked up by name from the service collection when using
// the Microsoft.Extensions.ApiDescription tool
// the <c>dotnet-getdocument</c> tool from the Microsoft.Extensions.ApiDescription.Server package.
internal interface IDocumentProvider
{
IEnumerable<string> GetDocumentNames();

Task GenerateAsync(string documentName, TextWriter writer);
}
}
49 changes: 42 additions & 7 deletions src/NSwag.AspNetCore/NSwag.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
<Authors>Rico Suter</Authors>
<PackageIconUrl>https://raw.githubusercontent.com/NSwag/NSwag/master/assets/NuGetIcon.png</PackageIconUrl>
<Company />
<NuspecFile>$(MSBuildProjectName).nuspec</NuspecFile>

<!-- Execute PopulateNuspec fairly late. -->
<GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);PopulateNuspec</GenerateNuspecDependsOn>

<MicrosoftAspNetCoreMvcCorePackageVersion>1.0.3</MicrosoftAspNetCoreMvcCorePackageVersion>
<MicrosoftAspNetCoreMvcFormattersJsonPackageVersion>1.0.3</MicrosoftAspNetCoreMvcFormattersJsonPackageVersion>
<MicrosoftAspNetCoreStaticFilesPackageVersion>1.0.2</MicrosoftAspNetCoreStaticFilesPackageVersion>
<MicrosoftExtensionsApiDescriptionServerPackageVersion>0.3.0-preview6.19307.2</MicrosoftExtensionsApiDescriptionServerPackageVersion>
<MicrosoftExtensionsFileProvidersEmbeddedPackageVersion>1.0.1</MicrosoftExtensionsFileProvidersEmbeddedPackageVersion>
<NETStandardLibraryPackageVersion>1.6.1</NETStandardLibraryPackageVersion>
<SystemIOFileSystemPackageVersion>4.3.0</SystemIOFileSystemPackageVersion>
<SystemXmlXPathXDocumentPackageVersion>4.0.1</SystemXmlXPathXDocumentPackageVersion>
</PropertyGroup>
<PropertyGroup>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
Expand All @@ -23,22 +36,44 @@
<EmbeddedResource Include="SwaggerUi3\**\*" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="1.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="1.0.3" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.0.2" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="$(MicrosoftAspNetCoreMvcCorePackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="$(MicrosoftAspNetCoreMvcFormattersJsonPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="$(MicrosoftAspNetCoreStaticFilesPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="$(MicrosoftExtensionsFileProvidersEmbeddedPackageVersion)" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' OR '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
<PackageReference Include="System.Xml.XPath.XDocument" Version="4.0.1" />
<PackageReference Include="System.IO.FileSystem" Version="$(SystemIOFileSystemPackageVersion)" />
<PackageReference Include="System.Xml.XPath.XDocument" Version="$(SystemXmlXPathXDocumentPackageVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NSwag.Annotations\NSwag.Annotations.csproj" />
<ProjectReference Include="..\NSwag.Core\NSwag.Core.csproj" />
<ProjectReference Include="..\NSwag.Generation.AspNetCore\NSwag.Generation.AspNetCore.csproj" />
<ProjectReference Include="..\NSwag.Generation\NSwag.Generation.csproj" />
</ItemGroup>
</Project>


<Target Name="PopulateNuspec">
<PropertyGroup>
<NuspecProperties>
id=$(PackageId);
authors=$(Authors);
configuration=$(Configuration);
description=$(PackageDescription);
version=$(PackageVersion);

microsoftAspNetCoreMvcCorePackageVersion=$(MicrosoftAspNetCoreMvcCorePackageVersion);
microsoftAspNetCoreMvcFormattersJsonPackageVersion=$(MicrosoftAspNetCoreMvcFormattersJsonPackageVersion);
microsoftAspNetCoreStaticFilesPackageVersion=$(MicrosoftAspNetCoreStaticFilesPackageVersion);
microsoftExtensionsApiDescriptionServerPackageVersion=$(MicrosoftExtensionsApiDescriptionServerPackageVersion);
microsoftExtensionsFileProvidersEmbeddedPackageVersion=$(MicrosoftExtensionsFileProvidersEmbeddedPackageVersion);
netStandardLibraryPackageVersion=$(NETStandardLibraryPackageVersion);
systemIOFileSystemPackageVersion=$(SystemIOFileSystemPackageVersion);
systemXmlXPathXDocumentPackageVersion=$(SystemXmlXPathXDocumentPackageVersion);
</NuspecProperties>
</PropertyGroup>
</Target>
</Project>
61 changes: 61 additions & 0 deletions src/NSwag.AspNetCore/NSwag.AspNetCore.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0"?>
<package>
<metadata>
<id>$id$</id>
<version>$version$</version>
<authors>$authors$</authors>
<description>$description$</description>
<tags>Swagger Documentation WebApi AspNet TypeScript CodeGen</tags>
<projectUrl>https://github.com/NSwag/NSwag</projectUrl>
<licenseUrl>https://github.com/NSwag/NSwag/blob/master/LICENSE.md</licenseUrl>
<iconUrl>https://raw.githubusercontent.com/NSwag/NSwag/master/assets/NuGetIcon.png</iconUrl>
<dependencies>
<group targetFramework=".NETFramework4.5.1">
<dependency id="NSwag.Annotations" version="$version$" exclude="Build,Analyzers" />
<dependency id="NSwag.Core" version="$version$" exclude="Build,Analyzers" />
<dependency id="NSwag.Generation.AspNetCore" version="$version$" exclude="Build,Analyzers" />
<dependency id="NSwag.Generation" version="$version$" exclude="Build,Analyzers" />
<dependency id="Microsoft.AspNetCore.Mvc.Core" version="$microsoftAspNetCoreMvcCorePackageVersion$" exclude="Build,Analyzers" />
<dependency id="Microsoft.AspNetCore.Mvc.Formatters.Json" version="$microsoftAspNetCoreMvcFormattersJsonPackageVersion$" exclude="Build,Analyzers" />
<dependency id="Microsoft.AspNetCore.StaticFiles" version="$microsoftAspNetCoreStaticFilesPackageVersion$" exclude="Build,Analyzers" />
<dependency id="Microsoft.Extensions.ApiDescription.Server" version="$microsoftExtensionsApiDescriptionServerPackageVersion$" />
<dependency id="Microsoft.Extensions.FileProviders.Embedded" version="$microsoftExtensionsFileProvidersEmbeddedPackageVersion$" exclude="Build,Analyzers" />
</group>
<group targetFramework=".NETStandard1.6">
<dependency id="NSwag.Annotations" version="$version$" exclude="Build,Analyzers" />
<dependency id="NSwag.Core" version="$version$" exclude="Build,Analyzers" />
<dependency id="NSwag.Generation.AspNetCore" version="$version$" exclude="Build,Analyzers" />
<dependency id="NSwag.Generation" version="$version$" exclude="Build,Analyzers" />
<dependency id="Microsoft.AspNetCore.Mvc.Core" version="$microsoftAspNetCoreMvcCorePackageVersion$" exclude="Build,Analyzers" />
<dependency id="Microsoft.AspNetCore.Mvc.Formatters.Json" version="$microsoftAspNetCoreMvcFormattersJsonPackageVersion$" exclude="Build,Analyzers" />
<dependency id="Microsoft.AspNetCore.StaticFiles" version="$microsoftAspNetCoreStaticFilesPackageVersion$" exclude="Build,Analyzers" />
<dependency id="Microsoft.Extensions.ApiDescription.Server" version="$microsoftExtensionsApiDescriptionServerPackageVersion$" />
<dependency id="Microsoft.Extensions.FileProviders.Embedded" version="$microsoftExtensionsFileProvidersEmbeddedPackageVersion$" exclude="Build,Analyzers" />
<dependency id="NETStandard.Library" version="$netStandardLibraryPackageVersion$" exclude="Build,Analyzers" />
<dependency id="System.IO.FileSystem" version="$systemIOFileSystemPackageVersion$" exclude="Build,Analyzers" />
<dependency id="System.Xml.XPath.XDocument" version="$systemXmlXPathXDocumentPackageVersion$" exclude="Build,Analyzers" />
</group>
<group targetFramework=".NETStandard2.0">
<dependency id="NSwag.Annotations" version="$version$" exclude="Build,Analyzers" />
<dependency id="NSwag.Core" version="$version$" exclude="Build,Analyzers" />
<dependency id="NSwag.Generation.AspNetCore" version="$version$" exclude="Build,Analyzers" />
<dependency id="NSwag.Generation" version="$version$" exclude="Build,Analyzers" />
<dependency id="Microsoft.AspNetCore.Mvc.Core" version="$microsoftAspNetCoreMvcCorePackageVersion$" exclude="Build,Analyzers" />
<dependency id="Microsoft.AspNetCore.Mvc.Formatters.Json" version="$microsoftAspNetCoreMvcFormattersJsonPackageVersion$" exclude="Build,Analyzers" />
<dependency id="Microsoft.AspNetCore.StaticFiles" version="$microsoftAspNetCoreStaticFilesPackageVersion$" exclude="Build,Analyzers" />
<dependency id="Microsoft.Extensions.ApiDescription.Server" version="$microsoftExtensionsApiDescriptionServerPackageVersion$" />
<dependency id="Microsoft.Extensions.FileProviders.Embedded" version="$microsoftExtensionsFileProvidersEmbeddedPackageVersion$" exclude="Build,Analyzers" />
<dependency id="System.IO.FileSystem" version="$systemIOFileSystemPackageVersion$" exclude="Build,Analyzers" />
<dependency id="System.Xml.XPath.XDocument" version="$systemXmlXPathXDocumentPackageVersion$" exclude="Build,Analyzers" />
</group>
</dependencies>
</metadata>
<files>
<file src="bin\$configuration$\net451\NSwag.AspNetCore.dll" target="lib\net451\" />
<file src="bin\$configuration$\net451\NSwag.AspNetCore.xml" target="lib\net451\" />
<file src="bin\$configuration$\netstandard1.6\NSwag.AspNetCore.dll" target="lib\netstandard1.6\" />
<file src="bin\$configuration$\netstandard1.6\NSwag.AspNetCore.xml" target="lib\netstandard1.6\" />
<file src="bin\$configuration$\netstandard2.0\NSwag.AspNetCore.dll" target="lib\netstandard2.0\" />
<file src="bin\$configuration$\netstandard2.0\NSwag.AspNetCore.xml" target="lib\netstandard2.0\" />
</files>
</package>
19 changes: 14 additions & 5 deletions src/NSwag.AspNetCore/OpenApiDocumentProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
// <author>Rico Suter, mail@rsuter.com</author>
//-----------------------------------------------------------------------

using Microsoft.Extensions.ApiDescription;
using Microsoft.Extensions.DependencyInjection;
using NSwag.Generation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.ApiDescriptions;
using Microsoft.Extensions.DependencyInjection;
using NSwag.Generation;

namespace NSwag.AspNetCore
{
Expand All @@ -40,7 +40,7 @@ public async Task<OpenApiDocument> GenerateAsync(string documentName)
if (group.Count() > 1)
{
throw new ArgumentException("The OpenAPI/Swagger document '" + group.Key + "' registered multiple times: " +
"Explicitely set the DocumentName property in " +
"Explicitly set the DocumentName property in " +
nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "() or " +
nameof(NSwagServiceCollectionExtensions.AddOpenApiDocument) + "().");
}
Expand All @@ -56,7 +56,16 @@ public async Task<OpenApiDocument> GenerateAsync(string documentName)
return await document.Generator.GenerateAsync(_serviceProvider);
}

// Called by the Microsoft.Extensions.ApiDescription tool
// Called by the <c>dotnet-getdocument</c> tool from the Microsoft.Extensions.ApiDescription.Server package.
IEnumerable<string> IDocumentProvider.GetDocumentNames()
{
// DocumentName may be null. But, if it is, cannot generate the registered document.
return _documents
.Where(document => document.DocumentName != null)
.Select(document => document.DocumentName);
}

// Called by the <c>dotnet-getdocument</c> tool from the Microsoft.Extensions.ApiDescription.Server package.
async Task IDocumentProvider.GenerateAsync(string documentName, TextWriter writer)
{
if (documentName == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,4 @@ private static string GetActionName(string actionName)
return actionName;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ private bool IsVoidResponse(Type returnType)
return returnType == null || returnType.FullName == "System.Void";
}
}
}
}
2 changes: 1 addition & 1 deletion src/NSwag.Npm/package-lock.json

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

Binary file removed src/UpgradeLog.htm
Binary file not shown.

0 comments on commit 1cf2396

Please sign in to comment.