From 6f4a7edca785fb479237ab27c4cf1e8c76ad8b22 Mon Sep 17 00:00:00 2001 From: Chris Martinez Date: Mon, 9 Oct 2023 07:16:44 -0700 Subject: [PATCH] Fix copying source to target options --- .../ODataApiExplorerOptionsFactory.cs | 8 +++++-- .../ApiExplorerOptionsFactory{T}.cs | 23 ++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/AspNetCore/OData/src/Asp.Versioning.OData.ApiExplorer/ApiExplorer/ODataApiExplorerOptionsFactory.cs b/src/AspNetCore/OData/src/Asp.Versioning.OData.ApiExplorer/ApiExplorer/ODataApiExplorerOptionsFactory.cs index 261b6c54..5e494688 100644 --- a/src/AspNetCore/OData/src/Asp.Versioning.OData.ApiExplorer/ApiExplorer/ODataApiExplorerOptionsFactory.cs +++ b/src/AspNetCore/OData/src/Asp.Versioning.OData.ApiExplorer/ApiExplorer/ODataApiExplorerOptionsFactory.cs @@ -69,8 +69,12 @@ public ODataApiExplorerOptionsFactory( } /// - protected override ODataApiExplorerOptions CreateInstance( string name ) => - new( new( CollateApiVersions( providers, Options ), modelConfigurations ) ); + protected override ODataApiExplorerOptions CreateInstance( string name ) + { + var options = new ODataApiExplorerOptions( new( CollateApiVersions( providers, Options ), modelConfigurations ) ); + CopyOptions( Options, options ); + return options; + } private static ODataApiVersionCollectionProvider CollateApiVersions( IApiVersionMetadataCollationProvider[] providers, diff --git a/src/AspNetCore/WebApi/src/Asp.Versioning.Mvc.ApiExplorer/ApiExplorerOptionsFactory{T}.cs b/src/AspNetCore/WebApi/src/Asp.Versioning.Mvc.ApiExplorer/ApiExplorerOptionsFactory{T}.cs index b2d866c9..1a79e0a3 100644 --- a/src/AspNetCore/WebApi/src/Asp.Versioning.Mvc.ApiExplorer/ApiExplorerOptionsFactory{T}.cs +++ b/src/AspNetCore/WebApi/src/Asp.Versioning.Mvc.ApiExplorer/ApiExplorerOptionsFactory{T}.cs @@ -55,14 +55,25 @@ public ApiExplorerOptionsFactory( /// protected override T CreateInstance( string name ) { - var apiVersioningOptions = Options; var options = base.CreateInstance( name ); + CopyOptions( Options, options ); + return options; + } - options.AssumeDefaultVersionWhenUnspecified = apiVersioningOptions.AssumeDefaultVersionWhenUnspecified; - options.ApiVersionParameterSource = apiVersioningOptions.ApiVersionReader; - options.DefaultApiVersion = apiVersioningOptions.DefaultApiVersion; - options.RouteConstraintName = apiVersioningOptions.RouteConstraintName; + /// + /// Copies the following source options to the target options. + /// + /// The source options. + /// The target options. + protected static void CopyOptions( ApiVersioningOptions sourceOptions, T targetOptions ) + { + ArgumentNullException.ThrowIfNull( targetOptions, nameof( targetOptions ) ); + ArgumentNullException.ThrowIfNull( sourceOptions, nameof( sourceOptions ) ); - return options; + targetOptions.AssumeDefaultVersionWhenUnspecified = sourceOptions.AssumeDefaultVersionWhenUnspecified; + targetOptions.ApiVersionParameterSource = sourceOptions.ApiVersionReader; + targetOptions.DefaultApiVersion = sourceOptions.DefaultApiVersion; + targetOptions.RouteConstraintName = sourceOptions.RouteConstraintName; + targetOptions.ApiVersionSelector = sourceOptions.ApiVersionSelector; } } \ No newline at end of file