Skip to content
Draft
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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@ts-common/source-map": "0.5.0",
"@ts-common/string-map": "0.3.0",
"autorest": "^3.8.0",
"fast-deep-equal": "^3.1.3",
"js-yaml": "^4.1.0",
"json-pointer": "0.6.2",
"json-refs": "^3.0.15",
Expand Down
3 changes: 2 additions & 1 deletion src/lib/util/resolveSwagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { toArray } from "@ts-common/iterator"
import { cloneDeep, Data, FilePosition, getFilePosition, getInfo, getPath, ObjectInfo } from "@ts-common/source-map"
import * as sourceMap from "source-map"
import * as sm from "@ts-common/string-map"
import equal from "fast-deep-equal"
import { readFileSync, writeFileSync } from "fs"
import * as path from "path"
import { pathToJsonPointer } from "./utils"
Expand Down Expand Up @@ -247,7 +248,7 @@ export class ResolveSwagger {
if (allOfSchema.properties) {
sm.keys(allOfSchema.properties).forEach(key => {
if (sm.keys(schemaList).some(k => k === key)) {
if (!this.isEqual(allOfSchema.properties[key], schemaList[key])) {
if (!this.isEqual(allOfSchema.properties[key], schemaList[key]) && !equal(allOfSchema.properties[key], schemaList[key])) {
const allOfProp = allOfSchema.properties[key]
const allOfPath = getPath(getInfo(allOfProp) as ObjectInfo)
const allOfOriginalPosition = this.map.originalPositionFor(getFilePosition(allOfProp) as FilePosition)
Expand Down
8 changes: 8 additions & 0 deletions src/test/incompatiblePropertiesTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import * as path from "path"
import { OpenApiDiff } from ".."
import { fileUrl } from "./fileUrl"

test.each(["different-names", "duplicate-names", "reference-equals", "structural-equals"])("should pass for %s", async testName => {
const diff = new OpenApiDiff({})
const file = `src/test/specs/incompatible-properties/${testName}.json`

// expected to pass
await diff.compare(file, file)
})

// 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
Expand Down
18 changes: 18 additions & 0 deletions src/test/specs/incompatible-properties/common-types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"swagger": "2.0",
"info": {
"title": "common-types",
"version": "1.0"
},
"paths": {},
"definitions": {
"Foo": {
"type": "object",
"properties": {
"p1": {
"type": "string"
}
}
}
}
}
31 changes: 31 additions & 0 deletions src/test/specs/incompatible-properties/different-names.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"swagger": "2.0",
"info": {
"title": "different-names",
"version": "1.0"
},
"paths": {},
"definitions": {
"Bar": {
"type": "object",
"properties": {
"p1": {
"type": "string"
}
},
"allOf": [
{
"$ref": "./common-types.json#/definitions/Foo"
}
]
},
"Baz": {
"type": "object",
"properties": {
"p1": {
"type": "object"
}
}
}
}
}
31 changes: 31 additions & 0 deletions src/test/specs/incompatible-properties/duplicate-names.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"swagger": "2.0",
"info": {
"title": "duplicate-names",
"version": "1.0"
},
"paths": {},
"definitions": {
"Bar": {
"type": "object",
"properties": {
"p1": {
"type": "string"
}
},
"allOf": [
{
"$ref": "./common-types.json#/definitions/Foo"
}
]
},
"Foo": {
"type": "object",
"properties": {
"p1": {
"type": "object"
}
}
}
}
}
37 changes: 37 additions & 0 deletions src/test/specs/incompatible-properties/reference-equals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"swagger": "2.0",
"info": {
"title": "structural-equality",
"version": "1.0"
},
"paths": {},
"definitions": {
"Foo": {
"type": "object",
"properties": {
"bar": {
"$ref": "#/definitions/MyObject"
}
},
"allOf": [
{
"$ref": "#/definitions/Foo2"
}
]
},
"Foo2": {
"type": "object",
"properties": {
"bar": {
"$ref": "#/definitions/MyObject"
}
}
},
"MyObject": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
37 changes: 37 additions & 0 deletions src/test/specs/incompatible-properties/structural-equals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"swagger": "2.0",
"info": {
"title": "structural-equality",
"version": "1.0"
},
"paths": {},
"definitions": {
"Foo": {
"type": "object",
"properties": {
"bar": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"allOf": [
{
"$ref": "#/definitions/Foo2"
}
]
},
"Foo2": {
"type": "object",
"properties": {
"bar": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
}
Loading