Skip to content

Commit

Permalink
Fix copying source to target options
Browse files Browse the repository at this point in the history
  • Loading branch information
commonsensesoftware committed Oct 9, 2023
1 parent 098747f commit 6f4a7ed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ public ODataApiExplorerOptionsFactory(
}

/// <inheritdoc />
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,25 @@ public ApiExplorerOptionsFactory(
/// <inheritdoc />
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;
/// <summary>
/// Copies the following source options to the target options.
/// </summary>
/// <param name="sourceOptions">The source options.</param>
/// <param name="targetOptions">The target options.</param>
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;
}
}

0 comments on commit 6f4a7ed

Please sign in to comment.