diff --git a/README.md b/README.md
index 72f4a43..0c0d419 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
@@ -39,6 +39,7 @@ Available options:
| --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. |
+| --strict | -s | 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..73548cd 100644
--- a/src/Criteo.OpenApi.Comparator.Cli/Options.cs
+++ b/src/Criteo.OpenApi.Comparator.Cli/Options.cs
@@ -27,6 +27,12 @@ public class Options
///
[Option('f', "outputFormat", Required = false, HelpText = "Specifies in which format the differences should be displayed (default Json). Possible values: Json | Text.")]
public OutputFormat OutputFormat { get; set; } = OutputFormat.Json;
+
+ ///
+ /// Enable strict mode
+ ///
+ [Option('s', "strict", Required = false, HelpText = "Enable strict mode: breaking changes are errors instead of warnings.")]
+ public bool StrictMode { get; set; }
}
///
@@ -44,4 +50,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);