-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3725 from RicoSuter/master
Release v13.14.4
- Loading branch information
Showing
64 changed files
with
753 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
samples/WithoutMiddleware/Sample.AspNetCore21/nswag_assembly_swagger.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
samples/WithoutMiddleware/Sample.AspNetCore21/nswag_project_swagger.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
samples/WithoutMiddleware/Sample.AspNetCore21/nswag_reflection_swagger.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,13 @@ | |
// <author>Rico Suter, [email protected]</author> | ||
//----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Newtonsoft.Json; | ||
|
||
#pragma warning disable CS0618 | ||
|
||
namespace NSwag.Commands.Generation.AspNetCore | ||
{ | ||
/// <summary>In-process entry point for the aspnetcore2swagger command.</summary> | ||
|
@@ -21,9 +21,11 @@ internal class AspNetCoreToOpenApiGeneratorCommandEntryPoint | |
public static void Process(string commandContent, string outputFile, string applicationName) | ||
{ | ||
var command = JsonConvert.DeserializeObject<AspNetCoreToSwaggerCommand>(commandContent); | ||
|
||
var previousWorkingDirectory = command.ChangeWorkingDirectoryAndSetAspNetCoreEnvironment(); | ||
var serviceProvider = GetServiceProvider(applicationName); | ||
|
||
var assemblyName = new AssemblyName(applicationName); | ||
var assembly = Assembly.Load(assemblyName); | ||
var serviceProvider = ServiceProviderResolver.GetServiceProvider(assembly); | ||
|
||
var assemblyLoader = new AssemblyLoader.AssemblyLoader(); | ||
var document = Task.Run(async () => | ||
|
@@ -35,65 +37,5 @@ public static void Process(string commandContent, string outputFile, string appl | |
Directory.CreateDirectory(outputPathDirectory); | ||
File.WriteAllText(outputFile, json); | ||
} | ||
|
||
private static IServiceProvider GetServiceProvider(string applicationName) | ||
{ | ||
var assemblyName = new AssemblyName(applicationName); | ||
var assembly = Assembly.Load(assemblyName); | ||
|
||
if (assembly.EntryPoint == null) | ||
{ | ||
throw new InvalidOperationException($"Unable to locate the program entry point for {assemblyName}."); | ||
} | ||
|
||
var entryPointType = assembly.EntryPoint.DeclaringType; | ||
var buildWebHostMethod = entryPointType.GetMethod("BuildWebHost"); | ||
var args = new string[0]; | ||
|
||
IServiceProvider serviceProvider = null; | ||
if (buildWebHostMethod != null) | ||
{ | ||
var result = buildWebHostMethod.Invoke(null, new object[] { args }); | ||
serviceProvider = ((IWebHost)result).Services; | ||
} | ||
else | ||
{ | ||
var createWebHostMethod = | ||
entryPointType?.GetRuntimeMethod("CreateWebHostBuilder", new[] { typeof(string[]) }) ?? | ||
entryPointType?.GetRuntimeMethod("CreateWebHostBuilder", new Type[0]); | ||
|
||
if (createWebHostMethod != null) | ||
{ | ||
var webHostBuilder = (IWebHostBuilder)createWebHostMethod.Invoke( | ||
null, createWebHostMethod.GetParameters().Length > 0 ? new object[] { args } : new object[0]); | ||
serviceProvider = webHostBuilder.Build().Services; | ||
} | ||
#if NET6_0 || NET5_0 || NETCOREAPP3_1 || NETCOREAPP3_0 | ||
else | ||
{ | ||
var createHostMethod = | ||
entryPointType?.GetRuntimeMethod("CreateHostBuilder", new[] { typeof(string[]) }) ?? | ||
entryPointType?.GetRuntimeMethod("CreateHostBuilder", new Type[0]); | ||
|
||
if (createHostMethod != null) | ||
{ | ||
var webHostBuilder = (Microsoft.Extensions.Hosting.IHostBuilder)createHostMethod.Invoke( | ||
null, createHostMethod.GetParameters().Length > 0 ? new object[] { args } : new object[0]); | ||
serviceProvider = webHostBuilder.Build().Services; | ||
} | ||
} | ||
#endif | ||
} | ||
|
||
if (serviceProvider != null) | ||
{ | ||
return serviceProvider; | ||
} | ||
|
||
throw new InvalidOperationException($"NSwag requires the entry point type {entryPointType.FullName} to have " + | ||
$"either an BuildWebHost or CreateWebHostBuilder/CreateHostBuilder method. " + | ||
$"See https://docs.microsoft.com/en-us/aspnet/core/fundamentals/hosting?tabs=aspnetcore2x " + | ||
$"for suggestions on ways to refactor your startup type."); | ||
} | ||
} | ||
} |
Oops, something went wrong.