-
Couldn't load subscription status.
- Fork 42
Url as a source #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Url as a source #112
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,15 +29,15 @@ public class Settings | |
| [SettingsInfo("The location of the old specification.", true)] | ||
| [SettingsAlias("o")] | ||
| [SettingsAlias("old")] | ||
| public string OldSpec { get; set; } | ||
| public Uri OldSpec { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the path to the new specification file. | ||
| /// </summary> | ||
| [SettingsInfo("The location of the new specification.", true)] | ||
| [SettingsAlias("n")] | ||
| [SettingsAlias("new")] | ||
| public string NewSpec { get; set; } | ||
| public Uri NewSpec { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// If set to true, print out help message. | ||
|
|
@@ -185,6 +185,10 @@ private static void PopulateSettings(object entityToPopulate, IDictionary<string | |
| { | ||
| property.SetValue(entityToPopulate, true); | ||
| } | ||
| else if (property.PropertyType == typeof(Uri)) | ||
| { | ||
| property.SetValue(entityToPopulate, new Uri(setting.Value.ToString())); | ||
| } | ||
| else if (property.PropertyType.GetTypeInfo().IsEnum) | ||
| { | ||
| property.SetValue(entityToPopulate, Enum.Parse(property.PropertyType, setting.Value.ToString(), true)); | ||
|
|
@@ -240,21 +244,37 @@ public void Validate() | |
| var doc = property.GetCustomAttributes<SettingsInfoAttribute>().FirstOrDefault(); | ||
| if (doc != null && doc.IsRequired && property.GetValue(this) == null) | ||
| { | ||
| Console.WriteLine(String.Format(Resources.ParameterValueIsMissing, property.Name)); | ||
| Console.WriteLine(string.Format(Resources.ParameterValueIsMissing, property.Name)); | ||
| throw new Exception(string.Format(Resources.ParameterValueIsMissing, property.Name)); | ||
| } | ||
| } | ||
|
|
||
| // Validate input Files | ||
| if (!File.Exists(Instance.OldSpec)) | ||
| if (!ValidateUri(Instance.OldSpec)) | ||
| { | ||
| throw new Exception(String.Format(Resources.InputMustBeAFile, "-old")); | ||
| throw new Exception(string.Format(Resources.InputMustBeAFileOrUrl, "-old")); | ||
| } | ||
|
|
||
| if (!File.Exists(Instance.NewSpec)) | ||
| if (!ValidateUri(Instance.NewSpec)) | ||
| { | ||
| throw new Exception(String.Format(Resources.InputMustBeAFile, "-new")); | ||
| throw new Exception(string.Format(Resources.InputMustBeAFileOrUrl, "-new")); | ||
| } | ||
| } | ||
|
|
||
| private bool ValidateUri(Uri uri) | ||
| { | ||
| if (Instance.OldSpec.Scheme == Uri.UriSchemeFile && | ||
| File.Exists(uri.AbsolutePath)) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| if (Instance.OldSpec.Scheme == Uri.UriSchemeHttp || Instance.OldSpec.Scheme == Uri.UriSchemeHttps) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
| { | ||
| // todo: validate the uri | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't a call to this do a basic validation ? https://msdn.microsoft.com/en-us/library/system.uri.iswellformeduristring(v=vs.110).aspx |
||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,14 +6,15 @@ | |
| using OpenApiDiff.Core; | ||
| using OpenApiDiff.Properties; | ||
| using System.IO; | ||
| using System.Net.Http; | ||
|
|
||
| namespace OpenApiDiff | ||
| { | ||
| internal class Program | ||
| { | ||
| private static int Main(string[] args) | ||
| { | ||
| Settings settings = Settings.GetInstance(args); | ||
| var settings = Settings.GetInstance(args); | ||
|
|
||
| if (settings.ShowHelp) | ||
| { | ||
|
|
@@ -30,10 +31,10 @@ private static int Main(string[] args) | |
| return 1; | ||
| } | ||
|
|
||
| SwaggerModeler modeler = new SwaggerModeler(); | ||
| var modeler = new SwaggerModeler(); | ||
|
|
||
| string swaggerPrev = File.ReadAllText(settings.OldSpec); | ||
| string swaggerNew = File.ReadAllText(settings.NewSpec); | ||
| var swaggerPrev = GetOpenApiSpec(settings.OldSpec); | ||
| var swaggerNew = GetOpenApiSpec(settings.NewSpec); | ||
|
|
||
| var messages = modeler.Compare(swaggerPrev, swaggerNew, settings); | ||
| foreach (var msg in messages) | ||
|
|
@@ -43,5 +44,26 @@ private static int Main(string[] args) | |
|
|
||
| return 0; | ||
| } | ||
|
|
||
|
|
||
| private static string GetOpenApiSpec(Uri uri) | ||
| { | ||
| if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps) | ||
| { | ||
| using (var client = new HttpClient()) | ||
| { | ||
| var response = client.GetAsync(uri).Result; | ||
| return response.Content.ReadAsStringAsync().Result; | ||
| } | ||
| } | ||
|
|
||
| if (uri.Scheme == Uri.UriSchemeFile) | ||
| { | ||
| return File.ReadAllText(uri.AbsolutePath); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you please provide a Gist where this has been run successfully so we make sure there is no regression |
||
| } | ||
|
|
||
| // unsupported Uri scheme | ||
| throw new NotImplementedException($"Given Uri scheme ({uri.Scheme}) is not supported yet."); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why arent you comparing the parameter and instead the
Instance.OldSpec