Add Path provider and path prefix provider into setting
This commit is contained in:
parent
5a83e6b553
commit
1643ba5ea1
|
@ -49,7 +49,8 @@ namespace Microsoft.OpenApi.OData.Edm
|
||||||
OperationHanderProvider = new OperationHandlerProvider();
|
OperationHanderProvider = new OperationHandlerProvider();
|
||||||
PathItemHanderProvider = new PathItemHandlerProvider();
|
PathItemHanderProvider = new PathItemHandlerProvider();
|
||||||
|
|
||||||
_pathProvider = new ODataPathProvider();
|
// If no path provider, use the default path provider.
|
||||||
|
_pathProvider = settings.PathProvider ?? new ODataPathProvider();
|
||||||
|
|
||||||
if (settings.EnableKeyAsSegment != null)
|
if (settings.EnableKeyAsSegment != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
// ------------------------------------------------------------
|
||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
|
||||||
|
// ------------------------------------------------------------
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
|
namespace Microsoft.OpenApi.OData.Extensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The interface for route prefix.
|
||||||
|
/// </summary>
|
||||||
|
public interface IODataRoutePathPrefixProvider
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The route prefix.
|
||||||
|
/// </summary>
|
||||||
|
public string PathPrefix { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The route prefix parameters.
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<OpenApiParameter> Parameters { get; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
// ------------------------------------------------------------
|
||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
|
||||||
|
// ------------------------------------------------------------
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
|
namespace Microsoft.OpenApi.OData.Extensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Default implementation of <see cref="IODataRoutePathPrefixProvider"/>.
|
||||||
|
/// </summary>
|
||||||
|
public class ODataRoutePathPrefixProvider : IODataRoutePathPrefixProvider
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets/sets the path prefix.
|
||||||
|
/// </summary>
|
||||||
|
public string PathPrefix { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets/sets the associated parameters for the path prefix.
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<OpenApiParameter> Parameters { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,9 @@
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using Microsoft.OpenApi.OData.Common;
|
||||||
|
using Microsoft.OpenApi.OData.Edm;
|
||||||
|
using Microsoft.OpenApi.OData.Extensions;
|
||||||
|
|
||||||
namespace Microsoft.OpenApi.OData
|
namespace Microsoft.OpenApi.OData
|
||||||
{
|
{
|
||||||
|
@ -118,7 +121,35 @@ namespace Microsoft.OpenApi.OData
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets/sets a value that specifies a prefix to be prepended to all generated paths.
|
/// Gets/sets a value that specifies a prefix to be prepended to all generated paths.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string PathPrefix { get; set; } = string.Empty;
|
public string PathPrefix
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (RoutePathPrefixProvider != null)
|
||||||
|
{
|
||||||
|
return RoutePathPrefixProvider.PathPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(value))
|
||||||
|
{
|
||||||
|
throw Error.ArgumentNullOrEmpty("value");
|
||||||
|
}
|
||||||
|
|
||||||
|
RoutePathPrefixProvider = new ODataRoutePathPrefixProvider
|
||||||
|
{
|
||||||
|
PathPrefix = value
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets/sets a route path prefix provider.
|
||||||
|
/// </summary>
|
||||||
|
public IODataRoutePathPrefixProvider RoutePathPrefixProvider { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets/Sets a value indicating whether or not to show the OpenAPI links in the responses.
|
/// Gets/Sets a value indicating whether or not to show the OpenAPI links in the responses.
|
||||||
|
@ -135,6 +166,11 @@ namespace Microsoft.OpenApi.OData
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool ShowRootPath { get; set; } = false;
|
public bool ShowRootPath { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets/sets a the path provider.
|
||||||
|
/// </summary>
|
||||||
|
public IODataPathProvider PathProvider { get; set; }
|
||||||
|
|
||||||
internal OpenApiConvertSettings Clone()
|
internal OpenApiConvertSettings Clone()
|
||||||
{
|
{
|
||||||
var newSettings = new OpenApiConvertSettings
|
var newSettings = new OpenApiConvertSettings
|
||||||
|
@ -159,10 +195,11 @@ namespace Microsoft.OpenApi.OData
|
||||||
EnableDiscriminatorValue = this.EnableDiscriminatorValue,
|
EnableDiscriminatorValue = this.EnableDiscriminatorValue,
|
||||||
EnableDerivedTypesReferencesForResponses = this.EnableDerivedTypesReferencesForResponses,
|
EnableDerivedTypesReferencesForResponses = this.EnableDerivedTypesReferencesForResponses,
|
||||||
EnableDerivedTypesReferencesForRequestBody = this.EnableDerivedTypesReferencesForRequestBody,
|
EnableDerivedTypesReferencesForRequestBody = this.EnableDerivedTypesReferencesForRequestBody,
|
||||||
PathPrefix = this.PathPrefix,
|
RoutePathPrefixProvider = this.RoutePathPrefixProvider,
|
||||||
ShowLinks = this.ShowLinks,
|
ShowLinks = this.ShowLinks,
|
||||||
ShowSchemaExamples = this.ShowSchemaExamples,
|
ShowSchemaExamples = this.ShowSchemaExamples,
|
||||||
ShowRootPath = this.ShowRootPath
|
ShowRootPath = this.ShowRootPath,
|
||||||
|
PathProvider = this.PathProvider
|
||||||
};
|
};
|
||||||
|
|
||||||
return newSettings;
|
return newSettings;
|
||||||
|
|
|
@ -128,6 +128,15 @@ namespace Microsoft.OpenApi.OData.Operation
|
||||||
}
|
}
|
||||||
|
|
||||||
AppendCustomParameters(operation);
|
AppendCustomParameters(operation);
|
||||||
|
|
||||||
|
// Add the route prefix parameter v1{data}
|
||||||
|
if (Context.Settings.RoutePathPrefixProvider != null && Context.Settings.RoutePathPrefixProvider.Parameters != null)
|
||||||
|
{
|
||||||
|
foreach (var parameter in Context.Settings.RoutePathPrefixProvider.Parameters)
|
||||||
|
{
|
||||||
|
operation.Parameters.Add(parameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -95,7 +95,6 @@ namespace Microsoft.OpenApi.OData.Generator.Tests
|
||||||
Assert.Contains("/some/prefix/Me", paths.Keys);
|
Assert.Contains("/some/prefix/Me", paths.Keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void CreatePathsReturnsForContractModelWithHierarhicalClass()
|
public void CreatePathsReturnsForContractModelWithHierarhicalClass()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue