Skip to content
This repository has been archived by the owner on Sep 13, 2019. It is now read-only.

Commit

Permalink
Fix path variables in URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesholcomb committed Jan 6, 2016
1 parent 37c5583 commit 39200b2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
18 changes: 6 additions & 12 deletions Postman.WebApi.MsBuildTask/CollectionGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,33 +157,27 @@ public PostmanCollection Create(string assemblyFilePath, string environmentKey,
}

// scrub curly braces from url parameter values
var cleanUrlParameterUrl = _urlParameterVariableRegEx.Replace(apiDescription.RelativePath, "=$1-value");

// get path variables from url
var pathVariables = _pathVariableRegEx.Matches(cleanUrlParameterUrl)
.Cast<Match>()
.Select(m => m.Value)
.Select(s => s.Substring(1, s.Length - 2))
.ToDictionary(s => s, s => string.Format("{0}-value", s));
var pathTokens = apiDescription.RelativePath.Split(new char[] { '?' }, 2);
var path = _pathVariableRegEx.Replace(pathTokens[0], ":$1");
var queryString = pathTokens.Length > 1 ? _urlParameterVariableRegEx.Replace(pathTokens[1], "=") : string.Empty;

// prefix url with postman environment key variable
var url = baseUrl + apiDescription.RelativePath;
var url = path + (pathTokens.Length > 1 ? "?" + queryString : string.Empty);

var postmanRequest = new PostmanRequest
{
CollectionId = postManCollection.Id,
Id = Guid.NewGuid(),
Name = apiDescription.RelativePath,
Name = url,
Description = ToMarkdown(apiDescription),
Url = url,
Url = baseUrl + url,
Method = apiDescription.HttpMethod.Method,
Headers = "Content-Type: application/json",
RawModeData = sampleData == null ? null : sampleData.Text,
DataMode = "raw",
Time = postManCollection.Timestamp,
DescriptionFormat = "markdown",
Responses = new Collection<string>(),
PathVariables = pathVariables,
Folder = postManFolder.Id
};

Expand Down
4 changes: 2 additions & 2 deletions Postman.WebApi.MsBuildTask/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("jamesholcomb")]
[assembly: AssemblyProduct("Postman.WebApi.MsBuildTask")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,4 +32,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.1.0")]
[assembly: AssemblyVersion("0.0.2.0")]
2 changes: 1 addition & 1 deletion build/Postman.WebApi.MsBuildTask.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask
TaskName="Postman.WebApi.MsBuildTask.GenerateTask"
AssemblyFile="$(SolutionDir)packages\Postman.WebApi.MsBuildTask.0.0.1.0\tools\Postman.WebApi.MsBuildTask.dll">
AssemblyFile="$(SolutionDir)packages\Postman.WebApi.MsBuildTask.0.0.2.0\tools\Postman.WebApi.MsBuildTask.dll">
</UsingTask>
<Target Name="AfterBuild">
<Postman.WebApi.MsBuildTask.GenerateTask
Expand Down

0 comments on commit 39200b2

Please sign in to comment.