@@ -7,9 +7,14 @@ import { fileUrl } from "./fileUrl"
77// Given a property with given type and name
88// When another property with the same name but an incompatible type is referenced
99// Then an issue is reported, with output providing the exact source file locations of both of the occurrences of the property.
10- test ( "incompatible-properties" , async ( ) => {
10+ //
11+ // Also ensures that $ref are resolved when determining if types are compatible.
12+ // For example, these should be incompatible:
13+ // 1. "bar": { "type":"string" }
14+ // 2. "bar": { "$ref":"#/definitions/MyObject" }, "MyObject": { "type": "object" }
15+ test . each ( [ "string-object" , "string-refobject" , "refstring-object" , "refstring-refobject" ] ) ( "incompatible-properties-%s" , async prop => {
1116 const diff = new OpenApiDiff ( { } )
12- const file = " src/test/specs/incompatible-properties.json"
17+ const file = ` src/test/specs/incompatible-properties/ ${ prop } .json`
1318 const filePath = fileUrl ( path . resolve ( file ) )
1419
1520 try {
@@ -19,11 +24,74 @@ test("incompatible-properties", async () => {
1924 const e = error as Error
2025 assert . equal (
2126 e . message ,
22- " incompatible properties : bar\n" +
23- " definitions/FooBarString /properties/bar\n" +
24- ` at ${ filePath } #L13 :8\n` +
25- " definitions/FooBarObject /properties/bar\n" +
26- ` at ${ filePath } #L26 :8`
27+ ` incompatible properties : ${ prop } \n` +
28+ ` definitions/Foo /properties/${ prop } \n` +
29+ ` at ${ filePath } #L12 :8\n` +
30+ ` definitions/Foo2 /properties/${ prop } \n` +
31+ ` at ${ filePath } #L25 :8`
2732 )
2833 }
2934} )
35+
36+ // test("incompatible-properties-string-refobject", async () => {
37+ // const diff = new OpenApiDiff({})
38+ // const file = "src/test/specs/incompatible-properties/string-refobject.json"
39+ // const filePath = fileUrl(path.resolve(file))
40+
41+ // try {
42+ // await diff.compare(file, file)
43+ // assert.fail("expected diff.compare() to throw")
44+ // } catch (error) {
45+ // const e = error as Error
46+ // assert.equal(
47+ // e.message,
48+ // "incompatible properties : string-refobject\n" +
49+ // " definitions/Foo/properties/string-refobject\n" +
50+ // ` at ${filePath}#L12:8\n` +
51+ // " definitions/Foo2/properties/string-refobject\n" +
52+ // ` at ${filePath}#L25:8`
53+ // )
54+ // }
55+ // })
56+
57+ // test("incompatible-properties-refstring-object", async () => {
58+ // const diff = new OpenApiDiff({})
59+ // const file = "src/test/specs/incompatible-properties/string-refobject.json"
60+ // const filePath = fileUrl(path.resolve(file))
61+
62+ // try {
63+ // await diff.compare(file, file)
64+ // assert.fail("expected diff.compare() to throw")
65+ // } catch (error) {
66+ // const e = error as Error
67+ // assert.equal(
68+ // e.message,
69+ // "incompatible properties : refstring-object\n" +
70+ // " definitions/Foo/properties/refstring-object\n" +
71+ // ` at ${filePath}#L12:8\n` +
72+ // " definitions/Foo2/properties/refstring-object\n" +
73+ // ` at ${filePath}#L25:8`
74+ // )
75+ // }
76+ // })
77+
78+ // test("incompatible-properties-refstring-refobject", async () => {
79+ // const diff = new OpenApiDiff({})
80+ // const file = "src/test/specs/incompatible-properties/refstring-refobject.json"
81+ // const filePath = fileUrl(path.resolve(file))
82+
83+ // try {
84+ // await diff.compare(file, file)
85+ // assert.fail("expected diff.compare() to throw")
86+ // } catch (error) {
87+ // const e = error as Error
88+ // assert.equal(
89+ // e.message,
90+ // "incompatible properties : refstring-refobject\n" +
91+ // " definitions/Foo/properties/refstring-refobject\n" +
92+ // ` at ${filePath}#L12:8\n` +
93+ // " definitions/Foo2/properties/refstring-refobject\n" +
94+ // ` at ${filePath}#L25:8`
95+ // )
96+ // }
97+ // })
0 commit comments