-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Infer field type from const value (#1174)
This change adds support for schemas that use the `const` keyword without and adjacent `type` keyword. For example: ```json { "type": "object", "properties": { "firstName": { "const": "Chuck" } } } ``` Signed-off-by: Lucian <lucian.buzzo@gmail.com>
- Loading branch information
1 parent
b481f58
commit 6e79281
Showing
3 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { expect } from "chai"; | ||
|
||
import { createFormComponent, createSandbox } from "./test_utils"; | ||
|
||
describe("const", () => { | ||
let sandbox; | ||
|
||
beforeEach(() => { | ||
sandbox = createSandbox(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
it("should render a schema that uses const with a string value", () => { | ||
const schema = { | ||
type: "object", | ||
properties: { | ||
foo: { const: "bar" }, | ||
}, | ||
}; | ||
|
||
const { node } = createFormComponent({ | ||
schema, | ||
}); | ||
|
||
expect(node.querySelector("input#root_foo")).not.eql(null); | ||
}); | ||
|
||
it("should render a schema that uses const with a number value", () => { | ||
const schema = { | ||
type: "object", | ||
properties: { | ||
foo: { const: 123 }, | ||
}, | ||
}; | ||
|
||
const { node } = createFormComponent({ | ||
schema, | ||
}); | ||
|
||
expect(node.querySelector("input#root_foo")).not.eql(null); | ||
}); | ||
|
||
it("should render a schema that uses const with a boolean value", () => { | ||
const schema = { | ||
type: "object", | ||
properties: { | ||
foo: { const: true }, | ||
}, | ||
}; | ||
|
||
const { node } = createFormComponent({ | ||
schema, | ||
}); | ||
|
||
expect(node.querySelector("input#root_foo[type='checkbox']")).not.eql(null); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters