-
Notifications
You must be signed in to change notification settings - Fork 42
Improve message for error "incompatible properties" #316
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2022240
Add test for incompatible properties
mikeharder 8e2b03e
test passes with existing error
mikeharder f8dfe77
Add test for compatible-properties
mikeharder f9a1bce
Remove unnecessary imports
mikeharder 859e4b8
Move tests to shared specs folder
mikeharder 316926c
Add json paths and file locations for incompatible properties
mikeharder 5b82292
Update test for improved error message
mikeharder 5260661
tslint
mikeharder a21e569
tslint
mikeharder e3a48ab
Update src/test/compatiblePropertiesTest.ts
mikeharder 107d853
Update src/test/incompatiblePropertiesTest.ts
mikeharder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import * as assert from "assert" | ||
| import * as path from "path" | ||
| import * as index from "../index" | ||
| import { fileUrl } from "./fileUrl" | ||
|
|
||
| // This test is part of regression test suite for https://github.com/Azure/azure-sdk-tools/issues/5981 | ||
| // Given a property with given type and name | ||
| // When another property with the same name and compatible type is referenced | ||
| // Then no issue is reported, as this is a valid scenario | ||
| test("compatible-properties", async () => { | ||
mikeharder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const diff = new index.OpenApiDiff({}) | ||
| const file = "src/test/specs/compatible-properties.json" | ||
| const resultStr = await diff.compare(file, file) | ||
| const result = JSON.parse(resultStr) | ||
| const filePath = fileUrl(path.resolve(file)) | ||
| const expected = [ | ||
| { | ||
| code: "NoVersionChange", | ||
| docUrl: "https://github.com/Azure/openapi-diff/tree/master/docs/rules/1001.md", | ||
| id: "1001", | ||
| message: "The versions have not changed.", | ||
| mode: "Update", | ||
| new: { | ||
| ref: `${filePath}#`, | ||
| path: "", | ||
| location: `${filePath}:1:1` | ||
| }, | ||
| old: { | ||
| ref: `${filePath}#`, | ||
| path: "", | ||
| location: `${filePath}:1:1` | ||
| }, | ||
| type: "Info" | ||
| } | ||
| ] | ||
| assert.deepStrictEqual(result, expected) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import * as assert from "assert" | ||
| import * as path from "path" | ||
| import * as index from "../index" | ||
mikeharder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import { fileUrl } from "./fileUrl" | ||
|
|
||
| // This test is part of regression test suite for https://github.com/Azure/azure-sdk-tools/issues/5981 | ||
| // Given a property with given type and name | ||
| // When another property with the same name but an incompatible type is referenced | ||
| // Then an issue is reported, with output providing the exact source file locations of both of the occurrences of the property. | ||
| test("incompatible-properties", async () => { | ||
mikeharder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const diff = new index.OpenApiDiff({}) | ||
| const file = "src/test/specs/incompatible-properties.json" | ||
| const filePath = fileUrl(path.resolve(file)) | ||
|
|
||
| try { | ||
| await diff.compare(file, file) | ||
| assert.fail("expected diff.compare() to throw") | ||
| } catch (error) { | ||
| const e = error as Error | ||
| assert.equal( | ||
| e.message, | ||
| "incompatible properties : bar\n" + | ||
| " definitions/FooBarString/properties/bar\n" + | ||
| ` at ${filePath}#L13:8\n` + | ||
| " definitions/FooBarObject/properties/bar\n" + | ||
| ` at ${filePath}#L26:8` | ||
| ) | ||
| } | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| { | ||
| "swagger": "2.0", | ||
| "info": { | ||
| "title": "xms-enum-name", | ||
| "version": "1.0" | ||
| }, | ||
| "paths": { | ||
| }, | ||
| "definitions": { | ||
| "FooBarString": { | ||
| "type":"object", | ||
| "properties": { | ||
| "bar": { | ||
| "type":"string" | ||
| } | ||
| }, | ||
| "allOf": [ | ||
| { | ||
| "$ref": "#/definitions/FooBarString2" | ||
| } | ||
| ] | ||
| }, | ||
| "FooBarString2": { | ||
| "type":"object", | ||
| "properties": { | ||
| "bar": { | ||
| "type":"string" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| { | ||
| "swagger": "2.0", | ||
| "info": { | ||
| "title": "xms-enum-name", | ||
| "version": "1.0" | ||
| }, | ||
| "paths": { | ||
| }, | ||
| "definitions": { | ||
| "FooBarString": { | ||
| "type":"object", | ||
| "properties": { | ||
| "bar": { | ||
| "type":"string" | ||
| } | ||
| }, | ||
| "allOf": [ | ||
| { | ||
| "$ref": "#/definitions/FooBarObject" | ||
| } | ||
| ] | ||
| }, | ||
| "FooBarObject": { | ||
| "type":"object", | ||
| "properties": { | ||
| "bar": { | ||
| "type":"object" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Change is just moving this code earlier, and passing
maptonew ResolveSwagger()so it can include original locations in errors.