Skip to content
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

Make option creation and provider creation public and more generic #1229

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 21 additions & 13 deletions Swashbuckle.Core/Application/SwaggerDocsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,26 @@ public void CustomProvider(Func<ISwaggerProvider, ISwaggerProvider> customProvid

internal ISwaggerProvider GetSwaggerProvider(HttpRequestMessage swaggerRequest)
{
var httpConfig = swaggerRequest.GetConfiguration();
return GetSwaggerProvider(swaggerRequest.GetConfiguration());
}

public ISwaggerProvider GetSwaggerProvider(HttpConfiguration httpConfig)
{
var options = GetSwaggerGeneratorOptions();

var defaultProvider = new SwaggerGenerator(
httpConfig.Services.GetApiExplorer(),
httpConfig.SerializerSettingsOrDefault(),
_versionInfoBuilder.Build(),
options);

return (_customProviderFactory != null)
? _customProviderFactory(defaultProvider)
: defaultProvider;
}

public SwaggerGeneratorOptions GetSwaggerGeneratorOptions()
{
var securityDefintitions = _securitySchemeBuilders.Any()
? _securitySchemeBuilders.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Build())
: null;
Expand All @@ -254,8 +272,8 @@ internal ISwaggerProvider GetSwaggerProvider(HttpRequestMessage swaggerRequest)
modelFilters.Insert(0, new ApplyXmlTypeComments(xmlDoc));
operationFilters.Insert(0, new ApplyXmlActionComments(xmlDoc));
}

var options = new SwaggerGeneratorOptions(
return new SwaggerGeneratorOptions(
versionSupportResolver: _versionSupportResolver,
schemes: _schemes,
securityDefinitions: securityDefintitions,
Expand All @@ -274,16 +292,6 @@ internal ISwaggerProvider GetSwaggerProvider(HttpRequestMessage swaggerRequest)
documentFilters: _documentFilters.Select(factory => factory()).ToList(),
conflictingActionsResolver: _conflictingActionsResolver
);

var defaultProvider = new SwaggerGenerator(
httpConfig.Services.GetApiExplorer(),
httpConfig.SerializerSettingsOrDefault(),
_versionInfoBuilder.Build(),
options);

return (_customProviderFactory != null)
? _customProviderFactory(defaultProvider)
: defaultProvider;
}

internal string GetRootUrl(HttpRequestMessage swaggerRequest)
Expand Down