Skip to content

Commit a484769

Browse files
committed
v7.0.0 πŸš€ - ReScript Schema v9 support
1 parent 5f63fe0 commit a484769

File tree

10 files changed

+179
-157
lines changed

10 files changed

+179
-157
lines changed

β€Ž__tests__/GhIssue8_test.resβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ test("Regression test", t => {
2828
"page": s.field("page", S.option(S.float->S.floatMin(1., ~message="Number must be greater than or equal to 1"))->S.Option.getOr(%raw(\`1\`))),
2929
"limit": s.field("limit", S.option(S.float->S.floatMin(1., ~message="Number must be greater than or equal to 1"))->S.Option.getOr(%raw(\`100\`))),
3030
}
31-
)->S.Object.strict`,
31+
)->S.strict`,
3232
)
3333
})

β€Ž__tests__/JSONSchema_test.resβ€Ž

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ test("Schema of object schema with one string discriminant", t => {
553553
})
554554

555555
test("Schema of object schema with Strip unknownKeys strategy allows additionalProperties", t => {
556-
let schema = S.object(s => s.field("field", S.string))->S.Object.strip
556+
let schema = S.object(s => s.field("field", S.string))->S.strip
557557

558558
t->Assert.deepEqual(
559559
JSONSchema.make(schema),
@@ -572,7 +572,7 @@ test("Schema of object schema with Strip unknownKeys strategy allows additionalP
572572
test(
573573
"Schema of object schema with Strict unknownKeys strategy disallows additionalProperties",
574574
t => {
575-
let schema = S.object(s => s.field("field", S.string))->S.Object.strict
575+
let schema = S.object(s => s.field("field", S.string))->S.strict
576576

577577
t->Assert.deepEqual(
578578
JSONSchema.make(schema),
@@ -752,7 +752,7 @@ test("Transformed schema schema with default fails when destruction failed", t =
752752

753753
t->Assert.deepEqual(
754754
JSONSchema.make(schema),
755-
Error(`[ReScript JSON Schema] Failed converting at ["field"]. Reason: Couldn't destruct default value. Error: Failed serializing to JSON at root. Reason: The S.transform serializer is missing`),
755+
Error(`[ReScript JSON Schema] Failed converting at ["field"]. Reason: Couldn't destruct default value. Error: Failed reverse converting to JSON at root. Reason: The S.transform serializer is missing`),
756756
)
757757
})
758758

@@ -923,28 +923,28 @@ test("Fails to create schema for schemas with optional items", t => {
923923
t->Assert.deepEqual(
924924
JSONSchema.make(S.dict(S.option(S.string))),
925925
Error(
926-
"[ReScript JSON Schema] Failed converting at root. Reason: Optional schema is not supported as Dict(Option(String)) item",
926+
"[ReScript JSON Schema] Failed converting at root. Reason: Optional schema is not supported as dict<string | undefined> item",
927927
),
928928
)
929929
t->Assert.deepEqual(
930930
JSONSchema.make(S.array(S.option(S.string))),
931931
Error(
932-
"[ReScript JSON Schema] Failed converting at root. Reason: Optional schema is not supported as Array(Option(String)) item",
932+
"[ReScript JSON Schema] Failed converting at root. Reason: Optional schema is not supported as array<string | undefined> item",
933933
),
934934
)
935935
t->Assert.deepEqual(
936936
JSONSchema.make(S.union([S.option(S.string), S.null(S.string)])),
937937
Error(
938-
"[ReScript JSON Schema] Failed converting at root. Reason: Optional schema is not supported as Union(Option(String), Null(String)) item",
938+
"[ReScript JSON Schema] Failed converting at root. Reason: Optional schema is not supported as string | undefined | string | null item",
939939
),
940940
)
941941
t->Assert.deepEqual(
942942
JSONSchema.make(S.tuple1(S.option(S.string))),
943-
Error(`[ReScript JSON Schema] Failed converting at ["0"]. Reason: Optional schema is not supported as Tuple(Option(String)) item`),
943+
Error(`[ReScript JSON Schema] Failed converting at ["0"]. Reason: Optional schema is not supported as [string | undefined] item`),
944944
)
945945
t->Assert.deepEqual(
946946
JSONSchema.make(S.tuple1(S.array(S.option(S.string)))),
947-
Error(`[ReScript JSON Schema] Failed converting at ["0"]. Reason: Optional schema is not supported as Array(Option(String)) item`),
947+
Error(`[ReScript JSON Schema] Failed converting at ["0"]. Reason: Optional schema is not supported as array<string | undefined> item`),
948948
)
949949
})
950950

β€Žonline/package-lock.jsonβ€Ž

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

β€Žonline/package.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"react-dom": "18.2.0",
1818
"rescript": "11.1.4",
1919
"rescript-json-schema": "./vendor/rescript-json-schema",
20-
"rescript-schema": "8.1.0"
20+
"rescript-schema": "9.0.1"
2121
},
2222
"devDependencies": {
2323
"@jihchi/vite-plugin-rescript": "^5.3.1",

β€Žonline/src/App.bs.mjsβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function App(props) {
4040
catch (raw_exn){
4141
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
4242
return setErrors(function (param) {
43-
return "Errors:\n" + Core__Option.getWithDefault(Core__Option.flatMap(Caml_js_exceptions.as_js_exn(exn), (function (exn) {
43+
return "Errors:\n" + Core__Option.getOr(Core__Option.flatMap(Caml_js_exceptions.as_js_exn(exn), (function (exn) {
4444
return exn.message;
4545
})), "Unknown error");
4646
});
@@ -50,13 +50,13 @@ function App(props) {
5050
var format = function () {
5151
try {
5252
return setJson(function (param) {
53-
return JSON.stringify(Json5.default.parse(json), null, 2);
53+
return JSON.stringify(Json5.default.parse(json), undefined, 2);
5454
});
5555
}
5656
catch (raw_exn){
5757
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
5858
return setErrors(function (param) {
59-
return "Errors:\n" + Core__Option.getWithDefault(Core__Option.flatMap(Caml_js_exceptions.as_js_exn(exn), (function (exn) {
59+
return "Errors:\n" + Core__Option.getOr(Core__Option.flatMap(Caml_js_exceptions.as_js_exn(exn), (function (exn) {
6060
return exn.message;
6161
})), "Unknown error");
6262
});

β€Žonline/src/App.resβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ let make = () => {
5353
`Errors:\n${exn
5454
->Exn.asJsExn
5555
->Option.flatMap(exn => exn->Exn.message)
56-
->Option.getWithDefault("Unknown error")}`
56+
->Option.getOr("Unknown error")}`
5757
)
5858
}
5959
}
@@ -64,14 +64,14 @@ let make = () => {
6464

6565
let format = () => {
6666
try {
67-
setJson(_ => JSON.stringifyWithIndent(parseJson5(json), 2))
67+
setJson(_ => JSON.stringify(parseJson5(json), ~space=2))
6868
} catch {
6969
| exn =>
7070
setErrors(_ =>
7171
`Errors:\n${exn
7272
->Exn.asJsExn
7373
->Option.flatMap(exn => exn->Exn.message)
74-
->Option.getWithDefault("Unknown error")}`
74+
->Option.getOr("Unknown error")}`
7575
)
7676
}
7777
}

β€Žpackage-lock.jsonβ€Ž

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

β€Žpackage.jsonβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rescript-json-schema",
3-
"version": "6.2.0",
3+
"version": "7.0.0",
44
"description": "πŸ“„ Typesafe JSON Schema for ReScript",
55
"keywords": [
66
"rescript",
@@ -42,11 +42,11 @@
4242
"@dzakh/rescript-ava": "3.0.0",
4343
"ava": "5.2.0",
4444
"rescript": "11.1.4",
45-
"rescript-schema": "8.1.0",
45+
"rescript-schema": "9.0.1",
4646
"c8": "8.0.1"
4747
},
4848
"peerDependencies": {
4949
"rescript": "11.x",
50-
"rescript-schema": ">=7 <=8.1"
50+
"rescript-schema": "^9.0.0"
5151
}
5252
}

0 commit comments

Comments
Β (0)