Skip to content

Commit 4e04c28

Browse files
committed
Merge branch 'develop'
2 parents 2beeef8 + 4c3e879 commit 4e04c28

22 files changed

+597
-7
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Simplify.Web.Postman.Models;
4+
5+
namespace Simplify.Web.Postman
6+
{
7+
/// <summary>
8+
/// Provides postman collection model builder
9+
/// </summary>
10+
public class CollectionBuilder
11+
{
12+
private readonly IList<ICollectionPartBuilder> _partBuilders;
13+
14+
/// <summary>
15+
/// Initializes a new instance of the <see cref="CollectionBuilder"/> class.
16+
/// </summary>
17+
/// <param name="partBuilders">The part builders.</param>
18+
/// <exception cref="ArgumentNullException">partBuilders</exception>
19+
public CollectionBuilder(IList<ICollectionPartBuilder> partBuilders)
20+
{
21+
_partBuilders = partBuilders ?? throw new ArgumentNullException(nameof(partBuilders));
22+
}
23+
24+
/// <summary>
25+
/// Builds the collection model.
26+
/// </summary>
27+
/// <returns></returns>
28+
public CollectionModel Create()
29+
{
30+
var model = new CollectionModel();
31+
32+
foreach (var partBuilder in _partBuilders)
33+
partBuilder.Build(model);
34+
35+
return model;
36+
}
37+
}
38+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System.IO;
2+
using Simplify.Web.Modules;
3+
using Simplify.Web.Postman.Json;
4+
using Simplify.Web.Postman.Models;
5+
using Simplify.Web.Postman.Settings;
6+
7+
namespace Simplify.Web.Postman
8+
{
9+
/// <summary>
10+
/// Provides postman collection to file exporter
11+
/// </summary>
12+
/// <seealso cref="ICollectionExporter" />
13+
public class FileCollectionExporter : ICollectionExporter
14+
{
15+
private readonly CollectionModelSerializer _serializer;
16+
private readonly IEnvironment _environment;
17+
private readonly IPostmanGenerationSettings _settings;
18+
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="FileCollectionExporter"/> class.
21+
/// </summary>
22+
/// <param name="serializer">The serializer.</param>
23+
/// <param name="environment">The environment.</param>
24+
/// <param name="settings">The settings.</param>
25+
public FileCollectionExporter(CollectionModelSerializer serializer, IEnvironment environment, IPostmanGenerationSettings settings)
26+
{
27+
_serializer = serializer;
28+
_environment = environment;
29+
_settings = settings;
30+
}
31+
32+
/// <summary>
33+
/// Exports the specified model.
34+
/// </summary>
35+
/// <param name="model">The model.</param>
36+
public void Export(CollectionModel model)
37+
{
38+
var folderPath = GenerateExportFolderPath();
39+
40+
if (!Directory.Exists(folderPath))
41+
Directory.CreateDirectory(folderPath);
42+
43+
File.WriteAllText(GenerateCollectionFilePath(folderPath), _serializer.Serialize(model));
44+
}
45+
46+
private string GenerateExportFolderPath()
47+
{
48+
return Path.Combine(_environment.SitePhysicalPath, _settings.GenerationFolderPath);
49+
}
50+
51+
private string GenerateCollectionFilePath(string folderPath)
52+
{
53+
return Path.Combine(folderPath, _settings.CollectionFileName + _settings.CollectionFileNamePostfix + ".json");
54+
}
55+
}
56+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Simplify.Web.Postman.Models;
2+
3+
namespace Simplify.Web.Postman
4+
{
5+
/// <summary>
6+
/// Represents postman collection exporter
7+
/// </summary>
8+
public interface ICollectionExporter
9+
{
10+
/// <summary>
11+
/// Exports the specified model.
12+
/// </summary>
13+
/// <param name="model">The model.</param>
14+
void Export(CollectionModel model);
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Simplify.Web.Postman.Models;
2+
3+
namespace Simplify.Web.Postman
4+
{
5+
/// <summary>
6+
/// Provides postman collection part builder
7+
/// </summary>
8+
public interface ICollectionPartBuilder
9+
{
10+
/// <summary>
11+
/// Builds the specified model part.
12+
/// </summary>
13+
/// <param name="model">The model.</param>
14+
void Build(CollectionModel model);
15+
}
16+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Text.Json;
2+
using Simplify.Web.Postman.Models;
3+
4+
namespace Simplify.Web.Postman.Json
5+
{
6+
/// <summary>
7+
/// Provides postman collection model serializer
8+
/// </summary>
9+
public class CollectionModelSerializer
10+
{
11+
/// <summary>
12+
/// Serializes the specified model.
13+
/// </summary>
14+
/// <param name="model">The model.</param>
15+
/// <returns></returns>
16+
public string Serialize(CollectionModel model)
17+
{
18+
return JsonSerializer.Serialize(model, new JsonSerializerOptions
19+
{
20+
PropertyNamingPolicy = new LowerCamelCasePolicy(),
21+
WriteIndented = true
22+
});
23+
}
24+
}
25+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Text.Json;
2+
3+
namespace Simplify.Web.Postman.Json
4+
{
5+
public class LowerCamelCasePolicy : JsonNamingPolicy
6+
{
7+
public override string ConvertName(string name)
8+
{
9+
if (name.Length > 0)
10+
return name.Substring(0, 1).ToLower() + name.Substring(1);
11+
12+
return "";
13+
}
14+
}
15+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#nullable disable
2+
3+
namespace Simplify.Web.Postman.Models
4+
{
5+
/// <summary>
6+
/// Provides postman collection header
7+
/// </summary>
8+
public class CollectionHeader
9+
{
10+
public string Name { get; set; }
11+
}
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#nullable disable
2+
3+
namespace Simplify.Web.Postman.Models
4+
{
5+
public class CollectionItem
6+
{
7+
public string Name { get; set; }
8+
9+
public Request Request { get; set; }
10+
}
11+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#nullable disable
2+
3+
using System.Collections.Generic;
4+
using System.Text.Json.Serialization;
5+
6+
namespace Simplify.Web.Postman.Models
7+
{
8+
/// <summary>
9+
/// Provides postman collection model
10+
/// </summary>
11+
public class CollectionModel
12+
{
13+
/// <summary>
14+
/// Gets or sets the header.
15+
/// </summary>
16+
/// <value>
17+
/// The header.
18+
/// </value>
19+
[JsonPropertyName("info")]
20+
public CollectionHeader Header { get; set; }
21+
22+
[JsonPropertyName("item")]
23+
public IList<CollectionItem> Items { get; set; } = new List<CollectionItem>();
24+
}
25+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#nullable disable
2+
3+
namespace Simplify.Web.Postman.Models
4+
{
5+
public class Request
6+
{
7+
public string Method { get; set; }
8+
9+
public Url Url { get; set; }
10+
}
11+
}

0 commit comments

Comments
 (0)