Skip to content

Commit

Permalink
v7.0.0 🚀 - ReScript Schema v9 support
Browse files Browse the repository at this point in the history
  • Loading branch information
DZakh committed Dec 16, 2024
1 parent 5f63fe0 commit a484769
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 157 deletions.
2 changes: 1 addition & 1 deletion __tests__/GhIssue8_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ test("Regression test", t => {
"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\`))),
"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\`))),
}
)->S.Object.strict`,
)->S.strict`,
)
})
16 changes: 8 additions & 8 deletions __tests__/JSONSchema_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ test("Schema of object schema with one string discriminant", t => {
})

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

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

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

t->Assert.deepEqual(
JSONSchema.make(schema),
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`),
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`),
)
})

Expand Down Expand Up @@ -923,28 +923,28 @@ test("Fails to create schema for schemas with optional items", t => {
t->Assert.deepEqual(
JSONSchema.make(S.dict(S.option(S.string))),
Error(
"[ReScript JSON Schema] Failed converting at root. Reason: Optional schema is not supported as Dict(Option(String)) item",
"[ReScript JSON Schema] Failed converting at root. Reason: Optional schema is not supported as dict<string | undefined> item",
),
)
t->Assert.deepEqual(
JSONSchema.make(S.array(S.option(S.string))),
Error(
"[ReScript JSON Schema] Failed converting at root. Reason: Optional schema is not supported as Array(Option(String)) item",
"[ReScript JSON Schema] Failed converting at root. Reason: Optional schema is not supported as array<string | undefined> item",
),
)
t->Assert.deepEqual(
JSONSchema.make(S.union([S.option(S.string), S.null(S.string)])),
Error(
"[ReScript JSON Schema] Failed converting at root. Reason: Optional schema is not supported as Union(Option(String), Null(String)) item",
"[ReScript JSON Schema] Failed converting at root. Reason: Optional schema is not supported as string | undefined | string | null item",
),
)
t->Assert.deepEqual(
JSONSchema.make(S.tuple1(S.option(S.string))),
Error(`[ReScript JSON Schema] Failed converting at ["0"]. Reason: Optional schema is not supported as Tuple(Option(String)) item`),
Error(`[ReScript JSON Schema] Failed converting at ["0"]. Reason: Optional schema is not supported as [string | undefined] item`),
)
t->Assert.deepEqual(
JSONSchema.make(S.tuple1(S.array(S.option(S.string)))),
Error(`[ReScript JSON Schema] Failed converting at ["0"]. Reason: Optional schema is not supported as Array(Option(String)) item`),
Error(`[ReScript JSON Schema] Failed converting at ["0"]. Reason: Optional schema is not supported as array<string | undefined> item`),
)
})

Expand Down
60 changes: 19 additions & 41 deletions online/package-lock.json

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

2 changes: 1 addition & 1 deletion online/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"react-dom": "18.2.0",
"rescript": "11.1.4",
"rescript-json-schema": "./vendor/rescript-json-schema",
"rescript-schema": "8.1.0"
"rescript-schema": "9.0.1"
},
"devDependencies": {
"@jihchi/vite-plugin-rescript": "^5.3.1",
Expand Down
6 changes: 3 additions & 3 deletions online/src/App.bs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function App(props) {
catch (raw_exn){
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
return setErrors(function (param) {
return "Errors:\n" + Core__Option.getWithDefault(Core__Option.flatMap(Caml_js_exceptions.as_js_exn(exn), (function (exn) {
return "Errors:\n" + Core__Option.getOr(Core__Option.flatMap(Caml_js_exceptions.as_js_exn(exn), (function (exn) {
return exn.message;
})), "Unknown error");
});
Expand All @@ -50,13 +50,13 @@ function App(props) {
var format = function () {
try {
return setJson(function (param) {
return JSON.stringify(Json5.default.parse(json), null, 2);
return JSON.stringify(Json5.default.parse(json), undefined, 2);
});
}
catch (raw_exn){
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
return setErrors(function (param) {
return "Errors:\n" + Core__Option.getWithDefault(Core__Option.flatMap(Caml_js_exceptions.as_js_exn(exn), (function (exn) {
return "Errors:\n" + Core__Option.getOr(Core__Option.flatMap(Caml_js_exceptions.as_js_exn(exn), (function (exn) {
return exn.message;
})), "Unknown error");
});
Expand Down
6 changes: 3 additions & 3 deletions online/src/App.res
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let make = () => {
`Errors:\n${exn
->Exn.asJsExn
->Option.flatMap(exn => exn->Exn.message)
->Option.getWithDefault("Unknown error")}`
->Option.getOr("Unknown error")}`
)
}
}
Expand All @@ -64,14 +64,14 @@ let make = () => {

let format = () => {
try {
setJson(_ => JSON.stringifyWithIndent(parseJson5(json), 2))
setJson(_ => JSON.stringify(parseJson5(json), ~space=2))
} catch {
| exn =>
setErrors(_ =>
`Errors:\n${exn
->Exn.asJsExn
->Option.flatMap(exn => exn->Exn.message)
->Option.getWithDefault("Unknown error")}`
->Option.getOr("Unknown error")}`
)
}
}
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rescript-json-schema",
"version": "6.2.0",
"version": "7.0.0",
"description": "📄 Typesafe JSON Schema for ReScript",
"keywords": [
"rescript",
Expand Down Expand Up @@ -42,11 +42,11 @@
"@dzakh/rescript-ava": "3.0.0",
"ava": "5.2.0",
"rescript": "11.1.4",
"rescript-schema": "8.1.0",
"rescript-schema": "9.0.1",
"c8": "8.0.1"
},
"peerDependencies": {
"rescript": "11.x",
"rescript-schema": ">=7 <=8.1"
"rescript-schema": "^9.0.0"
}
}
Loading

0 comments on commit a484769

Please sign in to comment.