Skip to content

Commit fb20b89

Browse files
committed
Make sure that the type discriminator is the first property
1 parent a3e4773 commit fb20b89

File tree

4 files changed

+2954
-2945
lines changed

4 files changed

+2954
-2945
lines changed

compiler/package-lock.json

Lines changed: 9 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
},
3535
"dependencies": {
3636
"chalk": "^4.1.2",
37+
"compiler-wasm-lib": "file:../compiler-rs/compiler-wasm-lib/pkg",
3738
"fastest-levenshtein": "^1.0.12",
3839
"ora": "^5.4.1",
39-
"safe-stable-stringify": "^2.3.1",
40-
"compiler-wasm-lib": "file:../compiler-rs/compiler-wasm-lib/pkg",
40+
"safe-stable-stringify": "^2.5.0",
4141
"semver": "^7.5.2",
4242
"ts-morph": "^13.0.3",
4343
"zx": "^4.3.0"

compiler/src/compiler.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,24 @@ export default class Compiler {
6262
this.model = await step(this.model, this.jsonSpec, this.errors)
6363
}
6464

65+
const customStringify = stringify.configure(
66+
{
67+
deterministic: (a, b) => {
68+
// Make sure the discriminator property is always emitted first
69+
if (a === 'kind') {
70+
return -1
71+
}
72+
if (b === 'kind') {
73+
return 1
74+
}
75+
return a.localeCompare(b)
76+
}
77+
})
78+
6579
await mkdir(join(this.outputFolder, 'schema'), { recursive: true })
6680
await writeFile(
6781
join(this.outputFolder, 'schema', 'schema.json'),
68-
stringify(this.model, null, 2),
82+
customStringify(this.model, null, 2),
6983
'utf8'
7084
)
7185

0 commit comments

Comments
 (0)