Skip to content

Commit

Permalink
🚀 2.0.0 (#7)
Browse files Browse the repository at this point in the history
* Update rescript-struct

* Support rescript-struct description

* 🚀 2.0.0
  • Loading branch information
DZakh committed Apr 5, 2023
1 parent 9005594 commit 04edd56
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 117 deletions.
9 changes: 3 additions & 6 deletions README.md
Expand Up @@ -21,7 +21,7 @@ Then add `rescript-json-schema` and `rescript-struct` to `bs-dependencies` in yo
{
...
+ "bs-dependencies": ["rescript-json-schema", "rescript-struct"]
+ "bsc-flags": ["-open ReScriptStruct"],
+ "bsc-flags": ["-open RescriptStruct"],
}
```

Expand All @@ -43,15 +43,12 @@ type author = {
let authorStruct = S.object(o => {
id: o->S.field("Id", S.float()),
tags: o->S.field("Tags", S.option(S.array(S.string()))->S.defaulted([])),
tags: o->S.field("Tags", S.option(S.array(S.string()))->S.default(() => [])),
isAproved: o->S.field(
"IsApproved",
S.union([S.literalVariant(String("Yes"), true), S.literalVariant(String("No"), false)]),
),
deprecatedAge: o->S.field(
"Age",
S.int()->S.deprecated(~message="Will be removed in APIv2", ()),
),
deprecatedAge: o->S.field("Age", S.int()->S.deprecate("Will be removed in APIv2")),
})
```

Expand Down
41 changes: 11 additions & 30 deletions __tests__/JSONSchema_test.res
Expand Up @@ -265,7 +265,10 @@ test("Schema of object struct with one string field", t => {
})

test("Schema of object struct with one string discriminant", t => {
let struct = S.object(o => o->S.discriminant("field", S.string()))
let struct = S.object(o => {
ignore(o->S.field("field", S.string()))
()
})

t->Assert.deepEqual(
JSONSchema.make(struct),
Expand Down Expand Up @@ -339,25 +342,8 @@ test("Schema of object struct with one optional string field", t => {
})

test("Schema of object struct with one deprecated string field", t => {
let struct = S.object(o => o->S.field("optionalField", S.string()->S.deprecated()))

t->Assert.deepEqual(
JSONSchema.make(struct),
Ok(
%raw(`{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {"optionalField": {"type": "string", "deprecated": true}},
"additionalProperties": true,
}`),
),
(),
)
})

test("Schema of object struct with one deprecated string field and message", t => {
let struct = S.object(o =>
o->S.field("optionalField", S.string()->S.deprecated(~message="Use another field", ()))
o->S.field("optionalField", S.string()->S.deprecate("Use another field"))
)

t->Assert.deepEqual(
Expand All @@ -380,9 +366,7 @@ test("Deprecated message overrides previous description", t => {
let struct = S.object(o =>
o->S.field(
"optionalField",
S.string()
->JSONSchema.description("Previous description")
->S.deprecated(~message="Use another field", ()),
S.string()->S.describe("Previous description")->S.deprecate("Use another field"),
)
)

Expand Down Expand Up @@ -478,7 +462,7 @@ test("Make JSONSchema throws error with object field wrapped in option multiple
})

test("Primitive struct schema with description", t => {
let struct = S.bool()->JSONSchema.description("A primitive struct")
let struct = S.bool()->S.describe("A primitive struct")

t->Assert.deepEqual(
JSONSchema.make(struct),
Expand Down Expand Up @@ -507,7 +491,7 @@ test("Transformed struct schema with default fails when destruction failed", t =
},
(),
),
)->S.defaulted("true"),
)->S.default(() => "true"),
)
)

Expand Down Expand Up @@ -538,7 +522,7 @@ test("Transformed struct schema uses default with correct type", t => {
},
(),
),
)->S.defaulted("true"),
)->S.default(() => "true"),
)
)

Expand Down Expand Up @@ -671,15 +655,12 @@ module Example = {
test("Example", t => {
let authorStruct = S.object(o => {
id: o->S.field("Id", S.float()),
tags: o->S.field("Tags", S.option(S.array(S.string()))->S.defaulted([])),
tags: o->S.field("Tags", S.option(S.array(S.string()))->S.default(() => [])),
isAproved: o->S.field(
"IsApproved",
S.union([S.literalVariant(String("Yes"), true), S.literalVariant(String("No"), false)]),
),
deprecatedAge: o->S.field(
"Age",
S.int()->S.deprecated(~message="Will be removed in APIv2", ()),
),
deprecatedAge: o->S.field("Age", S.int()->S.deprecate("Will be removed in APIv2")),
})

t->Assert.deepEqual(
Expand Down
2 changes: 1 addition & 1 deletion bsconfig.json
@@ -1,7 +1,7 @@
{
"name": "rescript-json-schema",
"namespace": false,
"bsc-flags": ["-open ReScriptStruct"],
"bsc-flags": ["-open RescriptStruct"],
"bs-dev-dependencies": ["@dzakh/rescript-ava"],
"bs-dependencies": ["rescript-struct"],
"suffix": ".bs.js",
Expand Down
30 changes: 15 additions & 15 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
Expand Up @@ -43,11 +43,11 @@
"@dzakh/rescript-ava": "2.1.0",
"ava": "5.1.0",
"c8": "7.13.0",
"rescript": "10.1.2",
"rescript-struct": "3.1.0"
"rescript": "10.1.4",
"rescript-struct": "4.0.0"
},
"peerDependencies": {
"rescript": "10.1.x",
"rescript-struct": "3.1.x"
"rescript-struct": "4.0.x"
}
}
76 changes: 37 additions & 39 deletions src/JSONSchema.bs.js

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

0 comments on commit 04edd56

Please sign in to comment.