diff --git a/README.md b/README.md
index 72f4a43..3078d5e 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ An OpenAPI tool to compare OpenAPI Specifications.
## C# Library
-The tool is available as a [nuget package](https://www.nuget.org/packages/Criteo.OpenApi.Comparator), directly usable into your C# application.
+The tool is available as a [nuget package](https://www.nuget.org/packages/Criteo.OpenApi.Comparator), directly usable into your C# application.
To install it run the command:
```bash
@@ -21,7 +21,7 @@ var differences = OpenApiComparator.Compare(
## Command line tool
-The comparator is also available as a [command line tool](https://www.nuget.org/packages/Criteo.OpenApi.Comparator.Cli/0.1.0).
+The comparator is also available as a [command line tool](https://www.nuget.org/packages/Criteo.OpenApi.Comparator.Cli/0.1.0).
To install it, run the command:
```bash
@@ -34,12 +34,13 @@ openapi-compare -o new_oas.json -n old_oas.json -f Json
```
Available options:
-| Option | Small | Required | Description |
-|----------------|-------|----------|--------------------------------------------------------------------------------------------------------------|
-| --old | -o | true | Path to old OpenAPI Specification |
-| --new | -n | true | Path to new OpenAPI Specification |
-| --outputFormat | -f | false | Specifies in which format the differences should be displayed (default Json). Possible values: Json \| Text. |
-| --help | -h | false | Log available options |
+| Option | Small | Required | Description |
+|----------------|-------|----------|---------------------------------------------------------------------------------------------------------------|
+| --old | -o | true | Path or URL to old OpenAPI Specification. |
+| --new | -n | true | Path or URL to new OpenAPI Specification. |
+| --outputFormat | -f | false | (Default: Json) Specifies in which format the differences should be displayed. Possible values: Json \| Text. |
+| --strict | -s | false | (Default: false) Enable strict mode: breaking changes are errors instead of warnings. |
+| --help | -h | false | Log available options |
## Comparison rules
diff --git a/src/Criteo.OpenApi.Comparator.Cli/Options.cs b/src/Criteo.OpenApi.Comparator.Cli/Options.cs
index 1f6feeb..efcfab0 100644
--- a/src/Criteo.OpenApi.Comparator.Cli/Options.cs
+++ b/src/Criteo.OpenApi.Comparator.Cli/Options.cs
@@ -13,20 +13,30 @@ public class Options
///
/// Path to old OpenAPI Specification
///
- [Option('o', "old", Required = true, HelpText = "Path or URL to old OpenAPI Specification.")]
+ [Option('o', "old", Required = true,
+ HelpText = "Path or URL to old OpenAPI Specification.")]
public string OldSpec { get; set; }
///
/// Path to new OpenAPI Specification
///
- [Option('n', "new", Required = true, HelpText = "Path or URL to new OpenAPI Specification.")]
+ [Option('n', "new", Required = true,
+ HelpText = "Path or URL to new OpenAPI Specification.")]
public string NewSpec { get; set; }
///
/// Specifies in which format the differences should be displayed (default Json)
///
- [Option('f', "outputFormat", Required = false, HelpText = "Specifies in which format the differences should be displayed (default Json). Possible values: Json | Text.")]
+ [Option('f', "outputFormat", Required = false, Default = OutputFormat.Json,
+ HelpText = "Specifies in which format the differences should be displayed. Possible values: Json | Text.")]
public OutputFormat OutputFormat { get; set; } = OutputFormat.Json;
+
+ ///
+ /// Enable strict mode
+ ///
+ [Option('s', "strict", Required = false, Default = false,
+ HelpText = "Enable strict mode: breaking changes are errors instead of warnings.")]
+ public bool StrictMode { get; set; } = false;
}
///
@@ -44,4 +54,4 @@ public enum OutputFormat
///
Text = 1,
}
-}
\ No newline at end of file
+}
diff --git a/src/Criteo.OpenApi.Comparator.Cli/Program.cs b/src/Criteo.OpenApi.Comparator.Cli/Program.cs
index 1c4b53f..fde605a 100644
--- a/src/Criteo.OpenApi.Comparator.Cli/Program.cs
+++ b/src/Criteo.OpenApi.Comparator.Cli/Program.cs
@@ -38,7 +38,8 @@ public static int Main(string[] args)
return 1;
}
- var differences = OpenApiComparator.Compare(oldOpenApiSpecification, newOpenApiSpecification);
+ var differences = OpenApiComparator.Compare(
+ oldOpenApiSpecification, newOpenApiSpecification, options.StrictMode);
DisplayOutput(differences, options.OutputFormat);
diff --git a/src/Criteo.OpenApi.Comparator/OpenApiComparator.cs b/src/Criteo.OpenApi.Comparator/OpenApiComparator.cs
index 8d4c669..1f6e546 100644
--- a/src/Criteo.OpenApi.Comparator/OpenApiComparator.cs
+++ b/src/Criteo.OpenApi.Comparator/OpenApiComparator.cs
@@ -17,12 +17,13 @@ public static class OpenApiComparator
///
/// The content of the old OpenAPI Specification
/// The content of the new OpenAPI Specification
- public static IEnumerable Compare(string oldOpenApiSpec, string newOpenApiSpec)
+ /// If true, then breaking changes are errors instead of warnings.
+ public static IEnumerable Compare(string oldOpenApiSpec, string newOpenApiSpec, bool strict = false)
{
var oldOpenApiDocument = OpenApiParser.Parse(oldOpenApiSpec);
var newOpenApiDocument = OpenApiParser.Parse(newOpenApiSpec);
- var context = new ComparisonContext(oldOpenApiDocument, newOpenApiDocument);
+ var context = new ComparisonContext(oldOpenApiDocument, newOpenApiDocument) { Strict = strict };
var comparator = new OpenApiDocumentComparator();
var comparisonMessages = comparator.Compare(context, oldOpenApiDocument.Typed, newOpenApiDocument.Typed);