63 lines
2.3 KiB
C#
63 lines
2.3 KiB
C#
using System;
|
|
using Kreta.Core.FeatureToggle;
|
|
using Kreta.Ellenorzo.Dto.VN.Interfaces;
|
|
using Kreta.Ellenorzo.WebApi.VN.Documentation.Helper;
|
|
using Swashbuckle.Examples;
|
|
|
|
namespace Kreta.Ellenorzo.WebApi.VN.Documentation
|
|
{
|
|
/// <summary>
|
|
/// Author: Kovács Kornél (DevKornél) Created On: 2019.05.
|
|
/// </summary>
|
|
internal class DummyExampleProvider<TController, TDto> : IExamplesProvider where TController : new() where TDto : IDtoDocumentation, new()
|
|
{
|
|
public object GetExamples()
|
|
{
|
|
object response = ExampleHelper.TryGetExampleFeatureDefaultExampleModel();
|
|
if (response != null)
|
|
{
|
|
return response;
|
|
}
|
|
|
|
TDto dto = new TDto();
|
|
object[] parameterArray = dto.Example.RequestParameter == null
|
|
? new object[] { }
|
|
: new[] { dto.Example.RequestParameter };
|
|
|
|
ExampleHelper.MockUser(dto.Example.MockUserName);
|
|
|
|
return new
|
|
{
|
|
RequestExample = dto.Example.RequestParameter,
|
|
RequestExampleUser = dto.Example.MockUserName,
|
|
ResponseExample = typeof(TController).GetMethod(dto.Example.MethodName).Invoke(new TController(), parameterArray)
|
|
};
|
|
}
|
|
}
|
|
|
|
internal class DummyExampleProviderWithDependencyInjection<TController, TDto> : IExamplesProvider where TDto : IDtoDocumentation, new()
|
|
{
|
|
public object GetExamples()
|
|
{
|
|
object response = ExampleHelper.TryGetExampleFeatureDefaultExampleModel();
|
|
if (response != null)
|
|
{
|
|
return response;
|
|
}
|
|
|
|
TDto dto = new TDto();
|
|
object[] parameterArray = dto.Example.RequestParameter == null
|
|
? new object[] { }
|
|
: new[] { dto.Example.RequestParameter };
|
|
|
|
ExampleHelper.MockUser(dto.Example.MockUserName);
|
|
|
|
return new
|
|
{
|
|
RequestExample = dto.Example.RequestParameter,
|
|
RequestExampleUser = dto.Example.MockUserName,
|
|
ResponseExample = typeof(TController).GetMethod(dto.Example.MethodName).Invoke((TController)Activator.CreateInstance(typeof(TController), FeatureContext.Instance), parameterArray)
|
|
};
|
|
}
|
|
}
|
|
}
|