Skip to content

Commit edd69b1

Browse files
authored
Fixes for local run (#284)
1 parent 7aa7018 commit edd69b1

File tree

7 files changed

+101
-62
lines changed

7 files changed

+101
-62
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## 0.10.4 Released on 2023-01-10
4+
5+
- fix rule index & support additionalProperties:true
6+
7+
## 0.10.3 Released on 2022-11-29
8+
9+
- fix adding enum value & command line exception
10+
11+
## 0.10.2 Released on 2022-11-02
12+
13+
- bugfix for RequiredStatusChange
14+
315
## 0.10.1 Released on 2022-10-15
416

517
- Bugfixes for ReferenceRedirection,AddedPropertyInResponse,DefaultValueChanged.

CONTRIBUTING.md

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Contributing
2+
3+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
4+
5+
## Prerequisites
6+
7+
- [Node.js](https://nodejs.org/) (14.x or higher)
8+
- [.NET runtime and SDK](https://aka.ms/dotnet-download)
9+
- [.NET CLI tools](https://github.com/dotnet/cli/releases) version 2.0.0 or higher
10+
11+
## Build scripts
12+
13+
Run `npm install` to install the required modules.
14+
15+
```sh
16+
npm install
17+
```
18+
19+
## How to build the C# code
20+
21+
The core logic for openapi-diff is written in C# and compiled to a .NET binary.
22+
23+
Use `dn.build` npm script to build the C# code.
24+
25+
```sh
26+
npm run dn.build
27+
```
28+
29+
## How to test the C# code
30+
31+
To run all tests under the repo
32+
33+
```sh
34+
npm run dn.test
35+
```
36+
37+
## How to build the TypeScript code
38+
39+
The CLI for openapi-diff is written in TypeScript and compiled to a Node.js binary.
40+
41+
Use `tsc` npm script to build the TypeScript code.
42+
43+
```sh
44+
npm run tsc
45+
```
46+
47+
## How to run locally
48+
49+
After you have built the C# and TypeScript code, you can run the openapi-diff tool locally.
50+
To run the openapi-diff tool locally, use the `npm run start` command.
51+
52+
```sh
53+
node dist/cli.js --help
54+
```
55+
56+
You can also install the package globally and run it from anywhere.
57+
58+
```sh
59+
npm install -g
60+
oad --help
61+
```

README.md

+4-41
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
npm install -g @azure/oad
77
```
88

9-
## git Usage
9+
# Usage
1010

1111
```bash
1212
vishrut@visshamac openapi-diff $ oad compare --help
@@ -25,49 +25,12 @@ Options:
2525
-j, --inJson A boolean flag indicating whether output format of the
2626
messages is json. [boolean] [default: true]
2727
-h, --help Show help [boolean]
28-
-o, --oldTagName The tag name for the old specification file. If include it
28+
-o, --oldTagName The tag name for the old specification file. If included it
2929
indicates that the old spec file is a readme file
30-
-n, --newTagName The tag name for the new specification file. If include it
30+
-n, --newTagName The tag name for the new specification file. If included it
3131
indicates that the new spec file is a readme file
3232
```
3333

34-
## Build dependencies
35-
36-
* [Node](https://nodejs.org) (10 or higher)
37-
* [Node Package Manager](https://www.npmjs.com/package/npm)
38-
* [.NET CLI tools](https://github.com/dotnet/cli/releases) version 2.0.0 or higher
39-
> You want the **.NET Core SDK Binaries** for your platform <br>
40-
>
41-
> `dotnet --version` <br>
42-
> `2.0.2` <br>
43-
44-
## Build scripts
45-
46-
### How to build
47-
48-
The first step would be to run `npm install` so we have all the required modules installed.
49-
50-
#### How to build the whole repo
51-
52-
```javascript
53-
gulp;
54-
```
55-
56-
### How to test
57-
58-
To run all tests under the repo
59-
60-
```javascript
61-
gulp test
62-
```
63-
64-
### How to bundle node package & install
65-
66-
```javascript
67-
gulp pack
68-
npm install -g oad-0.1.0.tgz
69-
```
70-
7134
# Contributing
7235

73-
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
36+
See [CONTRIBUTING.md](./CONTRIBUTING.md)

openapi-diff/src/core/OpenApiDiff/OpenApiDiff.csproj

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
<Import Project="$(common)package-info.proj" />
55

66
<PropertyGroup>
7-
<RuntimeIdentifiers>win7-x64</RuntimeIdentifiers>
87
<OutputType>Exe</OutputType>
9-
<TargetFramework>netcoreapp3.1</TargetFramework>
8+
<TargetFramework>netcoreapp6.0</TargetFramework>
109
<AssemblyName>OpenApiDiff</AssemblyName>
1110
<PackageTags>Microsoft OpenApiDiff</PackageTags>
1211
<Version>0.1.0</Version>

openapi-diff/src/modeler/AutoRest.Swagger.Tests/AutoRest.Swagger.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Import Project="$(common)project-xunittest.proj" />
55

66
<PropertyGroup>
7-
<TargetFramework>netcoreapp3.1</TargetFramework>
7+
<TargetFramework>netcoreapp6.0</TargetFramework>
88
<LangVersion>7.1</LangVersion>
99
</PropertyGroup>
1010

openapi-diff/src/modeler/AutoRest.Swagger.Tests/SwaggerModelerCompareTests.cs

+21-17
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ public void TypeObjectChanged()
166166
}
167167

168168
/// <summary>
169-
/// Verifies that if if you change the default value of a schema, it's caught .
169+
/// Verifies that if you change the default value of a schema, it's caught.
170170
/// </summary>
171171
[Fact]
172172
public void DefaultValueChanged()
173173
{
174174
var messages = CompareSwagger("default_changed_01.json").ToArray();
175175
var errors = messages.Where(m => m.Id == ComparisonMessages.DefaultValueChanged.Id).ToArray();
176176
Assert.NotNull(errors);
177-
Assert.Equal(errors.Count(), 8);
177+
Assert.Equal(8, errors.Count());
178178
}
179179

180180
/// <summary>
@@ -276,7 +276,7 @@ public void OperationIdRemoved()
276276
{
277277
var messages = CompareSwagger("removed_operation_id.json").ToArray();
278278
var missing = messages.Where(m => m.Id == ComparisonMessages.ModifiedOperationId.Id);
279-
Assert.Equal(1, missing.Count());
279+
Assert.Single(missing);
280280
var x = missing.First(m => m.Severity == Category.Error && m.NewJsonRef == "new/removed_operation_id.json#/paths/~1api~1Operations/get");
281281
Assert.NotNull(x.NewJson());
282282
Assert.NotNull(x.OldJson());
@@ -385,6 +385,10 @@ public void RequiredParameterAdded()
385385
Assert.Null(x.OldJson());
386386
}
387387

388+
/// <summary>
389+
/// Verifies that if you add an optional parameter, it is flagged
390+
/// </summary>
391+
[Fact]
388392
public void OptionalParameterAdded()
389393
{
390394
var messages = CompareSwagger("optional_parameter.json").ToArray();
@@ -429,7 +433,7 @@ public void AddedPropertyInResponse()
429433
}
430434

431435
/// <summary>
432-
/// Verifies that rules work on the recurive models
436+
/// Verifies that rules work on the recursive models
433437
/// </summary>
434438
[Fact]
435439
public void RecursiveModels()
@@ -492,11 +496,11 @@ public void PropertyRequiredChanged()
492496
{
493497
var messages = CompareSwagger("property_required_status_changed.json").ToArray();
494498
var missing = messages.Where(m => m.Id == ComparisonMessages.RequiredStatusChange.Id);
495-
Assert.Equal(missing.Count(),2);
499+
Assert.Equal(2, missing.Count());
496500
}
497501

498502
/// <summary>
499-
/// Verifieds that if you make an optional parameter required, it's caught.
503+
/// Verifies that if you make an optional parameter required, it's caught.
500504
/// </summary>
501505
[Fact]
502506
public void ParameterStatusMore()
@@ -693,7 +697,7 @@ public void RequestTypeConstraintsChanged()
693697
/// Verifies that making constraints stricter in requests are flagged, weaker are flagged and adding enum to parameters are flagged
694698
/// </summary>
695699
[Fact]
696-
public void RequestTypeContraintsWithNewEnum()
700+
public void RequestTypeConstraintsWithNewEnum()
697701
{
698702
var messages = CompareSwagger("enum_values_changed.json").Where(m => m.NewJsonRef.Contains("Parameters")).ToArray();
699703

@@ -741,7 +745,7 @@ public void ResponseTypeConstraintsChanged()
741745
/// Direction: requests
742746
/// </summary>
743747
[Fact]
744-
public void GobalParamArrayFormatChanged()
748+
public void GlobalParamArrayFormatChanged()
745749
{
746750
var messages = CompareSwagger("param_check_01.json").ToArray();
747751
var changed = messages.Where(m => m.Id == ComparisonMessages.ArrayCollectionFormatChanged.Id).ToArray();
@@ -766,7 +770,7 @@ public void GobalParamArrayFormatChanged()
766770
/// are just informational.
767771
/// </summary>
768772
[Fact]
769-
public void GobalParamTypeConstraintsChanged()
773+
public void GlobalParamTypeConstraintsChanged()
770774
{
771775
var messages = CompareSwagger("param_check_01.json").Where(m => m.NewJsonRef.Contains("parameters")).ToArray();
772776
var stricter = messages.Where(m => m.Id == ComparisonMessages.ConstraintIsStronger.Id && m.Severity == Category.Error).ToArray();
@@ -783,7 +787,7 @@ public void GobalParamTypeConstraintsChanged()
783787
/// Direction: responses
784788
/// </summary>
785789
[Fact]
786-
public void GobalResponseArrayFormatChanged()
790+
public void GlobalResponseArrayFormatChanged()
787791
{
788792
var messages = CompareSwagger("response_check_01.json").ToArray();
789793
var changed = messages.Where(m => m.Id == ComparisonMessages.ArrayCollectionFormatChanged.Id).ToArray();
@@ -892,24 +896,24 @@ public void ChangedParameterOrder()
892896
public void ChangedXmsLongRunningOperation()
893897
{
894898
var messages = CompareSwagger("long_running_operation.json").ToArray();
895-
Assert.Equal(1, messages.Where(m => m.Id == ComparisonMessages.XmsLongRunningOperationChanged.Id).Count());
899+
Assert.Single(messages.Where(m => m.Id == ComparisonMessages.XmsLongRunningOperationChanged.Id));
896900
}
897901

898902
[Fact]
899903
public void AddedOptionalProperty()
900904
{
901905
var messages = CompareSwagger("added_optional_property.json").ToArray();
902-
Assert.Equal(1, messages.Where(m => m.Id == ComparisonMessages.AddedOptionalProperty.Id).Count());
906+
Assert.Single(messages.Where(m => m.Id == ComparisonMessages.AddedOptionalProperty.Id));
903907
}
904908

905909

906-
// Verify a inline schema of response was changed to reference schema and a new proeprty was added.
910+
// Verify a inline schema of response was changed to reference schema and a new property was added.
907911
[Fact]
908912
public void AddedOptionalPropertyToInlineResponseSchema()
909913
{
910914
var messages = CompareSwagger("add_optional_property_01.json").ToArray();
911-
Assert.Equal(1, messages.Where(m => m.Id == ComparisonMessages.AddedPropertyInResponse.Id).Count());
912-
Assert.Equal(1, messages.Where(m => m.Id == ComparisonMessages.ReferenceRedirection.Id).Count());
915+
Assert.Single(messages.Where(m => m.Id == ComparisonMessages.AddedPropertyInResponse.Id));
916+
Assert.Single(messages.Where(m => m.Id == ComparisonMessages.ReferenceRedirection.Id));
913917
}
914918

915919
[Fact]
@@ -932,8 +936,8 @@ public void ReferenceChanged()
932936
{
933937
var messages = CompareSwagger("xms_client_name_changed.json").ToArray();
934938
var redirected = messages.Where(m => m.Id == ComparisonMessages.ReferenceRedirection.Id).ToArray();
935-
Assert.Equal(1, redirected.Count());
936-
Assert.Equal(redirected[0].NewJsonRef, "new/xms_client_name_changed.json#/paths/~1api~1Parameters/post/parameters/0/schema");
939+
Assert.Single(redirected);
940+
Assert.Equal("new/xms_client_name_changed.json#/paths/~1api~1Parameters/post/parameters/0/schema", redirected[0].NewJsonRef);
937941
}
938942
}
939943
}

src/cli.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Copyright (c) Microsoft Corporation. All rights reserved.
44
// Licensed under the MIT License. See License.txt in the project root for license information.
55

6-
import * as yargs from "yargs"
6+
import yargs from "yargs"
77
import { log } from "./lib/util/logging"
88

99
const defaultLogDir = log.directory

0 commit comments

Comments
 (0)