Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 0.10.4 Released on 2023-01-10

- fix rule index & support additionalProperties:true

## 0.10.3 Released on 2022-11-29

- fix adding enum value & command line exception

## 0.10.2 Released on 2022-11-02

- bugfix for RequiredStatusChange

## 0.10.1 Released on 2022-10-15

- Bugfixes for ReferenceRedirection,AddedPropertyInResponse,DefaultValueChanged.
Expand Down
61 changes: 61 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Contributing

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 [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

## Prerequisites

- [Node.js](https://nodejs.org/) (14.x or higher)
- [.NET runtime and SDK](https://aka.ms/dotnet-download)
- [.NET CLI tools](https://github.com/dotnet/cli/releases) version 2.0.0 or higher

## Build scripts

Run `npm install` to install the required modules.

```sh
npm install
```

## How to build the C# code

The core logic for openapi-diff is written in C# and compiled to a .NET binary.

Use `dn.build` npm script to build the C# code.

```sh
npm run dn.build
```

## How to test the C# code

To run all tests under the repo

```sh
npm run dn.test
```

## How to build the TypeScript code

The CLI for openapi-diff is written in TypeScript and compiled to a Node.js binary.

Use `tsc` npm script to build the TypeScript code.

```sh
npm run tsc
```

## How to run locally

After you have built the C# and TypeScript code, you can run the openapi-diff tool locally.
To run the openapi-diff tool locally, use the `npm run start` command.

```sh
node dist/cli.js --help
```

You can also install the package globally and run it from anywhere.

```sh
npm install -g
oad --help
```
45 changes: 4 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
npm install -g @azure/oad
```

## git Usage
# Usage

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

## Build dependencies

* [Node](https://nodejs.org) (10 or higher)
* [Node Package Manager](https://www.npmjs.com/package/npm)
* [.NET CLI tools](https://github.com/dotnet/cli/releases) version 2.0.0 or higher
> You want the **.NET Core SDK Binaries** for your platform <br>
>
> `dotnet --version` <br>
> `2.0.2` <br>

## Build scripts

### How to build

The first step would be to run `npm install` so we have all the required modules installed.

#### How to build the whole repo

```javascript
gulp;
```

### How to test

To run all tests under the repo

```javascript
gulp test
```

### How to bundle node package & install

```javascript
gulp pack
npm install -g oad-0.1.0.tgz
```

# Contributing

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 [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
See [CONTRIBUTING.md](./CONTRIBUTING.md)
3 changes: 1 addition & 2 deletions openapi-diff/src/core/OpenApiDiff/OpenApiDiff.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
<Import Project="$(common)package-info.proj" />

<PropertyGroup>
<RuntimeIdentifiers>win7-x64</RuntimeIdentifiers>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>netcoreapp6.0</TargetFramework>
<AssemblyName>OpenApiDiff</AssemblyName>
<PackageTags>Microsoft OpenApiDiff</PackageTags>
<Version>0.1.0</Version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Import Project="$(common)project-xunittest.proj" />

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>netcoreapp6.0</TargetFramework>
<LangVersion>7.1</LangVersion>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,15 @@ public void TypeObjectChanged()
}

/// <summary>
/// Verifies that if if you change the default value of a schema, it's caught .
/// Verifies that if you change the default value of a schema, it's caught.
/// </summary>
[Fact]
public void DefaultValueChanged()
{
var messages = CompareSwagger("default_changed_01.json").ToArray();
var errors = messages.Where(m => m.Id == ComparisonMessages.DefaultValueChanged.Id).ToArray();
Assert.NotNull(errors);
Assert.Equal(errors.Count(), 8);
Assert.Equal(8, errors.Count());
}

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

/// <summary>
/// Verifies that if you add an optional parameter, it is flagged
/// </summary>
[Fact]
public void OptionalParameterAdded()
{
var messages = CompareSwagger("optional_parameter.json").ToArray();
Expand Down Expand Up @@ -429,7 +433,7 @@ public void AddedPropertyInResponse()
}

/// <summary>
/// Verifies that rules work on the recurive models
/// Verifies that rules work on the recursive models
/// </summary>
[Fact]
public void RecursiveModels()
Expand Down Expand Up @@ -492,11 +496,11 @@ public void PropertyRequiredChanged()
{
var messages = CompareSwagger("property_required_status_changed.json").ToArray();
var missing = messages.Where(m => m.Id == ComparisonMessages.RequiredStatusChange.Id);
Assert.Equal(missing.Count(),2);
Assert.Equal(2, missing.Count());
}

/// <summary>
/// Verifieds that if you make an optional parameter required, it's caught.
/// Verifies that if you make an optional parameter required, it's caught.
/// </summary>
[Fact]
public void ParameterStatusMore()
Expand Down Expand Up @@ -693,7 +697,7 @@ public void RequestTypeConstraintsChanged()
/// Verifies that making constraints stricter in requests are flagged, weaker are flagged and adding enum to parameters are flagged
/// </summary>
[Fact]
public void RequestTypeContraintsWithNewEnum()
public void RequestTypeConstraintsWithNewEnum()
{
var messages = CompareSwagger("enum_values_changed.json").Where(m => m.NewJsonRef.Contains("Parameters")).ToArray();

Expand Down Expand Up @@ -741,7 +745,7 @@ public void ResponseTypeConstraintsChanged()
/// Direction: requests
/// </summary>
[Fact]
public void GobalParamArrayFormatChanged()
public void GlobalParamArrayFormatChanged()
{
var messages = CompareSwagger("param_check_01.json").ToArray();
var changed = messages.Where(m => m.Id == ComparisonMessages.ArrayCollectionFormatChanged.Id).ToArray();
Expand All @@ -766,7 +770,7 @@ public void GobalParamArrayFormatChanged()
/// are just informational.
/// </summary>
[Fact]
public void GobalParamTypeConstraintsChanged()
public void GlobalParamTypeConstraintsChanged()
{
var messages = CompareSwagger("param_check_01.json").Where(m => m.NewJsonRef.Contains("parameters")).ToArray();
var stricter = messages.Where(m => m.Id == ComparisonMessages.ConstraintIsStronger.Id && m.Severity == Category.Error).ToArray();
Expand All @@ -783,7 +787,7 @@ public void GobalParamTypeConstraintsChanged()
/// Direction: responses
/// </summary>
[Fact]
public void GobalResponseArrayFormatChanged()
public void GlobalResponseArrayFormatChanged()
{
var messages = CompareSwagger("response_check_01.json").ToArray();
var changed = messages.Where(m => m.Id == ComparisonMessages.ArrayCollectionFormatChanged.Id).ToArray();
Expand Down Expand Up @@ -892,24 +896,24 @@ public void ChangedParameterOrder()
public void ChangedXmsLongRunningOperation()
{
var messages = CompareSwagger("long_running_operation.json").ToArray();
Assert.Equal(1, messages.Where(m => m.Id == ComparisonMessages.XmsLongRunningOperationChanged.Id).Count());
Assert.Single(messages.Where(m => m.Id == ComparisonMessages.XmsLongRunningOperationChanged.Id));
}

[Fact]
public void AddedOptionalProperty()
{
var messages = CompareSwagger("added_optional_property.json").ToArray();
Assert.Equal(1, messages.Where(m => m.Id == ComparisonMessages.AddedOptionalProperty.Id).Count());
Assert.Single(messages.Where(m => m.Id == ComparisonMessages.AddedOptionalProperty.Id));
}


// Verify a inline schema of response was changed to reference schema and a new proeprty was added.
// Verify a inline schema of response was changed to reference schema and a new property was added.
[Fact]
public void AddedOptionalPropertyToInlineResponseSchema()
{
var messages = CompareSwagger("add_optional_property_01.json").ToArray();
Assert.Equal(1, messages.Where(m => m.Id == ComparisonMessages.AddedPropertyInResponse.Id).Count());
Assert.Equal(1, messages.Where(m => m.Id == ComparisonMessages.ReferenceRedirection.Id).Count());
Assert.Single(messages.Where(m => m.Id == ComparisonMessages.AddedPropertyInResponse.Id));
Assert.Single(messages.Where(m => m.Id == ComparisonMessages.ReferenceRedirection.Id));
}

[Fact]
Expand All @@ -932,8 +936,8 @@ public void ReferenceChanged()
{
var messages = CompareSwagger("xms_client_name_changed.json").ToArray();
var redirected = messages.Where(m => m.Id == ComparisonMessages.ReferenceRedirection.Id).ToArray();
Assert.Equal(1, redirected.Count());
Assert.Equal(redirected[0].NewJsonRef, "new/xms_client_name_changed.json#/paths/~1api~1Parameters/post/parameters/0/schema");
Assert.Single(redirected);
Assert.Equal("new/xms_client_name_changed.json#/paths/~1api~1Parameters/post/parameters/0/schema", redirected[0].NewJsonRef);
}
}
}
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

import * as yargs from "yargs"
import yargs from "yargs"
import { log } from "./lib/util/logging"

const defaultLogDir = log.directory
Expand Down