Skip to content

Commit 62dc128

Browse files
committed
fix: make test pass again, make output valid, amend sort order
1 parent 835f36e commit 62dc128

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

src/overlay.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,38 @@ function applyOverlayToOpenAPI(spec, overlay) {
1919
}
2020

2121
} else {
22-
// It must be an update
23-
jsonpath.apply(spec, a.target, (chunk) => {
24-
25-
// Deep merge using a module (built-in spread operator is only shallow)
26-
try {
22+
try {
23+
// It must be an update
24+
jsonpath.apply(spec, a.target, (chunk) => {
25+
// Deep merge using a module (built-in spread operator is only shallow)
2726
const merger = mergician({appendArrays: true})
2827
return merger(chunk, a.update)
29-
}
30-
catch (ex) {
31-
process.stderr.write(`Error applying overlay: ${ex.message}\n`)
32-
return chunk
33-
}
28+
});
29+
}
30+
catch (ex) {
31+
process.stderr.write(`Error applying overlay: ${ex.message}\n`)
32+
//return chunk
33+
}
3434

35-
});
3635
}
3736
})
3837

3938
return spec;
4039
}
4140

4241
function sortOpenAPIFields(field1, field2) {
43-
const orderedKeys = ["info", "servers", "paths", "components", "summary", "objectId", "description", "tags", "parameters", "responses"];
42+
const orderedKeys = ["info", "servers", "summary", "operationId", "tags", "paths", "components", "description", "parameters", "responses"];
4443

45-
const index1 = orderedKeys.indexOf(field1);
46-
const index2 = orderedKeys.indexOf(field2);
44+
const index1 = orderedKeys.indexOf(field1);
45+
const index2 = orderedKeys.indexOf(field2);
4746

48-
if (index1 === -1 || index2 === -1) {
49-
return 0;
50-
} else if (index1 > index2) {
51-
return 1;
52-
} else {
53-
return -1;
54-
}
47+
if (index1 === -1 || index2 === -1) {
48+
return 0;
49+
} else if (index1 > index2) {
50+
return 1;
51+
} else {
52+
return -1;
53+
}
5554
}
5655

5756
export function overlayFiles(openapiFile, overlayFile) {

test/expected/output1.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ paths:
1010
/pets:
1111
get:
1212
operationId: listPets
13-
info:
14-
x-overlay-applied: structured-overlay
15-
description: This is an added description
1613
tags:
1714
- pets
1815
- wildcard-done
@@ -44,6 +41,9 @@ paths:
4441
application/json:
4542
schema:
4643
$ref: '#/components/schemas/Error'
44+
x-info:
45+
x-overlay-applied: structured-overlay
46+
description: This is an added description
4747
post:
4848
foo:
4949
bar: hello

test/overlays/overlay.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ actions:
1111
- wildcard-done
1212
- target: $.paths['/pets'].get
1313
update:
14-
info:
14+
x-info:
1515
x-overlay-applied: structured-overlay
1616
description: This is an added description
1717
tags:

0 commit comments

Comments
 (0)